diff --git a/src/config.nim b/src/config.nim index 12c2291..218807b 100644 --- a/src/config.nim +++ b/src/config.nim @@ -27,7 +27,7 @@ when len(PEON_COMMIT_HASH) != 40: const PEON_BRANCH* = "master" when len(PEON_BRANCH) > 255: {.fatal: "The git branch name's length must be less than or equal to 255 characters".} -const DEBUG_TRACE_VM* = false # Traces VM execution +const DEBUG_TRACE_VM* = true # Traces VM execution const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO) const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation const DEBUG_TRACE_COMPILER* = false # Traces the compiler diff --git a/src/frontend/compiler.nim b/src/frontend/compiler.nim index ae8d41e..568b4cc 100644 --- a/src/frontend/compiler.nim +++ b/src/frontend/compiler.nim @@ -799,7 +799,7 @@ proc matchImpl(self: Compiler, name: string, kind: Type): Name = proc emitFunction(self: Compiler, name: Name) = ## Wrapper to emit LoadFunction instructions self.emitByte(LoadFunction) - self.emitBytes((name.codePos + 4).toTriple()) + self.emitBytes(name.codePos.toTriple()) proc generateCall(self: Compiler, fn: Name, args: seq[Expression]) = @@ -1526,8 +1526,8 @@ proc funDecl(self: Compiler, node: FunDecl) = self.declareName(node) self.frames.add(self.names.high()) let fn = self.names[^(node.arguments.len() + 1)] - fn.codePos = self.chunk.code.len() let jmp = self.emitJump(JumpForwards) + fn.codePos = self.chunk.code.len() for argument in node.arguments: self.emitByte(LoadArgument) if not node.returnType.isNil() and self.inferType(node.returnType).isNil(): diff --git a/src/frontend/meta/bytecode.nim b/src/frontend/meta/bytecode.nim index d5dcacd..d4601fa 100644 --- a/src/frontend/meta/bytecode.nim +++ b/src/frontend/meta/bytecode.nim @@ -141,7 +141,7 @@ const simpleInstructions* = {Return, LoadNil, BeginTry, FinishTry, Yield, Await, NoOp, PopClosure, SetResult, LoadArgument, - PopC, LoadFunctionObj, PushC} + PopC, PushC} # Constant instructions are instructions that operate on the bytecode constant table const constantInstructions* = {LoadInt64, LoadUInt64, @@ -153,7 +153,7 @@ const constantInstructions* = {LoadInt64, LoadUInt64, # Stack triple instructions operate on the stack at arbitrary offsets and pop arguments off of it in the form # of 24 bit integers -const stackTripleInstructions* = {StoreVar, LoadVar, LoadCLosure, StoreClosure} +const stackTripleInstructions* = {StoreVar, LoadVar, LoadCLosure, StoreClosure, } # Stack double instructions operate on the stack at arbitrary offsets and pop arguments off of it in the form # of 16 bit integers @@ -163,7 +163,7 @@ const stackDoubleInstructions* = {} const argumentDoubleInstructions* = {PopN, } # Argument double argument instructions take hardcoded arguments as 24 bit integers -const argumentTripleInstructions* = {} +const argumentTripleInstructions* = {LoadFunctionObj, } # Instructions that call functions const callInstructions* = {Call, } diff --git a/src/main.nim b/src/main.nim index 3de6480..5800ba4 100644 --- a/src/main.nim +++ b/src/main.nim @@ -76,7 +76,10 @@ proc repl(vm: PeonVM = newPeonVM()) = elif current == "#clear": stdout.write("\x1Bc") continue - input &= &"\n{current}\n" + elif current == "#showInput": + echo input + continue + input &= &"{current}\n" tokens = tokenizer.lex(input, "stdin") if tokens.len() == 0: continue diff --git a/src/util/debugger.nim b/src/util/debugger.nim index 3562620..51d5289 100644 --- a/src/util/debugger.nim +++ b/src/util/debugger.nim @@ -127,7 +127,7 @@ proc argumentTripleInstruction(self: Debugger, instruction: OpCode) = ## Debugs instructions that operate on a hardcoded value on the stack using a 24-bit operand var slot = [self.chunk.code[self.current + 1], self.chunk.code[self.current + 2], self.chunk.code[self.current + 3]].fromTriple() printInstruction(instruction) - stdout.styledWrite(fgGreen, ", has argument ", fgYellow, $slot) + stdout.styledWriteLine(fgGreen, ", has argument ", fgYellow, $slot) self.current += 4