Cleaned up and renamed some things
This commit is contained in:
parent
19a089f4a2
commit
f7733d925f
|
@ -24,7 +24,7 @@ import ../util/multibyte
|
|||
|
||||
|
||||
import strutils
|
||||
when DEBUG_TRACE_VM:
|
||||
when debugVM:
|
||||
import std/strformat
|
||||
|
||||
|
||||
|
@ -315,7 +315,7 @@ proc dispatch*(self: PeonVM) =
|
|||
var instruction {.register.}: OpCode
|
||||
while true:
|
||||
{.computedgoto.} # https://nim-lang.org/docs/manual.html#pragmas-computedgoto-pragma
|
||||
when DEBUG_TRACE_VM:
|
||||
when debugVM:
|
||||
echo &"IP: {self.ip}"
|
||||
echo &"Instruction: {OpCode(self.chunk.code[self.ip])}"
|
||||
if self.calls.len() !> 0:
|
||||
|
@ -450,7 +450,7 @@ proc dispatch*(self: PeonVM) =
|
|||
# Stores the value at the top of the operand stack
|
||||
# into the given call stack index
|
||||
let idx = self.readLong()
|
||||
when DEBUG_TRACE_VM:
|
||||
when debugVM:
|
||||
assert idx.int - self.calls.high() <= 1, "StoreVar index is bigger than the length of the call stack"
|
||||
if idx + self.frames[^1] <= self.calls.high().uint:
|
||||
self.setc(idx, self.pop())
|
||||
|
|
|
@ -14,25 +14,28 @@
|
|||
|
||||
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
|
||||
# Debug various components of peon
|
||||
const debugLexer* {.booldefine.} = false
|
||||
const debugParser* {.booldefine.} = false
|
||||
const debugCompiler* {.booldefine.} = false
|
||||
const debugVM* {.booldefine.} = false
|
||||
const debugGC* {.booldefine.} = false
|
||||
const debugMem* {.booldefine.} = false
|
||||
const debugSerializer* {.booldefine.} = false
|
||||
const PeonBytecodeMarker* = "PEON_BYTECODE"
|
||||
const HeapGrowFactor* = 2 # How much extra memory to allocate for dynamic arrays and garbage collection when resizing
|
||||
when HEAP_GROW_FACTOR <= 1:
|
||||
{.fatal: "Heap growth factor must be > 1".}
|
||||
const PEON_VERSION* = (major: 0, minor: 1, patch: 0)
|
||||
const PEON_RELEASE* = "alpha"
|
||||
const PEON_COMMIT_HASH* = "b273cd744883458a4a6354a0cc5f4f5d0f560c31"
|
||||
when len(PEON_COMMIT_HASH) != 40:
|
||||
const PeonVersion* = (major: 0, minor: 1, patch: 0)
|
||||
const PeonRelease* = "alpha"
|
||||
const PeonCommitHash* = "b273cd744883458a4a6354a0cc5f4f5d0f560c31"
|
||||
when len(PeonCommitHash) != 40:
|
||||
{.fatal: "The git commit hash must be exactly 40 characters long".}
|
||||
const PEON_BRANCH* = "unboxed-types"
|
||||
const PeonBranch* = "unboxed-types"
|
||||
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* = 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
|
||||
const PEON_VERSION_STRING* = &"Peon {PEON_VERSION.major}.{PEON_VERSION.minor}.{PEON_VERSION.patch} {PEON_RELEASE} ({PEON_BRANCH}, {CompileDate}, {CompileTime}, {PEON_COMMIT_HASH[0..8]}) [Nim {NimVersion}] on {hostOS} ({hostCPU})"
|
||||
const HELP_MESSAGE* = """The peon programming language, Copyright (C) 2022 Mattia Giambirtone & All Contributors
|
||||
const PeonVersionString* = &"Peon {PeonVersion.major}.{PeonVersion.minor}.{PeonVersion.patch} {PeonRelease} ({PeonBranch}, {CompileDate}, {CompileTime}, {PeonCommitHash[0..8]}) [Nim {NimVersion}] on {hostOS} ({hostCPU})"
|
||||
const HelpMessage* = """The peon programming language, Copyright (C) 2022 Mattia Giambirtone & All Contributors
|
||||
|
||||
This program is free software, see the license distributed with this program or check
|
||||
http://www.apache.org/licenses/LICENSE-2.0 for more info.
|
||||
|
|
|
@ -282,8 +282,6 @@ proc step(self: Compiler): ASTNode {.inline.} =
|
|||
proc emitByte(self: Compiler, byt: OpCode | uint8) {.inline.} =
|
||||
## Emits a single byte, writing it to
|
||||
## the current chunk being compiled
|
||||
when DEBUG_TRACE_COMPILER:
|
||||
echo &"DEBUG - Compiler: Emitting {$byt}"
|
||||
self.chunk.write(uint8 byt, self.peek().token.line)
|
||||
|
||||
|
||||
|
|
12
src/main.nim
12
src/main.nim
|
@ -27,14 +27,6 @@ import config
|
|||
# Forward declarations
|
||||
proc getLineEditor: LineEditor
|
||||
|
||||
# Handy dandy compile-time constants
|
||||
const debugLexer {.booldefine.} = false
|
||||
const debugParser {.booldefine.} = false
|
||||
const debugCompiler {.booldefine.} = false
|
||||
const debugSerializer {.booldefine.} = false
|
||||
const debugRuntime {.booldefine.} = false
|
||||
|
||||
|
||||
|
||||
proc repl =
|
||||
styledEcho fgMagenta, "Welcome into the peon REPL!"
|
||||
|
@ -131,7 +123,7 @@ proc repl =
|
|||
styledEcho fgGreen, "OK"
|
||||
else:
|
||||
styledEcho fgRed, "Corrupted"
|
||||
when debugRuntime:
|
||||
when debugVM:
|
||||
styledEcho fgCyan, "\n\nExecution step: "
|
||||
vm.run(serialized.chunk)
|
||||
except LexingError:
|
||||
|
@ -266,7 +258,7 @@ proc runFile(f: string, interactive: bool = false, fromString: bool = false) =
|
|||
styledEcho fgGreen, "OK"
|
||||
else:
|
||||
styledEcho fgRed, "Corrupted"
|
||||
when debugRuntime:
|
||||
when debugVM:
|
||||
styledEcho fgCyan, "\n\nExecution step: "
|
||||
vm.run(serialized.chunk)
|
||||
except LexingError:
|
||||
|
|
|
@ -62,7 +62,7 @@ proc newSerializer*(self: Serializer = nil): Serializer =
|
|||
|
||||
proc writeHeaders(self: Serializer, stream: var seq[byte]) =
|
||||
## Writes the Peon bytecode headers in-place into a byte stream
|
||||
stream.extend(BYTECODE_MARKER.toBytes())
|
||||
stream.extend(PeonBytecodeMarker.toBytes())
|
||||
stream.add(byte(PEON_VERSION.major))
|
||||
stream.add(byte(PEON_VERSION.minor))
|
||||
stream.add(byte(PEON_VERSION.patch))
|
||||
|
@ -106,10 +106,10 @@ proc readHeaders(self: Serializer, stream: seq[byte], serialized: Serialized): i
|
|||
## Reads the bytecode headers from a given stream
|
||||
## of bytes
|
||||
var stream = stream
|
||||
if stream[0..<len(BYTECODE_MARKER)] != BYTECODE_MARKER.toBytes():
|
||||
if stream[0..<len(PeonBytecodeMarker)] != PeonBytecodeMarker.toBytes():
|
||||
self.error("malformed bytecode marker")
|
||||
result += len(BYTECODE_MARKER)
|
||||
stream = stream[len(BYTECODE_MARKER)..^1]
|
||||
result += len(PeonBytecodeMarker)
|
||||
stream = stream[len(PeonBytecodeMarker)..^1]
|
||||
serialized.version = (major: int(stream[0]), minor: int(stream[1]), patch: int(stream[2]))
|
||||
stream = stream[3..^1]
|
||||
result += 3
|
||||
|
|
Loading…
Reference in New Issue