Fixed issues with returning/calling function objects
This commit is contained in:
parent
02f1f8a54d
commit
e3ab2fbdb6
|
@ -27,7 +27,7 @@ when len(PEON_COMMIT_HASH) != 40:
|
||||||
const PEON_BRANCH* = "master"
|
const PEON_BRANCH* = "master"
|
||||||
when len(PEON_BRANCH) > 255:
|
when len(PEON_BRANCH) > 255:
|
||||||
{.fatal: "The git branch name's length must be less than or equal to 255 characters".}
|
{.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_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
|
||||||
|
|
|
@ -799,7 +799,7 @@ proc matchImpl(self: Compiler, name: string, kind: Type): Name =
|
||||||
proc emitFunction(self: Compiler, name: Name) =
|
proc emitFunction(self: Compiler, name: Name) =
|
||||||
## Wrapper to emit LoadFunction instructions
|
## Wrapper to emit LoadFunction instructions
|
||||||
self.emitByte(LoadFunction)
|
self.emitByte(LoadFunction)
|
||||||
self.emitBytes((name.codePos + 4).toTriple())
|
self.emitBytes(name.codePos.toTriple())
|
||||||
|
|
||||||
|
|
||||||
proc generateCall(self: Compiler, fn: Name, args: seq[Expression]) =
|
proc generateCall(self: Compiler, fn: Name, args: seq[Expression]) =
|
||||||
|
@ -1526,8 +1526,8 @@ proc funDecl(self: Compiler, node: FunDecl) =
|
||||||
self.declareName(node)
|
self.declareName(node)
|
||||||
self.frames.add(self.names.high())
|
self.frames.add(self.names.high())
|
||||||
let fn = self.names[^(node.arguments.len() + 1)]
|
let fn = self.names[^(node.arguments.len() + 1)]
|
||||||
fn.codePos = self.chunk.code.len()
|
|
||||||
let jmp = self.emitJump(JumpForwards)
|
let jmp = self.emitJump(JumpForwards)
|
||||||
|
fn.codePos = self.chunk.code.len()
|
||||||
for argument in node.arguments:
|
for argument in node.arguments:
|
||||||
self.emitByte(LoadArgument)
|
self.emitByte(LoadArgument)
|
||||||
if not node.returnType.isNil() and self.inferType(node.returnType).isNil():
|
if not node.returnType.isNil() and self.inferType(node.returnType).isNil():
|
||||||
|
|
|
@ -141,7 +141,7 @@ const simpleInstructions* = {Return, LoadNil,
|
||||||
BeginTry, FinishTry, Yield,
|
BeginTry, FinishTry, Yield,
|
||||||
Await, NoOp, PopClosure,
|
Await, NoOp, PopClosure,
|
||||||
SetResult, LoadArgument,
|
SetResult, LoadArgument,
|
||||||
PopC, LoadFunctionObj, PushC}
|
PopC, PushC}
|
||||||
|
|
||||||
# Constant instructions are instructions that operate on the bytecode constant table
|
# Constant instructions are instructions that operate on the bytecode constant table
|
||||||
const constantInstructions* = {LoadInt64, LoadUInt64,
|
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
|
# Stack triple instructions operate on the stack at arbitrary offsets and pop arguments off of it in the form
|
||||||
# of 24 bit integers
|
# 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
|
# Stack double instructions operate on the stack at arbitrary offsets and pop arguments off of it in the form
|
||||||
# of 16 bit integers
|
# of 16 bit integers
|
||||||
|
@ -163,7 +163,7 @@ const stackDoubleInstructions* = {}
|
||||||
const argumentDoubleInstructions* = {PopN, }
|
const argumentDoubleInstructions* = {PopN, }
|
||||||
|
|
||||||
# Argument double argument instructions take hardcoded arguments as 24 bit integers
|
# Argument double argument instructions take hardcoded arguments as 24 bit integers
|
||||||
const argumentTripleInstructions* = {}
|
const argumentTripleInstructions* = {LoadFunctionObj, }
|
||||||
|
|
||||||
# Instructions that call functions
|
# Instructions that call functions
|
||||||
const callInstructions* = {Call, }
|
const callInstructions* = {Call, }
|
||||||
|
|
|
@ -76,7 +76,10 @@ proc repl(vm: PeonVM = newPeonVM()) =
|
||||||
elif current == "#clear":
|
elif current == "#clear":
|
||||||
stdout.write("\x1Bc")
|
stdout.write("\x1Bc")
|
||||||
continue
|
continue
|
||||||
input &= &"\n{current}\n"
|
elif current == "#showInput":
|
||||||
|
echo input
|
||||||
|
continue
|
||||||
|
input &= &"{current}\n"
|
||||||
tokens = tokenizer.lex(input, "stdin")
|
tokens = tokenizer.lex(input, "stdin")
|
||||||
if tokens.len() == 0:
|
if tokens.len() == 0:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -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
|
## 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()
|
var slot = [self.chunk.code[self.current + 1], self.chunk.code[self.current + 2], self.chunk.code[self.current + 3]].fromTriple()
|
||||||
printInstruction(instruction)
|
printInstruction(instruction)
|
||||||
stdout.styledWrite(fgGreen, ", has argument ", fgYellow, $slot)
|
stdout.styledWriteLine(fgGreen, ", has argument ", fgYellow, $slot)
|
||||||
self.current += 4
|
self.current += 4
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue