From 4a320008b2ca86e6507ade68d896240ba884f475 Mon Sep 17 00:00:00 2001 From: Ugric Date: Mon, 20 Mar 2023 00:17:43 +0000 Subject: [PATCH] move to test folder and fix import bug in shell --- src/import.go | 6 +++++- src/run.go | 4 +++- src/thread.go | 15 ++++++++++++--- test.ar | 3 --- example.ar => tests/example.ar | 0 makerandom.ar => tests/makerandom.ar | 0 tests/test.ar | 3 +++ test.csv => tests/test.csv | 0 tests/thread.ar | 14 ++++++++++++++ 9 files changed, 37 insertions(+), 8 deletions(-) delete mode 100644 test.ar rename example.ar => tests/example.ar (100%) rename makerandom.ar => tests/makerandom.ar (100%) create mode 100644 tests/test.ar rename test.csv => tests/test.csv (100%) create mode 100644 tests/thread.ar diff --git a/src/import.go b/src/import.go index 9997141..385fe8d 100644 --- a/src/import.go +++ b/src/import.go @@ -107,7 +107,11 @@ func importMod(realpath string, origin string, main bool) (ArObject, ArErr) { return ArObject{}, translationerr } ArgsArArray := []any{} - for _, arg := range Args[1:] { + withoutarfile := []string{} + if len(Args) > 1 { + withoutarfile = Args[1:] + } + for _, arg := range withoutarfile { ArgsArArray = append(ArgsArArray, arg) } global := newscope() diff --git a/src/run.go b/src/run.go index 2832743..00658ae 100644 --- a/src/run.go +++ b/src/run.go @@ -194,7 +194,9 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) { case bool: return x, ArErr{} case nil: - return nil, ArErr{} + return x, ArErr{} + case ArObject: + return x, ArErr{} } if stackoverflow { return nil, ArErr{ diff --git a/src/thread.go b/src/thread.go index df13d6b..0b73e2b 100644 --- a/src/thread.go +++ b/src/thread.go @@ -1,10 +1,13 @@ package main -import "sync" +import ( + "fmt" + "sync" +) func ArThread(args ...any) (any, ArErr) { - if len(args) == 0 { - return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread without a function", EXISTS: true} + if len(args) != 1 { + return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true} } var tocall any switch x := args[0].(type) { @@ -26,6 +29,9 @@ func ArThread(args ...any) (any, ArErr) { if hasrun { return nil, ArErr{TYPE: "Runtime Error", message: "Cannot start a thread twice", EXISTS: true} } + if len(args) != 0 { + return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true} + } hasrun = true wg.Add(1) go func() { @@ -40,6 +46,9 @@ func ArThread(args ...any) (any, ArErr) { } else if joined { return nil, ArErr{TYPE: "Runtime Error", message: "Cannot join a thread twice", EXISTS: true} } + if len(args) != 0 { + return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true} + } joined = true wg.Wait() return resp, err diff --git a/test.ar b/test.ar deleted file mode 100644 index 378fbf8..0000000 --- a/test.ar +++ /dev/null @@ -1,3 +0,0 @@ -import "csv" as csv - -term.log(csv.read("test.csv")) \ No newline at end of file diff --git a/example.ar b/tests/example.ar similarity index 100% rename from example.ar rename to tests/example.ar diff --git a/makerandom.ar b/tests/makerandom.ar similarity index 100% rename from makerandom.ar rename to tests/makerandom.ar diff --git a/tests/test.ar b/tests/test.ar new file mode 100644 index 0000000..ba68519 --- /dev/null +++ b/tests/test.ar @@ -0,0 +1,3 @@ +import "csv" as csv + +term.log(csv.read("tests/test.csv")) \ No newline at end of file diff --git a/test.csv b/tests/test.csv similarity index 100% rename from test.csv rename to tests/test.csv diff --git a/tests/thread.ar b/tests/thread.ar new file mode 100644 index 0000000..d282f4e --- /dev/null +++ b/tests/thread.ar @@ -0,0 +1,14 @@ +f() = do + term.log("Hello, world!") + term.time("threaded function") + for (i from 0 to 1000000) do + if (i % 100000 == 0) do + term.log("i = " + i) + term.timeEnd("threaded function") + term.log("Goodbye, world!") + +t = thread(f) +t.start() +term.time("main thread") +t.join() +term.timeEnd("main thread") \ No newline at end of file