mirror of
https://github.com/Open-Argon/argon-v2.git
synced 2026-10-28 09:44:03 +00:00
merge
This commit is contained in:
commit
0fb4840e2b
6 files changed
+211
-123
No files matched your search
+1
-2
@@ -2,8 +2,7 @@ package main
|
||||
|
||||
type opperator struct {
|
||||
t int
|
||||
x interface{}
|
||||
y interface{}
|
||||
vals []interface{}
|
||||
line int
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -1,8 +1,10 @@
|
||||
import "example.ar";
|
||||
log('start');
|
||||
var i = 0;
|
||||
while i < 100000000 [
|
||||
i = i add 1;
|
||||
];
|
||||
log('done');
|
||||
|
||||
if yes [
|
||||
log("cool")
|
||||
] else [
|
||||
]
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
log('done')
|
||||
@@ -57,6 +57,13 @@ func runprocess(codeseg any) any {
|
||||
for boolean(runop(whileloop.condition)) {
|
||||
run(whileloop.code)
|
||||
}
|
||||
case ifstatement:
|
||||
iff := codeseg.(ifstatement)
|
||||
if boolean(runop(iff.condition)) {
|
||||
run(iff.TRUE)
|
||||
} else {
|
||||
run(iff.FALSE)
|
||||
}
|
||||
case importType:
|
||||
importMod((codeseg.(importType).path).(string))
|
||||
case setVariable:
|
||||
@@ -133,6 +140,12 @@ func number(x any) float64 {
|
||||
return float64(x.(float32))
|
||||
case int:
|
||||
return float64(x.(int))
|
||||
case bool:
|
||||
if x.(bool) {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
default:
|
||||
num, err := strconv.ParseFloat(fmt.Sprint(x), 64)
|
||||
if err != nil {
|
||||
@@ -144,91 +157,139 @@ func number(x any) float64 {
|
||||
|
||||
func runOperator(opperation opperator) any {
|
||||
var output any
|
||||
switch opperation.t {
|
||||
case 0:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
if (x != false && x != nil) && (y != false && y != nil) {
|
||||
output = y
|
||||
} else {
|
||||
output = false
|
||||
}
|
||||
case 1:
|
||||
x := runop(opperation.x)
|
||||
if boolean(x) {
|
||||
output = x
|
||||
} else {
|
||||
y := runop(opperation.y)
|
||||
if boolean(y) {
|
||||
output = y
|
||||
for i := 0; i < len(opperation.vals); i++ {
|
||||
switch opperation.t {
|
||||
case 0:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = false
|
||||
if boolean(output) && boolean(x) {
|
||||
output = x
|
||||
} else {
|
||||
output = false
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
x := runop(opperation.vals[i])
|
||||
if boolean(x) {
|
||||
output = x
|
||||
break
|
||||
}
|
||||
case 2:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = xiny(output, x.([]any))
|
||||
}
|
||||
case 3:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = !xiny(output, x.([]interface{}))
|
||||
}
|
||||
case 4:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) <= number(x))
|
||||
}
|
||||
case 5:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) >= number(x))
|
||||
}
|
||||
case 6:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) < number(x))
|
||||
}
|
||||
case 7:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) > number(x))
|
||||
}
|
||||
case 8:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (output != x)
|
||||
}
|
||||
case 9:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (output == x)
|
||||
}
|
||||
case 10:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) - number(x))
|
||||
}
|
||||
case 11:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = dynamicAdd(output, x)
|
||||
}
|
||||
case 12:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = math.Pow(number(output), 1/number(x))
|
||||
}
|
||||
case 13:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = math.Pow(number(output), number(x))
|
||||
}
|
||||
case 14:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) * number(x))
|
||||
}
|
||||
case 15:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = math.Floor(number(output) / number(x))
|
||||
}
|
||||
case 16:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = math.Mod(number(output), number(x))
|
||||
}
|
||||
case 17:
|
||||
x := runop(opperation.vals[i])
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = (number(output) / number(x))
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = xiny(x, y.([]interface{}))
|
||||
case 3:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = !xiny(x, y.([]interface{}))
|
||||
case 4:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (number(x) <= number(y))
|
||||
case 5:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (number(x) >= number(y))
|
||||
case 6:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (number(x) < number(y))
|
||||
case 7:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (number(x) > number(y))
|
||||
case 8:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (x != y)
|
||||
case 9:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (x == y)
|
||||
case 10:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = (number(x) - number(y))
|
||||
case 11:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = dynamicAdd(x, y)
|
||||
case 12:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = math.Pow(number(x), 1/number(y))
|
||||
case 13:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = math.Pow(number(x), number(y))
|
||||
case 14:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = number(x) * number(y)
|
||||
case 15:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = math.Floor(number(x) / number(y))
|
||||
case 16:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = math.Mod(number(x), number(y))
|
||||
case 17:
|
||||
x := runop(opperation.x)
|
||||
y := runop(opperation.y)
|
||||
output = number(x) / number(y)
|
||||
}
|
||||
return output
|
||||
}
|
||||
+51
-26
@@ -8,16 +8,18 @@ import (
|
||||
)
|
||||
|
||||
var anyAndNewline = "((.)|(\\n))"
|
||||
var variableOnly = "([a-zA-Z_])([a-zA-Z0-9_])*"
|
||||
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 + "+ \\[.*)( *)")
|
||||
var ifCompile = makeRegex("( *)(if .+ \\[.*)( *)")
|
||||
var subCompile = makeRegex("( *)(sub " + variableOnly + "\\(" + anyAndNewline + "+\\) \\[.*)( *)")
|
||||
var ifCompile = makeRegex("( *)(if .+ \\[" + anyAndNewline + "*)( *)")
|
||||
var elseifCompile = makeRegex("( *)(\\] else if .+ \\[" + anyAndNewline + "*)( *)")
|
||||
var openCompile = makeRegex("( *)([a-z]+ " + anyAndNewline + "+ \\[.*)( *)")
|
||||
var elseCompile = makeRegex("( *)\\] else \\[( *)")
|
||||
var elseCompile = makeRegex("( *)\\] else \\[" + anyAndNewline + "*( *)")
|
||||
var closeCompile = makeRegex("( *)\\]( *)")
|
||||
var importCompile = makeRegex("( *)import " + anyAndNewline + "+( *)")
|
||||
var bracketsCompile = makeRegex("( *)\\(" + anyAndNewline + "*\\)( *)")
|
||||
var variableOnly = "([a-zA-Z_])([a-zA-Z0-9_])*"
|
||||
var functionCompile = makeRegex("( *)" + variableOnly + "\\(" + anyAndNewline + "*\\)( *)")
|
||||
var variableTextCompile = makeRegex("( *)" + variableOnly + "( *)")
|
||||
var setVariableCompile = makeRegex("( *)(((const|var) (" + variableOnly + "( *))=( *).+)|(( *)" + variableOnly + "( *))(( *)=( *).+))( *)")
|
||||
@@ -192,7 +194,7 @@ var getCodeInIndent = func(i int, codearray []code, isIf bool) ([]code, int) {
|
||||
})
|
||||
i++
|
||||
for {
|
||||
if closeCompile.MatchString(codearray[i].code) || (isIf && elseCompile.MatchString(codearray[i].code)) {
|
||||
if closeCompile.MatchString(codearray[i].code) || (isIf && (elseCompile.MatchString(codearray[i].code) || elseifCompile.MatchString(codearray[i].code))) {
|
||||
indent++
|
||||
if indent >= 0 {
|
||||
break
|
||||
@@ -212,21 +214,31 @@ var translateprocess = func(codeseg code) (interface{}, bool) {
|
||||
for j := 0; j < len(opperators[i]); j++ {
|
||||
split := strings.Split(codeseg.code, opperators[i][j])
|
||||
if len(split) > 1 {
|
||||
vals := []interface{}{}
|
||||
current := 0
|
||||
for k := 0; k < len(split); k++ {
|
||||
x := strings.Join(split[:k], opperators[i][j])
|
||||
y := strings.Join(split[k:], opperators[i][j])
|
||||
val1, worked := processfunc(code{code: x, line: codeseg.line})
|
||||
if !worked {
|
||||
continue
|
||||
currentstr := strings.Join(split[current:k], opperators[i][j])
|
||||
val, worked := processfunc(code{
|
||||
code: currentstr,
|
||||
line: codeseg.line,
|
||||
})
|
||||
if worked {
|
||||
vals = append(vals, val)
|
||||
current = k
|
||||
}
|
||||
val2, worked := processfunc(code{code: y, line: codeseg.line})
|
||||
if !worked {
|
||||
continue
|
||||
}
|
||||
if len(vals) >= 1 {
|
||||
currentstr := strings.Join(split[current:], opperators[i][j])
|
||||
val, worked := processfunc(code{
|
||||
code: currentstr,
|
||||
line: codeseg.line,
|
||||
})
|
||||
if worked {
|
||||
vals = append(vals, val)
|
||||
}
|
||||
return opperator{
|
||||
t: i,
|
||||
x: val1,
|
||||
y: val2,
|
||||
vals: vals,
|
||||
line: codeseg.line,
|
||||
}, true
|
||||
}
|
||||
@@ -318,20 +330,10 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
condition: condition,
|
||||
code: codeoutput,
|
||||
}, x
|
||||
} else if importCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
path, worked := processfunc(code{code: str[7:], line: codeseg.line})
|
||||
if !worked {
|
||||
log.Fatal("invalid import path on line ", codeseg.line+1)
|
||||
}
|
||||
return importType{
|
||||
path: path,
|
||||
line: codeseg.line,
|
||||
}, i + 1
|
||||
} else if ifCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
strlen := len(str)
|
||||
str = str[5:strlen]
|
||||
str = str[2:strlen]
|
||||
split := strings.SplitN(str, "[", 2)
|
||||
condition, worked := translateprocess(code{code: split[0],
|
||||
line: codeseg.line})
|
||||
@@ -347,11 +349,34 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
i = x
|
||||
codeoutput = append(codeoutput, resp)
|
||||
}
|
||||
elsecode := []any{}
|
||||
elsecodelen := 0
|
||||
if elseCompile.MatchString(codearray[x-1].code) {
|
||||
codedata, x := getCodeInIndent(x-1, codearray, false)
|
||||
elsecodelen = x - 3
|
||||
codelen := len(codedata)
|
||||
for i := 0; i < codelen; {
|
||||
resp, x := linefunc(i, codedata)
|
||||
i = x
|
||||
elsecode = append(elsecode, resp)
|
||||
}
|
||||
}
|
||||
|
||||
return ifstatement{
|
||||
condition: condition,
|
||||
TRUE: codeoutput,
|
||||
}, x
|
||||
FALSE: elsecode,
|
||||
}, x + elsecodelen
|
||||
} else if importCompile.MatchString(codeseg.code) {
|
||||
str := strings.Trim(codeseg.code, " ")
|
||||
path, worked := processfunc(code{code: str[7:], line: codeseg.line})
|
||||
if !worked {
|
||||
log.Fatal("invalid import path on line ", codeseg.line+1)
|
||||
}
|
||||
return importType{
|
||||
path: path,
|
||||
line: codeseg.line,
|
||||
}, i + 1
|
||||
} else if skipCompile.MatchString(codeseg.code) {
|
||||
} else {
|
||||
err := "Invalid syntax on line "
|
||||
|
||||
@@ -34,4 +34,10 @@ func init() {
|
||||
VAL: false,
|
||||
FUNC: false,
|
||||
}
|
||||
vars["unknown"] = variableValue{
|
||||
TYPE: "init",
|
||||
EXISTS: true,
|
||||
VAL: nil,
|
||||
FUNC: false,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user