Null my old friend

This commit is contained in:
Chuck Smith
2024-02-07 16:02:06 -05:00
parent 77401260a2
commit 6ba2d3abe4
5 changed files with 42 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ import (
const StackSize = 2048
var Null = &object.Null{}
var True = &object.Boolean{Value: true}
var False = &object.Boolean{Value: false}
@@ -99,6 +100,12 @@ func (vm *VM) Run() error {
if !isTruthy(condition) {
ip = pos - 1
}
case code.OpNull:
err := vm.push(Null)
if err != nil {
return err
}
}
}
@@ -111,6 +118,9 @@ func isTruthy(obj object.Object) bool {
case *object.Boolean:
return obj.Value
case *object.Null:
return false
default:
return true
}
@@ -211,6 +221,8 @@ func (vm *VM) executeBangOperator() error {
return vm.push(False)
case False:
return vm.push(True)
case Null:
return vm.push(True)
default:
return vm.push(False)
}