Added 'is' identity operator and implemented equality for booleans
This commit is contained in:
parent
de9b51152e
commit
42ba738620
|
@ -753,6 +753,8 @@ proc dispatch*(self: var PeonVM) =
|
|||
discard self.pop()
|
||||
discard self.pop()
|
||||
of ReplExit:
|
||||
# Preserves the VM's state for the next
|
||||
# execution. Used in the REPL
|
||||
return
|
||||
of Return:
|
||||
# Returns from a function.
|
||||
|
@ -992,6 +994,8 @@ proc dispatch*(self: var PeonVM) =
|
|||
self.push(self.getBool(cast[float32](self.pop()) !>= cast[float32](self.pop())))
|
||||
of Float32LessOrEqual:
|
||||
self.push(self.getBool(cast[float32](self.pop()) <= cast[float32](self.pop())))
|
||||
of Identity:
|
||||
self.push(cast[uint64](self.pop() == self.pop()))
|
||||
# Print opcodes
|
||||
of PrintInt64:
|
||||
echo cast[int64](self.pop())
|
||||
|
|
|
@ -136,6 +136,7 @@ type
|
|||
Float32GreaterOrEqual,
|
||||
Float32LessOrEqual,
|
||||
LogicalNot,
|
||||
Identity, # Pointer equality
|
||||
## Print opcodes
|
||||
PrintInt64,
|
||||
PrintUInt64,
|
||||
|
@ -270,7 +271,8 @@ const simpleInstructions* = {Return, LoadNil,
|
|||
Float32GreaterOrEqual,
|
||||
Float32LessOrEqual,
|
||||
DupTop,
|
||||
ReplExit
|
||||
ReplExit,
|
||||
Identity
|
||||
}
|
||||
|
||||
# Constant instructions are instructions that operate on the bytecode constant table
|
||||
|
|
|
@ -461,7 +461,8 @@ proc handleBuiltinFunction(self: BytecodeCompiler, fn: Type, args: seq[Expressio
|
|||
"PrintString": PrintString,
|
||||
"SysClock64": SysClock64,
|
||||
"LogicalNot": LogicalNot,
|
||||
"NegInf": LoadNInf
|
||||
"NegInf": LoadNInf,
|
||||
"Identity": Identity
|
||||
}.to_table()
|
||||
if fn.builtinOp == "print":
|
||||
let typ = self.inferOrError(args[0])
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
import values;
|
||||
|
||||
|
||||
operator `is`*[T: any](a, b: T): bool {
|
||||
#pragma[magic: "Identity", pure]
|
||||
}
|
||||
|
||||
|
||||
operator `>`*[T: UnsignedInteger](a, b: T): bool {
|
||||
#pragma[magic: "GreaterThan", pure]
|
||||
}
|
||||
|
@ -12,7 +17,7 @@ operator `<`*[T: UnsignedInteger](a, b: T): bool {
|
|||
}
|
||||
|
||||
|
||||
operator `==`*[T: Number | inf](a, b: T): bool {
|
||||
operator `==`*[T: Number | inf | bool](a, b: T): bool {
|
||||
#pragma[magic: "Equal", pure]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue