mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56: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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -126,7 +125,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
if typeof(a[0]) == "string" {
|
if typeof(a[0]) == "string" {
|
||||||
var name = ArValidToAny(a[0]).(string)
|
var name = ArValidToAny(a[0]).(string)
|
||||||
if name == "length" {
|
if name == "length" {
|
||||||
return Number(compiledNumber{big.NewInt(int64(len(arr)))}), ArErr{}
|
return Number(len(arr)), ArErr{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -100,8 +99,31 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if typeof(stepval) != "number" {
|
if typeof(stepval) != "number" {
|
||||||
return nil, ArErr{"Type Error", "for loop step value must be a number", loop.line, loop.path, loop.code, true}
|
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)
|
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)
|
direction_obj, err := CompareObjects(step, _zero_Number)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -118,11 +140,11 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if error != nil {
|
if error != nil {
|
||||||
return nil, ArErr{"Type Error", error.Error(), loop.line, loop.path, loop.code, true}
|
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 {
|
for currentDirection == direction {
|
||||||
resp, err := runVal(loop.body, append(stack, Map(anymap{
|
layer[loop.variable] = i
|
||||||
loop.variable: i,
|
resp, err := runVal(loop.body, stacks, stacklevel+1)
|
||||||
})), stacklevel+1)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func convertToArgon(obj any) any {
|
|||||||
case string:
|
case string:
|
||||||
return ArString(x)
|
return ArString(x)
|
||||||
case float64:
|
case float64:
|
||||||
return Number(compiledNumber{value: newNumber().SetFloat64(x)})
|
return Number(x)
|
||||||
case bool:
|
case bool:
|
||||||
return x
|
return x
|
||||||
case nil:
|
case nil:
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ var e_RAT, _ = new(big.Rat).SetString("2.718281828459045235360287471352662497757
|
|||||||
var e ArObject
|
var e ArObject
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
PI = Number(compiledNumber{PI_RAT})
|
PI = Number(PI_RAT)
|
||||||
e = Number(compiledNumber{e_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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -210,9 +209,7 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
return runTryCatch(x, stack, stacklevel+1)
|
return runTryCatch(x, stack, stacklevel+1)
|
||||||
case compiledNumber:
|
case compiledNumber:
|
||||||
return Number(x), ArErr{}
|
return Number(x.value), ArErr{}
|
||||||
case *big.Rat, *big.Int:
|
|
||||||
return Number(compiledNumber{x}), ArErr{}
|
|
||||||
case bool, ArObject, nil, Callable, builtinFunc, anymap:
|
case bool, ArObject, nil, Callable, builtinFunc, anymap:
|
||||||
return x, ArErr{}
|
return x, ArErr{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user