Add null literal
This commit is contained in:
@@ -155,6 +155,9 @@ func (c *Compiler) Compile(node ast.Node) error {
|
||||
integer := &object.Integer{Value: node.Value}
|
||||
c.emit(code.OpConstant, c.addConstant(integer))
|
||||
|
||||
case *ast.Null:
|
||||
c.emit(code.OpNull)
|
||||
|
||||
case *ast.Boolean:
|
||||
if node.Value {
|
||||
c.emit(code.OpTrue)
|
||||
|
||||
@@ -100,6 +100,14 @@ func TestBooleanExpressions(t *testing.T) {
|
||||
code.Make(code.OpPop),
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "null",
|
||||
expectedConstants: []interface{}{},
|
||||
expectedInstructions: []code.Instructions{
|
||||
code.Make(code.OpNull),
|
||||
code.Make(code.OpPop),
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "1 > 2",
|
||||
expectedConstants: []interface{}{1, 2},
|
||||
|
||||
Reference in New Issue
Block a user