small fixes
This commit is contained in:
4
build.sh
4
build.sh
@@ -6,7 +6,9 @@ dotnet build src/lang/Nub.Lang.CLI
|
|||||||
mkdir -p bin-int bin
|
mkdir -p bin-int bin
|
||||||
rm -rf bin-int/* bin/*
|
rm -rf bin-int/* bin/*
|
||||||
|
|
||||||
nub example | qbe | as -o bin-int/out.o
|
nub example > bin-int/out.ssa
|
||||||
|
qbe bin-int/out.ssa > bin-int/out.s
|
||||||
|
as -o bin-int/out.o bin-int/out.s
|
||||||
|
|
||||||
find src/runtime -name '*.s' | while read -r file; do
|
find src/runtime -name '*.s' | while read -r file; do
|
||||||
as "$file" -o "bin-int/$(basename "${file}" .s).o"
|
as "$file" -o "bin-int/$(basename "${file}" .s).o"
|
||||||
|
|||||||
@@ -241,16 +241,15 @@ public class QBEGenerator
|
|||||||
{
|
{
|
||||||
var definition = LookupStructDefinition(nubStructType.Namespace, nubStructType.Name);
|
var definition = LookupStructDefinition(nubStructType.Namespace, nubStructType.Name);
|
||||||
|
|
||||||
int size = 0;
|
var size = 0;
|
||||||
int maxAlignment = 1;
|
var maxAlignment = 1;
|
||||||
|
|
||||||
foreach (var field in definition.Fields)
|
foreach (var field in definition.Fields)
|
||||||
{
|
{
|
||||||
int fieldAlignment = AlignmentOf(field.Type);
|
var fieldAlignment = AlignmentOf(field.Type);
|
||||||
maxAlignment = Math.Max(maxAlignment, fieldAlignment);
|
maxAlignment = Math.Max(maxAlignment, fieldAlignment);
|
||||||
|
|
||||||
size = AlignTo(size, fieldAlignment);
|
size = AlignTo(size, fieldAlignment);
|
||||||
|
|
||||||
size += SizeOf(field.Type);
|
size += SizeOf(field.Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class SymbolTable
|
|||||||
|
|
||||||
public Func LookupFunc(string @namespace, string name)
|
public Func LookupFunc(string @namespace, string name)
|
||||||
{
|
{
|
||||||
return _functions.Single(x => x.Name == name);
|
return _functions.Single(x => x.Name == name && x.Namespace == @namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable LookupVariable(string name)
|
public Variable LookupVariable(string name)
|
||||||
@@ -100,4 +100,10 @@ public class SymbolTable
|
|||||||
public string Namespace { get; } = @namespace;
|
public string Namespace { get; } = @namespace;
|
||||||
public string GeneratedName { get; } = generatedName;
|
public string GeneratedName { get; } = generatedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Struct(string @namespace, string name) : Symbol(name)
|
||||||
|
{
|
||||||
|
public string Namespace { get; } = @namespace;
|
||||||
|
public string GeneratedName => $"{Namespace}_{Name}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ public class TypeChecker
|
|||||||
private List<SourceFile> _sourceFiles = [];
|
private List<SourceFile> _sourceFiles = [];
|
||||||
private List<Diagnostic> _diagnostics = [];
|
private List<Diagnostic> _diagnostics = [];
|
||||||
private NubType? _currentFunctionReturnType;
|
private NubType? _currentFunctionReturnType;
|
||||||
private List<AnonymousFuncNode> _anonymousFunctions = [];
|
private Queue<AnonymousFuncNode> _anonymousFunctions = [];
|
||||||
|
|
||||||
public DiagnosticsResult TypeCheck(List<SourceFile> sourceFiles)
|
public DiagnosticsResult TypeCheck(List<SourceFile> sourceFiles)
|
||||||
{
|
{
|
||||||
@@ -55,9 +55,10 @@ public class TypeChecker
|
|||||||
TypeCheckFuncDef(funcDef.Parameters, funcDef.Body, funcDef.ReturnType);
|
TypeCheckFuncDef(funcDef.Parameters, funcDef.Body, funcDef.ReturnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var anonymousFuncNode in _anonymousFunctions)
|
while (_anonymousFunctions.TryDequeue(out var func))
|
||||||
{
|
{
|
||||||
TypeCheckFuncDef(anonymousFuncNode.Parameters, anonymousFuncNode.Body, anonymousFuncNode.ReturnType);
|
TypeCheckFuncDef(func.Parameters, func.Body, func.ReturnType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DiagnosticsResult(_diagnostics);
|
return new DiagnosticsResult(_diagnostics);
|
||||||
@@ -375,7 +376,7 @@ public class TypeChecker
|
|||||||
|
|
||||||
private NubType TypeCheckAnonymousFunc(AnonymousFuncNode anonymousFunc)
|
private NubType TypeCheckAnonymousFunc(AnonymousFuncNode anonymousFunc)
|
||||||
{
|
{
|
||||||
_anonymousFunctions.Add(anonymousFunc);
|
_anonymousFunctions.Enqueue(anonymousFunc);
|
||||||
return new NubFuncType(anonymousFunc.ReturnType, anonymousFunc.Parameters.Select(p => p.Type).ToList());
|
return new NubFuncType(anonymousFunc.ReturnType, anonymousFunc.Parameters.Select(p => p.Type).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
.global _start
|
.global _start
|
||||||
_start:
|
_start:
|
||||||
mov rdi, rsp
|
mov rdi, rsp
|
||||||
# main([]^string): i64
|
# func main(args: []^string): i64
|
||||||
call main
|
call main
|
||||||
mov rdi, rax
|
mov rdi, rax
|
||||||
mov rax, 60
|
mov rax, 60
|
||||||
|
|||||||
Reference in New Issue
Block a user