mirror of https://github.com/japl-lang/japl.git
improve debug vm
improved coloring removed d:danger so debug output is present fixed frame length debug output
This commit is contained in:
parent
17913f1d7c
commit
5d98814d7d
|
@ -2,8 +2,7 @@
|
|||
// from nim itself (the nim compiler options are identical to those of
|
||||
// production.json)
|
||||
{"flags": {
|
||||
"gc": "none",
|
||||
"d": "danger"
|
||||
"gc": "none"
|
||||
},
|
||||
"verbose": true,
|
||||
"override_config": true,
|
||||
|
|
|
@ -37,7 +37,7 @@ proc clear*(self: CallFrame): int =
|
|||
inc result
|
||||
|
||||
proc getView*(self: CallFrame): ptr ArrayList[ptr Obj] =
|
||||
result = self.stack[self.slot..self.stack.high()]
|
||||
result = self.stack[self.slot..self.stack.len()]
|
||||
|
||||
|
||||
proc len*(self: CallFrame): int =
|
||||
|
|
|
@ -84,7 +84,7 @@ proc `[]`*[T](self: ptr ArrayList[T], slice: Hslice[int, int]): ptr ArrayList[T]
|
|||
## of the slice
|
||||
if self.length == 0:
|
||||
raise newException(IndexDefect, "ArrayList index out of bounds")
|
||||
if slice.a notin 0..self.length - 1 or slice.b notin 0..self.length - 1:
|
||||
if slice.a notin 0..self.length - 1 or slice.b notin 0..self.length:
|
||||
raise newException(IndexDefect, "ArrayList index out of bounds")
|
||||
result = newArrayList[T]()
|
||||
for i in countup(slice.a, slice.b - 1):
|
||||
|
|
|
@ -20,17 +20,29 @@ import ../types/baseObject
|
|||
import ../types/methods
|
||||
import ../types/arraylist
|
||||
import strformat
|
||||
import terminal
|
||||
|
||||
proc printName(name: string) =
|
||||
setForegroundColor(fgGreen)
|
||||
write stdout, name
|
||||
setForegroundColor(fgDefault)
|
||||
|
||||
proc nl =
|
||||
write stdout, "\n"
|
||||
|
||||
proc simpleInstruction(name: string, index: int): int =
|
||||
echo &"DEBUG - VM:\tInstruction -> {name}"
|
||||
write stdout, &"DEBUG - VM:\tInstruction -> "
|
||||
printName(name)
|
||||
nl()
|
||||
return index + 1
|
||||
|
||||
|
||||
proc byteInstruction(name: string, chunk: Chunk, offset: int): int =
|
||||
var slot = chunk.code[offset + 1]
|
||||
echo &"DEBUG - VM:\tInstruction -> {name}, points to slot {slot}"
|
||||
write stdout, &"DEBUG - VM:\tInstruction -> "
|
||||
printName(name)
|
||||
write stdout, &", points to slot {slot}"
|
||||
nl()
|
||||
return offset + 2
|
||||
|
||||
|
||||
|
@ -39,7 +51,10 @@ proc constantInstruction(name: string, chunk: Chunk, offset: int): int =
|
|||
var constantArray: array[3, uint8] = [chunk.code[offset + 1], chunk.code[offset + 2], chunk.code[offset + 3]]
|
||||
var constant: int
|
||||
copyMem(constant.addr, constantArray.addr, sizeof(constantArray))
|
||||
echo &"DEBUG - VM:\tInstruction -> {name}, points to slot {constant}"
|
||||
write stdout, &"DEBUG - VM:\tInstruction -> "
|
||||
printName(name)
|
||||
write stdout, &", points to slot {constant}"
|
||||
nl()
|
||||
let obj = chunk.consts[constant]
|
||||
echo &"DEBUG - VM:\tOperand -> {stringify(obj)}\nDEBUG - VM:\tValue kind -> {obj.kind}"
|
||||
return offset + 4
|
||||
|
@ -49,7 +64,10 @@ proc jumpInstruction(name: string, chunk: Chunk, offset: int): int =
|
|||
var jumpArray: array[2, uint8] = [chunk.code[offset + 1], chunk.code[offset + 2]]
|
||||
var jump: int
|
||||
copyMem(jump.addr, jumpArray.addr, sizeof(uint16))
|
||||
echo &"DEBUG - VM:\tInstruction -> {name}\nDEBUG - VM:\tJump size -> {jump}"
|
||||
write stdout, &"DEBUG - VM:\tInstruction -> "
|
||||
printName(name)
|
||||
write stdout, &"\nDEBUG - VM:\tJump size -> {jump}"
|
||||
nl()
|
||||
return offset + 3
|
||||
|
||||
|
||||
|
|
12
src/vm.nim
12
src/vm.nim
|
@ -44,6 +44,9 @@ import types/arraylist
|
|||
# in production builds
|
||||
import util/debug
|
||||
|
||||
when DEBUG_TRACE_VM:
|
||||
import terminal
|
||||
|
||||
|
||||
type
|
||||
KeyboardInterrupt* = object of CatchableError
|
||||
|
@ -292,12 +295,17 @@ proc readConstant(self: CallFrame): ptr Obj =
|
|||
|
||||
|
||||
|
||||
proc showRuntime*(self: VM, frame: CallFrame, iteration: uint64) =
|
||||
when DEBUG_TRACE_VM:
|
||||
proc showRuntime*(self: VM, frame: CallFrame, iteration: uint64) =
|
||||
## Shows debug information about the current
|
||||
## state of the virtual machine
|
||||
|
||||
let view = frame.getView()
|
||||
setForegroundColor(fgYellow)
|
||||
stdout.write("DEBUG - VM: General information\n")
|
||||
stdout.write(&"DEBUG - VM:\tIteration -> {iteration}\nDEBUG - VM:\tStack -> [")
|
||||
stdout.write(&"DEBUG - VM:\tIteration -> {iteration}\n")
|
||||
setForegroundColor(fgDefault)
|
||||
stdout.write("DEBUG - VM:\tStack -> [")
|
||||
for i, v in self.stack:
|
||||
stdout.write(stringify(v))
|
||||
if i < self.stack.high():
|
||||
|
|
Loading…
Reference in New Issue