mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
make wasm work
This commit is contained in:
10
src/array.go
10
src/array.go
@@ -351,7 +351,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
return runCall(call{
|
return runCall(call{
|
||||||
args[1],
|
args[1],
|
||||||
[]any{a}, "", 0, "",
|
[]any{a}, "", 0, "",
|
||||||
}, stack{vars, newscope()}, 0)
|
}, stack{}, 0)
|
||||||
})
|
})
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -400,7 +400,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
vv, err := runCall(call{
|
vv, err := runCall(call{
|
||||||
args[0],
|
args[0],
|
||||||
[]any{v}, "", 0, "",
|
[]any{v}, "", 0, "",
|
||||||
}, stack{vars, newscope()}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -431,7 +431,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
vv, err := runCall(call{
|
vv, err := runCall(call{
|
||||||
args[0],
|
args[0],
|
||||||
[]any{v}, "", 0, "",
|
[]any{v}, "", 0, "",
|
||||||
}, stack{vars, newscope()}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -448,7 +448,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "TypeError",
|
||||||
message: "missing argument",
|
message: "missing argument, expected 2 got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -472,7 +472,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
v, err = runCall(call{
|
v, err = runCall(call{
|
||||||
args[0],
|
args[0],
|
||||||
[]any{v, vv}, "", 0, "",
|
[]any{v, vv}, "", 0, "",
|
||||||
}, stack{vars, newscope()}, 0)
|
}, stack{}, 0)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package main
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
func makeGlobal() ArObject {
|
||||||
var vars = Map(anymap{})
|
var vars = Map(anymap{})
|
||||||
|
|
||||||
func init() {
|
|
||||||
vars.obj["global"] = vars
|
vars.obj["global"] = vars
|
||||||
vars.obj["term"] = ArTerm
|
vars.obj["term"] = ArTerm
|
||||||
vars.obj["number"] = builtinFunc{"number", ArgonNumber}
|
vars.obj["number"] = builtinFunc{"number", ArgonNumber}
|
||||||
@@ -150,4 +149,5 @@ func init() {
|
|||||||
return ArArray([]any{}), ArErr{}
|
return ArArray([]any{}), ArErr{}
|
||||||
}}
|
}}
|
||||||
vars.obj["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
vars.obj["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
||||||
|
return vars
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/garbageCollect.go
Normal file
15
src/garbageCollect.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func garbageCollect() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
runtime.GC()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ func readFile(path string) []UNPARSEcode {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func importMod(realpath string, origin string, main bool) (ArObject, ArErr) {
|
func importMod(realpath string, origin string, main bool, global ArObject) (ArObject, ArErr) {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "Import Error",
|
TYPE: "Import Error",
|
||||||
message: "importing in WASM is currently not supported",
|
message: "importing in WASM is currently not supported",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func newscope() ArObject {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := make(chan ArObject)
|
c := make(chan ArObject)
|
||||||
|
garbageCollect()
|
||||||
obj := js.Global().Get("Object").New()
|
obj := js.Global().Get("Object").New()
|
||||||
obj.Set("eval", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
obj.Set("eval", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||||
code := ""
|
code := ""
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func runImport(importOBJ ArImport, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, ArErr{"File Error", "could not get current working directory", importOBJ.line, importOBJ.path, importOBJ.code, true}
|
return nil, ArErr{"File Error", "could not get current working directory", importOBJ.line, importOBJ.path, importOBJ.code, true}
|
||||||
}
|
}
|
||||||
stackMap, err := importMod(path, ex, false)
|
stackMap, err := importMod(path, ex, false, stack[0])
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
if err.line == 0 {
|
if err.line == 0 {
|
||||||
err.line = importOBJ.line
|
err.line = importOBJ.line
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ var ArRandom = Map(anymap{
|
|||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|
||||||
func init() {
|
func initRandom() {
|
||||||
rand.Seed(
|
rand.Seed(
|
||||||
time.Now().UnixMicro(),
|
time.Now().UnixMicro(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func shell() {
|
func shell(global ArObject) {
|
||||||
global := stack{vars, newscope()}
|
stack := stack{global, newscope()}
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -41,7 +41,7 @@ func shell() {
|
|||||||
if translationerr.EXISTS {
|
if translationerr.EXISTS {
|
||||||
panicErr(translationerr)
|
panicErr(translationerr)
|
||||||
}
|
}
|
||||||
output, runimeErr := ThrowOnNonLoop(run(translated, global))
|
output, runimeErr := ThrowOnNonLoop(run(translated, stack))
|
||||||
output = openReturn(output)
|
output = openReturn(output)
|
||||||
|
|
||||||
if runimeErr.EXISTS {
|
if runimeErr.EXISTS {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func ArThread(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
var resp any
|
var resp any
|
||||||
var err ArErr
|
var err ArErr
|
||||||
currentscope := stack{vars, newscope()}
|
|
||||||
hasrun := false
|
hasrun := false
|
||||||
joined := false
|
joined := false
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@@ -38,7 +38,7 @@ func ArThread(args ...any) (any, ArErr) {
|
|||||||
hasrun = true
|
hasrun = true
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
resp, err = runCall(call{tocall, []any{}, "", 0, ""}, currentscope, 0)
|
resp, err = runCall(call{tocall, []any{}, "", 0, ""}, nil, 0)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isnot(code) {
|
}
|
||||||
|
if isnot(code) {
|
||||||
return parseNot(code, index, codelines, isLine)
|
return parseNot(code, index, codelines, isLine)
|
||||||
}
|
}
|
||||||
if isSetVariable(code) {
|
if isSetVariable(code) {
|
||||||
@@ -75,7 +76,8 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isNumber(code) {
|
}
|
||||||
|
if isNumber(code) {
|
||||||
return parseNumber(code)
|
return parseNumber(code)
|
||||||
} else if isNegative(code) {
|
} else if isNegative(code) {
|
||||||
return parseNegative(code, index, codelines)
|
return parseNegative(code, index, codelines)
|
||||||
@@ -85,21 +87,26 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
return parseSquareroot(code, index, codelines)
|
return parseSquareroot(code, index, codelines)
|
||||||
} else if isFactorial(code) {
|
} else if isFactorial(code) {
|
||||||
return parseFactorial(code, index, codelines)
|
return parseFactorial(code, index, codelines)
|
||||||
} else if isCall(code) {
|
}
|
||||||
|
if isCall(code) {
|
||||||
resp, worked, err, i = parseCall(code, index, codelines)
|
resp, worked, err, i = parseCall(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isVariable(code) {
|
}
|
||||||
|
if isVariable(code) {
|
||||||
return parseVariable(code)
|
return parseVariable(code)
|
||||||
} else if isArray(code) {
|
}
|
||||||
|
if isArray(code) {
|
||||||
resp, worked, err, i = parseArray(code, index, codelines)
|
resp, worked, err, i = parseArray(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isMapGet(code) {
|
}
|
||||||
|
if isMapGet(code) {
|
||||||
return mapGetParse(code, index, codelines)
|
return mapGetParse(code, index, codelines)
|
||||||
} else if isIndexGet(code) {
|
}
|
||||||
|
if isIndexGet(code) {
|
||||||
resp, worked, err, i = indexGetParse(code, index, codelines)
|
resp, worked, err, i = indexGetParse(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
|
|||||||
8
tests/memoryLeakTest.ar
Normal file
8
tests/memoryLeakTest.ar
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
f() = do
|
||||||
|
a = []
|
||||||
|
for (i from 0 to 10000000) a.append(i)
|
||||||
|
|
||||||
|
term.log("start")
|
||||||
|
f()
|
||||||
|
term.log("end")
|
||||||
|
time.snooze(100000000)
|
||||||
Reference in New Issue
Block a user