From 23a9a443d60ca574495c5f3ed136272a5197a78c Mon Sep 17 00:00:00 2001 From: William Bell Date: Sat, 9 Mar 2024 15:11:56 +0000 Subject: [PATCH] add byte object --- src/built-ins.go | 6 ++++++ tests/chatbot code.ar | 20 ++++++++++++++++++++ tests/rng.ar | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 tests/chatbot code.ar create mode 100644 tests/rng.ar diff --git a/src/built-ins.go b/src/built-ins.go index bf0a5ec..5e51e0e 100644 --- a/src/built-ins.go +++ b/src/built-ins.go @@ -79,6 +79,12 @@ func makeGlobal() ArObject { } return ArBuffer([]byte{}), ArErr{} }} + vars["byte"] = builtinFunc{"byte", func(a ...any) (any, ArErr) { + if len(a) != 0 { + return nil, ArErr{TYPE: "TypeError", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true} + } + return ArByte(0), ArErr{} + }} vars["throwError"] = builtinFunc{"throwError", ArThrowError} vars["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) { if len(a) == 0 { diff --git a/tests/chatbot code.ar b/tests/chatbot code.ar new file mode 100644 index 0000000..1361617 --- /dev/null +++ b/tests/chatbot code.ar @@ -0,0 +1,20 @@ +# This is a comment + +term.log("Hello World!") # Printing to console/output + +value = "Hello" # Declaring a variable + +do # Start of indented block + combined = value + " World!" + term.log(combined) + +loop = true # Using true condition + +while (loop) do # While loop syntax + term.log("Looping...") + loop = false # Using false condition + +if (value == "Hello") do # If statement syntax + term.log("The value is Hello") +else do # else block + term.log("The value is not Hello") \ No newline at end of file diff --git a/tests/rng.ar b/tests/rng.ar new file mode 100644 index 0000000..265b901 --- /dev/null +++ b/tests/rng.ar @@ -0,0 +1,2 @@ +forever do + term.log(random()) \ No newline at end of file