Fixed issues when debugSerializer == true
This commit is contained in:
parent
9cedc72f68
commit
60028ed664
|
@ -136,6 +136,7 @@ type
|
||||||
|
|
||||||
IdentExpr* = ref object of Expression
|
IdentExpr* = ref object of Expression
|
||||||
name*: Token
|
name*: Token
|
||||||
|
depth*: int
|
||||||
|
|
||||||
GroupingExpr* = ref object of Expression
|
GroupingExpr* = ref object of Expression
|
||||||
expression*: Expression
|
expression*: Expression
|
||||||
|
@ -181,6 +182,7 @@ type
|
||||||
isPure*: bool
|
isPure*: bool
|
||||||
returnType*: Expression
|
returnType*: Expression
|
||||||
hasExplicitReturn*: bool
|
hasExplicitReturn*: bool
|
||||||
|
freeVars*: seq[IdentExpr]
|
||||||
|
|
||||||
|
|
||||||
SliceExpr* = ref object of Expression
|
SliceExpr* = ref object of Expression
|
||||||
|
@ -262,6 +264,7 @@ type
|
||||||
isPure*: bool
|
isPure*: bool
|
||||||
returnType*: Expression
|
returnType*: Expression
|
||||||
hasExplicitReturn*: bool
|
hasExplicitReturn*: bool
|
||||||
|
freeVars*: seq[IdentExpr]
|
||||||
|
|
||||||
TypeDecl* = ref object of Declaration
|
TypeDecl* = ref object of Declaration
|
||||||
name*: IdentExpr
|
name*: IdentExpr
|
||||||
|
@ -395,10 +398,11 @@ proc newCharExpr*(literal: Token): CharExpr =
|
||||||
result.token = literal
|
result.token = literal
|
||||||
|
|
||||||
|
|
||||||
proc newIdentExpr*(name: Token): IdentExpr =
|
proc newIdentExpr*(name: Token, depth: int = 0): IdentExpr =
|
||||||
result = IdentExpr(kind: identExpr)
|
result = IdentExpr(kind: identExpr)
|
||||||
result.name = name
|
result.name = name
|
||||||
result.token = name
|
result.token = name
|
||||||
|
result.depth = depth
|
||||||
|
|
||||||
|
|
||||||
proc newGroupingExpr*(expression: Expression, token: Token): GroupingExpr =
|
proc newGroupingExpr*(expression: Expression, token: Token): GroupingExpr =
|
||||||
|
@ -410,7 +414,7 @@ proc newGroupingExpr*(expression: Expression, token: Token): GroupingExpr =
|
||||||
proc newLambdaExpr*(arguments: seq[tuple[name: IdentExpr, valueType: Expression]],
|
proc newLambdaExpr*(arguments: seq[tuple[name: IdentExpr, valueType: Expression]],
|
||||||
defaults: seq[Expression], body: Statement, isGenerator: bool,
|
defaults: seq[Expression], body: Statement, isGenerator: bool,
|
||||||
isAsync: bool, token: Token, returnType: Expression, pragmas: seq[Pragma],
|
isAsync: bool, token: Token, returnType: Expression, pragmas: seq[Pragma],
|
||||||
generics: seq[tuple[name: IdentExpr, cond: Expression]]): LambdaExpr =
|
generics: seq[tuple[name: IdentExpr, cond: Expression]], freeVars: seq[IdentExpr] = @[]): LambdaExpr =
|
||||||
result = LambdaExpr(kind: lambdaExpr)
|
result = LambdaExpr(kind: lambdaExpr)
|
||||||
result.body = body
|
result.body = body
|
||||||
result.arguments = arguments
|
result.arguments = arguments
|
||||||
|
@ -422,6 +426,7 @@ proc newLambdaExpr*(arguments: seq[tuple[name: IdentExpr, valueType: Expression]
|
||||||
result.isPure = false
|
result.isPure = false
|
||||||
result.pragmas = pragmas
|
result.pragmas = pragmas
|
||||||
result.generics = generics
|
result.generics = generics
|
||||||
|
result.freeVars = freeVars
|
||||||
|
|
||||||
|
|
||||||
proc newGetItemExpr*(obj: Expression, name: IdentExpr,
|
proc newGetItemExpr*(obj: Expression, name: IdentExpr,
|
||||||
|
@ -611,7 +616,7 @@ proc newVarDecl*(name: IdentExpr, value: Expression, isConst: bool = false,
|
||||||
proc newFunDecl*(name: IdentExpr, arguments: seq[tuple[name: IdentExpr, valueType: Expression]], defaults: seq[Expression],
|
proc newFunDecl*(name: IdentExpr, arguments: seq[tuple[name: IdentExpr, valueType: Expression]], defaults: seq[Expression],
|
||||||
body: Statement, isAsync, isGenerator: bool,
|
body: Statement, isAsync, isGenerator: bool,
|
||||||
isPrivate: bool, token: Token, pragmas: seq[Pragma],
|
isPrivate: bool, token: Token, pragmas: seq[Pragma],
|
||||||
returnType: Expression, generics: seq[tuple[name: IdentExpr, cond: Expression]]): FunDecl =
|
returnType: Expression, generics: seq[tuple[name: IdentExpr, cond: Expression]], freeVars: seq[IdentExpr] = @[]): FunDecl =
|
||||||
result = FunDecl(kind: funDecl)
|
result = FunDecl(kind: funDecl)
|
||||||
result.name = name
|
result.name = name
|
||||||
result.arguments = arguments
|
result.arguments = arguments
|
||||||
|
@ -625,6 +630,7 @@ proc newFunDecl*(name: IdentExpr, arguments: seq[tuple[name: IdentExpr, valueTyp
|
||||||
result.returnType = returnType
|
result.returnType = returnType
|
||||||
result.isPure = false
|
result.isPure = false
|
||||||
result.generics = generics
|
result.generics = generics
|
||||||
|
result.freeVars = freeVars
|
||||||
|
|
||||||
|
|
||||||
proc newTypeDecl*(name: IdentExpr, fields: seq[tuple[name: IdentExpr, valueType: Expression, isPrivate: bool]],
|
proc newTypeDecl*(name: IdentExpr, fields: seq[tuple[name: IdentExpr, valueType: Expression, isPrivate: bool]],
|
||||||
|
|
|
@ -307,7 +307,7 @@ proc primary(self: Parser): Expression =
|
||||||
of Integer:
|
of Integer:
|
||||||
result = newIntExpr(self.step())
|
result = newIntExpr(self.step())
|
||||||
of Identifier:
|
of Identifier:
|
||||||
result = newIdentExpr(self.step())
|
result = newIdentExpr(self.step(), self.scopeDepth)
|
||||||
of LeftParen:
|
of LeftParen:
|
||||||
let tok = self.step()
|
let tok = self.step()
|
||||||
result = newGroupingExpr(self.expression(), tok)
|
result = newGroupingExpr(self.expression(), tok)
|
||||||
|
@ -417,7 +417,7 @@ proc call(self: Parser): Expression =
|
||||||
result = self.makeCall(result)
|
result = self.makeCall(result)
|
||||||
elif self.match(Dot):
|
elif self.match(Dot):
|
||||||
self.expect(Identifier, "expecting attribute name after '.'")
|
self.expect(Identifier, "expecting attribute name after '.'")
|
||||||
result = newGetItemExpr(result, newIdentExpr(self.peek(-1)), self.peek(-1))
|
result = newGetItemExpr(result, newIdentExpr(self.peek(-1), self.scopeDepth), self.peek(-1))
|
||||||
elif self.match(LeftBracket):
|
elif self.match(LeftBracket):
|
||||||
self.parseGenericArgs() # TODO
|
self.parseGenericArgs() # TODO
|
||||||
result = self.makeCall(result)
|
result = self.makeCall(result)
|
||||||
|
@ -647,7 +647,7 @@ proc forEachStmt(self: Parser): Statement =
|
||||||
self.currentLoop = Loop
|
self.currentLoop = Loop
|
||||||
self.expect(LeftParen, "expecting '(' after 'foreach'")
|
self.expect(LeftParen, "expecting '(' after 'foreach'")
|
||||||
self.expect(Identifier)
|
self.expect(Identifier)
|
||||||
var identifier = newIdentExpr(self.peek(-1))
|
var identifier = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
self.expect(":")
|
self.expect(":")
|
||||||
var expression = self.expression()
|
var expression = self.expression()
|
||||||
self.expect(RightParen)
|
self.expect(RightParen)
|
||||||
|
@ -665,7 +665,7 @@ proc importStmt(self: Parser, fromStmt: bool = false): Statement =
|
||||||
tok = self.peek(-1)
|
tok = self.peek(-1)
|
||||||
# TODO: New AST node
|
# TODO: New AST node
|
||||||
self.expect(Identifier, "expecting module name(s) after import statement")
|
self.expect(Identifier, "expecting module name(s) after import statement")
|
||||||
result = newImportStmt(newIdentExpr(self.peek(-1)), tok)
|
result = newImportStmt(newIdentExpr(self.peek(-1), self.scopeDepth), tok)
|
||||||
endOfLine("missing semicolon after import statement")
|
endOfLine("missing semicolon after import statement")
|
||||||
|
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ proc parsePragmas(self: Parser): seq[Pragma] =
|
||||||
if self.peek(-1).lexeme in names:
|
if self.peek(-1).lexeme in names:
|
||||||
self.error("duplicate pragmas are not allowed")
|
self.error("duplicate pragmas are not allowed")
|
||||||
names.add(self.peek(-1).lexeme)
|
names.add(self.peek(-1).lexeme)
|
||||||
name = newIdentExpr(self.peek(-1))
|
name = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
if not self.match(":"):
|
if not self.match(":"):
|
||||||
if self.match("]"):
|
if self.match("]"):
|
||||||
result.add(newPragma(name, @[]))
|
result.add(newPragma(name, @[]))
|
||||||
|
@ -833,7 +833,7 @@ proc varDecl(self: Parser, isLet: bool = false,
|
||||||
var tok = self.peek(-1)
|
var tok = self.peek(-1)
|
||||||
var value: Expression
|
var value: Expression
|
||||||
self.expect(Identifier, &"expecting identifier after '{tok.lexeme}'")
|
self.expect(Identifier, &"expecting identifier after '{tok.lexeme}'")
|
||||||
var name = newIdentExpr(self.peek(-1))
|
var name = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
let isPrivate = not self.match("*")
|
let isPrivate = not self.match("*")
|
||||||
self.checkDecl(isPrivate)
|
self.checkDecl(isPrivate)
|
||||||
var valueType: IdentExpr
|
var valueType: IdentExpr
|
||||||
|
@ -844,7 +844,7 @@ proc varDecl(self: Parser, isLet: bool = false,
|
||||||
# the compiler may be able to infer
|
# the compiler may be able to infer
|
||||||
# the type later!
|
# the type later!
|
||||||
self.expect(Identifier, "expecting type name after ':'")
|
self.expect(Identifier, "expecting type name after ':'")
|
||||||
valueType = newIdentExpr(self.peek(-1))
|
valueType = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
if self.match("="):
|
if self.match("="):
|
||||||
hasInit = true
|
hasInit = true
|
||||||
value = self.expression()
|
value = self.expression()
|
||||||
|
@ -883,7 +883,7 @@ proc parseDeclArguments(self: Parser, arguments: var seq[tuple[name: IdentExpr,
|
||||||
if arguments.len > 255:
|
if arguments.len > 255:
|
||||||
self.error("cannot have more than 255 arguments in function declaration")
|
self.error("cannot have more than 255 arguments in function declaration")
|
||||||
self.expect(Identifier, "expecting parameter name")
|
self.expect(Identifier, "expecting parameter name")
|
||||||
parameter.name = newIdentExpr(self.peek(-1))
|
parameter.name = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
if self.match(":"):
|
if self.match(":"):
|
||||||
parameter.valueType = self.expression()
|
parameter.valueType = self.expression()
|
||||||
for i in countdown(arguments.high(), 0):
|
for i in countdown(arguments.high(), 0):
|
||||||
|
@ -931,7 +931,7 @@ proc parseGenerics(self: Parser, decl: Declaration) =
|
||||||
var gen: tuple[name: IdentExpr, cond: Expression]
|
var gen: tuple[name: IdentExpr, cond: Expression]
|
||||||
while not self.check(RightBracket) and not self.done():
|
while not self.check(RightBracket) and not self.done():
|
||||||
self.expect(Identifier, "expecting generic type name")
|
self.expect(Identifier, "expecting generic type name")
|
||||||
gen.name = newIdentExpr(self.peek(-1))
|
gen.name = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
if self.match(":"):
|
if self.match(":"):
|
||||||
gen.cond = self.expression()
|
gen.cond = self.expression()
|
||||||
decl.generics.add(gen)
|
decl.generics.add(gen)
|
||||||
|
@ -957,7 +957,7 @@ proc funDecl(self: Parser, isAsync: bool = false, isGenerator: bool = false,
|
||||||
# or an expression. Fortunately anonymous functions
|
# or an expression. Fortunately anonymous functions
|
||||||
# are nameless, so we can sort the ambiguity by checking
|
# are nameless, so we can sort the ambiguity by checking
|
||||||
# if there's an identifier after the keyword
|
# if there's an identifier after the keyword
|
||||||
self.currentFunction = newFunDecl(newIdentExpr(self.peek(-1)), arguments, defaults, newBlockStmt(@[], Token()),
|
self.currentFunction = newFunDecl(newIdentExpr(self.peek(-1), self.scopeDepth), arguments, defaults, newBlockStmt(@[], Token()),
|
||||||
isAsync=isAsync,
|
isAsync=isAsync,
|
||||||
isGenerator=isGenerator,
|
isGenerator=isGenerator,
|
||||||
isPrivate=true,
|
isPrivate=true,
|
||||||
|
@ -1121,7 +1121,7 @@ proc typeDecl(self: Parser): TypeDecl =
|
||||||
self.expect(Identifier, "expecting type name after 'type'")
|
self.expect(Identifier, "expecting type name after 'type'")
|
||||||
let isPrivate = not self.match("*")
|
let isPrivate = not self.match("*")
|
||||||
self.checkDecl(isPrivate)
|
self.checkDecl(isPrivate)
|
||||||
var name = newIdentExpr(self.peek(-1))
|
var name = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
var fields: seq[tuple[name: IdentExpr, valueType: Expression, isPrivate: bool]] = @[]
|
var fields: seq[tuple[name: IdentExpr, valueType: Expression, isPrivate: bool]] = @[]
|
||||||
var defaults: seq[Expression] = @[]
|
var defaults: seq[Expression] = @[]
|
||||||
var generics: seq[tuple[name: IdentExpr, cond: Expression]] = @[]
|
var generics: seq[tuple[name: IdentExpr, cond: Expression]] = @[]
|
||||||
|
@ -1141,7 +1141,7 @@ proc typeDecl(self: Parser): TypeDecl =
|
||||||
argType: Expression
|
argType: Expression
|
||||||
while not self.match(RightBrace) and not self.done():
|
while not self.match(RightBrace) and not self.done():
|
||||||
self.expect(Identifier, "expecting field name")
|
self.expect(Identifier, "expecting field name")
|
||||||
argName = newIdentExpr(self.peek(-1))
|
argName = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||||
argPrivate = not self.match("*")
|
argPrivate = not self.match("*")
|
||||||
self.expect(":", "expecting ':' after field name")
|
self.expect(":", "expecting ':' after field name")
|
||||||
argType = self.expression()
|
argType = self.expression()
|
||||||
|
|
|
@ -35,6 +35,10 @@ const debugSerializer {.booldefine.} = false
|
||||||
const debugRuntime {.booldefine.} = false
|
const debugRuntime {.booldefine.} = false
|
||||||
|
|
||||||
|
|
||||||
|
when debugSerializer:
|
||||||
|
import nimSHA2
|
||||||
|
|
||||||
|
|
||||||
proc repl(vm: PeonVM = newPeonVM()) =
|
proc repl(vm: PeonVM = newPeonVM()) =
|
||||||
styledEcho fgMagenta, "Welcome into the peon REPL!"
|
styledEcho fgMagenta, "Welcome into the peon REPL!"
|
||||||
var
|
var
|
||||||
|
@ -234,9 +238,7 @@ proc runFile(f: string, interactive: bool = false, fromString: bool = false) =
|
||||||
serializer.dumpFile(compiled, f, path)
|
serializer.dumpFile(compiled, f, path)
|
||||||
serialized = serializer.loadFile(path)
|
serialized = serializer.loadFile(path)
|
||||||
when debugSerializer:
|
when debugSerializer:
|
||||||
var hashMatches = computeSHA256(input).toHex().toLowerAscii() == serialized.fileHash
|
|
||||||
styledEcho fgCyan, "Serialization step: "
|
styledEcho fgCyan, "Serialization step: "
|
||||||
styledEcho fgBlue, &"\t- File hash: ", fgYellow, serialized.fileHash, fgBlue, " (", if hashMatches: fgGreen else: fgRed, if hashMatches: "OK" else: "Fail", fgBlue, ")"
|
|
||||||
styledEcho fgBlue, "\t- Peon version: ", fgYellow, &"{serialized.version.major}.{serialized.version.minor}.{serialized.version.patch}", fgBlue, " (commit ", fgYellow, serialized.commit[0..8], fgBlue, ") on branch ", fgYellow, serialized.branch
|
styledEcho fgBlue, "\t- Peon version: ", fgYellow, &"{serialized.version.major}.{serialized.version.minor}.{serialized.version.patch}", fgBlue, " (commit ", fgYellow, serialized.commit[0..8], fgBlue, ") on branch ", fgYellow, serialized.branch
|
||||||
stdout.styledWriteLine(fgBlue, "\t- Compilation date & time: ", fgYellow, fromUnix(serialized.compileDate).format("d/M/yyyy HH:mm:ss"))
|
stdout.styledWriteLine(fgBlue, "\t- Compilation date & time: ", fgYellow, fromUnix(serialized.compileDate).format("d/M/yyyy HH:mm:ss"))
|
||||||
stdout.styledWrite(fgBlue, &"\t- Constants segment: ")
|
stdout.styledWrite(fgBlue, &"\t- Constants segment: ")
|
||||||
|
|
Loading…
Reference in New Issue