move to test folder and fix import bug in shell

This commit is contained in:
2023-03-20 00:17:43 +00:00
parent b56c1fc485
commit 4a320008b2
9 changed files with 37 additions and 8 deletions

View File

@@ -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()

View File

@@ -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{

View File

@@ -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

View File

@@ -1,3 +0,0 @@
import "csv" as csv
term.log(csv.read("test.csv"))

3
tests/test.ar Normal file
View File

@@ -0,0 +1,3 @@
import "csv" as csv
term.log(csv.read("tests/test.csv"))

14
tests/thread.ar Normal file
View File

@@ -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")