Fixed a bug in the debugger when visualizing encoded dictionary elements and simplified dispatching code inside Compiler.expression() for literals
This commit is contained in:
parent
71dfac87dd
commit
cb34a22a53
|
@ -3,3 +3,4 @@ nimblecache/
|
||||||
htmldocs/
|
htmldocs/
|
||||||
main
|
main
|
||||||
*.jplc
|
*.jplc
|
||||||
|
.vscode/
|
||||||
|
|
|
@ -632,19 +632,14 @@ proc expression(self: Compiler, node: ASTNode) =
|
||||||
of binaryExpr:
|
of binaryExpr:
|
||||||
# Binary expressions such as 2 ^ 5 and 0.66 * 3.14
|
# Binary expressions such as 2 ^ 5 and 0.66 * 3.14
|
||||||
self.binary(BinaryExpr(node))
|
self.binary(BinaryExpr(node))
|
||||||
of intExpr, hexExpr, binExpr, octExpr, strExpr, falseExpr, trueExpr, infExpr, nanExpr, floatExpr, nilExpr:
|
of intExpr, hexExpr, binExpr, octExpr, strExpr, falseExpr, trueExpr, infExpr, nanExpr, floatExpr, nilExpr,
|
||||||
# Fortunately for us, all of these AST nodes types inherit from the base LiteralExpr
|
tupleExpr, setExpr, listExpr, dictExpr:
|
||||||
# type
|
# Since all of these AST nodes mostly share
|
||||||
self.literal(LiteralExpr(node))
|
# the same overall structure, and the kind
|
||||||
of tupleExpr, setExpr, listExpr:
|
|
||||||
# Since all of these AST nodes share
|
|
||||||
# the same structure, and the kind
|
|
||||||
# discriminant is enough to tell one
|
# discriminant is enough to tell one
|
||||||
# from the other, why bother with
|
# from the other, why bother with
|
||||||
# specialized cases when one is enough?
|
# specialized cases when one is enough?
|
||||||
self.literal(ListExpr(node))
|
self.literal(node)
|
||||||
of dictExpr:
|
|
||||||
self.literal(DictExpr(node))
|
|
||||||
else:
|
else:
|
||||||
self.error(&"invalid AST node of kind {node.kind} at expression(): {node} (This is an internal error and most likely a bug)") # TODO
|
self.error(&"invalid AST node of kind {node.kind} at expression(): {node} (This is an internal error and most likely a bug)") # TODO
|
||||||
|
|
||||||
|
@ -655,7 +650,6 @@ proc statement(self: Compiler, node: ASTNode) =
|
||||||
of exprStmt:
|
of exprStmt:
|
||||||
self.expression(ExprStmt(node).expression)
|
self.expression(ExprStmt(node).expression)
|
||||||
self.emitByte(Pop) # Expression statements discard their value. Their main use case is side effects in function calls
|
self.emitByte(Pop) # Expression statements discard their value. Their main use case is side effects in function calls
|
||||||
# TODO
|
|
||||||
of NodeKind.ifStmt:
|
of NodeKind.ifStmt:
|
||||||
self.ifStmt(IfStmt(node))
|
self.ifStmt(IfStmt(node))
|
||||||
of delStmt:
|
of delStmt:
|
||||||
|
|
|
@ -15,18 +15,18 @@
|
||||||
import strformat
|
import strformat
|
||||||
|
|
||||||
const BYTECODE_MARKER* = "JAPL_BYTECODE"
|
const BYTECODE_MARKER* = "JAPL_BYTECODE"
|
||||||
const MAP_LOAD_FACTOR* = 0.75 # Load factor for builtin hashmaps
|
const MAP_LOAD_FACTOR* = 0.75 # Load factor for builtin hashmaps
|
||||||
const HEAP_GROW_FACTOR* = 2 # How much extra memory to allocate for dynamic arrays and garbage collection when resizing
|
const HEAP_GROW_FACTOR* = 2 # How much extra memory to allocate for dynamic arrays and garbage collection when resizing
|
||||||
const MAX_STACK_FRAMES* = 800 # The maximum number of stack frames at any one time. Acts as a recursion limiter (1 frame = 1 call)
|
const MAX_STACK_FRAMES* = 800 # The maximum number of stack frames at any one time. Acts as a recursion limiter (1 frame = 1 call)
|
||||||
const JAPL_VERSION* = (major: 0, minor: 4, patch: 0)
|
const JAPL_VERSION* = (major: 0, minor: 4, patch: 0)
|
||||||
const JAPL_RELEASE* = "alpha"
|
const JAPL_RELEASE* = "alpha"
|
||||||
const JAPL_COMMIT_HASH* = "e234c8caaff25f6edf69329cf8a17531cb7914dd"
|
const JAPL_COMMIT_HASH* = "e234c8caaff25f6edf69329cf8a17531cb7914dd"
|
||||||
const JAPL_BRANCH* = "master"
|
const JAPL_BRANCH* = "master"
|
||||||
const DEBUG_TRACE_VM* = false # Traces VM execution
|
const DEBUG_TRACE_VM* = false # Traces VM execution
|
||||||
const SKIP_STDLIB_INIT* = false # Skips stdlib initialization (can be imported manually)
|
const SKIP_STDLIB_INIT* = false # Skips stdlib initialization (can be imported manually)
|
||||||
const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO)
|
const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO)
|
||||||
const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation
|
const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation
|
||||||
const DEBUG_TRACE_COMPILER* = false # Traces the compiler
|
const DEBUG_TRACE_COMPILER* = false # Traces the compiler
|
||||||
const JAPL_VERSION_STRING* = &"JAPL {JAPL_VERSION.major}.{JAPL_VERSION.minor}.{JAPL_VERSION.patch} {JAPL_RELEASE} ({JAPL_BRANCH}, {CompileDate}, {CompileTime}, {JAPL_COMMIT_HASH[0..8]}) [Nim {NimVersion}] on {hostOS} ({hostCPU})"
|
const JAPL_VERSION_STRING* = &"JAPL {JAPL_VERSION.major}.{JAPL_VERSION.minor}.{JAPL_VERSION.patch} {JAPL_RELEASE} ({JAPL_BRANCH}, {CompileDate}, {CompileTime}, {JAPL_COMMIT_HASH[0..8]}) [Nim {NimVersion}] on {hostOS} ({hostCPU})"
|
||||||
const HELP_MESSAGE* = """The JAPL programming language, Copyright (C) 2021 Mattia Giambirtone & All Contributors
|
const HELP_MESSAGE* = """The JAPL programming language, Copyright (C) 2021 Mattia Giambirtone & All Contributors
|
||||||
|
|
||||||
|
|
|
@ -138,10 +138,12 @@ proc collectionInstruction(instruction: OpCode, chunk: Chunk, offset: int): int
|
||||||
setForegroundColor(fgGreen)
|
setForegroundColor(fgGreen)
|
||||||
of BuildDict:
|
of BuildDict:
|
||||||
var elements: seq[tuple[key: ASTNode, value: ASTNode]] = @[]
|
var elements: seq[tuple[key: ASTNode, value: ASTNode]] = @[]
|
||||||
for n in countup(0, (elemCount - 1) * 2):
|
for n in countup(0, (elemCount - 1) * 2, 2):
|
||||||
elements.add((key: chunk.consts[n], value: chunk.consts[n + 1]))
|
elements.add((key: chunk.consts[n], value: chunk.consts[n + 1]))
|
||||||
|
printDebug("Elements: ")
|
||||||
setForegroundColor(fgYellow)
|
setForegroundColor(fgYellow)
|
||||||
printDebug(&"""Elements: [{elements.join(", ")}]""")
|
stdout.write(&"""[{elements.join(", ")}]""")
|
||||||
|
setForegroundColor(fgGreen)
|
||||||
else:
|
else:
|
||||||
discard # Unreachable
|
discard # Unreachable
|
||||||
echo ""
|
echo ""
|
||||||
|
|
Loading…
Reference in New Issue