Fixed some issues with strings and added debug print to fibonacci test
This commit is contained in:
parent
edef50deca
commit
7ef5b4dfbf
|
@ -268,7 +268,7 @@ proc constReadString(self: PeonVM, size: int, idx: int): PeonObject =
|
|||
## chunk's constant table and
|
||||
## returns a Peon object. Assumes
|
||||
## the constant is a string
|
||||
result = PeonObject(kind: String, str: self.chunk.consts[idx..<size].fromBytes())
|
||||
result = PeonObject(kind: String, str: self.chunk.consts[idx..< idx + size].fromBytes())
|
||||
|
||||
|
||||
proc constReadFloat32(self: PeonVM, idx: int): PeonObject =
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import strformat
|
||||
|
||||
|
||||
const debugVM {.booldefine.} = false
|
||||
const BYTECODE_MARKER* = "PEON_BYTECODE"
|
||||
const HEAP_GROW_FACTOR* = 2 # How much extra memory to allocate for dynamic arrays and garbage collection when resizing
|
||||
when HEAP_GROW_FACTOR <= 1:
|
||||
|
@ -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* = debugVM # 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
|
||||
|
|
|
@ -305,7 +305,7 @@ proc makeConstant(self: Compiler, val: Expression, typ: Type): array[3, uint8] =
|
|||
of Int64, UInt64:
|
||||
result = self.chunk.writeConstant(v.toLong())
|
||||
of String:
|
||||
result = self.chunk.writeConstant(v.toBytes())
|
||||
result = self.chunk.writeConstant(val.token.lexeme[1..^1].toBytes())
|
||||
of Float32:
|
||||
var f: float = 0.0
|
||||
discard parseFloat(val.token.lexeme, f)
|
||||
|
@ -343,7 +343,7 @@ proc emitConstant(self: Compiler, obj: Expression, kind: Type) =
|
|||
let str = LiteralExpr(obj).literal.lexeme
|
||||
if str.len() >= 16777216:
|
||||
self.error("string constants cannot be larger than 16777215 bytes")
|
||||
self.emitBytes(str.len().toTriple())
|
||||
self.emitBytes((str.len() - 2).toTriple())
|
||||
of Float32:
|
||||
self.emitByte(LoadFloat32)
|
||||
of Float64:
|
||||
|
|
|
@ -195,7 +195,7 @@ proc incLine(self: Lexer) =
|
|||
## Increments the lexer's line
|
||||
## counter and updates internal
|
||||
## line metadata
|
||||
self.lines.add((self.lastLine, self.current - 1))
|
||||
self.lines.add((self.lastLine, self.current))
|
||||
self.lastLine = self.current
|
||||
self.line += 1
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ fn fib(n: int): int {
|
|||
}
|
||||
|
||||
|
||||
print("Computing the value of fib(25)");
|
||||
var x = clock();
|
||||
print(fib(25));
|
||||
print(clock() - x);
|
||||
print("Done!");
|
|
@ -36,3 +36,8 @@ fn print*(x: float) {
|
|||
fn print*(x: int) {
|
||||
#pragma[magic: "GenericPrint"]
|
||||
}
|
||||
|
||||
|
||||
fn print*(x: string) {
|
||||
#pragma[magic: "GenericPrint"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue