mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 00:46:07 +00:00
make for loops use int64 to hopefully speed up iterations
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -126,7 +125,7 @@ func ArArray(arr []any) ArObject {
|
||||
if typeof(a[0]) == "string" {
|
||||
var name = ArValidToAny(a[0]).(string)
|
||||
if name == "length" {
|
||||
return Number(compiledNumber{big.NewInt(int64(len(arr)))}), ArErr{}
|
||||
return Number(len(arr)), ArErr{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -100,8 +99,31 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
||||
if typeof(stepval) != "number" {
|
||||
return nil, ArErr{"Type Error", "for loop step value must be a number", loop.line, loop.path, loop.code, true}
|
||||
}
|
||||
i := from
|
||||
step := stepval.(ArObject)
|
||||
if isNumberInt64(from) && isNumberInt64(to) && isNumberInt64(step) {
|
||||
i, _ := numberToInt64(from)
|
||||
to_, _ := numberToInt64(to)
|
||||
step_, _ := numberToInt64(step)
|
||||
layer := anymap{}
|
||||
stacks := append(stack, Map(layer))
|
||||
for i <= to_ {
|
||||
layer[loop.variable] = Number(i)
|
||||
resp, err := runVal(loop.body, stacks, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
switch x := resp.(type) {
|
||||
case Return:
|
||||
return x, ArErr{}
|
||||
case Break:
|
||||
return nil, ArErr{}
|
||||
case Continue:
|
||||
}
|
||||
i += step_
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}
|
||||
i := from
|
||||
direction_obj, err := CompareObjects(step, _zero_Number)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
@@ -118,11 +140,11 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
||||
if error != nil {
|
||||
return nil, ArErr{"Type Error", error.Error(), loop.line, loop.path, loop.code, true}
|
||||
}
|
||||
fmt.Println(currentDirection, direction)
|
||||
layer := anymap{}
|
||||
stacks := append(stack, Map(layer))
|
||||
for currentDirection == direction {
|
||||
resp, err := runVal(loop.body, append(stack, Map(anymap{
|
||||
loop.variable: i,
|
||||
})), stacklevel+1)
|
||||
layer[loop.variable] = i
|
||||
resp, err := runVal(loop.body, stacks, stacklevel+1)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func convertToArgon(obj any) any {
|
||||
case string:
|
||||
return ArString(x)
|
||||
case float64:
|
||||
return Number(compiledNumber{value: newNumber().SetFloat64(x)})
|
||||
return Number(x)
|
||||
case bool:
|
||||
return x
|
||||
case nil:
|
||||
|
||||
@@ -8,6 +8,6 @@ var e_RAT, _ = new(big.Rat).SetString("2.718281828459045235360287471352662497757
|
||||
var e ArObject
|
||||
|
||||
func init() {
|
||||
PI = Number(compiledNumber{PI_RAT})
|
||||
e = Number(compiledNumber{e_RAT})
|
||||
PI = Number(PI_RAT)
|
||||
e = Number(e_RAT)
|
||||
}
|
||||
|
||||
1297
src/number.go
1297
src/number.go
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -210,9 +209,7 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
}
|
||||
return runTryCatch(x, stack, stacklevel+1)
|
||||
case compiledNumber:
|
||||
return Number(x), ArErr{}
|
||||
case *big.Rat, *big.Int:
|
||||
return Number(compiledNumber{x}), ArErr{}
|
||||
return Number(x.value), ArErr{}
|
||||
case bool, ArObject, nil, Callable, builtinFunc, anymap:
|
||||
return x, ArErr{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user