derete the fil #2
|
@ -15,10 +15,13 @@
|
|||
|
||||
type
|
||||
ObjectKind* = enum
|
||||
## Enumeration of Peon
|
||||
## types
|
||||
objFloat, objInt, objBool,
|
||||
objNil, objNan, objInf,
|
||||
objString
|
||||
PeonObject* = ref object of RootObj
|
||||
|
||||
kind*: ObjectKind
|
||||
Nil* = ref object of PeonObject
|
||||
Nan* = ref object of PeonObject
|
||||
|
@ -47,6 +50,9 @@ type
|
|||
Float64* = ref object of PeonObject
|
||||
value*: float64
|
||||
|
||||
# We create a type alias for floats
|
||||
# and integers depending on the current
|
||||
# platform's native sizes
|
||||
when sizeof(int) == 8:
|
||||
type Int = Int64
|
||||
elif sizeof(int) == 4:
|
||||
|
@ -61,7 +67,7 @@ when sizeof(float) == 8:
|
|||
else:
|
||||
type Float = Float32
|
||||
|
||||
|
||||
# Simple constructors for builtin types
|
||||
proc newNil*: Nil = Nil(kind: objNil)
|
||||
proc newNan*: Nan = Nan(kind: objNan)
|
||||
proc newInf*(positive: bool): Inf = Inf(kind: objInf, positive: positive)
|
||||
|
|
|
@ -44,6 +44,7 @@ proc newPeonVM*: PeonVM =
|
|||
for _ in 0..<INITIAL_STACK_SIZE:
|
||||
result.stack.add(result.cache[0])
|
||||
|
||||
# Getters for singleton types (they are cached!)
|
||||
|
||||
proc getNil*(self: PeonVM): Nil = Nil(self.cache[0])
|
||||
|
||||
|
@ -59,8 +60,11 @@ proc getInf*(self: PeonVM, positive: bool): Inf =
|
|||
|
||||
proc getNan*(self: PeonVM): Nan = types.Nan(self.cache[5])
|
||||
|
||||
# Stack primitives
|
||||
|
||||
proc push(self: PeonVM, obj: PeonObject) =
|
||||
## Pushes a Peon object onto the
|
||||
## stack
|
||||
if self.sp >= self.stack.high():
|
||||
for _ in 0..self.stack.len():
|
||||
self.stack.add(newNil())
|
||||
|
@ -69,6 +73,9 @@ proc push(self: PeonVM, obj: PeonObject) =
|
|||
|
||||
|
||||
proc pop(self: PeonVM): PeonObject =
|
||||
## Pops a Peon object off the
|
||||
## stack, decreasing the stack
|
||||
## pointer. The object is returned
|
||||
dec(self.sp)
|
||||
return self.stack[self.sp]
|
||||
|
||||
|
|
|
@ -509,7 +509,7 @@ proc parseBackticks(self: Lexer) =
|
|||
|
||||
while not self.match("`") and not self.done():
|
||||
discard self.step()
|
||||
self.createToken(CustomOperator)
|
||||
self.createToken(Identifier)
|
||||
# Strips the backticks
|
||||
self.tokens[^1].lexeme = self.tokens[^1].lexeme[1..^2]
|
||||
|
||||
|
|
|
@ -74,9 +74,6 @@ type
|
|||
# stuff I haven't thought about yet
|
||||
Whitespace,
|
||||
Tab,
|
||||
|
||||
CustomOperator, # Arbitrary user-defined operator (contains the operator's lexeme for operators
|
||||
# that are not identifiers)
|
||||
|
||||
|
||||
Token* = ref object
|
||||
|
|
Loading…
Reference in New Issue