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