Added a few more tests
This commit is contained in:
parent
a370961218
commit
da651355b9
|
@ -263,12 +263,11 @@ proc constReadUInt8(self: PeonVM, idx: int): PeonObject =
|
||||||
result = PeonObject(kind: UInt8, uTiny: self.chunk.consts[idx])
|
result = PeonObject(kind: UInt8, uTiny: self.chunk.consts[idx])
|
||||||
|
|
||||||
|
|
||||||
proc constReadString(self: PeonVM, idx: int): PeonObject =
|
proc constReadString(self: PeonVM, size: int, idx: int): PeonObject =
|
||||||
## Reads a constant from the
|
## Reads a constant from the
|
||||||
## chunk's constant table and
|
## chunk's constant table and
|
||||||
## returns a Peon object. Assumes
|
## returns a Peon object. Assumes
|
||||||
## the constant is a string
|
## the constant is a string
|
||||||
let size = self.readLong()
|
|
||||||
result = PeonObject(kind: String, str: self.chunk.consts[idx..<size].fromBytes())
|
result = PeonObject(kind: String, str: self.chunk.consts[idx..<size].fromBytes())
|
||||||
|
|
||||||
|
|
||||||
|
@ -346,7 +345,7 @@ proc dispatch*(self: PeonVM) =
|
||||||
of LoadUInt8:
|
of LoadUInt8:
|
||||||
self.push(self.constReadUInt8(int(self.readLong())))
|
self.push(self.constReadUInt8(int(self.readLong())))
|
||||||
of LoadString:
|
of LoadString:
|
||||||
self.push(self.constReadString(int(self.readLong())))
|
self.push(self.constReadString(int(self.readLong()), int(self.readLong())))
|
||||||
of LoadFloat32:
|
of LoadFloat32:
|
||||||
self.push(self.constReadFloat32(int(self.readLong())))
|
self.push(self.constReadFloat32(int(self.readLong())))
|
||||||
of LoadFloat64:
|
of LoadFloat64:
|
||||||
|
|
|
@ -160,10 +160,16 @@ proc loadAddressInstruction(self: Debugger, instruction: OpCode) =
|
||||||
|
|
||||||
proc constantInstruction(self: Debugger, instruction: OpCode) =
|
proc constantInstruction(self: Debugger, instruction: OpCode) =
|
||||||
## Debugs instructions that operate on the constant table
|
## Debugs instructions that operate on the constant table
|
||||||
|
var size: uint
|
||||||
|
if instruction == LoadString:
|
||||||
|
size = [self.chunk.code[self.current + 1], self.chunk.code[self.current + 2], self.chunk.code[self.current + 3]].fromTriple()
|
||||||
|
self.current += 3
|
||||||
var constant = [self.chunk.code[self.current + 1], self.chunk.code[self.current + 2], self.chunk.code[self.current + 3]].fromTriple()
|
var constant = [self.chunk.code[self.current + 1], self.chunk.code[self.current + 2], self.chunk.code[self.current + 3]].fromTriple()
|
||||||
printInstruction(instruction)
|
printInstruction(instruction)
|
||||||
stdout.styledWriteLine(fgGreen, &", points to constant at position ", fgYellow, $constant)
|
stdout.styledWrite(fgGreen, &", points to constant at position ", fgYellow, $constant)
|
||||||
self.current += 4
|
self.current += 4
|
||||||
|
if instruction == LoadString:
|
||||||
|
stdout.styledWriteLine(fgGreen, " of length ", fgYellow, $size)
|
||||||
|
|
||||||
|
|
||||||
proc jumpInstruction(self: Debugger, instruction: OpCode) =
|
proc jumpInstruction(self: Debugger, instruction: OpCode) =
|
||||||
|
@ -179,7 +185,6 @@ proc jumpInstruction(self: Debugger, instruction: OpCode) =
|
||||||
self.checkFrameStart(i)
|
self.checkFrameStart(i)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proc disassembleInstruction*(self: Debugger) =
|
proc disassembleInstruction*(self: Debugger) =
|
||||||
## Takes one bytecode instruction and prints it
|
## Takes one bytecode instruction and prints it
|
||||||
printDebug("Offset: ")
|
printDebug("Offset: ")
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
operator `<`(a, b: int): bool {
|
||||||
|
#pragma[magic: "LessThanInt64", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
operator `-`(a, b: float): float {
|
||||||
|
#pragma[magic: "SubFloat64", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
operator `-`(a, b: int): int {
|
||||||
|
#pragma[magic: "SubInt64", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
operator `+`(a, b: int): int {
|
||||||
|
#pragma[magic: "AddInt64", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
operator `/`(a, b: int): int {
|
||||||
|
#pragma[magic: "DivInt64", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn clock: float {
|
||||||
|
#pragma[magic: "SysClock64", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn print(x: float) {
|
||||||
|
#pragma[magic: "GenericPrint"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn print(x: int) {
|
||||||
|
#pragma[magic: "GenericPrint"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn fib(n: int): int {
|
||||||
|
if n < 2 {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
return fib(n - 2) + fib(n - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var x = clock();
|
||||||
|
print(fib(25));
|
||||||
|
print(clock() - x);
|
|
@ -0,0 +1,6 @@
|
||||||
|
operator `<`(a, b: int): bool {#pragma[magic: "LessThanInt64", pure]}
|
||||||
|
operator `>`(a, b: int): bool {return b < a;}
|
||||||
|
|
||||||
|
|
||||||
|
3 > 2;
|
||||||
|
2 < 3;
|
Loading…
Reference in New Issue