From a706fdad7a5832c647e55294686eabe350a34bfd Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Mon, 27 Mar 2023 19:14:22 +0200 Subject: [PATCH] Made VM helpers pure --- src/backend/vm.nim | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/backend/vm.nim b/src/backend/vm.nim index 640be27..213026f 100644 --- a/src/backend/vm.nim +++ b/src/backend/vm.nim @@ -371,19 +371,19 @@ proc newPeonVM*: PeonVM = # Getters for singleton types {.push inline.} -proc getNil*(self: var PeonVM): uint64 = self.cache[2] +func getNil*(self: var PeonVM): uint64 = self.cache[2] -proc getBool*(self: var PeonVM, value: bool): uint64 = +func getBool*(self: var PeonVM, value: bool): uint64 = if value: return self.cache[1] return self.cache[0] -proc getInf*(self: var PeonVM, positive: bool): uint64 = +func getInf*(self: var PeonVM, positive: bool): uint64 = if positive: return self.cache[3] return self.cache[4] -proc getNan*(self: var PeonVM): uint64 = self.cache[5] +func getNan*(self: var PeonVM): uint64 = self.cache[5] # Thanks to nim's *genius* idea of making x > y a template @@ -393,11 +393,11 @@ proc getNan*(self: var PeonVM): uint64 = self.cache[5] # and https://github.com/nim-lang/Nim/issues/10425 and try not to # bang your head against the nearest wall), we need a custom operator # that preserves the natural order of evaluation -proc `!>`[T](a, b: T): auto {.inline.} = +func `!>`[T](a, b: T): auto = b < a -proc `!>=`[T](a, b: T): auto {.inline, used.} = +proc `!>=`[T](a, b: T): auto {.used.} = b <= a @@ -405,26 +405,26 @@ proc `!>=`[T](a, b: T): auto {.inline, used.} = # that go through the (get|set|peek)c wrappers are frame-relative, # meaning that the given index is added to the current stack frame's # bottom to obtain an absolute stack index -proc push(self: var PeonVM, obj: uint64) = +func push(self: var PeonVM, obj: uint64) = ## Pushes a value object onto the ## operand stack self.operands.add(obj) -proc pop(self: var PeonVM): uint64 = +func pop(self: var PeonVM): uint64 = ## Pops a value off the operand ## stack and returns it return self.operands.pop() -proc peekb(self: PeonVM, distance: BackwardsIndex = ^1): uint64 = +func peekb(self: PeonVM, distance: BackwardsIndex = ^1): uint64 = ## Returns the value at the given (backwards) ## distance from the top of the operand stack ## without consuming it return self.operands[distance] -proc peek(self: PeonVM, distance: int = 0): uint64 = +func peek(self: PeonVM, distance: int = 0): uint64 = ## Returns the value at the given ## distance from the top of the ## operand stack without consuming it @@ -433,33 +433,33 @@ proc peek(self: PeonVM, distance: int = 0): uint64 = return self.operands[self.operands.high() + distance] -proc pushc(self: var PeonVM, val: uint64) = +func pushc(self: var PeonVM, val: uint64) = ## Pushes a value onto the ## call stack self.calls.add(val) -proc popc(self: var PeonVM): uint64 = +func popc(self: var PeonVM): uint64 = ## Pops a value off the call ## stack and returns it return self.calls.pop() -proc peekc(self: PeonVM, distance: int = 0): uint64 {.used.} = +func peekc(self: PeonVM, distance: int = 0): uint64 {.used.} = ## Returns the value at the given ## distance from the top of the ## call stack without consuming it return self.calls[self.calls.high() + distance] -proc getc(self: PeonVM, idx: int): uint64 = +func getc(self: PeonVM, idx: int): uint64 = ## Getter method that abstracts ## indexing our call stack through ## stack frames return self.calls[idx.uint64 + self.frames[^1]] -proc setc(self: var PeonVM, idx: int, val: uint64) = +func setc(self: var PeonVM, idx: int, val: uint64) = ## Setter method that abstracts ## indexing our call stack through ## stack frames