Refactor
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Nub.Lang.Parsing;
|
using Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
namespace Nub.Lang.Generation;
|
namespace Nub.Lang.Backend.Custom;
|
||||||
|
|
||||||
public class Generator
|
public class CustomGenerator
|
||||||
{
|
{
|
||||||
private const string Entrypoint = "main";
|
private const string Entrypoint = "main";
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public class Generator
|
|||||||
private int _stringIndex;
|
private int _stringIndex;
|
||||||
private int _labelIndex;
|
private int _labelIndex;
|
||||||
|
|
||||||
public Generator(IReadOnlyCollection<DefinitionNode> definitions)
|
public CustomGenerator(IReadOnlyCollection<DefinitionNode> definitions)
|
||||||
{
|
{
|
||||||
_strings = [];
|
_strings = [];
|
||||||
_definitions = definitions;
|
_definitions = definitions;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Nub.Lang.Parsing;
|
using Nub.Core;
|
||||||
using Nub.Core;
|
using Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
namespace Nub.Lang.Generation;
|
namespace Nub.Lang.Backend.Custom;
|
||||||
|
|
||||||
public class SymbolTable
|
public class SymbolTable
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Lexing;
|
namespace Nub.Lang.Frontend.Lexing;
|
||||||
|
|
||||||
public class IdentifierToken(string value) : Token
|
public class IdentifierToken(string value) : Token
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
|
|
||||||
namespace Nub.Lang.Lexing;
|
namespace Nub.Lang.Frontend.Lexing;
|
||||||
|
|
||||||
public class Lexer
|
public class Lexer
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Lexing;
|
namespace Nub.Lang.Frontend.Lexing;
|
||||||
|
|
||||||
public class LiteralToken(Type type, string value) : Token
|
public class LiteralToken(Type type, string value) : Token
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Lexing;
|
namespace Nub.Lang.Frontend.Lexing;
|
||||||
|
|
||||||
public class SymbolToken(Symbol symbol) : Token
|
public class SymbolToken(Symbol symbol) : Token
|
||||||
{
|
{
|
||||||
3
Nub.Lang/Nub.Lang/Frontend/Lexing/Token.cs
Normal file
3
Nub.Lang/Nub.Lang/Frontend/Lexing/Token.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Nub.Lang.Frontend.Lexing;
|
||||||
|
|
||||||
|
public abstract class Token;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class BinaryExpressionNode(ExpressionNode left, BinaryExpressionOperator @operator, ExpressionNode right) : ExpressionNode
|
public class BinaryExpressionNode(ExpressionNode left, BinaryExpressionOperator @operator, ExpressionNode right) : ExpressionNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class BlockNode(IReadOnlyCollection<StatementNode> statements) : Node
|
public class BlockNode(IReadOnlyCollection<StatementNode> statements) : Node
|
||||||
{
|
{
|
||||||
3
Nub.Lang/Nub.Lang/Frontend/Parsing/DefinitionNode.cs
Normal file
3
Nub.Lang/Nub.Lang/Frontend/Parsing/DefinitionNode.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
|
public abstract class DefinitionNode : Node;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public abstract class ExpressionNode : Node
|
public abstract class ExpressionNode : Node
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
|
|
||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class ExternFuncDefinitionNode(string name, IReadOnlyCollection<FuncParameter> parameters, Optional<Type> returnType) : DefinitionNode
|
public class ExternFuncDefinitionNode(string name, IReadOnlyCollection<FuncParameter> parameters, Optional<Type> returnType) : DefinitionNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class FuncCall(string name, IReadOnlyCollection<ExpressionNode> parameters)
|
public class FuncCall(string name, IReadOnlyCollection<ExpressionNode> parameters)
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class FuncCallExpressionNode(FuncCall funcCall) : ExpressionNode
|
public class FuncCallExpressionNode(FuncCall funcCall) : ExpressionNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class FuncCallStatementNode(FuncCall funcCall) : StatementNode
|
public class FuncCallStatementNode(FuncCall funcCall) : StatementNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class GlobalVariableDefinitionNode(string name, ExpressionNode value) : DefinitionNode
|
public class GlobalVariableDefinitionNode(string name, ExpressionNode value) : DefinitionNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class IdentifierNode(string identifier) : ExpressionNode
|
public class IdentifierNode(string identifier) : ExpressionNode
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
|
|
||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class IfNode(ExpressionNode condition, BlockNode body, Optional<Variant<IfNode, BlockNode>> @else) : StatementNode
|
public class IfNode(ExpressionNode condition, BlockNode body, Optional<Variant<IfNode, BlockNode>> @else) : StatementNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class LiteralNode(string literal, Type type) : ExpressionNode
|
public class LiteralNode(string literal, Type type) : ExpressionNode
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
|
|
||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class LocalFuncDefinitionNode(string name, IReadOnlyCollection<FuncParameter> parameters, BlockNode body, Optional<Type> returnType) : DefinitionNode
|
public class LocalFuncDefinitionNode(string name, IReadOnlyCollection<FuncParameter> parameters, BlockNode body, Optional<Type> returnType) : DefinitionNode
|
||||||
{
|
{
|
||||||
3
Nub.Lang/Nub.Lang/Frontend/Parsing/Node.cs
Normal file
3
Nub.Lang/Nub.Lang/Frontend/Parsing/Node.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
|
public abstract class Node;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Nub.Lang.Lexing;
|
|
||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
|
using Nub.Lang.Frontend.Lexing;
|
||||||
|
|
||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class Parser
|
public class Parser
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
|
|
||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class ReturnNode(Optional<ExpressionNode> value) : StatementNode
|
public class ReturnNode(Optional<ExpressionNode> value) : StatementNode
|
||||||
{
|
{
|
||||||
3
Nub.Lang/Nub.Lang/Frontend/Parsing/StatementNode.cs
Normal file
3
Nub.Lang/Nub.Lang/Frontend/Parsing/StatementNode.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
|
public abstract class StatementNode : Node;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class Syscall(IReadOnlyCollection<ExpressionNode> parameters)
|
public class Syscall(IReadOnlyCollection<ExpressionNode> parameters)
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class SyscallExpressionNode(Syscall syscall) : ExpressionNode
|
public class SyscallExpressionNode(Syscall syscall) : ExpressionNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class SyscallStatementNode(Syscall syscall) : StatementNode
|
public class SyscallStatementNode(Syscall syscall) : StatementNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class VariableAssignmentNode(string name, ExpressionNode value) : StatementNode
|
public class VariableAssignmentNode(string name, ExpressionNode value) : StatementNode
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
namespace Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
public class VariableReassignmentNode(string name, ExpressionNode value) : StatementNode
|
public class VariableReassignmentNode(string name, ExpressionNode value) : StatementNode
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Nub.Core;
|
using Nub.Core;
|
||||||
using Nub.Lang.Parsing;
|
using Nub.Lang.Frontend.Parsing;
|
||||||
|
|
||||||
namespace Nub.Lang.Typing;
|
namespace Nub.Lang.Frontend.Typing;
|
||||||
|
|
||||||
public class Func(string name, IReadOnlyCollection<FuncParameter> parameters, Optional<BlockNode> body, Optional<Type> returnType)
|
public class Func(string name, IReadOnlyCollection<FuncParameter> parameters, Optional<BlockNode> body, Optional<Type> returnType)
|
||||||
{
|
{
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Nub.Lang.Lexing;
|
|
||||||
|
|
||||||
public abstract class Token;
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
nasm -g -felf64 out.asm -o out.o
|
|
||||||
nasm -g -felf64 core/strlen.asm -o strlen.o
|
|
||||||
nasm -g -felf64 core/strcmp.asm -o strcmp.o
|
|
||||||
|
|
||||||
ld -o out out.o strlen.o strcmp.o
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
|
||||||
|
|
||||||
public abstract class DefinitionNode : Node;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
|
||||||
|
|
||||||
public abstract class Node;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Nub.Lang.Parsing;
|
|
||||||
|
|
||||||
public abstract class StatementNode : Node;
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Nub.Lang.Generation;
|
using Nub.Lang.Backend.Custom;
|
||||||
using Nub.Lang.Lexing;
|
using Nub.Lang.Frontend.Lexing;
|
||||||
using Nub.Lang.Parsing;
|
using Nub.Lang.Frontend.Parsing;
|
||||||
using Nub.Lang.Typing;
|
using Nub.Lang.Frontend.Typing;
|
||||||
|
|
||||||
var src = File.ReadAllText(args[0]);
|
var src = File.ReadAllText(args[0]);
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ var definitions = parser.Parse();
|
|||||||
var typer = new ExpressionTyper(definitions);
|
var typer = new ExpressionTyper(definitions);
|
||||||
typer.Populate();
|
typer.Populate();
|
||||||
|
|
||||||
var generator = new Generator(definitions);
|
var generator = new CustomGenerator(definitions);
|
||||||
var asm = generator.Generate();
|
var asm = generator.Generate();
|
||||||
|
|
||||||
Console.WriteLine(asm);
|
Console.WriteLine(asm);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace core;
|
namespace core;
|
||||||
|
|
||||||
extern func strlen(msg: String): int64;
|
|
||||||
extern func strcmp(a: String, b: String): bool;
|
extern func strcmp(a: String, b: String): bool;
|
||||||
3
Nub.Lang/Nub.Lang/input/core/string/strlen.nub
Normal file
3
Nub.Lang/Nub.Lang/input/core/string/strlen.nub
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace core;
|
||||||
|
|
||||||
|
extern func strlen(msg: String): int64;
|
||||||
6
Nub.Lang/Nub.Lang/output/build.sh
Normal file
6
Nub.Lang/Nub.Lang/output/build.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
nasm -g -felf64 out.asm -o out.o
|
||||||
|
nasm -g -felf64 ../input/core/string/strlen.asm -o strlen.o
|
||||||
|
nasm -g -felf64 ../input/core/string/strcmp.asm -o strcmp.o
|
||||||
|
|
||||||
|
ld -o out out.o strlen.o strcmp.o
|
||||||
Reference in New Issue
Block a user