fix operation translation taking ages

This commit is contained in:
2023-06-18 01:20:21 +01:00
parent 63d7616053
commit 14ae68b9d1
24 changed files with 576 additions and 441 deletions

View File

@@ -551,7 +551,8 @@ func ArArray(arr []any) ArObject {
for i, v := range arr {
res, err := runOperation(operationType{
operation: 8,
values: []any{v, args[0].(ArObject).obj["__value__"].([]any)[i]},
value1: v,
value2: args[0].(ArObject).obj["__value__"].([]any)[i],
}, stack{}, 0)
if err.EXISTS {
return nil, err
@@ -575,7 +576,8 @@ func ArArray(arr []any) ArObject {
for _, v := range arr {
res, err := runOperation(operationType{
operation: 8,
values: []any{v, args[0]},
value1: v,
value2: args[0],
}, stack{}, 0)
if err.EXISTS {
return nil, err

View File

@@ -13,10 +13,7 @@ func anyToBool(x any) bool {
case nil:
return false
case ArObject:
if typeof(x) == "array" {
return len(x.obj["__value__"].([]any)) != 0
}
return len(x.obj) != 0
return anyToBool(ArValidToAny(x))
case builtinFunc:
return true
case Callable:

View File

@@ -3,19 +3,41 @@ package main
import (
"fmt"
"os"
"sync"
)
var debug = os.Getenv("__ARGON_DEBUG__") == "true"
func debugPrintln(a ...any) {
var __debugPrints = [][]any{}
var __debugPrintsLock = sync.RWMutex{}
func debugInit() {
if debug {
fmt.Println("In debug mode...")
go func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("debugPrintln: panic:", r)
}
}()
fmt.Println(a...)
for {
__debugPrintsLock.RLock()
for _, v := range __debugPrints {
fmt.Println(v...)
}
__debugPrintsLock.RUnlock()
__debugPrintsLock.Lock()
__debugPrints = [][]any{}
__debugPrintsLock.Unlock()
}
}()
}
}
func debugPrintln(a ...any) {
if debug {
__debugPrintsLock.Lock()
__debugPrints = append(__debugPrints, a)
__debugPrintsLock.Unlock()
}
}

View File

@@ -58,3 +58,9 @@ func getPassword(args ...any) (string, error) {
fmt.Print("\r")
return string(password), nil
}
func pause() {
fmt.Print("Press any key to continue...")
term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
}

View File

@@ -15,7 +15,7 @@ func newscope() ArObject {
}
func main() {
debugPrintln("In debug mode...")
debugInit()
if !debug {
defer func() {

View File

@@ -196,7 +196,8 @@ func Map(m anymap) ArObject {
}
val, err := runOperation(operationType{
operation: 9,
values: []any{v, a[k]},
value1: v,
value2: a[k],
}, stack{}, 0)
if err.EXISTS {
return val, err

View File

@@ -15,13 +15,20 @@ func isNegative(code UNPARSEcode) bool {
return negativeCompile.MatchString(code.code)
}
func parseNegative(code UNPARSEcode, index int, codeline []UNPARSEcode) (negative, bool, ArErr, int) {
func parseNegative(code UNPARSEcode, index int, codeline []UNPARSEcode) (any, bool, ArErr, int) {
trimmed := strings.TrimSpace(code.code)
trimmednegative := strings.TrimLeft(trimmed, "-")
difference := len(trimmed) - len(trimmednegative)
resp, worked, err, i := translateVal(UNPARSEcode{
code: strings.TrimSpace(code.code)[1:],
code: trimmednegative,
realcode: code.realcode,
line: code.line,
path: code.path,
}, index, codeline, 0)
if difference%2 == 0 {
return resp, worked, err, i
}
return negative{
VAL: resp,
line: code.line,

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"math"
"reflect"
"strings"
)
var operations = [][]string{
@@ -50,7 +51,8 @@ var one = newNumber().SetInt64(1)
type operationType struct {
operation int
values []any
value1 any
value2 any
line int
code string
path string
@@ -58,67 +60,60 @@ type operationType struct {
func parseOperations(code UNPARSEcode, index int, codelines []UNPARSEcode) (operationType, bool, ArErr, int) {
for i := 0; i < len(operations); i++ {
values := []any{}
current := 0
totalindex := 1
for l := 0; l < len(code.code); l++ {
for j := 0; j < len(operations[i]); j++ {
if len(code.code[l:]) >= len(operations[i][j]) && code.code[l:l+len(operations[i][j])] == operations[i][j] {
resp, success, _, respindex := translateVal(
UNPARSEcode{
code: code.code[current:l],
realcode: code.realcode,
line: code.line,
path: code.path,
}, index, codelines, 0)
if success {
totalindex += respindex - 1
values = append(values, resp)
current = l + len(operations[i][j])
}
}
for j := 0; j < len(operations[i]); j++ {
split := strings.Split(code.code, operations[i][j])
if len(split) <= 1 {
continue
}
}
if len(values) > 0 {
resp, success, err, respindex := translateVal(
UNPARSEcode{
code: code.code[current:],
for k := 0; k < len(split)-1; k++ {
if len(strings.TrimSpace(split[k])) == 0 || len(strings.TrimSpace(split[k+1])) == 0 {
break
}
val1, worked, err, step1 := translateVal(UNPARSEcode{
code: strings.Join(split[:k+1], operations[i][j]),
realcode: code.realcode,
line: code.line,
path: code.path,
}, index, codelines, 0)
if success {
totalindex += respindex - 1
values = append(values, resp)
if !worked || err.EXISTS {
if k == len(split)-1 {
return operationType{}, false, err, 0
} else {
continue
}
}
val2, worked, err, step2 := translateVal(UNPARSEcode{
code: strings.Join(split[k+1:], operations[i][j]),
realcode: code.realcode,
line: code.line,
path: code.path,
}, index, codelines, 0)
if !worked || err.EXISTS {
if k == len(split)-1 {
return operationType{}, false, err, 0
} else {
continue
}
}
return operationType{
i,
values,
val1,
val2,
code.line,
code.realcode,
code.code,
code.path,
}, true, err, totalindex
}, true, ArErr{}, step1 + step2 - 1
}
return operationType{}, false, err, totalindex
}
}
return operationType{}, false, ArErr{}, 0
}
func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
if len(o.values) != 2 {
return false, ArErr{
"Runtime Error",
"Invalid number of values for comparison",
o.line,
o.path,
o.code,
true,
}
}
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -127,7 +122,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
}
resp2, err := runVal(
o.values[1],
o.value2,
stack,
stacklevel+1,
)
@@ -261,7 +256,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -272,52 +267,46 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
if isAnyNumber(resp) {
output = newNumber().Set(resp.(number))
}
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if typeof(output) == "number" && typeof(resp) == "number" {
output = output.(number).Sub(output.(number), resp.(number))
continue
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Subtract__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
output = val
continue
}
}
return nil, ArErr{
"Runtime Error",
"Cannot subtract type '" + typeof(resp) + "' from type '" + typeof(output) + "'",
o.line,
o.path,
o.code,
true,
}
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if typeof(output) == "number" && typeof(resp) == "number" {
return output.(number).Sub(output.(number), resp.(number)), ArErr{}
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Subtract__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
return val, ArErr{}
}
}
return nil, ArErr{
"Runtime Error",
"Cannot subtract type '" + typeof(resp) + "' from type '" + typeof(output) + "'",
o.line,
o.path,
o.code,
true,
}
return output, ArErr{}
}
func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -328,52 +317,49 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
if isAnyNumber(resp) {
output = newNumber().Set(resp.(number))
}
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" && typeof(output) == "number" {
output = output.(number).Quo(output.(number), resp.(number))
continue
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Divide__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
output = val
continue
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" && typeof(output) == "number" {
output = output.(number).Quo(output.(number), resp.(number))
return output, ArErr{}
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Divide__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
}
return nil, ArErr{
"Runtime Error",
"Cannot divide type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
output = val
return output, ArErr{}
}
}
return output, ArErr{}
return nil, ArErr{
"Runtime Error",
"Cannot divide type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
}
}
func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -384,51 +370,64 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
if typeof(output) == "number" {
output = newNumber().Set(output.(number))
}
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if typeof(output) == "number" && typeof(resp) == "number" {
output = output.(number).Add(output.(number), resp.(number))
continue
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Add__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if typeof(output) == "number" && typeof(resp) == "number" {
output = output.(number).Add(output.(number), resp.(number))
return output, ArErr{}
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Add__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if !err.EXISTS {
output = val
continue
return output, ArErr{}
}
}
return nil, ArErr{
"Runtime Error",
"Cannot add type '" + typeof(resp) + "' to type '" + typeof(output) + "'",
o.line,
o.path,
o.code,
true,
}
if x, ok := resp.(ArObject); ok {
if y, ok := x.obj["__PostAdd__"]; ok {
val, err := runCall(
call{
y,
[]any{output},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if !err.EXISTS {
output = val
return output, ArErr{}
}
}
}
return (output), ArErr{}
return nil, ArErr{
"Runtime Error",
"Cannot add type '" + typeof(resp) + "' to type '" + typeof(output) + "'",
o.line,
o.path,
o.code,
true,
}
}
func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -439,88 +438,100 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
if isAnyNumber(resp) {
output = newNumber().Set(resp.(number))
}
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if typeof(output) == "number" && typeof(resp) == "number" {
output = output.(number).Mul(output.(number), resp.(number))
continue
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Multiply__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
output = val
continue
}
}
return nil, ArErr{
"Runtime Error",
"Cannot multiply type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
}
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if typeof(output) == "number" && typeof(resp) == "number" {
output = output.(number).Mul(output.(number), resp.(number))
return output, ArErr{}
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Multiply__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
output = val
return output, ArErr{}
}
}
return nil, ArErr{
"Runtime Error",
"Cannot multiply type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
}
return output, ArErr{}
}
func calcAnd(o operationType, stack stack, stacklevel int) (any, ArErr) {
var output any = false
for i := 0; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if !anyToBool(resp) {
return resp, ArErr{}
}
output = resp
resp, err := runVal(
o.value1,
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
return output, ArErr{}
if !anyToBool(resp) {
return resp, ArErr{}
}
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
if err.EXISTS {
return nil, err
}
if !anyToBool(resp) {
return resp, ArErr{}
}
return resp, ArErr{}
}
func calcOr(o operationType, stack stack, stacklevel int) (any, ArErr) {
var output any = false
for i := 0; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if anyToBool(resp) {
return resp, ArErr{}
}
output = resp
resp, err := runVal(
o.value1,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
return output, ArErr{}
if anyToBool(resp) {
return resp, ArErr{}
}
resp, err = runVal(
o.value1,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if anyToBool(resp) {
return resp, ArErr{}
}
return resp, ArErr{}
}
// InSlice checks if an element is present in a slice of any type.
// It returns true if the element is found, false otherwise.
func InSlice(a any, list []any) bool {
for _, b := range list {
if b == a {
@@ -529,41 +540,35 @@ func InSlice(a any, list []any) bool {
}
return false
}
// calcNotIn is a function that calculates the 'not in' operation between two values.
// It takes in an operationType 'o', a stack 'stack', and a stack level 'stacklevel'.
// It returns an 'any' value and an 'ArErr' error.
// The 'o' parameter contains information about the operation to be performed, including the values to be compared, the line of code, and the file path.
func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
if len(o.values) != 2 {
return false, ArErr{
"Runtime Error",
"Invalid number of arguments for 'not in'",
o.line,
o.path,
o.code,
true,
}
}
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return false, err
}
resp2, err := runVal(
o.values[1],
o.value2,
stack,
stacklevel+1,
)
if err.EXISTS {
return false, err
}
if x, ok := resp.(ArObject); ok {
if x, ok := resp2.(ArObject); ok {
if y, ok := x.obj["__NotContains__"]; ok {
return runCall(
call{
y,
[]any{resp2},
[]any{resp},
o.code,
o.line,
o.path,
@@ -580,19 +585,13 @@ func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
}
}
// calcIn is a function that calculates the 'in' operation between two values.
// It takes in an operationType 'o', a stack 'stack', and a stack level 'stacklevel'.
// It returns an 'any' value and an 'ArErr' error.
// The 'o' parameter contains information about the operation to be performed, including the values to be compared, the line of code, and the file path.
func calcIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
if len(o.values) != 2 {
return false, ArErr{
"Runtime Error",
"Invalid number of arguments for 'not in'",
o.line,
o.path,
o.code,
true,
}
}
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -601,7 +600,7 @@ func calcIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
}
resp2, err := runVal(
o.values[1],
o.value2,
stack,
stacklevel+1,
)
@@ -676,7 +675,7 @@ func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, A
func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -687,55 +686,52 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
if isAnyNumber(resp) {
output = newNumber().Set(resp.(number))
}
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" && typeof(output) == "number" {
x := newNumber().Set(resp.(number))
x.Quo(output.(number), x)
x = floor(x)
x.Mul(x, resp.(number))
output.(number).Sub(output.(number), x)
continue
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Modulo__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
output = val
continue
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" && typeof(output) == "number" {
x := newNumber().Set(resp.(number))
x.Quo(output.(number), x)
x = floor(x)
x.Mul(x, resp.(number))
output.(number).Sub(output.(number), x)
return output, ArErr{}
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__Modulo__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
}
return nil, ArErr{
"Runtime Error",
"Cannot calculate modulus of type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
output = val
return output, ArErr{}
}
}
return output, ArErr{}
return nil, ArErr{
"Runtime Error",
"Cannot calculate modulus of type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
}
}
func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -746,51 +742,48 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
if isAnyNumber(resp) {
output = newNumber().Set(resp.(number))
}
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" && typeof(output) == "number" {
output = output.(number).Quo(output.(number), resp.(number))
continue
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__IntDivide__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
output = val
continue
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" && typeof(output) == "number" {
output = output.(number).Quo(output.(number), resp.(number))
return output, ArErr{}
} else if x, ok := output.(ArObject); ok {
if y, ok := x.obj["__IntDivide__"]; ok {
val, err := runCall(
call{
y,
[]any{resp},
o.code,
o.line,
o.path,
}, stack, stacklevel+1)
if err.EXISTS {
return nil, err
}
}
return nil, ArErr{
"Runtime Error",
"Cannot divide type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
output = val
return output, ArErr{}
}
}
return output, ArErr{}
return nil, ArErr{
"Runtime Error",
"Cannot divide type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
}
}
func calcPower(o operationType, stack stack, stacklevel int) (number, ArErr) {
resp, err := runVal(
o.values[0],
o.value1,
stack,
stacklevel+1,
)
@@ -809,69 +802,67 @@ func calcPower(o operationType, stack stack, stacklevel int) (number, ArErr) {
}
}
output := newNumber().Set(resp.(number))
for i := 1; i < len(o.values); i++ {
resp, err := runVal(
o.values[i],
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" {
n := newNumber().Set(resp.(number))
if n.Cmp(newNumber().SetInt64(10)) <= 0 {
toOut := newNumber().SetInt64(1)
clone := newNumber().Set(output)
nAbs := (abs(newNumber().Set(n)))
j := newNumber()
for ; j.Cmp(nAbs) < 0; j.Add(j, one) {
toOut.Mul(toOut, clone)
}
resp, err = runVal(
o.value2,
stack,
stacklevel+1,
)
resp = ArValidToAny(resp)
if err.EXISTS {
return nil, err
}
if typeof(resp) == "number" {
n := newNumber().Set(resp.(number))
if n.Cmp(newNumber().SetInt64(10)) <= 0 {
toOut := newNumber().SetInt64(1)
clone := newNumber().Set(output)
nAbs := (abs(newNumber().Set(n)))
j := newNumber()
for ; j.Cmp(nAbs) < 0; j.Add(j, one) {
toOut.Mul(toOut, clone)
}
nAbs.Sub(nAbs, j)
if nAbs.Cmp(newNumber()) < 0 {
j.Sub(j, one)
n1, _ := toOut.Float64()
n2, _ := nAbs.Float64()
calculated := newNumber().SetFloat64(math.Pow(n1, n2))
if calculated == nil {
calculated = infinity
}
toOut.Mul(toOut, calculated)
}
if n.Cmp(newNumber()) < 0 {
toOut.Quo(newNumber().SetInt64(1), toOut)
}
output.Set(toOut)
} else if n.Cmp(newNumber().SetInt64(1)) != 0 {
n1, _ := output.Float64()
n2, _ := n.Float64()
nAbs.Sub(nAbs, j)
if nAbs.Cmp(newNumber()) < 0 {
j.Sub(j, one)
n1, _ := toOut.Float64()
n2, _ := nAbs.Float64()
calculated := newNumber().SetFloat64(math.Pow(n1, n2))
if calculated == nil {
calculated = infinity
}
output.Mul(output, calculated)
toOut.Mul(toOut, calculated)
}
if n.Cmp(newNumber()) < 0 {
toOut.Quo(newNumber().SetInt64(1), toOut)
}
output.Set(toOut)
} else if n.Cmp(newNumber().SetInt64(1)) != 0 {
n1, _ := output.Float64()
n2, _ := n.Float64()
calculated := newNumber().SetFloat64(math.Pow(n1, n2))
if calculated == nil {
calculated = infinity
}
output.Mul(output, calculated)
}
/*
n1, _ := output.Float64()
n2, _ := resp.(number).Float64()
output = newNumber().SetFloat64(math.Pow(n1, n2))
if output == nil {
output = infinity
}
*/
} else {
return nil, ArErr{
"Runtime Error",
"Cannot calculate power of type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
/*
n1, _ := output.Float64()
n2, _ := resp.(number).Float64()
output = newNumber().SetFloat64(math.Pow(n1, n2))
if output == nil {
output = infinity
}
*/
} else {
return nil, ArErr{
"Runtime Error",
"Cannot calculate power of type '" + typeof(resp) + "'",
o.line,
o.path,
o.code,
true,
}
}
return output, ArErr{}

View File

@@ -567,6 +567,18 @@ func ArString(str string) ArObject {
}
return strings.Join([]string{str, a[0].(string)}, ""), ArErr{}
}}
obj.obj["__PostAdd__"] = builtinFunc{
"__PostAdd__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
a[0] = ArValidToAny(a[0])
if typeof(a[0]) != "string" {
a[0] = anyToArgon(a[0], false, false, 3, 0, false, 0)
}
return strings.Join([]string{a[0].(string), str}, ""), ArErr{}
}}
obj.obj["__Multiply__"] = builtinFunc{
"__Multiply__",
func(a ...any) (any, ArErr) {

View File

@@ -131,11 +131,12 @@ var ArInput = Map(
}
return ArString(resp), ArErr{}
}},
"__call__": builtinFunc{"input", func(args ...any) (any, ArErr) {
return input(args...), ArErr{}
}},
"pause": builtinFunc{"pause", func(args ...any) (any, ArErr) {
pause()
return nil, ArErr{}
}},
},
)
func init() {
ArInput.obj["__call__"] = builtinFunc{"input", func(args ...any) (any, ArErr) {
return input(args...), ArErr{}
}}
}

View File

@@ -151,6 +151,7 @@ func translate(codelines []UNPARSEcode) ([]any, ArErr) {
if err.EXISTS {
return nil, err
}
translated = append(translated, val)
}
return translated, ArErr{}