mirror of
https://github.com/Open-Argon/argon-v2.git
synced 2026-10-28 09:44:03 +00:00
fix bug when calling function from another module/file and add indexing
This commit is contained in:
1 parent
1cb3e37e47
commit
142dbe5812
13 files changed
+337
-225
No files matched your search
@@ -36,7 +36,7 @@ func main() {
|
||||
if len(os.Args) == 1 {
|
||||
shell()
|
||||
} else {
|
||||
_, err := importMod(os.Args[1], ex)
|
||||
_, err := importMod(os.Args[1], ex, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
import 'maths'
|
||||
import maths
|
||||
@@ -1,10 +1,8 @@
|
||||
# constants
|
||||
# a sub library of maths
|
||||
|
||||
from 'functions' import sqrt
|
||||
|
||||
pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
|
||||
|
||||
e = 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931277361782154249992295763514822082698951936680331825288693984964651058209392398294887933203625094431173012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509961818815930416903515988885193458072738667385894228792284998920868058257492796104841984443634632449684875602336248270419786232090021609902353043699418491463140934317381436405462531520961836908887070167683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354
|
||||
|
||||
goldenRatio = (1 + sqrt(5)) / 2
|
||||
goldenRatio = (1 + (5 to the power of .5)) / 2
|
||||
@@ -1,6 +1,8 @@
|
||||
# functions
|
||||
# a sub library of maths
|
||||
|
||||
from constants import e
|
||||
|
||||
sub factorial(num) [
|
||||
num = whole(num)
|
||||
answer = 1
|
||||
|
||||
@@ -34,18 +34,18 @@
|
||||
|
||||
# trigonometry
|
||||
|
||||
import 'trigonometry'
|
||||
import trigonometry
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# math functions
|
||||
|
||||
import 'functions'
|
||||
import functions
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# initialize math numbers
|
||||
|
||||
import 'constants'
|
||||
import constants
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
@@ -1,13 +1,14 @@
|
||||
# trigonometry
|
||||
# a sub library of maths
|
||||
|
||||
from 'functions' import abs, sqrt, mod
|
||||
from functions import abs, sqrt, mod
|
||||
from constants import pi
|
||||
|
||||
# trigonometry
|
||||
|
||||
sub sin(theta) [
|
||||
result = -(mod(theta divided by 180, 1) minus .5) to the power of 2 times 4 plus 1
|
||||
if ((theta div 180) div 1) mod 2 is not equal to 0 [
|
||||
if theta div 180 div 1 mod 2 is not equal to 0 [
|
||||
result = result times -1
|
||||
]
|
||||
return result
|
||||
@@ -31,6 +32,11 @@ sub acos(result) [
|
||||
return asin(result) - 90
|
||||
]
|
||||
|
||||
# make a inverse tan function
|
||||
# e.g. atan(tan(x)) = x
|
||||
# use asin and acos to get theta
|
||||
# use tan to get result
|
||||
|
||||
sub atan(result) [
|
||||
return
|
||||
return asin(result*acos(result))
|
||||
]
|
||||
+26
-4
@@ -8,12 +8,11 @@ type opperator struct {
|
||||
|
||||
type variable struct {
|
||||
variable string
|
||||
splices []any
|
||||
line int
|
||||
}
|
||||
|
||||
type funcCallType struct {
|
||||
name variable
|
||||
FUNC any
|
||||
args []any
|
||||
line int
|
||||
}
|
||||
@@ -56,8 +55,7 @@ type setVariable struct {
|
||||
|
||||
type setFunction struct {
|
||||
name string
|
||||
args []string
|
||||
code []any
|
||||
FUNC callableFunction
|
||||
line int
|
||||
}
|
||||
|
||||
@@ -88,3 +86,27 @@ type tryType struct {
|
||||
type errorType struct {
|
||||
val any
|
||||
}
|
||||
|
||||
type deleteType struct {
|
||||
variable variable
|
||||
line int
|
||||
}
|
||||
|
||||
type builtinFunc struct {
|
||||
name string
|
||||
FUNC func(...any) (any, any)
|
||||
}
|
||||
|
||||
type callableFunction struct {
|
||||
name any
|
||||
args []string
|
||||
code []any
|
||||
vargroups []map[string]variableValue
|
||||
line int
|
||||
}
|
||||
|
||||
type indexType struct {
|
||||
to any
|
||||
index any
|
||||
line int
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
client
|
||||
proto udp
|
||||
explicit-exit-notify
|
||||
remote 212.71.237.189 60005
|
||||
dev tun
|
||||
resolv-retry infinite
|
||||
nobind
|
||||
persist-key
|
||||
persist-tun
|
||||
remote-cert-tls server
|
||||
verify-x509-name server_wnJuJy53oNsHdwUB name
|
||||
auth SHA256
|
||||
auth-nocache
|
||||
cipher AES-128-GCM
|
||||
tls-client
|
||||
tls-version-min 1.2
|
||||
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
|
||||
ignore-unknown-option block-outside-dns
|
||||
setenv opt block-outside-dns # Prevent Windows 10 DNS leak
|
||||
verb 3
|
||||
<ca>
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIB1zCCAX2gAwIBAgIUb8tI/ox5s8DPwc13FER4ckU0yFQwCgYIKoZIzj0EAwIw
|
||||
HjEcMBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJSE1qSzAeFw0yMjAzMDcwOTU3MjZa
|
||||
Fw0zMjAzMDQwOTU3MjZaMB4xHDAaBgNVBAMME2NuX2N1S3lGOThnT2FJSUhNaksw
|
||||
WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARC7zM+9KYCZIVXl7i38BCK62wYu8W4
|
||||
LrTFpFOK7DI7uaFcT544rEzDQIz3JY2HYMxN+nOtOybxfioHkZtvUUkao4GYMIGV
|
||||
MB0GA1UdDgQWBBSj9j7NNN2V1z2MvYTkeRGGDLsndjBZBgNVHSMEUjBQgBSj9j7N
|
||||
NN2V1z2MvYTkeRGGDLsndqEipCAwHjEcMBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJ
|
||||
SE1qS4IUb8tI/ox5s8DPwc13FER4ckU0yFQwDAYDVR0TBAUwAwEB/zALBgNVHQ8E
|
||||
BAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANXx1cZ+WhaXaya/I0Z+XRm3oMq6Jx3W
|
||||
A65DUw4GKAOJAiBnL44bRCoA74kU755wau0i4IThZC5QLNoY4CJ82CaooQ==
|
||||
-----END CERTIFICATE-----
|
||||
</ca>
|
||||
<cert>
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIB4DCCAYWgAwIBAgIRALja307VuXV/gGvUkGElDBkwCgYIKoZIzj0EAwIwHjEc
|
||||
MBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJSE1qSzAeFw0yMjA2MjkxNjU0MzZaFw0y
|
||||
NDEwMDExNjU0MzZaMBcxFTATBgNVBAMMDGdlb3JnZS1waG9uZTBZMBMGByqGSM49
|
||||
AgEGCCqGSM49AwEHA0IABCslkMIcIiB5E7FaC3dTC7/iapKI9bexr9NahwMjd7aS
|
||||
L/G4zlh+JCIH8A65y1DCzCazlJ3bYX7Rja9iXx2mRWCjgaowgacwCQYDVR0TBAIw
|
||||
ADAdBgNVHQ4EFgQUiilqCz4C01AgMbX+j3GRkK6oOfswWQYDVR0jBFIwUIAUo/Y+
|
||||
zTTdldc9jL2E5HkRhgy7J3ahIqQgMB4xHDAaBgNVBAMME2NuX2N1S3lGOThnT2FJ
|
||||
SUhNakuCFG/LSP6MebPAz8HNdxREeHJFNMhUMBMGA1UdJQQMMAoGCCsGAQUFBwMC
|
||||
MAsGA1UdDwQEAwIHgDAKBggqhkjOPQQDAgNJADBGAiEAjrzNh3gFr1EGIcVwzvwH
|
||||
lWswm8KkIPLHuuQZisqGBokCIQDX4FGUbyDbXmVVD4W5zU9mCQ5Qj37IlEpUMFcM
|
||||
1Ey1lQ==
|
||||
-----END CERTIFICATE-----
|
||||
</cert>
|
||||
<key>
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg1lNu8HVoPPre6s9G
|
||||
/mRZ8uIEFCweqCzVThUPioXHaVehRANCAAQrJZDCHCIgeROxWgt3Uwu/4mqSiPW3
|
||||
sa/TWocDI3e2ki/xuM5YfiQiB/AOuctQwswms5Sd22F+0Y2vYl8dpkVg
|
||||
-----END PRIVATE KEY-----
|
||||
</key>
|
||||
<tls-crypt>
|
||||
#
|
||||
# 2048 bit OpenVPN static key
|
||||
#
|
||||
-----BEGIN OpenVPN Static key V1-----
|
||||
b827cd4cb18dc59de1bbd785f513de31
|
||||
fa2b3bb1d916892b06c2284f139d09d4
|
||||
6c034d7aeb5f30401a28dce36ded937c
|
||||
9ed60e0f6c07f577776a72fc6e1d9902
|
||||
7ff102bf78d43c8600e9a26498ccddbb
|
||||
e54e7cabc1963cc18df35a4237944094
|
||||
ceec82ecb6d221bd528b6d49c07ed3b9
|
||||
689892c542e517a37679cf685bca2638
|
||||
34db373071aaf06416704287a8ed0ae8
|
||||
1b893b82f6b2a595f9be96148b03e141
|
||||
16b683216a8c83c6001eef69a9bff581
|
||||
10e38b20deae2337ea3a3ce1e5562146
|
||||
aa4263b7fc79b7fb2dd23ea5d6bac5cf
|
||||
ee0e70e23097a56244c5bbbf3c91a1f2
|
||||
c7be0a74cf6b31a5032f2d24cdffeaba
|
||||
4daa8b7f124018cc946b8cca0d07844b
|
||||
-----END OpenVPN Static key V1-----
|
||||
</tls-crypt>
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
from 'maths/trigonometry' import tan, atan
|
||||
var input = input('text: ')
|
||||
|
||||
x = tan(19)
|
||||
y = atan(x)
|
||||
log(x, tan(y), y)
|
||||
i = 0
|
||||
while i < len(input) [
|
||||
log(input[i])
|
||||
i = i + 1
|
||||
]
|
||||
@@ -15,8 +15,9 @@ func FileExists(filename string) bool {
|
||||
}
|
||||
|
||||
var modules = map[string](map[string]variableValue){}
|
||||
var importing = map[string]any{}
|
||||
|
||||
func importMod(realpath string, origin string) (map[string]variableValue, any) {
|
||||
func importMod(realpath string, origin string, main bool) (map[string]variableValue, any) {
|
||||
extention := filepath.Ext(realpath)
|
||||
path := realpath
|
||||
if extention == "" {
|
||||
@@ -24,11 +25,11 @@ func importMod(realpath string, origin string) (map[string]variableValue, any) {
|
||||
}
|
||||
ex, err := os.Getwd()
|
||||
if err != nil {
|
||||
return map[string]variableValue{}, err
|
||||
return nil, err
|
||||
}
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
return map[string]variableValue{}, err
|
||||
return nil, err
|
||||
}
|
||||
executable = filepath.Dir(executable)
|
||||
pathsToTest := []string{filepath.Join(origin, realpath, "init.ar"), filepath.Join(origin, path), filepath.Join(origin, "modules", path), filepath.Join(origin, "modules", realpath, "init.ar"), filepath.Join(ex, path), filepath.Join(ex, "modules", realpath, "init.ar"), filepath.Join(ex, "modules", path), filepath.Join(executable, "modules", realpath, "init.ar"), filepath.Join(executable, "modules", path)}
|
||||
@@ -38,29 +39,48 @@ func importMod(realpath string, origin string) (map[string]variableValue, any) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if modules[p] == nil {
|
||||
if importing[p] == true {
|
||||
return nil, fmt.Sprint("Recursive import of ", p, " detected.\n\nHow to fix?\nCurrently this error cannot be pin pointed by Argons error detection, but this can be caused by a circular import or by a module that imports itself. Check .ar files inside ", origin, " for circular imports, or maybe this is an issue with one of the libaries used in the project so maybe get in contact with the library author.")
|
||||
} else if importing[p] == nil {
|
||||
importing[p] = true
|
||||
modules[p] = map[string]variableValue{}
|
||||
data, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
return map[string]variableValue{}, err
|
||||
return nil, err
|
||||
}
|
||||
stringdata := string(data)
|
||||
moduledata := modules[p]
|
||||
if main {
|
||||
vars["__main__"] = variableValue{
|
||||
TYPE: "const",
|
||||
VAL: p,
|
||||
EXISTS: true,
|
||||
origin: p,
|
||||
FUNC: false,
|
||||
}
|
||||
}
|
||||
_, e := runStr(stringdata, p, moduledata)
|
||||
if e != nil {
|
||||
return map[string]variableValue{}, e
|
||||
return nil, e
|
||||
}
|
||||
importing[p] = false
|
||||
}
|
||||
return modules[p], nil
|
||||
}
|
||||
|
||||
func runStr(str string, origin string, variables map[string]variableValue) ([][]any, any) {
|
||||
translated, err := translate(str)
|
||||
fmt.Println(origin, ":", translated)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ty, _, resp := run(translated, origin, []map[string]variableValue{vars, variables})
|
||||
fileparams := map[string]variableValue{"__file__": {
|
||||
TYPE: "const",
|
||||
VAL: origin,
|
||||
EXISTS: true,
|
||||
origin: origin,
|
||||
FUNC: false,
|
||||
}}
|
||||
ty, _, resp := run(translated, origin, []map[string]variableValue{vars, fileparams, variables})
|
||||
if ty != nil {
|
||||
if ty == "error" {
|
||||
return nil, resp[len(resp)-1][0]
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -61,8 +60,14 @@ func anyToArgon(x any, quote bool) string {
|
||||
output = append(output, anyToArgon(x[i], true))
|
||||
}
|
||||
return "[" + strings.Join(output, ", ") + "]"
|
||||
case variable:
|
||||
return "<function " + x.variable + ">"
|
||||
case builtinFunc:
|
||||
return fmt.Sprint("<function ", x.name, ">")
|
||||
case callableFunction:
|
||||
if x.name != nil {
|
||||
return fmt.Sprint("<function ", x.name, ">")
|
||||
} else {
|
||||
return "<anonymous function>"
|
||||
}
|
||||
default:
|
||||
return fmt.Sprint(x)
|
||||
}
|
||||
@@ -86,11 +91,7 @@ func runprocess(codeseg any, origin string, vargroups []map[string]variableValue
|
||||
myvar = vargroups[len(vargroups)-1][codeseg.variable]
|
||||
}
|
||||
if myvar.EXISTS != nil {
|
||||
if myvar.TYPE != "func" && myvar.TYPE != "init_function" {
|
||||
return myvar.VAL, "value"
|
||||
} else {
|
||||
return codeseg, "value"
|
||||
}
|
||||
return myvar.VAL, "value"
|
||||
}
|
||||
return ("undecared variable " + codeseg.variable + ": " + origin + ":" + fmt.Sprint(codeseg.line+1)), "error"
|
||||
case funcCallType:
|
||||
@@ -164,7 +165,7 @@ func runprocess(codeseg any, origin string, vargroups []map[string]variableValue
|
||||
if ty == "error" {
|
||||
return resp, ty
|
||||
}
|
||||
importvars, err := importMod(resp.(string), filepath.Dir(origin))
|
||||
importvars, err := importMod(fmt.Sprint(resp), filepath.Dir(origin), false)
|
||||
if err != nil {
|
||||
return err, "error"
|
||||
}
|
||||
@@ -193,16 +194,79 @@ func runprocess(codeseg any, origin string, vargroups []map[string]variableValue
|
||||
} else {
|
||||
return value, "error"
|
||||
}
|
||||
case indexType:
|
||||
to, ty := runop(codeseg.to, origin, vargroups)
|
||||
if ty == "error" {
|
||||
return to, ty
|
||||
}
|
||||
|
||||
index, ty := runop(codeseg.index, origin, vargroups)
|
||||
if ty == "error" {
|
||||
return to, ty
|
||||
}
|
||||
switch value := to.(type) {
|
||||
case string:
|
||||
index, err := number(index)
|
||||
if err != nil {
|
||||
return err, "error"
|
||||
}
|
||||
i := int(index)
|
||||
if i >= len(value) {
|
||||
return "index out of range on line " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
|
||||
} else if i < 0 {
|
||||
i = len(value) + i
|
||||
}
|
||||
return string(value[i]), "value"
|
||||
case []any:
|
||||
index, err := number(index)
|
||||
if err != nil {
|
||||
return err, "error"
|
||||
}
|
||||
i := int(index)
|
||||
if i >= len(value) {
|
||||
return "index out of range on line " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
|
||||
} else if i < 0 {
|
||||
i = len(value) + i
|
||||
}
|
||||
return value[i], "value"
|
||||
case map[string]any:
|
||||
key := fmt.Sprint(index)
|
||||
if value[key] == nil {
|
||||
return "'" + key + "' not in value on line " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
|
||||
}
|
||||
return value[key], "value"
|
||||
default:
|
||||
return "value not indexable " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
|
||||
}
|
||||
case returnType:
|
||||
var val any = nil
|
||||
var ty any = "return"
|
||||
if codeseg.val != nil {
|
||||
vars, worked := runop(codeseg.val, origin, vargroups)
|
||||
if worked == nil {
|
||||
return "return statement must return a value: " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
|
||||
} else if worked == "error" {
|
||||
return vars, "error"
|
||||
}
|
||||
val = vars
|
||||
}
|
||||
return val, "return"
|
||||
return val, ty
|
||||
case deleteType:
|
||||
var varigroup map[string]variableValue
|
||||
for i := len(vargroups) - 1; i >= 0; i-- {
|
||||
if vargroups[i][codeseg.variable.variable].EXISTS != nil {
|
||||
varigroup = vargroups[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if varigroup[codeseg.variable.variable].EXISTS == nil {
|
||||
varigroup = vargroups[len(vargroups)-1]
|
||||
}
|
||||
if varigroup[codeseg.variable.variable].EXISTS != nil {
|
||||
delete(varigroup, codeseg.variable.variable)
|
||||
return nil, nil
|
||||
}
|
||||
return "undeclared variable " + codeseg.variable.variable + ": " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
|
||||
case breakType:
|
||||
return nil, "break"
|
||||
case continueType:
|
||||
@@ -212,53 +276,24 @@ func runprocess(codeseg any, origin string, vargroups []map[string]variableValue
|
||||
}
|
||||
|
||||
func callFunc(call funcCallType, vargroups []map[string]variableValue, origin string) (any, any) {
|
||||
var variables map[string]variableValue
|
||||
for i := len(vargroups) - 1; i >= 0; i-- {
|
||||
if vargroups[i][call.name.variable].EXISTS != nil {
|
||||
variables = vargroups[i]
|
||||
break
|
||||
}
|
||||
resp, ty := runprocess(call.FUNC, origin, vargroups)
|
||||
if ty == "error" {
|
||||
return resp, ty
|
||||
}
|
||||
|
||||
if variables[call.name.variable].EXISTS == nil {
|
||||
return ("undecared function '" + call.name.variable + "': " + origin + ":" + fmt.Sprint(call.line+1)), "error"
|
||||
}
|
||||
callable := call
|
||||
for variables[callable.name.variable].TYPE != "func" && variables[callable.name.variable].TYPE != "init_function" && fmt.Sprint(reflect.TypeOf(variables[callable.name.variable].VAL)) == "main.variable" {
|
||||
callable = funcCallType{name: variables[callable.name.variable].VAL.(variable), args: callable.args, line: callable.line}
|
||||
}
|
||||
for i := len(vargroups) - 1; i >= 0; i-- {
|
||||
if vargroups[i][callable.name.variable].EXISTS != nil {
|
||||
variables = vargroups[i]
|
||||
break
|
||||
switch variable := resp.(type) {
|
||||
case callableFunction:
|
||||
if len(call.args) != len(variable.args) {
|
||||
return "invalid number of arguments: " + origin + ":" + fmt.Sprint(call.line+1), "error"
|
||||
}
|
||||
}
|
||||
if variables[callable.name.variable].TYPE != "func" && variables[callable.name.variable].TYPE != "init_function" {
|
||||
return ("'" + call.name.variable + "' is not a function: " + origin + ":" + fmt.Sprint(call.line+1)), "error"
|
||||
}
|
||||
if variables[callable.name.variable].FUNC {
|
||||
|
||||
argvals := []any{}
|
||||
for i := 0; i < len(callable.args); i++ {
|
||||
resp, ty := runprocess(callable.args[i], origin, vargroups)
|
||||
if ty == "error" {
|
||||
return resp, ty
|
||||
}
|
||||
argvals = append(argvals, resp)
|
||||
}
|
||||
val, err := variables[callable.name.variable].VAL.(func(...any) (any, any))(argvals...)
|
||||
if err != nil {
|
||||
return err, "error"
|
||||
}
|
||||
return val, "value"
|
||||
} else {
|
||||
argvars := make(map[string]variableValue)
|
||||
for i := 0; i < len(callable.args); i++ {
|
||||
resp, ty := runprocess(callable.args[i], origin, vargroups)
|
||||
for i := 0; i < len(variable.args); i++ {
|
||||
resp, ty := runprocess(call.args[i], origin, vargroups)
|
||||
if ty == "error" {
|
||||
return resp, ty
|
||||
}
|
||||
name := variables[callable.name.variable].VAL.(setFunction).args[i]
|
||||
name := variable.args[i]
|
||||
argvars[name] = variableValue{
|
||||
VAL: resp,
|
||||
TYPE: "var",
|
||||
@@ -266,11 +301,38 @@ func callFunc(call funcCallType, vargroups []map[string]variableValue, origin st
|
||||
FUNC: false,
|
||||
}
|
||||
}
|
||||
ty, val, _ := run(variables[callable.name.variable].VAL.(setFunction).code, origin, append(vargroups, modules[variables[callable.name.variable].origin], argvars))
|
||||
ty, val, _ := run(variable.code, origin, append(variable.vargroups, argvars))
|
||||
if ty != "return" && ty != "error" && ty != nil {
|
||||
return fmt.Sprint(ty) + " is not allowed in function: " + origin + ":" + fmt.Sprint(callable.line+1), "error"
|
||||
return fmt.Sprint(ty) + " is not allowed in function: " + origin + ":" + fmt.Sprint(variable.line+1), "error"
|
||||
} else if ty == "error" {
|
||||
return val, ty
|
||||
}
|
||||
return val, "value"
|
||||
case builtinFunc:
|
||||
argvals := []any{}
|
||||
for i := 0; i < len(call.args); i++ {
|
||||
resp, ty := runprocess(call.args[i], origin, vargroups)
|
||||
if ty == "error" {
|
||||
return resp, ty
|
||||
}
|
||||
argvals = append(argvals, resp)
|
||||
}
|
||||
val, err := variable.FUNC(argvals...)
|
||||
if err != nil {
|
||||
return err, "error"
|
||||
}
|
||||
return val, "value"
|
||||
default:
|
||||
return ("value is not a function: " + origin + ":" + fmt.Sprint(call.line+1)), "error"
|
||||
}
|
||||
}
|
||||
|
||||
func isCallableFunc(x any) bool {
|
||||
switch x.(type) {
|
||||
case callableFunction:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,18 +349,24 @@ func setVariableVal(x setVariable, vargroups [](map[string]variableValue), origi
|
||||
variable = vargroups[len(vargroups)-1]
|
||||
}
|
||||
if variable[x.variable.variable].EXISTS == nil {
|
||||
resp, ty := runop(x.value, origin, vargroups)
|
||||
if ty == "error" {
|
||||
return resp
|
||||
}
|
||||
var val any
|
||||
var TYPE = x.TYPE
|
||||
if TYPE == "preset" {
|
||||
TYPE = "var"
|
||||
if isCallableFunc(x.value) {
|
||||
val = x.value
|
||||
} else {
|
||||
resp, ty := runop(x.value, origin, vargroups)
|
||||
if ty == "error" {
|
||||
return resp
|
||||
}
|
||||
val = resp
|
||||
if TYPE == "preset" {
|
||||
TYPE = "var"
|
||||
}
|
||||
}
|
||||
vargroups[len(vargroups)-1][x.variable.variable] = variableValue{
|
||||
TYPE: TYPE,
|
||||
EXISTS: true,
|
||||
VAL: resp,
|
||||
VAL: val,
|
||||
origin: origin,
|
||||
FUNC: false,
|
||||
}
|
||||
@@ -332,15 +400,16 @@ func setFunctionVal(x setFunction, vargroups []map[string]variableValue, origin
|
||||
break
|
||||
}
|
||||
}
|
||||
x.FUNC.vargroups = vargroups
|
||||
if variable[x.name].EXISTS == nil {
|
||||
vargroups[len(vargroups)-1][x.name] = variableValue{
|
||||
TYPE: "func",
|
||||
TYPE: "var",
|
||||
EXISTS: true,
|
||||
VAL: x,
|
||||
VAL: x.FUNC,
|
||||
FUNC: false,
|
||||
origin: origin,
|
||||
}
|
||||
} else if variable[x.name].TYPE == "func" {
|
||||
} else if variable[x.name].TYPE == "var" {
|
||||
vari := variable[x.name]
|
||||
vari.VAL = x
|
||||
vari.FUNC = false
|
||||
|
||||
+99
-21
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
var anyAndNewline = "((.)|(\\n))"
|
||||
var variableOnly = "([a-zA-Z_])([a-zA-Z0-9_])*"
|
||||
var variableWithIndexes = variableOnly + "(\\[" + anyAndNewline + "+\\]|\\.variableOnly)*"
|
||||
var variableWithIndexes = variableOnly + "(\\[" + anyAndNewline + "+\\]|\\." + variableOnly + ")*"
|
||||
var stringCompile = makeRegex("(( *)\"((\\\\([a-z\\\"'`]))|[^\\\"])*\"( *))|(( *)'((\\\\([a-z\\'\"`]))|[^\\'])*'( *))|(( *)(`(\\\\[a-z\\\"'`\\n]|[^\\`])*`)( *))")
|
||||
var numberCompile = makeRegex("( *)(\\-)?(([0-9]*(\\.[0-9]+)?)(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
|
||||
var whileCompile = makeRegex("( *)(while( )+" + anyAndNewline + "+( )+\\[" + anyAndNewline + "*)( *)")
|
||||
@@ -20,12 +20,14 @@ var closeCompile = makeRegex("( *)\\]( *)")
|
||||
var switchCloseCompile = makeRegex("( *)" + anyAndNewline + "*\\]" + anyAndNewline + "*\\[" + anyAndNewline + "*( *)")
|
||||
var importCompile = makeRegex("( *)((import " + anyAndNewline + "+)|(from( +)" + anyAndNewline + "+( +)import( +)(( *)" + variableOnly + "( *)(\\,( *)" + variableOnly + "( *))*)))( *)")
|
||||
var bracketsCompile = makeRegex("( *)\\(" + anyAndNewline + "*\\)( *)")
|
||||
var functionCompile = makeRegex("( *)" + variableOnly + "\\(" + anyAndNewline + "*\\)( *)")
|
||||
var functionCompile = makeRegex("( *)" + anyAndNewline + "+\\(" + anyAndNewline + "*\\)( *)")
|
||||
var indexCompile = makeRegex("( *)" + anyAndNewline + "+\\[" + anyAndNewline + "+\\]( *)")
|
||||
var variableTextCompile = makeRegex("( *)" + variableWithIndexes + "( *)")
|
||||
var variableonlyCompile = makeRegex(variableOnly)
|
||||
var setVariableCompile = makeRegex("( *)(((const|var) (" + variableOnly + "( *))=( *)" + anyAndNewline + "+)|(( *)" + variableOnly + "( *))(( *)=( *)" + anyAndNewline + "+))( *)")
|
||||
var callErrorCompile = makeRegex("( *)(error(( )+" + anyAndNewline + "+))( *)")
|
||||
var returnStatementCompile = makeRegex("( *)(return(( )+" + anyAndNewline + "*)?)( *)")
|
||||
var deleteStatmentCompile = makeRegex("( *)(delete( )+" + variableWithIndexes + ")( *)")
|
||||
var itemsCompiled = makeRegex("( *)(\\[" + anyAndNewline + "*\\])( *)")
|
||||
var breakStatementCompile = makeRegex("( *)break( *)")
|
||||
var continueStatementCompile = makeRegex("( *)continue( *)")
|
||||
@@ -364,20 +366,40 @@ var translateprocess = func(codeseg code) (any, bool, any) {
|
||||
}, true, nil
|
||||
} else if functionCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
bracketsplit := strings.SplitN(str, "(", 2)
|
||||
funcname := strings.Trim(bracketsplit[0], " ")
|
||||
params := bracketsplit[1][:len(bracketsplit[1])-1]
|
||||
indent := 0
|
||||
output := []byte{}
|
||||
for i := len(str) - 2; i >= 0; i-- {
|
||||
if str[i] == ')' {
|
||||
indent++
|
||||
} else if str[i] == '(' {
|
||||
indent--
|
||||
if indent < 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
output = append([]byte{str[i]}, output...)
|
||||
}
|
||||
params := string(output[:])
|
||||
paramstranslated, worked, err := getValuesFromCommas(params, codeseg.line)
|
||||
if !worked {
|
||||
return nil, false, "invalid params on line " + fmt.Sprint(codeseg.line+1)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
FUNC, worked, err := processfunc(code{
|
||||
code: str[:len(str)-len(params)-2],
|
||||
line: codeseg.line,
|
||||
})
|
||||
if !worked {
|
||||
return nil, false, "invalid value on line " + fmt.Sprint(codeseg.line+1)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if worked {
|
||||
return funcCallType{
|
||||
name: variable{
|
||||
variable: funcname,
|
||||
splices: []any{},
|
||||
line: codeseg.line,
|
||||
},
|
||||
FUNC: FUNC,
|
||||
args: paramstranslated,
|
||||
line: codeseg.line,
|
||||
}, true, nil
|
||||
@@ -402,6 +424,50 @@ var translateprocess = func(codeseg code) (any, bool, any) {
|
||||
line: codeseg.line,
|
||||
}, true, nil
|
||||
}
|
||||
} else if indexCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
indent := 0
|
||||
output := []byte{}
|
||||
for i := len(str) - 2; i >= 0; i-- {
|
||||
if str[i] == ']' {
|
||||
indent++
|
||||
} else if str[i] == '[' {
|
||||
indent--
|
||||
if indent < 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
output = append([]byte{str[i]}, output...)
|
||||
}
|
||||
value := string(output[:])
|
||||
resp, worked, err := processfunc(code{
|
||||
code: value,
|
||||
line: codeseg.line,
|
||||
})
|
||||
if !worked {
|
||||
return nil, false, "invalid index value on line " + fmt.Sprint(codeseg.line+1)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
index := resp
|
||||
|
||||
resp, worked, err = processfunc(code{
|
||||
code: str[:len(str)-len(value)-2],
|
||||
line: codeseg.line,
|
||||
})
|
||||
if !worked {
|
||||
return nil, false, "invalid value on line " + fmt.Sprint(codeseg.line+1)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
return indexType{
|
||||
to: resp,
|
||||
index: index,
|
||||
line: codeseg.line,
|
||||
}, true, nil
|
||||
} else if numberCompile.MatchString(codeseg.code) {
|
||||
if s, err := strconv.ParseFloat(strings.Trim(codeseg.code, " "), 64); err == nil {
|
||||
return s, true, nil
|
||||
@@ -411,7 +477,6 @@ var translateprocess = func(codeseg code) (any, bool, any) {
|
||||
} else if variableTextCompile.MatchString(codeseg.code) {
|
||||
return variable{
|
||||
variable: strings.Trim(codeseg.code, " "),
|
||||
splices: []any{},
|
||||
line: codeseg.line,
|
||||
}, true, nil
|
||||
}
|
||||
@@ -445,13 +510,6 @@ var translateline = func(i int, codearray []code) (any, int, any) {
|
||||
}, i + 1, nil
|
||||
} else if skipCompile.MatchString(codeseg.code) {
|
||||
return nil, i + 1, nil
|
||||
}
|
||||
resp, worked, err := translateprocess(codeseg)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if worked {
|
||||
return resp, i + 1, nil
|
||||
} else if setVariableCompile.MatchString(codeseg.code) {
|
||||
VAR := strings.Split(codeseg.code, "=")
|
||||
firstSplit := strings.Split(strings.Trim(VAR[0], " "), " ")
|
||||
@@ -472,12 +530,27 @@ var translateline = func(i int, codearray []code) (any, int, any) {
|
||||
TYPE: TYPE,
|
||||
variable: variable{
|
||||
variable: vari,
|
||||
splices: []any{},
|
||||
line: codeseg.line,
|
||||
},
|
||||
value: resp,
|
||||
line: codeseg.line,
|
||||
}, i + 1, nil
|
||||
}
|
||||
resp, worked, err := translateprocess(codeseg)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if worked {
|
||||
return resp, i + 1, nil
|
||||
} else if deleteStatmentCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
return deleteType{
|
||||
variable: variable{
|
||||
variable: str[7:],
|
||||
line: codeseg.line,
|
||||
},
|
||||
line: codeseg.line,
|
||||
}, i + 1, nil
|
||||
} else if whileCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
strlen := len(str)
|
||||
@@ -683,8 +756,13 @@ var translateline = func(i int, codearray []code) (any, int, any) {
|
||||
}
|
||||
return setFunction{
|
||||
name: functionname,
|
||||
args: args,
|
||||
code: codeoutput,
|
||||
FUNC: callableFunction{
|
||||
name: functionname,
|
||||
args: args,
|
||||
code: codeoutput,
|
||||
line: codeseg.line,
|
||||
},
|
||||
line: codeseg.line,
|
||||
}, x, nil
|
||||
} else if importCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
|
||||
+31
-37
@@ -6,15 +6,15 @@ var vars = make(map[string]variableValue)
|
||||
|
||||
func init() {
|
||||
vars["log"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonLog,
|
||||
VAL: builtinFunc{"log", ArgonLog},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["input"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonInput,
|
||||
VAL: builtinFunc{"input", ArgonInput},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["yes"] = variableValue{
|
||||
@@ -48,94 +48,88 @@ func init() {
|
||||
FUNC: false,
|
||||
}
|
||||
vars["number"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonNumber,
|
||||
VAL: builtinFunc{"number", ArgonNumber},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["whole"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonWhole,
|
||||
VAL: builtinFunc{"whole", ArgonWhole},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["string"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonString,
|
||||
VAL: builtinFunc{"string", ArgonString},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["license"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonLicense,
|
||||
VAL: builtinFunc{"license", ArgonLicense},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["exec"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: exec,
|
||||
VAL: builtinFunc{"exec", exec},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["eval"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: eval,
|
||||
VAL: builtinFunc{"eval", eval},
|
||||
FUNC: true,
|
||||
}
|
||||
|
||||
vars["append"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonAppend,
|
||||
VAL: builtinFunc{"append", ArgonAppend},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["extend"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonExtend,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["len"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonLen,
|
||||
VAL: builtinFunc{"len", ArgonLen},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["join"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonJoin,
|
||||
VAL: builtinFunc{"join", ArgonJoin},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["random"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonRandom,
|
||||
VAL: builtinFunc{"random", ArgonRandom},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["randomSetSeed"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonSetSeed,
|
||||
FUNC: true,
|
||||
}
|
||||
vars["randomSetSeed"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
EXISTS: true,
|
||||
VAL: ArgonSetSeed,
|
||||
VAL: builtinFunc{"randomSetSeed", ArgonSetSeed},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["time"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonTime,
|
||||
VAL: builtinFunc{"time", ArgonTime},
|
||||
FUNC: true,
|
||||
}
|
||||
vars["sleep"] = variableValue{
|
||||
TYPE: "init_function",
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: ArgonSleep,
|
||||
VAL: builtinFunc{"sleep", ArgonSleep},
|
||||
FUNC: true,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user