type checking and error handling for builtins improved.
Some checks failed
Build / build (push) Successful in 11m16s
Test / build (push) Failing after 17m0s

This commit is contained in:
Chuck Smith
2024-03-25 16:18:08 -04:00
parent 1c99d2198b
commit 6d234099d1
52 changed files with 650 additions and 433 deletions

View File

@@ -1,6 +1,9 @@
package builtins
import "monkey/object"
import (
"monkey/object"
"monkey/typing"
)
import (
"bufio"
@@ -11,15 +14,17 @@ import (
// Input ...
func Input(args ...object.Object) object.Object {
if len(args) > 0 {
obj, ok := args[0].(*object.String)
if !ok {
return newError(
"argument to `input` not supported, got %s",
args[0].Type(),
)
}
fmt.Fprintf(os.Stdout, obj.Value)
if err := typing.Check(
"input", args,
typing.RangeOfArgs(0, 1),
typing.WithTypes(object.STRING_OBJ),
); err != nil {
return newError(err.Error())
}
if len(args) == 1 {
prompt := args[0].(*object.String).Value
fmt.Fprintf(os.Stdout, prompt)
}
buffer := bufio.NewReader(os.Stdin)