Skip to content

Commit

Permalink
add exit() builtin
Browse files Browse the repository at this point in the history
Signed-off-by: Flipez <code@brauser.io>
  • Loading branch information
Flipez committed Sep 29, 2021
1 parent b45f87a commit 09ad1b5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions evaluator/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evaluator
import (
"fmt"
"github.com/flipez/rocket-lang/object"
"os"
)

var builtins = map[string]*object.Builtin{
Expand Down Expand Up @@ -125,6 +126,20 @@ var builtins = map[string]*object.Builtin{
fmt.Println(arg.Inspect())
}

return NULL
},
},
"exit": &object.Builtin{
Fn: func(args ...object.Object) object.Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1", len(args))
}
if args[0].Type() != object.INTEGER_OBJ {
return newError("argument to `exit` must be INTEGER, got=%s", args[0].Type())
}

os.Exit(int(args[0].(*object.Integer).Value))

return NULL
},
},
Expand Down

0 comments on commit 09ad1b5

Please sign in to comment.