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()
|
||||||
discard self.pop()
|
discard self.pop()
|
||||||
of ReplExit:
|
of ReplExit:
|
||||||
|
# Preserves the VM's state for the next
|
||||||
|
# execution. Used in the REPL
|
||||||
return
|
return
|
||||||
of Return:
|
of Return:
|
||||||
# Returns from a function.
|
# 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())))
|
self.push(self.getBool(cast[float32](self.pop()) !>= cast[float32](self.pop())))
|
||||||
of Float32LessOrEqual:
|
of Float32LessOrEqual:
|
||||||
self.push(self.getBool(cast[float32](self.pop()) <= cast[float32](self.pop())))
|
self.push(self.getBool(cast[float32](self.pop()) <= cast[float32](self.pop())))
|
||||||
|
of Identity:
|
||||||
|
self.push(cast[uint64](self.pop() == self.pop()))
|
||||||
# Print opcodes
|
# Print opcodes
|
||||||
of PrintInt64:
|
of PrintInt64:
|
||||||
echo cast[int64](self.pop())
|
echo cast[int64](self.pop())
|
||||||
|
|
|
@ -136,6 +136,7 @@ type
|
||||||
Float32GreaterOrEqual,
|
Float32GreaterOrEqual,
|
||||||
Float32LessOrEqual,
|
Float32LessOrEqual,
|
||||||
LogicalNot,
|
LogicalNot,
|
||||||
|
Identity, # Pointer equality
|
||||||
## Print opcodes
|
## Print opcodes
|
||||||
PrintInt64,
|
PrintInt64,
|
||||||
PrintUInt64,
|
PrintUInt64,
|
||||||
|
@ -270,7 +271,8 @@ const simpleInstructions* = {Return, LoadNil,
|
||||||
Float32GreaterOrEqual,
|
Float32GreaterOrEqual,
|
||||||
Float32LessOrEqual,
|
Float32LessOrEqual,
|
||||||
DupTop,
|
DupTop,
|
||||||
ReplExit
|
ReplExit,
|
||||||
|
Identity
|
||||||
}
|
}
|
||||||
|
|
||||||
# Constant instructions are instructions that operate on the bytecode constant table
|
# 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,
|
"PrintString": PrintString,
|
||||||
"SysClock64": SysClock64,
|
"SysClock64": SysClock64,
|
||||||
"LogicalNot": LogicalNot,
|
"LogicalNot": LogicalNot,
|
||||||
"NegInf": LoadNInf
|
"NegInf": LoadNInf,
|
||||||
|
"Identity": Identity
|
||||||
}.to_table()
|
}.to_table()
|
||||||
if fn.builtinOp == "print":
|
if fn.builtinOp == "print":
|
||||||
let typ = self.inferOrError(args[0])
|
let typ = self.inferOrError(args[0])
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
import values;
|
import values;
|
||||||
|
|
||||||
|
|
||||||
|
operator `is`*[T: any](a, b: T): bool {
|
||||||
|
#pragma[magic: "Identity", pure]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
operator `>`*[T: UnsignedInteger](a, b: T): bool {
|
operator `>`*[T: UnsignedInteger](a, b: T): bool {
|
||||||
#pragma[magic: "GreaterThan", pure]
|
#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]
|
#pragma[magic: "Equal", pure]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue