Fixed all bugs: test suite is passing
This commit is contained in:
parent
d048870165
commit
b93ac201f2
|
@ -231,7 +231,7 @@ proc statement(self: Compiler, node: Statement)
|
||||||
proc declaration(self: Compiler, node: Declaration)
|
proc declaration(self: Compiler, node: Declaration)
|
||||||
proc peek(self: Compiler, distance: int = 0): ASTNode
|
proc peek(self: Compiler, distance: int = 0): ASTNode
|
||||||
proc identifier(self: Compiler, node: IdentExpr)
|
proc identifier(self: Compiler, node: IdentExpr)
|
||||||
proc varDecl(self: Compiler, node: VarDecl, name: Name)
|
proc varDecl(self: Compiler, node: VarDecl)
|
||||||
proc specialize(self: Compiler, name: Name, args: seq[Expression]): Name
|
proc specialize(self: Compiler, name: Name, args: seq[Expression]): Name
|
||||||
proc matchImpl(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowFwd: bool = true): Name
|
proc matchImpl(self: Compiler, name: string, kind: Type, node: ASTNode = nil, allowFwd: bool = true): Name
|
||||||
proc infer(self: Compiler, node: LiteralExpr, allowGeneric: bool = false): Type
|
proc infer(self: Compiler, node: LiteralExpr, allowGeneric: bool = false): Type
|
||||||
|
@ -501,8 +501,6 @@ proc resolve(self: Compiler, name: string): Name =
|
||||||
## resolved, it is also compiled on-the-fly
|
## resolved, it is also compiled on-the-fly
|
||||||
for obj in reversed(self.names):
|
for obj in reversed(self.names):
|
||||||
if obj.ident.token.lexeme == name:
|
if obj.ident.token.lexeme == name:
|
||||||
if obj.kind == NameKind.Argument and obj.belongsTo != self.currentFunction:
|
|
||||||
continue
|
|
||||||
if obj.owner != self.currentModule:
|
if obj.owner != self.currentModule:
|
||||||
# We don't own this name, but we
|
# We don't own this name, but we
|
||||||
# may still have access to it
|
# may still have access to it
|
||||||
|
@ -1991,7 +1989,7 @@ proc deferStmt(self: Compiler, node: DeferStmt) =
|
||||||
|
|
||||||
proc returnStmt(self: Compiler, node: ReturnStmt) =
|
proc returnStmt(self: Compiler, node: ReturnStmt) =
|
||||||
## Compiles return statements
|
## Compiles return statements
|
||||||
self.check(node.value, self.currentFunction.valueType.returnType)
|
|
||||||
if not node.value.isNil():
|
if not node.value.isNil():
|
||||||
self.expression(node.value)
|
self.expression(node.value)
|
||||||
self.emitByte(OpCode.SetResult, node.token.line)
|
self.emitByte(OpCode.SetResult, node.token.line)
|
||||||
|
@ -2177,7 +2175,7 @@ proc statement(self: Compiler, node: Statement) =
|
||||||
self.expression(Expression(node))
|
self.expression(Expression(node))
|
||||||
|
|
||||||
|
|
||||||
proc varDecl(self: Compiler, node: VarDecl, name: Name) =
|
proc varDecl(self: Compiler, node: VarDecl) =
|
||||||
## Compiles variable declarations
|
## Compiles variable declarations
|
||||||
|
|
||||||
# Our parser guarantees that the variable declaration
|
# Our parser guarantees that the variable declaration
|
||||||
|
@ -2199,9 +2197,11 @@ proc varDecl(self: Compiler, node: VarDecl, name: Name) =
|
||||||
self.check(node.value, expected)
|
self.check(node.value, expected)
|
||||||
# If this doesn't fail, then we're good
|
# If this doesn't fail, then we're good
|
||||||
typ = expected
|
typ = expected
|
||||||
name.valueType = typ
|
|
||||||
self.expression(node.value)
|
self.expression(node.value)
|
||||||
self.emitByte(StoreVar, node.token.line)
|
self.emitByte(StoreVar, node.token.line)
|
||||||
|
self.declareName(node)
|
||||||
|
var name = self.names[^1]
|
||||||
|
name.valueType = typ
|
||||||
self.emitBytes(self.getStackPos(name).toTriple(), node.token.line)
|
self.emitBytes(self.getStackPos(name).toTriple(), node.token.line)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2309,13 +2309,13 @@ proc declaration(self: Compiler, node: Declaration) =
|
||||||
## right away, but rather only when they're referenced
|
## right away, but rather only when they're referenced
|
||||||
## the first time
|
## the first time
|
||||||
case node.kind:
|
case node.kind:
|
||||||
of NodeKind.varDecl, NodeKind.funDecl, NodeKind.typeDecl:
|
of NodeKind.funDecl, NodeKind.typeDecl:
|
||||||
self.declareName(node)
|
self.declareName(node)
|
||||||
if node.kind == NodeKind.varDecl:
|
of NodeKind.varDecl:
|
||||||
# We compile this immediately because we
|
# We compile this immediately because we
|
||||||
# need to keep the stack in the right state
|
# need to keep the stack in the right state
|
||||||
# at runtime
|
# at runtime
|
||||||
self.varDecl(VarDecl(node), self.names[^1])
|
self.varDecl(VarDecl(node))
|
||||||
else:
|
else:
|
||||||
self.statement(Statement(node))
|
self.statement(Statement(node))
|
||||||
|
|
||||||
|
|
|
@ -297,6 +297,7 @@ proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints
|
||||||
styledEcho fgBlue, "Source line: " , fgDefault, line
|
styledEcho fgBlue, "Source line: " , fgDefault, line
|
||||||
styledEcho fgCyan, " ".repeat(len("Source line: ") + line.find(lexeme)) & "^".repeat(abs(relPos.stop - relPos.start - line.find(lexeme)))
|
styledEcho fgCyan, " ".repeat(len("Source line: ") + line.find(lexeme)) & "^".repeat(abs(relPos.stop - relPos.start - line.find(lexeme)))
|
||||||
except CompileError:
|
except CompileError:
|
||||||
|
raise
|
||||||
let exc = CompileError(getCurrentException())
|
let exc = CompileError(getCurrentException())
|
||||||
let lexeme = exc.node.token.lexeme
|
let lexeme = exc.node.token.lexeme
|
||||||
var lineNo = exc.node.token.line
|
var lineNo = exc.node.token.line
|
||||||
|
|
|
@ -9,4 +9,4 @@ fn makeAdder(x: int): fn (n: int): int {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print(makeAdder(5)(2)); # 7
|
print(makeAdder(5)(2)); # 7
|
||||||
|
|
|
@ -8,5 +8,5 @@ fn foo: int;
|
||||||
print(foo());
|
print(foo());
|
||||||
|
|
||||||
|
|
||||||
fn foo: int {return 42;}
|
fn foo: int {return 42;} # Commenting this line will cause an error
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import std;
|
import std;
|
||||||
|
|
||||||
|
|
||||||
var x = 1;
|
var x = 100000;
|
||||||
var y = "just a test";
|
var y = "just a test";
|
||||||
print(y);
|
print(y);
|
||||||
print("Starting GC torture test");
|
print("Starting GC torture test");
|
||||||
|
|
Loading…
Reference in New Issue