mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
Compare commits
48 Commits
test
...
oop_number
| Author | SHA1 | Date | |
|---|---|---|---|
| bfdb7b6e6a | |||
| 70f2c47e4f | |||
| b4a02be086 | |||
| 14a94274c4 | |||
| 53f7637234 | |||
| 7c23db80d4 | |||
| 3761070e82 | |||
| 7aadb812e4 | |||
| 5afa0b10c7 | |||
| 9945e1590f | |||
| d48b0ab7b6 | |||
| 051581c84b | |||
| 677643eeed | |||
| f0876bd5ac | |||
| 37a3d56b5f | |||
| 0a8952bc3b | |||
| a8fb5d4c1f | |||
| 42e12933bf | |||
| 31158dfb89 | |||
| e8d25d231c | |||
| bf15b435c2 | |||
|
|
82aae37479 | ||
| 269430b025 | |||
| 23a9a443d6 | |||
| fafc016ea5 | |||
| a57d79587e | |||
| 046ad89679 | |||
| cf040a5209 | |||
| efcc155e55 | |||
| 56f5fbd61a | |||
|
|
7a7f785b64 | ||
| b3a07d7f63 | |||
| 7f86d345ae | |||
| 4b66d23597 | |||
| c207c0668d | |||
| 65c608e088 | |||
| 8e887aeaff | |||
| 6dee9d6874 | |||
| 6295e23d1b | |||
| 140ce3d2a8 | |||
| 501bbff1a2 | |||
| 541ff1b172 | |||
| b93ecdc4d7 | |||
| 8d62e4c0c1 | |||
| 3f2c7d8f5b | |||
| 820da24175 | |||
| 41b716c690 | |||
| 2a801a19d8 |
24
.github/workflows/build_release.yml
vendored
Normal file
24
.github/workflows/build_release.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# workflow name
|
||||||
|
name: Generate release-artifacts
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- created
|
||||||
|
|
||||||
|
# workflow tasks
|
||||||
|
jobs:
|
||||||
|
generate:
|
||||||
|
name: Generate cross-platform builds
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout the repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Generate build files
|
||||||
|
uses: thatisuday/go-cross-build@v1
|
||||||
|
with:
|
||||||
|
platforms: 'linux/amd64, darwin/amd64, windows/amd64'
|
||||||
|
package: 'src'
|
||||||
|
name: 'argon'
|
||||||
|
compress: 'true'
|
||||||
|
dest: 'bin'
|
||||||
45
.github/workflows/build_releases.yml
vendored
45
.github/workflows/build_releases.yml
vendored
@@ -1,45 +0,0 @@
|
|||||||
name: Build and Release Go Binary
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types:
|
|
||||||
- created
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build and Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: 1.20 # Use your desired Go version
|
|
||||||
|
|
||||||
- name: Build Go project
|
|
||||||
run: go build -o argon ./src
|
|
||||||
|
|
||||||
- name: Create release
|
|
||||||
id: create_release
|
|
||||||
uses: actions/create-release@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
tag_name: ${{ github.ref }}
|
|
||||||
release_name: Release ${{ github.ref }}
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
|
|
||||||
- name: Upload binary to release
|
|
||||||
id: upload-release-asset
|
|
||||||
uses: actions/upload-release-asset@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
|
||||||
asset_path: ./argon
|
|
||||||
asset_name: argon
|
|
||||||
asset_content_type: application/octet-stream
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "argon-v3",
|
|
||||||
"version": "3.0.1"
|
|
||||||
}
|
|
||||||
5
go.mod
5
go.mod
@@ -7,7 +7,10 @@ require (
|
|||||||
github.com/wadey/go-rounding v1.1.0
|
github.com/wadey/go-rounding v1.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/joho/godotenv v1.5.1 // indirect
|
require (
|
||||||
|
github.com/chzyer/readline v1.5.1 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2
|
github.com/gabriel-vasile/mimetype v1.4.2
|
||||||
|
|||||||
5
go.sum
5
go.sum
@@ -1,3 +1,7 @@
|
|||||||
|
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
|
||||||
|
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
|
||||||
|
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
|
||||||
|
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
|
||||||
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
|
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
|
||||||
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
|
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
@@ -19,6 +23,7 @@ golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
|||||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
[{"Name":"welcome","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=welcome\u0026version=1.0.0","Remote":"isotope.wbell.dev"},{"Name":"this","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=this\u0026version=1.0.0","Remote":"isotope.wbell.dev"},{"Name":"csv.ar","Version":"1.0.0","URL":"http://isotope.wbell.dev/isotope-download?name=csv.ar\u0026version=1.0.0","Remote":"isotope.wbell.dev"}]
|
|
||||||
@@ -5,7 +5,9 @@
|
|||||||
<h1>Argon v3</h1>
|
<h1>Argon v3</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
ARGON 3 is a math-driven programming language designed to make code easy to read and write. It's not meant to be fast, as it's interpreted. This specification should be used as a guideline, and is subject to change for later versions. Later updates for Argon 3 should be backwards compatible (where possible) with code designed for older versions of the interpreter.
|
[](https://github.com/Open-Argon/argon-v3/actions/workflows/go.yml)
|
||||||
|
|
||||||
|
ARGON 3 is a math-driven programming language designed to make code easy to read and write. It's not meant to be fast, as it's interpreted.
|
||||||
|
|
||||||
## 📚 Features
|
## 📚 Features
|
||||||
- Easy to read and write: Argon 3 is designed with clarity of code in mind, making it easier for you and others to read and write code.
|
- Easy to read and write: Argon 3 is designed with clarity of code in mind, making it easier for you and others to read and write code.
|
||||||
@@ -13,7 +15,6 @@ ARGON 3 is a math-driven programming language designed to make code easy to read
|
|||||||
- Math-driven: Designed for mathematical computations, Argon 3 uses techniques and rules set in maths. It's designed to be easy for mathematicians to write and understand algorithms in.
|
- Math-driven: Designed for mathematical computations, Argon 3 uses techniques and rules set in maths. It's designed to be easy for mathematicians to write and understand algorithms in.
|
||||||
- Interpreted: Argon 3 is an interpreted language, so you don't need to compile your code before running it.
|
- Interpreted: Argon 3 is an interpreted language, so you don't need to compile your code before running it.
|
||||||
- Cross-platform: Argon 3 can be run on any platform that has an interpreter for it.
|
- Cross-platform: Argon 3 can be run on any platform that has an interpreter for it.
|
||||||
- Lightweight: The Argon 3 interpreter is small and doesn't require a lot of system resources to run.
|
|
||||||
|
|
||||||
## 💻 Installation
|
## 💻 Installation
|
||||||
As of now, Argon 3 does not have an installer. Feel free to clone this repo and run the `build` file for your plateform. the build will be found in `bin/argon(.exe)`.
|
As of now, Argon 3 does not have an installer. Feel free to clone this repo and run the `build` file for your plateform. the build will be found in `bin/argon(.exe)`.
|
||||||
|
|||||||
9
server_test/app.ar
Normal file
9
server_test/app.ar
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import "http.ar" as http
|
||||||
|
|
||||||
|
let server = http.server()
|
||||||
|
|
||||||
|
let home(req,res) = do
|
||||||
|
res.send("hello world")
|
||||||
|
server.get("/",home)
|
||||||
|
|
||||||
|
server.run()
|
||||||
4
server_test/argon-package.json
Normal file
4
server_test/argon-package.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"name": "server-test",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
1
server_test/iso-lock.json
Normal file
1
server_test/iso-lock.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"Name":"http.ar","Version":"1.1.6","URL":"https://isotope.wbell.dev/isotope-download?name=http.ar\u0026version=1.1.6","Remote":"isotope.wbell.dev"}]
|
||||||
48
src/abs.go
48
src/abs.go
@@ -40,38 +40,28 @@ func parseAbs(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runAbs(x ABS, stack stack, stacklevel int) (any, ArErr) {
|
func runAbs(x ABS, stack stack, stacklevel int) (any, ArErr) {
|
||||||
resp, err := runVal(x.body, stack, stacklevel+1)
|
value, err := runVal(x, stack, stacklevel+1)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(resp) != "number" {
|
switch value := value.(type) {
|
||||||
return nil, ArErr{TYPE: "Runtime Error",
|
case ArObject:
|
||||||
message: fmt.Sprintf("abs expected number, got %s", typeof(resp)),
|
if Callable, ok := value.obj["__abs__"]; ok {
|
||||||
EXISTS: true,
|
return runCall(call{
|
||||||
|
Callable: Callable,
|
||||||
|
Args: []any{},
|
||||||
|
Code: x.code,
|
||||||
|
Line: x.line,
|
||||||
|
Path: x.path,
|
||||||
|
}, stack, stacklevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return abs(resp.(number)), ArErr{}
|
return nil, ArErr{
|
||||||
|
"TypeError",
|
||||||
|
fmt.Sprint("abs() not supported on ", typeof(value)),
|
||||||
|
x.line,
|
||||||
|
x.path,
|
||||||
|
x.code,
|
||||||
|
true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func abs(x number) number {
|
|
||||||
if x.Sign() < 0 {
|
|
||||||
return x.Neg(x)
|
|
||||||
}
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
var ArAbs = builtinFunc{"abs", func(args ...any) (any, ArErr) {
|
|
||||||
if len(args) != 1 {
|
|
||||||
return nil, ArErr{TYPE: "Runtime Error",
|
|
||||||
message: fmt.Sprintf("abs expected 1 argument, got %d", len(args)),
|
|
||||||
EXISTS: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if typeof(args[0]) != "number" {
|
|
||||||
return nil, ArErr{TYPE: "Runtime Error",
|
|
||||||
message: fmt.Sprintf("abs expected number, got %s", typeof(args[0])),
|
|
||||||
EXISTS: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return abs(args[0].(number)), ArErr{}
|
|
||||||
}}
|
|
||||||
|
|||||||
232
src/array.go
232
src/array.go
@@ -23,7 +23,48 @@ func ArArray(arr []any) ArObject {
|
|||||||
anymap{
|
anymap{
|
||||||
"__name__": "array",
|
"__name__": "array",
|
||||||
"__value__": arr,
|
"__value__": arr,
|
||||||
"length": newNumber().SetUint64(uint64(len(arr))),
|
},
|
||||||
|
}
|
||||||
|
val.obj["__json__"] = builtinFunc{
|
||||||
|
"__json__",
|
||||||
|
func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "number" {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: "expected number, got " + typeof(args[0]),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output := []string{}
|
||||||
|
|
||||||
|
level, err := numberToInt64(args[0].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, value := range arr {
|
||||||
|
str, err := jsonstringify(value, level+1)
|
||||||
|
if err != nil {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output = append(output, str)
|
||||||
|
}
|
||||||
|
return "[" + strings.Join(output, ", ") + "]", ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
val.obj["__setindex__"] = builtinFunc{
|
val.obj["__setindex__"] = builtinFunc{
|
||||||
@@ -31,29 +72,37 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "number" {
|
if typeof(a[0]) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "dex must be a number",
|
message: "dex must be a number",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !a[0].(number).IsInt() {
|
if !isNumberInt(a[0].(ArObject)) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "index must be an integer",
|
message: "index must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := int(a[0].(number).Num().Int64())
|
num64, err := numberToInt64(a[0].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := int(num64)
|
||||||
if num < 0 || num >= len(arr) {
|
if num < 0 || num >= len(arr) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "IndexError",
|
TYPE: "Index Error",
|
||||||
message: "index out of range",
|
message: "index out of range",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -68,8 +117,18 @@ func ArArray(arr []any) ArObject {
|
|||||||
// a[0] is start
|
// a[0] is start
|
||||||
// a[1] is end
|
// a[1] is end
|
||||||
// a[2] is step
|
// a[2] is step
|
||||||
if len(a) > 3 {
|
if len(a) > 3 || len(a) == 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if len(a) == 1 {
|
||||||
|
if typeof(a[0]) == "string" {
|
||||||
|
var name = ArValidToAny(a[0]).(string)
|
||||||
|
if name == "length" {
|
||||||
|
return Number(len(arr)), ArErr{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
start int = 0
|
start int = 0
|
||||||
@@ -79,40 +138,64 @@ func ArArray(arr []any) ArObject {
|
|||||||
{
|
{
|
||||||
if a[0] == nil {
|
if a[0] == nil {
|
||||||
start = 0
|
start = 0
|
||||||
} else if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
|
} else if typeof(a[0]) != "number" || !isNumberInt(a[0].(ArObject)) {
|
||||||
return "", ArErr{
|
return "", ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "slice index must be an integer",
|
message: "slice index must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
start = int(a[0].(number).Num().Int64())
|
start64, err := numberToInt64(a[0].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start = int(start64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(a) > 1 {
|
if len(a) > 1 {
|
||||||
if a[1] == nil {
|
if a[1] == nil {
|
||||||
end = len(arr)
|
end = len(arr)
|
||||||
} else if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
|
} else if typeof(a[1]) != "number" || !isNumberInt(a[1].(ArObject)) {
|
||||||
return "", ArErr{
|
return "", ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "slice index must be an integer",
|
message: "slice index must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
end = int(a[1].(number).Num().Int64())
|
end64, err := numberToInt64(a[1].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end = int(end64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(a) > 2 {
|
if len(a) > 2 {
|
||||||
if a[2] == nil {
|
if a[2] == nil {
|
||||||
step = 1
|
step = 1
|
||||||
} else if typeof(a[2]) != "number" || !a[2].(number).IsInt() {
|
} else if typeof(a[2]) != "number" || !isNumberInt(a[2].(ArObject)) {
|
||||||
return "", ArErr{
|
return "", ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "slice index must be an integer",
|
message: "slice index must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
step = int(a[2].(number).Num().Int64())
|
step64, err := numberToInt64(a[2].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return "", ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
step = int(step64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var ogStart = start
|
var ogStart = start
|
||||||
@@ -127,7 +210,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
}
|
}
|
||||||
if start >= len(arr) || start < 0 {
|
if start >= len(arr) || start < 0 {
|
||||||
return "", ArErr{
|
return "", ArErr{
|
||||||
TYPE: "IndexError",
|
TYPE: "Index Error",
|
||||||
message: "index out of range, trying to access index " + fmt.Sprint(ogStart) + " in array of length " + fmt.Sprint(len(arr)),
|
message: "index out of range, trying to access index " + fmt.Sprint(ogStart) + " in array of length " + fmt.Sprint(len(arr)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -155,35 +238,42 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "number" {
|
if typeof(args[0]) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a number",
|
message: "argument must be a number",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !args[0].(number).IsInt() {
|
if !isNumberInt(args[0].(ArObject)) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be an integer",
|
message: "argument must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := int(args[0].(number).Num().Int64())
|
num64, err := (numberToInt64(args[0].(ArObject)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := int(num64)
|
||||||
if num < 0 || num >= len(arr) {
|
if num < 0 || num >= len(arr) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "IndexError",
|
TYPE: "Index Error",
|
||||||
message: "index out of range",
|
message: "index out of range",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = append(arr[:num], arr[num+1:]...)
|
arr = append(arr[:num], arr[num+1:]...)
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -192,13 +282,12 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = append(arr, args...)
|
arr = append(arr, args...)
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -208,35 +297,42 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "number" {
|
if typeof(args[0]) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a number",
|
message: "argument must be a number",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !args[0].(number).IsInt() {
|
if !isNumberInt(args[0].(ArObject)) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be an integer",
|
message: "argument must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := int(args[0].(number).Num().Int64())
|
num64, err := numberToInt64(args[0].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := int(num64)
|
||||||
if num < 0 || num > len(arr) {
|
if num < 0 || num > len(arr) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "IndexError",
|
TYPE: "Index Error",
|
||||||
message: "index out of range",
|
message: "index out of range",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = append(arr[:num], append(args[1:], arr[num:]...)...)
|
arr = append(arr[:num], append(args[1:], arr[num:]...)...)
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -246,7 +342,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "too many arguments",
|
message: "too many arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -254,35 +350,41 @@ func ArArray(arr []any) ArObject {
|
|||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
if typeof(args[0]) != "number" {
|
if typeof(args[0]) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a number",
|
message: "argument must be a number",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !args[0].(number).IsInt() {
|
if !isNumberInt(args[0].(ArObject)) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be an integer",
|
message: "argument must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := int(args[0].(number).Num().Int64())
|
num64, err := (numberToInt64(args[0].(ArObject)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num := int(num64)
|
||||||
if num < 0 || num >= len(arr) {
|
if num < 0 || num >= len(arr) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "IndexError",
|
TYPE: "Index Error",
|
||||||
message: "index out of range",
|
message: "index out of range",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v := arr[num]
|
v := arr[num]
|
||||||
arr = append(arr[:num], arr[num+1:]...)
|
arr = append(arr[:num], arr[num+1:]...)
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return v, ArErr{}
|
return v, ArErr{}
|
||||||
}
|
}
|
||||||
v := arr[len(arr)-1]
|
v := arr[len(arr)-1]
|
||||||
arr = arr[:len(arr)-1]
|
arr = arr[:len(arr)-1]
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return v, ArErr{}
|
return v, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -292,13 +394,12 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "too many arguments",
|
message: "too many arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = []any{}
|
arr = []any{}
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -308,20 +409,19 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "array" {
|
if typeof(args[0]) != "array" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be an array",
|
message: "argument must be an array",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = append(arr, args[0].(ArObject).obj["__value__"].([]any)...)
|
arr = append(arr, args[0].(ArObject).obj["__value__"].([]any)...)
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -331,7 +431,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) > 2 {
|
if len(args) > 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "too many arguments",
|
message: "too many arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -340,7 +440,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
if len(args) >= 1 {
|
if len(args) >= 1 {
|
||||||
if typeof(args[0]) != "boolean" {
|
if typeof(args[0]) != "boolean" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a boolean",
|
message: "argument must be a boolean",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -350,7 +450,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
if len(args) == 2 {
|
if len(args) == 2 {
|
||||||
if typeof(args[1]) != "function" {
|
if typeof(args[1]) != "function" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a function",
|
message: "argument must be a function",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -370,7 +470,6 @@ func ArArray(arr []any) ArObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = output
|
arr = output
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}
|
}
|
||||||
@@ -386,7 +485,6 @@ func ArArray(arr []any) ArObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
arr = output
|
arr = output
|
||||||
val.obj["length"] = newNumber().SetUint64(uint64(len(arr)))
|
|
||||||
val.obj["__value__"] = arr
|
val.obj["__value__"] = arr
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -396,14 +494,14 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "function" {
|
if typeof(args[0]) != "function" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a function",
|
message: "argument must be a function",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -427,14 +525,14 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "function" {
|
if typeof(args[0]) != "function" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a function",
|
message: "argument must be a function",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -460,14 +558,14 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument, expected 2 got " + fmt.Sprint(len(args)),
|
message: "missing argument, expected 2 got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "function" {
|
if typeof(args[0]) != "function" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a function",
|
message: "argument must be a function",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -498,14 +596,14 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a string",
|
message: "argument must be a string",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -514,7 +612,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if typeof(v) != "string" {
|
if typeof(v) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "array must be an array of strings",
|
message: "array must be an array of strings",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -529,14 +627,14 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument(s)",
|
message: "missing argument(s)",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "array" {
|
if typeof(args[0]) != "array" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be an array",
|
message: "argument must be an array",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -550,7 +648,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -580,7 +678,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -605,7 +703,7 @@ func ArArray(arr []any) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "missing argument",
|
message: "missing argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "math/big"
|
||||||
|
|
||||||
func AnyToArValid(arr any) any {
|
func AnyToArValid(arr any) any {
|
||||||
switch arr := arr.(type) {
|
switch arr := arr.(type) {
|
||||||
case []any:
|
case []any:
|
||||||
@@ -12,6 +14,8 @@ func AnyToArValid(arr any) any {
|
|||||||
return ArBuffer(arr)
|
return ArBuffer(arr)
|
||||||
case byte:
|
case byte:
|
||||||
return ArByte(arr)
|
return ArByte(arr)
|
||||||
|
case int, int64, float64, float32, *big.Rat, *big.Int:
|
||||||
|
return Number(arr)
|
||||||
default:
|
default:
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
@@ -26,20 +30,3 @@ func ArValidToAny(a any) any {
|
|||||||
}
|
}
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func ArValidToHash(a any) (any, ArErr) {
|
|
||||||
switch a := a.(type) {
|
|
||||||
case ArObject:
|
|
||||||
if callable, ok := a.obj["__hash__"]; ok {
|
|
||||||
value, err := runCall(call{
|
|
||||||
Callable: callable,
|
|
||||||
Args: []any{},
|
|
||||||
}, stack{}, 0)
|
|
||||||
if err.EXISTS {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return value, ArErr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return a, ArErr{}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ func anyToBool(x any) bool {
|
|||||||
switch x := x.(type) {
|
switch x := x.(type) {
|
||||||
case string:
|
case string:
|
||||||
return x != ""
|
return x != ""
|
||||||
case number:
|
|
||||||
return x.Cmp(newNumber()) != 0
|
|
||||||
case bool:
|
case bool:
|
||||||
return x
|
return x
|
||||||
case nil:
|
case nil:
|
||||||
|
|||||||
@@ -6,18 +6,11 @@ import (
|
|||||||
|
|
||||||
var bracketsCompile = makeRegex(`( *)\((.|\n)+\)( *)`)
|
var bracketsCompile = makeRegex(`( *)\((.|\n)+\)( *)`)
|
||||||
|
|
||||||
type brackets struct {
|
|
||||||
VAL any
|
|
||||||
line int
|
|
||||||
code string
|
|
||||||
path string
|
|
||||||
}
|
|
||||||
|
|
||||||
func isBrackets(code UNPARSEcode) bool {
|
func isBrackets(code UNPARSEcode) bool {
|
||||||
return bracketsCompile.MatchString(code.code)
|
return bracketsCompile.MatchString(code.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseBrackets(code UNPARSEcode, index int, codeline []UNPARSEcode) (brackets, bool, ArErr, int) {
|
func parseBrackets(code UNPARSEcode, index int, codeline []UNPARSEcode) (any, bool, ArErr, int) {
|
||||||
trimmed := strings.TrimSpace(code.code)
|
trimmed := strings.TrimSpace(code.code)
|
||||||
resp, worked, err, i := translateVal(UNPARSEcode{
|
resp, worked, err, i := translateVal(UNPARSEcode{
|
||||||
code: trimmed[1 : len(trimmed)-1],
|
code: trimmed[1 : len(trimmed)-1],
|
||||||
@@ -25,10 +18,5 @@ func parseBrackets(code UNPARSEcode, index int, codeline []UNPARSEcode) (bracket
|
|||||||
line: code.line,
|
line: code.line,
|
||||||
path: code.path,
|
path: code.path,
|
||||||
}, index, codeline, 0)
|
}, index, codeline, 0)
|
||||||
return brackets{
|
return resp, worked, err, i
|
||||||
VAL: resp,
|
|
||||||
line: code.line,
|
|
||||||
code: code.realcode,
|
|
||||||
path: code.path,
|
|
||||||
}, worked, err, i
|
|
||||||
}
|
}
|
||||||
|
|||||||
245
src/buffer.go
245
src/buffer.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,19 +16,19 @@ func ArByte(Byte byte) ArObject {
|
|||||||
obj.obj["__string__"] = builtinFunc{
|
obj.obj["__string__"] = builtinFunc{
|
||||||
"__string__",
|
"__string__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
return "<byte>", ArErr{}
|
return ArString("0x" + hex.EncodeToString([]byte{Byte})), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["__repr__"] = builtinFunc{
|
obj.obj["__repr__"] = builtinFunc{
|
||||||
"__repr__",
|
"__repr__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
return "<byte>", ArErr{}
|
return ArString("<byte 0x" + hex.EncodeToString([]byte{Byte}) + ">"), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["number"] = builtinFunc{
|
obj.obj["number"] = builtinFunc{
|
||||||
"number",
|
"number",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
return newNumber().SetInt64(int64(Byte)), ArErr{}
|
return Number(int64(Byte)), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["from"] = builtinFunc{
|
obj.obj["from"] = builtinFunc{
|
||||||
@@ -35,30 +36,22 @@ func ArByte(Byte byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected at least 1 argument, got 0",
|
message: "expected at least 1 argument, got 0",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
switch x := a[0].(type) {
|
switch x := a[0].(type) {
|
||||||
case number:
|
case int64:
|
||||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
if x > 255 || x < 0 {
|
||||||
return nil, ArErr{
|
|
||||||
TYPE: "TypeError",
|
|
||||||
message: "expected integer, got " + fmt.Sprint(x),
|
|
||||||
EXISTS: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
n := x.Num().Int64()
|
|
||||||
if n > 255 || n < 0 {
|
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "ValueError",
|
TYPE: "ValueError",
|
||||||
message: "expected number between 0 and 255, got " + fmt.Sprint(floor(x).Num().Int64()),
|
message: "expected number between 0 and 255, got " + fmt.Sprint(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Byte = byte(n)
|
Byte = byte(x)
|
||||||
case string:
|
case string:
|
||||||
if len(x) != 1 {
|
if len(x) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -70,7 +63,7 @@ func ArByte(Byte byte) ArObject {
|
|||||||
Byte = byte(x[0])
|
Byte = byte(x[0])
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected number or string, got " + typeof(x),
|
message: "expected number or string, got " + typeof(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -86,19 +79,18 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
obj: anymap{
|
obj: anymap{
|
||||||
"__name__": "buffer",
|
"__name__": "buffer",
|
||||||
"__value__": buf,
|
"__value__": buf,
|
||||||
"length": newNumber().SetInt64(int64(len(buf))),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["__string__"] = builtinFunc{
|
obj.obj["__string__"] = builtinFunc{
|
||||||
"__string__",
|
"__string__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
return "<buffer>", ArErr{}
|
return ArString("<buffer length=" + fmt.Sprint(len(buf)) + ">"), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["__repr__"] = builtinFunc{
|
obj.obj["__repr__"] = builtinFunc{
|
||||||
"__repr__",
|
"__repr__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
return "<buffer>", ArErr{}
|
return ArString("<buffer length=" + fmt.Sprint(len(buf)) + ">"), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["from"] = builtinFunc{
|
obj.obj["from"] = builtinFunc{
|
||||||
@@ -106,7 +98,7 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected at least 1 argument, got 0",
|
message: "expected at least 1 argument, got 0",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -120,19 +112,20 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
case []any:
|
case []any:
|
||||||
outputbuf := []byte{}
|
outputbuf := []byte{}
|
||||||
for _, v := range x {
|
for _, v := range x {
|
||||||
switch y := v.(type) {
|
V := ArValidToAny(v)
|
||||||
case number:
|
switch y := V.(type) {
|
||||||
if y.Denom().Cmp(one.Denom()) != 0 {
|
case int64:
|
||||||
|
if y > 255 || y < 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "ValueError",
|
||||||
message: "Cannot convert non-integer to byte",
|
message: "expected number between 0 and 255, got " + fmt.Sprint(y),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outputbuf = append(outputbuf, byte(y.Num().Int64()))
|
outputbuf = append(outputbuf, byte(y))
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "Cannot convert " + typeof(v) + " to byte",
|
message: "Cannot convert " + typeof(v) + " to byte",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -141,13 +134,12 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
buf = outputbuf
|
buf = outputbuf
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected string or buffer, got " + typeof(x),
|
message: "expected string or buffer, got " + typeof(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj.obj["__value__"] = buf
|
obj.obj["__value__"] = buf
|
||||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
|
||||||
return obj, ArErr{}
|
return obj, ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -156,7 +148,7 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -164,7 +156,7 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
splitVal := ArValidToAny(a[0])
|
splitVal := ArValidToAny(a[0])
|
||||||
if typeof(splitVal) != "buffer" {
|
if typeof(splitVal) != "buffer" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected buffer, got " + typeof(splitVal),
|
message: "expected buffer, got " + typeof(splitVal),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -173,20 +165,19 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
nVal := ArValidToAny(a[1])
|
nVal := ArValidToAny(a[1])
|
||||||
if typeof(nVal) != "number" {
|
if typeof(nVal) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected number, got " + typeof(nVal),
|
message: "expected number, got " + typeof(nVal),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nNum := nVal.(number)
|
n, err := numberToInt64(nVal.(ArObject))
|
||||||
if nNum.Denom().Cmp(one.Denom()) != 0 {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected integer, got " + fmt.Sprint(nNum),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n := nNum.Num().Int64()
|
|
||||||
var result [][]byte
|
var result [][]byte
|
||||||
start := 0
|
start := 0
|
||||||
var i int64
|
var i int64
|
||||||
@@ -216,7 +207,7 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -224,7 +215,7 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
splitVal := ArValidToAny(a[0])
|
splitVal := ArValidToAny(a[0])
|
||||||
if typeof(splitVal) != "buffer" {
|
if typeof(splitVal) != "buffer" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected buffer, got " + typeof(splitVal),
|
message: "expected buffer, got " + typeof(splitVal),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -255,44 +246,42 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startVal := ArValidToAny(a[0])
|
if typeof(a[0]) != "number" || typeof(a[1]) != "number" {
|
||||||
if typeof(startVal) != "number" {
|
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected number, got " + typeof(startVal),
|
message: "expected number, got " + typeof(a[0]) + " and " + typeof(a[1]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
start := startVal.(number)
|
start, err := numberToInt64(ArValidToAny(a[0]).(ArObject))
|
||||||
if start.Denom().Cmp(one.Denom()) != 0 {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected integer, got " + fmt.Sprint(start),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endVal := ArValidToAny(a[1])
|
end, err := numberToInt64(ArValidToAny(a[1]).(ArObject))
|
||||||
if typeof(endVal) != "number" {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected number, got " + typeof(endVal),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end := endVal.(number)
|
if start < 0 || end < 0 || start > int64(len(buf)) || end > int64(len(buf)) {
|
||||||
if end.Denom().Cmp(one.Denom()) != 0 {
|
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Index Error",
|
||||||
message: "expected integer, got " + fmt.Sprint(end),
|
message: "index out of range",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ArBuffer(buf[floor(start).Num().Int64():floor(end).Num().Int64()]), ArErr{}
|
return ArBuffer(buf[start:end]), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
obj.obj["to"] = builtinFunc{
|
obj.obj["to"] = builtinFunc{
|
||||||
@@ -300,14 +289,14 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected string, got " + typeof(a[0]),
|
message: "expected string, got " + typeof(a[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -325,12 +314,12 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
case "array":
|
case "array":
|
||||||
output := []any{}
|
output := []any{}
|
||||||
for _, v := range buf {
|
for _, v := range buf {
|
||||||
output = append(output, newNumber().SetInt64(int64(v)))
|
output = append(output, Number(int64(v)))
|
||||||
}
|
}
|
||||||
return ArArray(output), ArErr{}
|
return ArArray(output), ArErr{}
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected string, bytes or array, got '" + Type + "'",
|
message: "expected string, bytes or array, got '" + Type + "'",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -342,22 +331,22 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
switch x := a[0].(type) {
|
switch x := a[0].(type) {
|
||||||
case number:
|
case int64:
|
||||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
if x > 255 || x < 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "ValueError",
|
||||||
message: "Cannot convert non-integer to byte",
|
message: "expected number between 0 and 255, got " + fmt.Sprint(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf = append(buf, byte(x.Num().Int64()))
|
buf = append(buf, byte(x))
|
||||||
case string:
|
case string:
|
||||||
buf = append(buf, []byte(x)...)
|
buf = append(buf, []byte(x)...)
|
||||||
case []byte:
|
case []byte:
|
||||||
@@ -365,18 +354,18 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
case []any:
|
case []any:
|
||||||
for _, v := range x {
|
for _, v := range x {
|
||||||
switch y := v.(type) {
|
switch y := v.(type) {
|
||||||
case number:
|
case int64:
|
||||||
if y.Denom().Cmp(one.Denom()) != 0 {
|
if y > 255 || y < 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "ValueError",
|
||||||
message: "Cannot convert non-integer to byte",
|
message: "expected number between 0 and 255, got " + fmt.Sprint(y),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf = append(buf, byte(y.Num().Int64()))
|
buf = append(buf, byte(y))
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "Cannot convert " + typeof(v) + " to byte",
|
message: "Cannot convert " + typeof(v) + " to byte",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -384,13 +373,12 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected string, buffer or array, got " + typeof(x),
|
message: "expected string, buffer or array, got " + typeof(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj.obj["__value__"] = buf
|
obj.obj["__value__"] = buf
|
||||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
|
||||||
return obj, ArErr{}
|
return obj, ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -399,7 +387,7 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
message: "expected 2 arguments, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -408,30 +396,29 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
values := ArValidToAny(a[1])
|
values := ArValidToAny(a[1])
|
||||||
if typeof(poss) != "number" {
|
if typeof(poss) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected number, got " + typeof(poss),
|
message: "expected number, got " + typeof(poss),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos := poss.(number)
|
posNum, err := numberToInt64(poss.(ArObject))
|
||||||
if pos.Denom().Cmp(one.Denom()) != 0 {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "position must be an integer",
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
posNum := pos.Num().Int64()
|
|
||||||
switch x := values.(type) {
|
switch x := values.(type) {
|
||||||
case number:
|
case int64:
|
||||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
if x > 255 || x < 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "ValueError",
|
||||||
message: "Cannot convert non-integer to byte",
|
message: "expected number between 0 and 255, got " + fmt.Sprint(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf = append(buf[:posNum], append([]byte{byte(x.Num().Int64())}, buf[posNum:]...)...)
|
buf = append(buf[:posNum], append([]byte{byte(x)}, buf[posNum:]...)...)
|
||||||
case string:
|
case string:
|
||||||
buf = append(buf[:posNum], append([]byte(x), buf[posNum:]...)...)
|
buf = append(buf[:posNum], append([]byte(x), buf[posNum:]...)...)
|
||||||
case []byte:
|
case []byte:
|
||||||
@@ -439,18 +426,18 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
case []any:
|
case []any:
|
||||||
for _, v := range x {
|
for _, v := range x {
|
||||||
switch y := v.(type) {
|
switch y := v.(type) {
|
||||||
case number:
|
case int64:
|
||||||
if y.Denom().Cmp(one.Denom()) != 0 {
|
if y > 255 || y < 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "ValueError",
|
||||||
message: "Cannot convert non-integer to byte",
|
message: "expected number between 0 and 255, got " + fmt.Sprint(y),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf = append(buf[:posNum], append([]byte{byte(y.Num().Int64())}, buf[posNum:]...)...)
|
buf = append(buf[:posNum], append([]byte{byte(y)}, buf[posNum:]...)...)
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "Cannot convert " + typeof(v) + " to byte",
|
message: "Cannot convert " + typeof(v) + " to byte",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -458,22 +445,67 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected string or buffer, got " + typeof(x),
|
message: "expected string or buffer, got " + typeof(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj.obj["__value__"] = buf
|
obj.obj["__value__"] = buf
|
||||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
|
||||||
return obj, ArErr{}
|
return obj, ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
obj.obj["__getindex__"] = builtinFunc{
|
||||||
|
"__getindex__",
|
||||||
|
func(a ...any) (any, ArErr) {
|
||||||
|
if len(a) != 1 {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if len(a) == 1 {
|
||||||
|
if typeof(a[0]) == "string" {
|
||||||
|
var name = ArValidToAny(a[0]).(string)
|
||||||
|
if name == "length" {
|
||||||
|
return Number(len(buf)), ArErr{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
poss := a[0]
|
||||||
|
if typeof(poss) != "number" {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: "expected number, got " + typeof(poss),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
posNum, err := numberToInt64(poss.(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if posNum < 0 || posNum >= int64(len(buf)) {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Index Error",
|
||||||
|
message: "index out of range",
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ArByte(buf[posNum]), ArErr{}
|
||||||
|
},
|
||||||
|
}
|
||||||
obj.obj["remove"] = builtinFunc{
|
obj.obj["remove"] = builtinFunc{
|
||||||
"remove",
|
"remove",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(a)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -481,23 +513,28 @@ func ArBuffer(buf []byte) ArObject {
|
|||||||
poss := ArValidToAny(a[0])
|
poss := ArValidToAny(a[0])
|
||||||
if typeof(poss) != "number" {
|
if typeof(poss) != "number" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected number, got " + typeof(poss),
|
message: "expected number, got " + typeof(poss),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos := poss.(number)
|
posNum, err := numberToInt64(poss.(ArObject))
|
||||||
if pos.Denom().Cmp(one.Denom()) != 0 {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "position must be an integer",
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if posNum < 0 || posNum >= int64(len(buf)) {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Index Error",
|
||||||
|
message: "index out of range",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
posNum := pos.Num().Int64()
|
|
||||||
buf = append(buf[:posNum], buf[posNum+1:]...)
|
buf = append(buf[:posNum], buf[posNum+1:]...)
|
||||||
obj.obj["__value__"] = buf
|
obj.obj["__value__"] = buf
|
||||||
obj.obj["length"] = newNumber().SetInt64(int64(len(buf)))
|
|
||||||
return obj, ArErr{}
|
return obj, ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func ArgonString(args ...any) (any, ArErr) {
|
|||||||
|
|
||||||
func ArgonNumber(args ...any) (any, ArErr) {
|
func ArgonNumber(args ...any) (any, ArErr) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return newNumber(), ArErr{}
|
return _zero_Number, ArErr{}
|
||||||
}
|
}
|
||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
switch x := args[0].(type) {
|
switch x := args[0].(type) {
|
||||||
@@ -27,17 +27,17 @@ func ArgonNumber(args ...any) (any, ArErr) {
|
|||||||
if !isNumber(UNPARSEcode{code: x}) {
|
if !isNumber(UNPARSEcode{code: x}) {
|
||||||
return nil, ArErr{TYPE: "Conversion Error", message: "Cannot convert " + anyToArgon(x, true, true, 3, 0, false, 0) + " to a number", EXISTS: true}
|
return nil, ArErr{TYPE: "Conversion Error", message: "Cannot convert " + anyToArgon(x, true, true, 3, 0, false, 0) + " to a number", EXISTS: true}
|
||||||
}
|
}
|
||||||
N, _ := newNumber().SetString(x)
|
N := Number(x)
|
||||||
return N, ArErr{}
|
return N, ArErr{}
|
||||||
case number:
|
case int64, *big.Int, *big.Rat:
|
||||||
return x, ArErr{}
|
return Number(x), ArErr{}
|
||||||
case bool:
|
case bool:
|
||||||
if x {
|
if x {
|
||||||
return newNumber().SetInt64(1), ArErr{}
|
return _one_Number, ArErr{}
|
||||||
}
|
}
|
||||||
return newNumber(), ArErr{}
|
return _zero_Number, ArErr{}
|
||||||
case nil:
|
case nil:
|
||||||
return newNumber(), ArErr{}
|
return _zero_Number, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, ArErr{TYPE: "Number Error", message: "Cannot convert " + typeof(args[0]) + " to a number", EXISTS: true}
|
return nil, ArErr{TYPE: "Number Error", message: "Cannot convert " + typeof(args[0]) + " to a number", EXISTS: true}
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ func makeGlobal() ArObject {
|
|||||||
vars["env"] = env
|
vars["env"] = env
|
||||||
vars["term"] = ArTerm
|
vars["term"] = ArTerm
|
||||||
vars["ArgonVersion"] = ArString(VERSION)
|
vars["ArgonVersion"] = ArString(VERSION)
|
||||||
|
vars["ArgonVersionNumber"] = newNumber().SetInt64(VERSION_NUM)
|
||||||
vars["number"] = builtinFunc{"number", ArgonNumber}
|
vars["number"] = builtinFunc{"number", ArgonNumber}
|
||||||
vars["string"] = builtinFunc{"string", ArgonString}
|
vars["string"] = builtinFunc{"string", ArgonString}
|
||||||
vars["socket"] = Map(anymap{
|
vars["socket"] = Map(anymap{
|
||||||
"server": builtinFunc{"server", ArSocketServer},
|
"server": builtinFunc{"server", ArSocketServer},
|
||||||
"client": builtinFunc{"client", ArSocketClient},
|
"client": builtinFunc{"client", ArSocketClient},
|
||||||
})
|
})
|
||||||
vars["infinity"] = infinity
|
vars["eval"] = builtinFunc{"eval", AReval}
|
||||||
vars["map"] = builtinFunc{"map", func(a ...any) (any, ArErr) {
|
vars["map"] = builtinFunc{"map", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return Map(anymap{}), ArErr{}
|
return Map(anymap{}), ArErr{}
|
||||||
@@ -32,7 +33,7 @@ func makeGlobal() ArObject {
|
|||||||
case []any:
|
case []any:
|
||||||
if len(y) == 2 {
|
if len(y) == 2 {
|
||||||
if isUnhashable(y[0]) {
|
if isUnhashable(y[0]) {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot use unhashable value as key: " + typeof(y[0]), EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot use unhashable value as key: " + typeof(y[0]), EXISTS: true}
|
||||||
}
|
}
|
||||||
key := ArValidToAny(y[0])
|
key := ArValidToAny(y[0])
|
||||||
newmap[key] = y[1]
|
newmap[key] = y[1]
|
||||||
@@ -49,31 +50,42 @@ func makeGlobal() ArObject {
|
|||||||
}
|
}
|
||||||
return Map(newmap), ArErr{}
|
return Map(newmap), ArErr{}
|
||||||
}
|
}
|
||||||
return x, ArErr{}
|
|
||||||
|
newmap := anymap{}
|
||||||
|
for key, val := range x.obj {
|
||||||
|
newmap[key] = val
|
||||||
|
}
|
||||||
|
return Map(newmap), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot create map from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["hex"] = builtinFunc{"hex", func(a ...any) (any, ArErr) {
|
vars["hex"] = builtinFunc{"hex", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "expected 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "expected 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
switch x := a[0].(type) {
|
switch x := a[0].(type) {
|
||||||
case number:
|
case number:
|
||||||
if x.Denom().Cmp(one.Denom()) != 0 {
|
if x.Denom().Cmp(_one_Rat.Denom()) != 0 {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert non-integer to hex", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert non-integer to hex", EXISTS: true}
|
||||||
}
|
}
|
||||||
n := x.Num().Int64()
|
n := x.Num().Int64()
|
||||||
return ArString(fmt.Sprintf("%x", n)), ArErr{}
|
return ArString(fmt.Sprintf("%x", n)), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to hex", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert '" + typeof(a[0]) + "' to hex", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["buffer"] = builtinFunc{"buffer", func(a ...any) (any, ArErr) {
|
vars["buffer"] = builtinFunc{"buffer", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 0 {
|
if len(a) != 0 {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
}
|
}
|
||||||
return ArBuffer([]byte{}), ArErr{}
|
return ArBuffer([]byte{}), ArErr{}
|
||||||
}}
|
}}
|
||||||
|
vars["byte"] = builtinFunc{"byte", func(a ...any) (any, ArErr) {
|
||||||
|
if len(a) != 0 {
|
||||||
|
return nil, ArErr{TYPE: "Type Error", message: "expected 0 arguments, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
|
}
|
||||||
|
return ArByte(0), ArErr{}
|
||||||
|
}}
|
||||||
vars["throwError"] = builtinFunc{"throwError", ArThrowError}
|
vars["throwError"] = builtinFunc{"throwError", ArThrowError}
|
||||||
vars["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) {
|
vars["array"] = builtinFunc{"array", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
@@ -97,7 +109,7 @@ func makeGlobal() ArObject {
|
|||||||
}
|
}
|
||||||
return ArArray(newarray), ArErr{}
|
return ArArray(newarray), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot create array from '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot create array from '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["boolean"] = builtinFunc{"boolean", func(a ...any) (any, ArErr) {
|
vars["boolean"] = builtinFunc{"boolean", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
@@ -124,11 +136,11 @@ func makeGlobal() ArObject {
|
|||||||
switch x := a[1].(type) {
|
switch x := a[1].(type) {
|
||||||
case number:
|
case number:
|
||||||
if !x.IsInt() {
|
if !x.IsInt() {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
|
||||||
}
|
}
|
||||||
precision = x
|
precision = x
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +148,7 @@ func makeGlobal() ArObject {
|
|||||||
case number:
|
case number:
|
||||||
return round(newNumber().Set(x), int(precision.Num().Int64())), ArErr{}
|
return round(newNumber().Set(x), int(precision.Num().Int64())), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot round '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot round '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["floor"] = builtinFunc{"floor", func(a ...any) (any, ArErr) {
|
vars["floor"] = builtinFunc{"floor", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
@@ -147,7 +159,7 @@ func makeGlobal() ArObject {
|
|||||||
case number:
|
case number:
|
||||||
return floor(x), ArErr{}
|
return floor(x), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot floor '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot floor '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["ceil"] = builtinFunc{"ceil", func(a ...any) (any, ArErr) {
|
vars["ceil"] = builtinFunc{"ceil", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
@@ -159,7 +171,7 @@ func makeGlobal() ArObject {
|
|||||||
case number:
|
case number:
|
||||||
return ceil(x), ArErr{}
|
return ceil(x), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot ceil '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot ceil '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["sqrt"] = builtinFunc{"sqrt", ArgonSqrt}
|
vars["sqrt"] = builtinFunc{"sqrt", ArgonSqrt}
|
||||||
vars["file"] = ArFile
|
vars["file"] = ArFile
|
||||||
@@ -180,7 +192,6 @@ func makeGlobal() ArObject {
|
|||||||
vars["todeg"] = ArToDeg
|
vars["todeg"] = ArToDeg
|
||||||
vars["colour"] = ArColour
|
vars["colour"] = ArColour
|
||||||
vars["torad"] = ArToRad
|
vars["torad"] = ArToRad
|
||||||
vars["abs"] = ArAbs
|
|
||||||
vars["fraction"] = builtinFunc{"fraction", func(a ...any) (any, ArErr) {
|
vars["fraction"] = builtinFunc{"fraction", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return nil, ArErr{TYPE: "fraction", message: "fraction takes 1 argument",
|
return nil, ArErr{TYPE: "fraction", message: "fraction takes 1 argument",
|
||||||
@@ -205,7 +216,7 @@ func makeGlobal() ArObject {
|
|||||||
return resp, ArErr{}
|
return resp, ArErr{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot fraction '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot fraction '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
vars["dir"] = builtinFunc{"dir", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
@@ -216,7 +227,7 @@ func makeGlobal() ArObject {
|
|||||||
case ArObject:
|
case ArObject:
|
||||||
newarray := []any{}
|
newarray := []any{}
|
||||||
for key := range x.obj {
|
for key := range x.obj {
|
||||||
newarray = append(newarray, key)
|
newarray = append(newarray, AnyToArValid(key))
|
||||||
}
|
}
|
||||||
return ArArray(newarray), ArErr{}
|
return ArArray(newarray), ArErr{}
|
||||||
}
|
}
|
||||||
@@ -224,7 +235,7 @@ func makeGlobal() ArObject {
|
|||||||
}}
|
}}
|
||||||
vars["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
vars["subprocess"] = builtinFunc{"subprocess", ArSubprocess}
|
||||||
vars["sequence"] = builtinFunc{"sequence", ArSequence}
|
vars["sequence"] = builtinFunc{"sequence", ArSequence}
|
||||||
vars["|"] = builtinFunc{"exit", func(a ...any) (any, ArErr) {
|
vars["exit"] = builtinFunc{"exit", func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
@@ -239,11 +250,12 @@ func makeGlobal() ArObject {
|
|||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{TYPE: "chr", message: "chr takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
return nil, ArErr{TYPE: "chr", message: "chr takes 1 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
}
|
}
|
||||||
|
a[0] = ArValidToAny(a[0])
|
||||||
switch x := a[0].(type) {
|
switch x := a[0].(type) {
|
||||||
case number:
|
case int64:
|
||||||
return string([]rune{rune(floor(x).Num().Int64())}), ArErr{}
|
return string([]rune{rune(x)}), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["ord"] = builtinFunc{"ord", func(a ...any) (any, ArErr) {
|
vars["ord"] = builtinFunc{"ord", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
@@ -257,7 +269,7 @@ func makeGlobal() ArObject {
|
|||||||
}
|
}
|
||||||
return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{}
|
return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot convert '" + typeof(a[0]) + "' to string", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["max"] = builtinFunc{"max", func(a ...any) (any, ArErr) {
|
vars["max"] = builtinFunc{"max", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
@@ -284,7 +296,7 @@ func makeGlobal() ArObject {
|
|||||||
}
|
}
|
||||||
return max, ArErr{}
|
return max, ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["min"] = builtinFunc{"min", func(a ...any) (any, ArErr) {
|
vars["min"] = builtinFunc{"min", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
@@ -311,7 +323,7 @@ func makeGlobal() ArObject {
|
|||||||
}
|
}
|
||||||
return max, ArErr{}
|
return max, ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot get max of type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
vars["path"] = ArPath
|
vars["path"] = ArPath
|
||||||
vars["typeof"] = builtinFunc{"typeof", func(a ...any) (any, ArErr) {
|
vars["typeof"] = builtinFunc{"typeof", func(a ...any) (any, ArErr) {
|
||||||
@@ -329,7 +341,7 @@ func makeGlobal() ArObject {
|
|||||||
case string:
|
case string:
|
||||||
return ArString(sha256Hash(x)), ArErr{}
|
return ArString(sha256Hash(x)), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot hash type '" + typeof(a[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot hash type '" + typeof(a[0]) + "'", EXISTS: true}
|
||||||
}}
|
}}
|
||||||
return Map(vars)
|
return Map(vars)
|
||||||
}
|
}
|
||||||
|
|||||||
102
src/colour.go
102
src/colour.go
@@ -12,18 +12,26 @@ var ArColour = Map(
|
|||||||
"set": builtinFunc{"set", func(a ...any) (any, ArErr) {
|
"set": builtinFunc{"set", func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "set() takes exactly 2 argument (" + fmt.Sprint(len(a)) + " given)",
|
message: "set() takes exactly 2 argument (" + fmt.Sprint(len(a)) + " given)",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var c *color.Color
|
var c *color.Color
|
||||||
var s string
|
var s string
|
||||||
if x, ok := a[0].(number); ok {
|
if x, ok := a[0].(ArObject); ok {
|
||||||
c = color.Set(color.Attribute(x.Num().Int64()))
|
colour_int64, err := numberToInt64(x)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: err.Error(),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = color.New(color.Attribute(colour_int64))
|
||||||
} else {
|
} else {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "set() argument 1 must be an number, not " + typeof(a[0]),
|
message: "set() argument 1 must be an number, not " + typeof(a[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -32,7 +40,7 @@ var ArColour = Map(
|
|||||||
s = ArValidToAny(a[1]).(string)
|
s = ArValidToAny(a[1]).(string)
|
||||||
} else {
|
} else {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "set() argument 2 must be a string, not " + typeof(a[1]),
|
message: "set() argument 2 must be a string, not " + typeof(a[1]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -45,52 +53,52 @@ var ArColour = Map(
|
|||||||
}},
|
}},
|
||||||
"bg": Map(
|
"bg": Map(
|
||||||
anymap{
|
anymap{
|
||||||
"black": newNumber().SetInt64(int64(color.BgBlack)),
|
"black": Number(int64(color.BgBlack)),
|
||||||
"red": newNumber().SetInt64(int64(color.BgRed)),
|
"red": Number(int64(color.BgRed)),
|
||||||
"green": newNumber().SetInt64(int64(color.BgGreen)),
|
"green": Number(int64(color.BgGreen)),
|
||||||
"yellow": newNumber().SetInt64(int64(color.BgYellow)),
|
"yellow": Number(int64(color.BgYellow)),
|
||||||
"blue": newNumber().SetInt64(int64(color.BgBlue)),
|
"blue": Number(int64(color.BgBlue)),
|
||||||
"magenta": newNumber().SetInt64(int64(color.BgMagenta)),
|
"magenta": Number(int64(color.BgMagenta)),
|
||||||
"cyan": newNumber().SetInt64(int64(color.BgCyan)),
|
"cyan": Number(int64(color.BgCyan)),
|
||||||
"white": newNumber().SetInt64(int64(color.BgWhite)),
|
"white": Number(int64(color.BgWhite)),
|
||||||
"hiBlack": newNumber().SetInt64(int64(color.BgHiBlack)),
|
"hiBlack": Number(int64(color.BgHiBlack)),
|
||||||
"hiRed": newNumber().SetInt64(int64(color.BgHiRed)),
|
"hiRed": Number(int64(color.BgHiRed)),
|
||||||
"hiGreen": newNumber().SetInt64(int64(color.BgHiGreen)),
|
"hiGreen": Number(int64(color.BgHiGreen)),
|
||||||
"hiYellow": newNumber().SetInt64(int64(color.BgHiYellow)),
|
"hiYellow": Number(int64(color.BgHiYellow)),
|
||||||
"hiBlue": newNumber().SetInt64(int64(color.BgHiBlue)),
|
"hiBlue": Number(int64(color.BgHiBlue)),
|
||||||
"hiMagenta": newNumber().SetInt64(int64(color.BgHiMagenta)),
|
"hiMagenta": Number(int64(color.BgHiMagenta)),
|
||||||
"hiCyan": newNumber().SetInt64(int64(color.BgHiCyan)),
|
"hiCyan": Number(int64(color.BgHiCyan)),
|
||||||
"hiWhite": newNumber().SetInt64(int64(color.BgHiWhite)),
|
"hiWhite": Number(int64(color.BgHiWhite)),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
"fg": Map(
|
"fg": Map(
|
||||||
anymap{
|
anymap{
|
||||||
"black": newNumber().SetInt64(int64(color.FgBlack)),
|
"black": Number(int64(color.FgBlack)),
|
||||||
"red": newNumber().SetInt64(int64(color.FgRed)),
|
"red": Number(int64(color.FgRed)),
|
||||||
"green": newNumber().SetInt64(int64(color.FgGreen)),
|
"green": Number(int64(color.FgGreen)),
|
||||||
"yellow": newNumber().SetInt64(int64(color.FgYellow)),
|
"yellow": Number(int64(color.FgYellow)),
|
||||||
"blue": newNumber().SetInt64(int64(color.FgBlue)),
|
"blue": Number(int64(color.FgBlue)),
|
||||||
"magenta": newNumber().SetInt64(int64(color.FgMagenta)),
|
"magenta": Number(int64(color.FgMagenta)),
|
||||||
"cyan": newNumber().SetInt64(int64(color.FgCyan)),
|
"cyan": Number(int64(color.FgCyan)),
|
||||||
"white": newNumber().SetInt64(int64(color.FgWhite)),
|
"white": Number(int64(color.FgWhite)),
|
||||||
"hiBlack": newNumber().SetInt64(int64(color.FgHiBlack)),
|
"hiBlack": Number(int64(color.FgHiBlack)),
|
||||||
"hiRed": newNumber().SetInt64(int64(color.FgHiRed)),
|
"hiRed": Number(int64(color.FgHiRed)),
|
||||||
"hiGreen": newNumber().SetInt64(int64(color.FgHiGreen)),
|
"hiGreen": Number(int64(color.FgHiGreen)),
|
||||||
"hiYellow": newNumber().SetInt64(int64(color.FgHiYellow)),
|
"hiYellow": Number(int64(color.FgHiYellow)),
|
||||||
"hiBlue": newNumber().SetInt64(int64(color.FgHiBlue)),
|
"hiBlue": Number(int64(color.FgHiBlue)),
|
||||||
"hiMagenta": newNumber().SetInt64(int64(color.FgHiMagenta)),
|
"hiMagenta": Number(int64(color.FgHiMagenta)),
|
||||||
"hiCyan": newNumber().SetInt64(int64(color.FgHiCyan)),
|
"hiCyan": Number(int64(color.FgHiCyan)),
|
||||||
"hiWhite": newNumber().SetInt64(int64(color.FgHiWhite)),
|
"hiWhite": Number(int64(color.FgHiWhite)),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
"reset": newNumber().SetInt64(int64(color.Reset)),
|
"reset": Number(int64(color.Reset)),
|
||||||
"bold": newNumber().SetInt64(int64(color.Bold)),
|
"bold": Number(int64(color.Bold)),
|
||||||
"faint": newNumber().SetInt64(int64(color.Faint)),
|
"faint": Number(int64(color.Faint)),
|
||||||
"italic": newNumber().SetInt64(int64(color.Italic)),
|
"italic": Number(int64(color.Italic)),
|
||||||
"underline": newNumber().SetInt64(int64(color.Underline)),
|
"underline": Number(int64(color.Underline)),
|
||||||
"blinkSlow": newNumber().SetInt64(int64(color.BlinkSlow)),
|
"blinkSlow": Number(int64(color.BlinkSlow)),
|
||||||
"blinkRapid": newNumber().SetInt64(int64(color.BlinkRapid)),
|
"blinkRapid": Number(int64(color.BlinkRapid)),
|
||||||
"reverseVideo": newNumber().SetInt64(int64(color.ReverseVideo)),
|
"reverseVideo": Number(int64(color.ReverseVideo)),
|
||||||
"concealed": newNumber().SetInt64(int64(color.Concealed)),
|
"concealed": Number(int64(color.Concealed)),
|
||||||
"crossedOut": newNumber().SetInt64(int64(color.CrossedOut)),
|
"crossedOut": Number(int64(color.CrossedOut)),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ func debugInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func debugPrintln(a ...any) {
|
func debugPrintln(a ...any) {
|
||||||
if debug {
|
switch debug {
|
||||||
|
case true:
|
||||||
__debugPrintsLock.Lock()
|
__debugPrintsLock.Lock()
|
||||||
__debugPrints = append(__debugPrints, a)
|
__debugPrints = append(__debugPrints, a)
|
||||||
__debugPrintsLock.Unlock()
|
__debugPrintsLock.Unlock()
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ func isDoWrap(code UNPARSEcode) bool {
|
|||||||
func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool, ArErr, int) {
|
func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool, ArErr, int) {
|
||||||
currentindent := len(code.realcode) - len(strings.TrimLeft(code.realcode, " "))
|
currentindent := len(code.realcode) - len(strings.TrimLeft(code.realcode, " "))
|
||||||
var setindent int = -1
|
var setindent int = -1
|
||||||
var i = index + 1
|
var allCodelines = []UNPARSEcode{}
|
||||||
translated := []any{}
|
i := index + 1
|
||||||
for i < len(codelines) {
|
for ; i < len(codelines); i++ {
|
||||||
|
|
||||||
if isBlank(codelines[i]) {
|
if isBlank(codelines[i]) {
|
||||||
i++
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
indent := len(codelines[i].code) - len(strings.TrimLeft(codelines[i].code, " "))
|
indent := len(codelines[i].code) - len(strings.TrimLeft(codelines[i].code, " "))
|
||||||
@@ -34,8 +34,15 @@ func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, boo
|
|||||||
if indent <= currentindent {
|
if indent <= currentindent {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
allCodelines = append(allCodelines, codelines[i])
|
||||||
|
}
|
||||||
|
finalLines := i
|
||||||
|
codelines = allCodelines
|
||||||
|
translated := []any{}
|
||||||
|
for i := 0; i < len(codelines); {
|
||||||
|
indent := len(codelines[i].code) - len(strings.TrimLeft(codelines[i].code, " "))
|
||||||
if indent != setindent {
|
if indent != setindent {
|
||||||
return nil, false, ArErr{"Syntax Error", "invalid indent", i, code.path, codelines[i].code, true}, 1
|
return nil, false, ArErr{"Syntax Error", "invalid indent", code.line, code.path, codelines[i].code, true}, 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val, _, err, step := translateVal(codelines[i], i, codelines, 3)
|
val, _, err, step := translateVal(codelines[i], i, codelines, 3)
|
||||||
@@ -45,13 +52,15 @@ func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, boo
|
|||||||
}
|
}
|
||||||
translated = append(translated, val)
|
translated = append(translated, val)
|
||||||
}
|
}
|
||||||
return dowrap{run: translated, line: code.line, path: code.path, code: code.realcode}, true, ArErr{}, i - index
|
return dowrap{run: translated, line: code.line, path: code.path, code: code.realcode}, true, ArErr{}, finalLines - index
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDoWrap(d dowrap, stack stack, stacklevel int) (any, ArErr) {
|
func runDoWrap(d dowrap, Stack stack, stacklevel int) (any, ArErr) {
|
||||||
newstack := append(stack, newscope())
|
newstack := append(Stack, newscope())
|
||||||
|
newstackCopy := make(stack, len(newstack))
|
||||||
|
copy(newstackCopy, newstack)
|
||||||
for _, v := range d.run {
|
for _, v := range d.run {
|
||||||
val, err := runVal(v, newstack, stacklevel+1)
|
val, err := runVal(v, newstackCopy, stacklevel+1)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,19 +16,19 @@ type ArErr struct {
|
|||||||
func ArThrowError(a ...any) (any, ArErr) {
|
func ArThrowError(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "throwError takes 2 arguments, " + fmt.Sprint(len(a)) + " given",
|
message: "throwError takes 2 arguments, " + fmt.Sprint(len(a)) + " given",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(a[0]) != "string" {
|
} else if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "throwError type must be a string",
|
message: "throwError type must be a string",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(a[1]) != "string" {
|
} else if typeof(a[1]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "throwError message must be a string",
|
message: "throwError message must be a string",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
|
|||||||
41
src/eval_function.go
Normal file
41
src/eval_function.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func AReval(a ...any) (any, ArErr) {
|
||||||
|
if len(a) < 1 || len(a) > 2 {
|
||||||
|
return nil, ArErr{TYPE: "Type Error", message: "expected 1 or 2 argument, got " + fmt.Sprint(len(a)), EXISTS: true}
|
||||||
|
}
|
||||||
|
var expression string
|
||||||
|
if typeof(a[0]) != "string" {
|
||||||
|
return nil, ArErr{TYPE: "Type Error", message: "expected string as first argument, got " + typeof(a[0]), EXISTS: true}
|
||||||
|
}
|
||||||
|
expression = ArValidToAny(a[0]).(string)
|
||||||
|
|
||||||
|
// translate the expression
|
||||||
|
var code UNPARSEcode = UNPARSEcode{
|
||||||
|
code: expression,
|
||||||
|
realcode: expression,
|
||||||
|
line: 0,
|
||||||
|
path: "eval",
|
||||||
|
}
|
||||||
|
translated, err := translate([]UNPARSEcode{code})
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var scope ArObject
|
||||||
|
if len(a) == 2 {
|
||||||
|
if typeof(a[1]) != "map" {
|
||||||
|
return nil, ArErr{TYPE: "Type Error", message: "expected map as second argument, got " + typeof(a[1]), EXISTS: true}
|
||||||
|
}
|
||||||
|
scope = a[1].(ArObject)
|
||||||
|
} else {
|
||||||
|
scope = newscope()
|
||||||
|
}
|
||||||
|
|
||||||
|
var stack stack = []ArObject{scope}
|
||||||
|
|
||||||
|
// run the translated expression
|
||||||
|
return run(translated, stack)
|
||||||
|
}
|
||||||
@@ -28,36 +28,26 @@ func isFactorial(code UNPARSEcode) bool {
|
|||||||
return factorialCompiled.MatchString(code.code)
|
return factorialCompiled.MatchString(code.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fact(n number) number {
|
|
||||||
if n.Cmp(newNumber().SetInt64(1000)) >= 0 {
|
|
||||||
return infinity
|
|
||||||
} else if n.Cmp(newNumber().SetInt64(0)) == -1 {
|
|
||||||
return newNumber().SetInt64(0)
|
|
||||||
} else if n.Cmp(newNumber().SetInt64(0)) == 0 {
|
|
||||||
return newNumber().SetInt64(1)
|
|
||||||
}
|
|
||||||
result := newNumber().SetInt64(1)
|
|
||||||
for i := newNumber().SetInt64(2); i.Cmp(n) <= 0; i.Add(i, newNumber().SetInt64(1)) {
|
|
||||||
result.Mul(result, i)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func runFactorial(f factorial, stack stack, stacklevel int) (any, ArErr) {
|
func runFactorial(f factorial, stack stack, stacklevel int) (any, ArErr) {
|
||||||
val, err := runVal(f.value, stack, stacklevel+1)
|
val, err := runVal(f.value, stack, stacklevel+1)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
switch x := val.(type) {
|
switch val := val.(type) {
|
||||||
case number:
|
case ArObject:
|
||||||
if !x.IsInt() {
|
if callable, ok := val.obj["__factorial__"]; ok {
|
||||||
return nil, ArErr{"Runtime Error", "cannot use factorial on non-integer", f.line, f.path, f.code, true}
|
return runCall(call{
|
||||||
|
Callable: callable,
|
||||||
|
Args: []any{},
|
||||||
|
Code: f.code,
|
||||||
|
Line: f.line,
|
||||||
|
Path: f.path,
|
||||||
|
}, stack, stacklevel)
|
||||||
}
|
}
|
||||||
if x.Cmp(newNumber().SetInt64(0)) == -1 {
|
}
|
||||||
return nil, ArErr{"Runtime Error", "cannot use factorial on negative number", f.line, f.path, f.code, true}
|
return nil, ArErr{
|
||||||
}
|
TYPE: "TypeError",
|
||||||
return fact(x), ArErr{}
|
message: "factorial not defined for type",
|
||||||
default:
|
EXISTS: true,
|
||||||
return nil, ArErr{"Runtime Error", "cannot use factorial on non-number of type '" + typeof(val) + "'", f.line, f.path, f.code, true}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
67
src/file.go
67
src/file.go
@@ -12,8 +12,73 @@ import (
|
|||||||
var ArFile = Map(anymap{
|
var ArFile = Map(anymap{
|
||||||
"read": builtinFunc{"read", ArRead},
|
"read": builtinFunc{"read", ArRead},
|
||||||
"write": builtinFunc{"write", ArWrite},
|
"write": builtinFunc{"write", ArWrite},
|
||||||
|
"move": builtinFunc{"move", ARmoveFile},
|
||||||
|
"copy": builtinFunc{"copy", ARcopyFile},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
func ARmoveFile(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 2 {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "move takes 2 arguments, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "string" {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "move takes a string not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||||
|
}
|
||||||
|
if typeof(args[1]) != "string" {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "move takes a string not type '" + typeof(args[1]) + "'", EXISTS: true}
|
||||||
|
}
|
||||||
|
args[0] = ArValidToAny(args[0])
|
||||||
|
args[1] = ArValidToAny(args[1])
|
||||||
|
err := os.Rename(args[0].(string), args[1].(string))
|
||||||
|
if err != nil {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
|
}
|
||||||
|
return nil, ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFile(src, dst string) (int64, error) {
|
||||||
|
sourceFileStat, err := os.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !sourceFileStat.Mode().IsRegular() {
|
||||||
|
return 0, fmt.Errorf("%s is not a regular file", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
source, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
|
destination, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer destination.Close()
|
||||||
|
nBytes, err := io.Copy(destination, source)
|
||||||
|
return nBytes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func ARcopyFile(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 2 {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "copy takes 2 arguments, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||||
|
}
|
||||||
|
if typeof(args[0]) != "string" {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "copy takes a string not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||||
|
}
|
||||||
|
if typeof(args[1]) != "string" {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "copy takes a string not type '" + typeof(args[1]) + "'", EXISTS: true}
|
||||||
|
}
|
||||||
|
args[0] = ArValidToAny(args[0])
|
||||||
|
args[1] = ArValidToAny(args[1])
|
||||||
|
_, err := copyFile(args[0].(string), args[1].(string))
|
||||||
|
if err != nil {
|
||||||
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
|
}
|
||||||
|
return nil, ArErr{}
|
||||||
|
}
|
||||||
|
|
||||||
func readtext(file *os.File) (string, error) {
|
func readtext(file *os.File) (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, err := io.Copy(&buf, file)
|
_, err := io.Copy(&buf, file)
|
||||||
@@ -70,7 +135,7 @@ func ArRead(args ...any) (any, ArErr) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
}
|
}
|
||||||
return jsonparse(text), ArErr{}
|
return jsonparse(text)
|
||||||
}},
|
}},
|
||||||
"contentType": builtinFunc{"contentType", func(...any) (any, ArErr) {
|
"contentType": builtinFunc{"contentType", func(...any) (any, ArErr) {
|
||||||
file.Seek(0, io.SeekStart)
|
file.Seek(0, io.SeekStart)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func parseForLoop(code UNPARSEcode, index int, codelines []UNPARSEcode) (forLoop
|
|||||||
innertotalstep += stepstep - 1
|
innertotalstep += stepstep - 1
|
||||||
stepval = stepval_
|
stepval = stepval_
|
||||||
} else {
|
} else {
|
||||||
stepval = newNumber().SetInt64(1)
|
stepval = _one_Number
|
||||||
}
|
}
|
||||||
to := strings.TrimSpace(valsplit[0])
|
to := strings.TrimSpace(valsplit[0])
|
||||||
toval, worked, err, tostep := translateVal(UNPARSEcode{code: to, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 0)
|
toval, worked, err, tostep := translateVal(UNPARSEcode{code: to, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 0)
|
||||||
@@ -63,7 +63,7 @@ func parseForLoop(code UNPARSEcode, index int, codelines []UNPARSEcode) (forLoop
|
|||||||
}
|
}
|
||||||
innertotalstep += tostep - 1
|
innertotalstep += tostep - 1
|
||||||
body := strings.Join(tosplit[i:], ")")
|
body := strings.Join(tosplit[i:], ")")
|
||||||
bodyval, worked, err, bodystep := translateVal(UNPARSEcode{code: body, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 1)
|
bodyval, worked, err, bodystep := translateVal(UNPARSEcode{code: body, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 3)
|
||||||
if !worked {
|
if !worked {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return forLoop{}, worked, err, bodystep
|
return forLoop{}, worked, err, bodystep
|
||||||
@@ -83,7 +83,7 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if typeof(fromval) != "number" {
|
if typeof(fromval) != "number" {
|
||||||
return nil, ArErr{"Type Error", "for loop from value must be a number", loop.line, loop.path, loop.code, true}
|
return nil, ArErr{"Type Error", "for loop from value must be a number", loop.line, loop.path, loop.code, true}
|
||||||
}
|
}
|
||||||
from := fromval.(number)
|
from := fromval.(ArObject)
|
||||||
toval, err := runVal(loop.to, stack, stacklevel+1)
|
toval, err := runVal(loop.to, stack, stacklevel+1)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -91,7 +91,7 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if typeof(toval) != "number" {
|
if typeof(toval) != "number" {
|
||||||
return nil, ArErr{"Type Error", "for loop to value must be a number", loop.line, loop.path, loop.code, true}
|
return nil, ArErr{"Type Error", "for loop to value must be a number", loop.line, loop.path, loop.code, true}
|
||||||
}
|
}
|
||||||
to := toval.(number)
|
to := toval.(ArObject)
|
||||||
stepval, err := runVal(loop.step, stack, stacklevel+1)
|
stepval, err := runVal(loop.step, stack, stacklevel+1)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -99,11 +99,52 @@ 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}
|
||||||
}
|
}
|
||||||
step := stepval.(number)
|
step := stepval.(ArObject)
|
||||||
for i := newNumber().Set(from); i.Cmp(to) == -1; i = i.Add(i, step) {
|
if isNumberInt64(from) && isNumberInt64(to) && isNumberInt64(step) {
|
||||||
resp, err := runVal(loop.body, append(stack, Map(anymap{
|
i, _ := numberToInt64(from)
|
||||||
loop.variable: newNumber().Set(i),
|
to_, _ := numberToInt64(to)
|
||||||
})), stacklevel+1)
|
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
|
||||||
|
}
|
||||||
|
currentDirection_obj, err := CompareObjects(to, i)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
currentDirection, error := numberToInt64(currentDirection_obj)
|
||||||
|
if error != nil {
|
||||||
|
return nil, ArErr{"Type Error", error.Error(), loop.line, loop.path, loop.code, true}
|
||||||
|
}
|
||||||
|
direction, error := numberToInt64(direction_obj)
|
||||||
|
if error != nil {
|
||||||
|
return nil, ArErr{"Type Error", error.Error(), loop.line, loop.path, loop.code, true}
|
||||||
|
}
|
||||||
|
layer := anymap{}
|
||||||
|
stacks := append(stack, Map(layer))
|
||||||
|
for currentDirection == direction {
|
||||||
|
layer[loop.variable] = i
|
||||||
|
resp, err := runVal(loop.body, stacks, stacklevel+1)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -113,7 +154,22 @@ func runForLoop(loop forLoop, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
case Break:
|
case Break:
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
case Continue:
|
case Continue:
|
||||||
continue
|
}
|
||||||
|
i, err = AddObjects(i, step)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
currentDirection_obj, err = CompareObjects(to, i)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
currentDirection, error = numberToInt64(currentDirection_obj)
|
||||||
|
if error != nil {
|
||||||
|
return nil, ArErr{"Type Error", error.Error(), loop.line, loop.path, loop.code, true}
|
||||||
|
}
|
||||||
|
direction, error = numberToInt64(direction_obj)
|
||||||
|
if error != nil {
|
||||||
|
return nil, ArErr{"Type Error", error.Error(), loop.line, loop.path, loop.code, true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func mapGet(r ArMapGet, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
"TypeError",
|
"Type Error",
|
||||||
"cannot read " + anyToArgon(key, true, true, 3, 0, false, 0) + " from type '" + typeof(resp) + "'",
|
"cannot read " + anyToArgon(key, true, true, 3, 0, false, 0) + " from type '" + typeof(resp) + "'",
|
||||||
r.Line,
|
r.Line,
|
||||||
r.Path,
|
r.Path,
|
||||||
@@ -123,19 +123,10 @@ func indexGetParse(code UNPARSEcode, index int, codelines []UNPARSEcode) (ArMapG
|
|||||||
}, 1
|
}, 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var hashabletypes = []string{
|
|
||||||
"number",
|
|
||||||
"string",
|
|
||||||
"bool",
|
|
||||||
"null",
|
|
||||||
}
|
|
||||||
|
|
||||||
func isUnhashable(val any) bool {
|
func isUnhashable(val any) bool {
|
||||||
keytype := typeof(val)
|
switch val.(type) {
|
||||||
for _, v := range hashabletypes {
|
case int64, float64, string, bool, nil:
|
||||||
if v == keytype {
|
return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst
|
|||||||
conditions := []statement{}
|
conditions := []statement{}
|
||||||
var ELSE any
|
var ELSE any
|
||||||
i := index
|
i := index
|
||||||
|
codeline[i] = code
|
||||||
for i < len(codeline) && (elseifstatmentCompile.MatchString(codeline[i].code) || i == index) {
|
for i < len(codeline) && (elseifstatmentCompile.MatchString(codeline[i].code) || i == index) {
|
||||||
trimmed := strings.TrimSpace(codeline[i].code)
|
trimmed := strings.TrimSpace(codeline[i].code)
|
||||||
trimmed = strings.TrimSpace(trimmed[strings.Index(trimmed, "("):])
|
trimmed = strings.TrimSpace(trimmed[strings.Index(trimmed, "("):])
|
||||||
@@ -69,7 +70,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst
|
|||||||
},
|
},
|
||||||
i,
|
i,
|
||||||
codeline,
|
codeline,
|
||||||
2,
|
3,
|
||||||
)
|
)
|
||||||
if err.EXISTS || !worked {
|
if err.EXISTS || !worked {
|
||||||
return ifstatement{}, worked, err, step
|
return ifstatement{}, worked, err, step
|
||||||
@@ -98,7 +99,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst
|
|||||||
},
|
},
|
||||||
i,
|
i,
|
||||||
codeline,
|
codeline,
|
||||||
2,
|
3,
|
||||||
)
|
)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return ifstatement{}, false, err, step
|
return ifstatement{}, false, err, step
|
||||||
|
|||||||
176
src/import.go
176
src/import.go
@@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var imported = make(map[string]ArObject)
|
var imported = make(map[string]ArObject)
|
||||||
|
var translatedImports = make(map[string]translatedImport)
|
||||||
var importing = make(map[string]bool)
|
var importing = make(map[string]bool)
|
||||||
|
|
||||||
const modules_folder = "argon_modules"
|
const modules_folder = "argon_modules"
|
||||||
@@ -41,67 +42,31 @@ func readFile(path string) ([]UNPARSEcode, error) {
|
|||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func importMod(realpath string, origin string, main bool, global ArObject) (ArObject, ArErr) {
|
type translatedImport struct {
|
||||||
extention := filepath.Ext(realpath)
|
translated []any
|
||||||
path := realpath
|
p string
|
||||||
if extention == "" {
|
path string
|
||||||
path += ".ar"
|
origin string
|
||||||
}
|
}
|
||||||
ex, err := os.Getwd()
|
|
||||||
if err != nil {
|
var runTranslatedImport func(translatedImport, ArObject, bool) (ArObject, ArErr)
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Could not get working directory", EXISTS: true}
|
var ex string
|
||||||
}
|
var exc string
|
||||||
exc, err := os.Executable()
|
var exc_dir string
|
||||||
if err != nil {
|
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Could not get executable", EXISTS: true}
|
func init() {
|
||||||
}
|
runTranslatedImport = __runTranslatedImport
|
||||||
executable := filepath.Dir(exc)
|
ex, _ = os.Getwd()
|
||||||
isABS := filepath.IsAbs(path)
|
exc, _ = os.Executable()
|
||||||
var pathsToTest []string
|
exc_dir = filepath.Dir(exc)
|
||||||
if isABS {
|
}
|
||||||
pathsToTest = []string{
|
|
||||||
filepath.Join(path),
|
func __runTranslatedImport(translatedImport translatedImport, global ArObject, main bool) (ArObject, ArErr) {
|
||||||
filepath.Join(realpath, "init.ar"),
|
|
||||||
}
|
if _, ok := imported[translatedImport.p]; ok {
|
||||||
} else {
|
return imported[translatedImport.p], ArErr{}
|
||||||
pathsToTest = []string{
|
|
||||||
filepath.Join(origin, path),
|
|
||||||
filepath.Join(origin, realpath, "init.ar"),
|
|
||||||
filepath.Join(origin, modules_folder, path),
|
|
||||||
filepath.Join(origin, modules_folder, realpath, "init.ar"),
|
|
||||||
filepath.Join(ex, path),
|
|
||||||
filepath.Join(ex, modules_folder, path),
|
|
||||||
filepath.Join(ex, modules_folder, realpath, "init.ar"),
|
|
||||||
filepath.Join(executable, modules_folder, path),
|
|
||||||
filepath.Join(executable, modules_folder, realpath, "init.ar"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var p string
|
|
||||||
var found bool
|
|
||||||
for _, p = range pathsToTest {
|
|
||||||
if FileExists(p) {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "File does not exist: " + path, EXISTS: true}
|
|
||||||
} else if importing[p] {
|
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Circular import: " + path, EXISTS: true}
|
|
||||||
} else if _, ok := imported[p]; ok {
|
|
||||||
return imported[p], ArErr{}
|
|
||||||
}
|
|
||||||
importing[p] = true
|
|
||||||
codelines, err := readFile(p)
|
|
||||||
if err != nil {
|
|
||||||
return ArObject{}, ArErr{TYPE: "Import Error", message: "Could not read file: " + path, EXISTS: true}
|
|
||||||
}
|
|
||||||
translated, translationerr := translate(codelines)
|
|
||||||
|
|
||||||
if translationerr.EXISTS {
|
|
||||||
return ArObject{}, translationerr
|
|
||||||
}
|
|
||||||
ArgsArArray := []any{}
|
ArgsArArray := []any{}
|
||||||
withoutarfile := []string{}
|
withoutarfile := []string{}
|
||||||
if len(Args) > 1 {
|
if len(Args) > 1 {
|
||||||
@@ -114,30 +79,89 @@ func importMod(realpath string, origin string, main bool, global ArObject) (ArOb
|
|||||||
localvars := Map(anymap{
|
localvars := Map(anymap{
|
||||||
"program": Map(anymap{
|
"program": Map(anymap{
|
||||||
"args": ArArray(ArgsArArray),
|
"args": ArArray(ArgsArArray),
|
||||||
"origin": ArString(origin),
|
"origin": ArString(translatedImport.origin),
|
||||||
"import": builtinFunc{"import", func(args ...any) (any, ArErr) {
|
"cwd": ArString(ex),
|
||||||
if len(args) != 1 {
|
"exc": ArString(exc),
|
||||||
return nil, ArErr{"Import Error", "Invalid number of arguments", 0, realpath, "", true}
|
|
||||||
}
|
|
||||||
if _, ok := args[0].(string); !ok {
|
|
||||||
return nil, ArErr{"Import Error", "Invalid argument type", 0, realpath, "", true}
|
|
||||||
}
|
|
||||||
return importMod(args[0].(string), filepath.Dir(filepath.ToSlash(p)), false, global)
|
|
||||||
}},
|
|
||||||
"cwd": ArString(ex),
|
|
||||||
"exc": ArString(exc),
|
|
||||||
"file": Map(anymap{
|
"file": Map(anymap{
|
||||||
"name": ArString(filepath.Base(p)),
|
"name": ArString(filepath.Base(translatedImport.p)),
|
||||||
"path": ArString(p),
|
"path": ArString(translatedImport.p),
|
||||||
}),
|
}),
|
||||||
"main": main,
|
"main": main,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
_, runimeErr := run(translated, stack{global, localvars, local})
|
imported[translatedImport.p] = local
|
||||||
importing[p] = false
|
_, runimeErr := run(translatedImport.translated, stack{global, localvars, local})
|
||||||
if runimeErr.EXISTS {
|
if runimeErr.EXISTS {
|
||||||
return ArObject{}, runimeErr
|
return ArObject{}, runimeErr
|
||||||
}
|
}
|
||||||
imported[p] = local
|
|
||||||
return local, ArErr{}
|
return local, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func translateImport(realpath string, origin string, topLevelOnly bool) (translatedImport, ArErr) {
|
||||||
|
extention := filepath.Ext(realpath)
|
||||||
|
path := realpath
|
||||||
|
if extention == "" {
|
||||||
|
path += ".ar"
|
||||||
|
}
|
||||||
|
isABS := filepath.IsAbs(path)
|
||||||
|
var pathsToTest []string
|
||||||
|
if isABS {
|
||||||
|
pathsToTest = []string{
|
||||||
|
filepath.Join(path),
|
||||||
|
filepath.Join(realpath, "init.ar"),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pathsToTest = []string{
|
||||||
|
filepath.Join(exc_dir, path),
|
||||||
|
filepath.Join(exc_dir, realpath, "init.ar"),
|
||||||
|
filepath.Join(exc_dir, modules_folder, path),
|
||||||
|
filepath.Join(exc_dir, modules_folder, realpath, "init.ar"),
|
||||||
|
}
|
||||||
|
var currentPath string = origin
|
||||||
|
var oldPath string = ""
|
||||||
|
for currentPath != oldPath {
|
||||||
|
pathsToTest = append(pathsToTest,
|
||||||
|
filepath.Join(currentPath, path),
|
||||||
|
filepath.Join(currentPath, realpath, "init.ar"),
|
||||||
|
filepath.Join(currentPath, modules_folder, path),
|
||||||
|
filepath.Join(currentPath, modules_folder, realpath, "init.ar"))
|
||||||
|
if topLevelOnly {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
oldPath = currentPath
|
||||||
|
currentPath = filepath.Dir(currentPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var p string
|
||||||
|
var found bool
|
||||||
|
for _, p = range pathsToTest {
|
||||||
|
if FileExists(p) {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
return translatedImport{}, ArErr{TYPE: "Import Error", message: "File does not exist: " + path, EXISTS: true}
|
||||||
|
} else if importing[p] {
|
||||||
|
return translatedImport{}, ArErr{TYPE: "Import Error", message: "Circular import: " + path, EXISTS: true}
|
||||||
|
} else if _, ok := translatedImports[p]; ok {
|
||||||
|
return translatedImports[p], ArErr{}
|
||||||
|
}
|
||||||
|
importing[p] = true
|
||||||
|
codelines, err := readFile(p)
|
||||||
|
if err != nil {
|
||||||
|
return translatedImport{}, ArErr{TYPE: "Import Error", message: "Could not read file: " + path, EXISTS: true}
|
||||||
|
}
|
||||||
|
|
||||||
|
importing[p] = true
|
||||||
|
translated, translationerr := translate(codelines)
|
||||||
|
importing[p] = false
|
||||||
|
|
||||||
|
if translationerr.EXISTS {
|
||||||
|
return translatedImport{}, translationerr
|
||||||
|
}
|
||||||
|
|
||||||
|
translatedImports[p] = translatedImport{translated, p, path, origin}
|
||||||
|
return translatedImports[p], ArErr{}
|
||||||
|
}
|
||||||
|
|||||||
68
src/input.go
68
src/input.go
@@ -1,23 +1,36 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/chzyer/readline"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func input(args ...any) string {
|
var tempFilePath = os.TempDir() + "/argon_input_history.tmp"
|
||||||
|
|
||||||
|
func input(args ...any) (string, error) {
|
||||||
output := []any{}
|
output := []any{}
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
|
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
|
||||||
}
|
}
|
||||||
fmt.Print(output...)
|
message := fmt.Sprint(output...)
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
rl, err := readline.NewEx(&readline.Config{
|
||||||
scanner.Scan()
|
Prompt: message,
|
||||||
input := scanner.Text()
|
HistoryFile: tempFilePath,
|
||||||
return input
|
HistorySearchFold: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create readline instance: %v", err)
|
||||||
|
}
|
||||||
|
defer rl.Close()
|
||||||
|
line, err := rl.Readline()
|
||||||
|
if err != nil { // io.EOF or other error
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return line, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPassword(args ...any) (string, error) {
|
func getPassword(args ...any) (string, error) {
|
||||||
@@ -25,38 +38,21 @@ func getPassword(args ...any) (string, error) {
|
|||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
|
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
|
||||||
}
|
}
|
||||||
fmt.Print(output...)
|
message := fmt.Sprint(output...)
|
||||||
password := []byte{}
|
rl, err := readline.NewEx(&readline.Config{
|
||||||
|
Prompt: message,
|
||||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
MaskRune: '*',
|
||||||
|
EnableMask: true,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("Failed to create readline instance: %v", err)
|
||||||
}
|
}
|
||||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
defer rl.Close()
|
||||||
|
line, err := rl.Readline()
|
||||||
for {
|
if err != nil { // io.EOF or other error
|
||||||
char := make([]byte, 1)
|
return "", err
|
||||||
_, err := os.Stdin.Read(char)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if char[0] == 3 || char[0] == 4 {
|
|
||||||
return "", fmt.Errorf("keyboard interupt")
|
|
||||||
} else if char[0] == '\r' || char[0] == '\n' {
|
|
||||||
fmt.Println()
|
|
||||||
break
|
|
||||||
} else if char[0] == '\b' || char[0] == 127 {
|
|
||||||
if len(password) > 0 {
|
|
||||||
password = password[:len(password)-1]
|
|
||||||
fmt.Print("\b \b")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
password = append(password, char[0])
|
|
||||||
fmt.Print("*")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fmt.Print("\r")
|
return line, nil
|
||||||
return string(password), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pause() {
|
func pause() {
|
||||||
|
|||||||
76
src/json.go
76
src/json.go
@@ -3,9 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func convertToArgon(obj any) any {
|
func convertToArgon(obj any) any {
|
||||||
@@ -24,7 +22,7 @@ func convertToArgon(obj any) any {
|
|||||||
case string:
|
case string:
|
||||||
return ArString(x)
|
return ArString(x)
|
||||||
case float64:
|
case float64:
|
||||||
return newNumber().SetFloat64(x)
|
return Number(x)
|
||||||
case bool:
|
case bool:
|
||||||
return x
|
return x
|
||||||
case nil:
|
case nil:
|
||||||
@@ -33,45 +31,40 @@ func convertToArgon(obj any) any {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonparse(str string) any {
|
func jsonparse(str string) (any, ArErr) {
|
||||||
var jsonMap any
|
var jsonMap any
|
||||||
json.Unmarshal([]byte(str), &jsonMap)
|
var err = json.Unmarshal([]byte(str), &jsonMap)
|
||||||
return convertToArgon(jsonMap)
|
if err != nil {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
|
}
|
||||||
|
return convertToArgon(jsonMap), ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonstringify(obj any, level int) (string, error) {
|
func jsonstringify(obj any, level int64) (string, error) {
|
||||||
if level > 100 {
|
if level > 100 {
|
||||||
return "", errors.New("json stringify error: too many levels")
|
return "", errors.New("json stringify error: too many levels")
|
||||||
}
|
}
|
||||||
output := []string{}
|
|
||||||
obj = ArValidToAny(obj)
|
|
||||||
switch x := obj.(type) {
|
switch x := obj.(type) {
|
||||||
case anymap:
|
case ArObject:
|
||||||
for key, value := range x {
|
if callable, ok := x.obj["__json__"]; ok {
|
||||||
str, err := jsonstringify(value, level+1)
|
val, err := runCall(
|
||||||
if err != nil {
|
call{
|
||||||
return "", err
|
Callable: callable,
|
||||||
|
Args: []any{Int64ToNumber(level)},
|
||||||
|
},
|
||||||
|
stack{},
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
if err.EXISTS {
|
||||||
|
return "", errors.New(err.message)
|
||||||
}
|
}
|
||||||
output = append(output, ""+strconv.Quote(anyToArgon(key, false, true, 3, 0, false, 0))+": "+str)
|
val = ArValidToAny(val)
|
||||||
}
|
if x, ok := val.(string); ok {
|
||||||
return "{" + strings.Join(output, ", ") + "}", nil
|
return x, nil
|
||||||
case []any:
|
} else {
|
||||||
for _, value := range x {
|
return "", errors.New("json stringify error: __json__ must return a string")
|
||||||
str, err := jsonstringify(value, level+1)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
output = append(output, str)
|
|
||||||
}
|
}
|
||||||
return "[" + strings.Join(output, ", ") + "]", nil
|
|
||||||
case string:
|
|
||||||
return strconv.Quote(x), nil
|
|
||||||
case number:
|
|
||||||
num, _ := x.Float64()
|
|
||||||
if math.IsNaN(num) || math.IsInf(num, 0) {
|
|
||||||
return "null", nil
|
|
||||||
}
|
|
||||||
return numberToString(x, false), nil
|
|
||||||
case bool:
|
case bool:
|
||||||
return strconv.FormatBool(x), nil
|
return strconv.FormatBool(x), nil
|
||||||
case nil:
|
case nil:
|
||||||
@@ -90,13 +83,24 @@ var ArJSON = Map(anymap{
|
|||||||
return nil, ArErr{TYPE: "Runtime Error", message: "parse takes a string not a '" + typeof(args[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Runtime Error", message: "parse takes a string not a '" + typeof(args[0]) + "'", EXISTS: true}
|
||||||
}
|
}
|
||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
return jsonparse(args[0].(string)), ArErr{}
|
return jsonparse(args[0].(string))
|
||||||
}},
|
}},
|
||||||
"stringify": builtinFunc{"stringify", func(args ...any) (any, ArErr) {
|
"stringify": builtinFunc{"stringify", func(args ...any) (any, ArErr) {
|
||||||
if len(args) == 0 {
|
if len(args) != 1 && len(args) != 2 {
|
||||||
return nil, ArErr{TYPE: "Runtime Error", message: "stringify takes 1 argument", EXISTS: true}
|
return nil, ArErr{TYPE: "Runtime Error", message: "stringify takes 1 or 2 arguments", EXISTS: true}
|
||||||
}
|
}
|
||||||
str, err := jsonstringify(args[0], 0)
|
var level int64 = 0
|
||||||
|
if len(args) == 2 {
|
||||||
|
if typeof(args[1]) != "number" {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error", message: "stringify takes a number not a '" + typeof(args[1]) + "'", EXISTS: true}
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
level, err = numberToInt64(args[1].(ArObject))
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str, err := jsonstringify(args[0], level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ func Ln(x number) number {
|
|||||||
n1, _ := x.Float64()
|
n1, _ := x.Float64()
|
||||||
n2, _ := output.Float64()
|
n2, _ := output.Float64()
|
||||||
output = newNumber().SetFloat64(math.Pow(n1, n2))
|
output = newNumber().SetFloat64(math.Pow(n1, n2))
|
||||||
if output == nil {
|
|
||||||
output = infinity
|
|
||||||
}
|
|
||||||
output.Sub(output, newNumber().SetInt64(1))
|
output.Sub(output, newNumber().SetInt64(1))
|
||||||
output.Mul(output, N)
|
output.Mul(output, N)
|
||||||
return output
|
return output
|
||||||
|
|||||||
21
src/main.go
21
src/main.go
@@ -10,13 +10,8 @@ var Args = os.Args[1:]
|
|||||||
|
|
||||||
type stack = []ArObject
|
type stack = []ArObject
|
||||||
|
|
||||||
const VERSION = "3.0.1"
|
const VERSION = "3.1.0 oop numbers beta 1"
|
||||||
|
const VERSION_NUM = 7
|
||||||
// Example struct
|
|
||||||
type Person struct {
|
|
||||||
Name string
|
|
||||||
Age int
|
|
||||||
}
|
|
||||||
|
|
||||||
func newscope() ArObject {
|
func newscope() ArObject {
|
||||||
return Map(anymap{})
|
return Map(anymap{})
|
||||||
@@ -28,7 +23,7 @@ func main() {
|
|||||||
if !debug {
|
if !debug {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
fmt.Println("There was a fundamental error in argon v3 that caused it to crash.")
|
fmt.Println("There was a fundamental error in argon v" + VERSION + " that caused it to crash.")
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("website:", website)
|
fmt.Println("website:", website)
|
||||||
fmt.Println("docs:", docs)
|
fmt.Println("docs:", docs)
|
||||||
@@ -50,7 +45,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
initRandom()
|
|
||||||
garbageCollect()
|
garbageCollect()
|
||||||
global := makeGlobal()
|
global := makeGlobal()
|
||||||
if len(Args) == 0 {
|
if len(Args) == 0 {
|
||||||
@@ -61,12 +55,15 @@ func main() {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
panic(e)
|
panic(e)
|
||||||
}
|
}
|
||||||
_, err := importMod(Args[0], ex, true, global)
|
translated, err := translateImport(Args[0], ex, true)
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
panicErr(err)
|
panicErr(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if threadCount > 0 {
|
_, runimeErr := runTranslatedImport(translated, global, true)
|
||||||
<-threadChan
|
if runimeErr.EXISTS {
|
||||||
|
panicErr(runimeErr)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
threadChan.Wait()
|
||||||
}
|
}
|
||||||
|
|||||||
83
src/map.go
83
src/map.go
@@ -36,7 +36,7 @@ func runCreateMap(m createMap, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
if isUnhashable(keyVal) {
|
if isUnhashable(keyVal) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
"TypeError",
|
"Type Error",
|
||||||
"unhashable type: '" + typeof(keyVal) + "'",
|
"unhashable type: '" + typeof(keyVal) + "'",
|
||||||
m.line,
|
m.line,
|
||||||
m.path,
|
m.path,
|
||||||
@@ -114,18 +114,17 @@ func parseMap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, bool,
|
|||||||
}, true, ArErr{}, countIndex
|
}, true, ArErr{}, countIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
var mutex = sync.RWMutex{}
|
|
||||||
var listenersMutex = sync.RWMutex{}
|
|
||||||
|
|
||||||
func Map(m anymap) ArObject {
|
func Map(m anymap) ArObject {
|
||||||
|
var mutex = sync.RWMutex{}
|
||||||
|
var listenersMutex = sync.RWMutex{}
|
||||||
var currentID uint32 = 0
|
var currentID uint32 = 0
|
||||||
listeners := map[any]map[uint32]any{}
|
listeners := map[any]map[uint32]any{}
|
||||||
obj := ArObject{
|
obj := ArObject{
|
||||||
obj: anymap{
|
obj: anymap{
|
||||||
"__value__": m,
|
"__value__": m,
|
||||||
"__name__": "map",
|
"__name__": "map",
|
||||||
"get": builtinFunc{
|
"get_value": builtinFunc{
|
||||||
"get",
|
"get_value",
|
||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) < 1 || len(args) > 2 {
|
if len(args) < 1 || len(args) > 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -161,7 +160,7 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -201,7 +200,7 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -241,11 +240,12 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
|
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
args[0] = ArValidToAny(args[0])
|
||||||
if isUnhashable(args[0]) {
|
if isUnhashable(args[0]) {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "Runtime Error",
|
TYPE: "Runtime Error",
|
||||||
@@ -274,12 +274,60 @@ func Map(m anymap) ArObject {
|
|||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"__deleteindex__": builtinFunc{
|
||||||
|
"__deleteindex__",
|
||||||
|
func(args ...any) (any, ArErr) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Type Error",
|
||||||
|
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isUnhashable(args[0]) {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: "unhashable type: " + typeof(args[0]),
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key := ArValidToAny(args[0])
|
||||||
|
mutex.RLock()
|
||||||
|
if _, ok := m[key]; !ok {
|
||||||
|
mutex.RUnlock()
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "KeyError",
|
||||||
|
message: "key " + fmt.Sprint(key) + " not found",
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mutex.RUnlock()
|
||||||
|
listenersMutex.RLock()
|
||||||
|
if _, ok := listeners[key]; ok {
|
||||||
|
for _, v := range listeners[key] {
|
||||||
|
runCall(
|
||||||
|
call{
|
||||||
|
Callable: v,
|
||||||
|
Args: []any{},
|
||||||
|
},
|
||||||
|
stack{},
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listenersMutex.RUnlock()
|
||||||
|
mutex.Lock()
|
||||||
|
delete(m, key)
|
||||||
|
mutex.Unlock()
|
||||||
|
return nil, ArErr{}
|
||||||
|
},
|
||||||
|
},
|
||||||
"__getindex__": builtinFunc{
|
"__getindex__": builtinFunc{
|
||||||
"__getindex__",
|
"__getindex__",
|
||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -330,7 +378,7 @@ func Map(m anymap) ArObject {
|
|||||||
debugPrintln("Equal", args)
|
debugPrintln("Equal", args)
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
message: "expected 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -372,7 +420,7 @@ func Map(m anymap) ArObject {
|
|||||||
debugPrintln("copy", args)
|
debugPrintln("copy", args)
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -391,7 +439,7 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
|
message: "expected 2 arguments, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -406,7 +454,7 @@ func Map(m anymap) ArObject {
|
|||||||
}
|
}
|
||||||
if typeof(args[1]) != "function" {
|
if typeof(args[1]) != "function" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected function, got " + typeof(args[1]),
|
message: "expected function, got " + typeof(args[1]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -425,7 +473,7 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -444,7 +492,7 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -458,6 +506,7 @@ func Map(m anymap) ArObject {
|
|||||||
return ArArray(keys), ArErr{}
|
return ArArray(keys), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.obj["__Boolean__"] = builtinFunc{
|
obj.obj["__Boolean__"] = builtinFunc{
|
||||||
"__Boolean__",
|
"__Boolean__",
|
||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
@@ -475,7 +524,7 @@ func Map(m anymap) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
message: "expected 0 arguments, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var PI, _ = newNumber().SetString("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989")
|
import "math/big"
|
||||||
var e, _ = newNumber().SetString("2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931277361782154249992295763514822082698951936680331825288693984964651058209392398294887933203625094431173012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509961818815930416903515988885193458072738667385894228792284998920868058257492796104841984443634632449684875602336248270419786232090021609902353043699418491463140934317381436405462531520961836908887070167683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354")
|
|
||||||
var infinity, _ = newNumber().SetString("1e1000")
|
var PI_RAT, _ = new(big.Rat).SetString("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989")
|
||||||
|
var PI ArObject
|
||||||
|
var e_RAT, _ = new(big.Rat).SetString("2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931277361782154249992295763514822082698951936680331825288693984964651058209392398294887933203625094431173012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509961818815930416903515988885193458072738667385894228792284998920868058257492796104841984443634632449684875602336248270419786232090021609902353043699418491463140934317381436405462531520961836908887070167683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354")
|
||||||
|
var e ArObject
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
PI = Number(PI_RAT)
|
||||||
|
e = Number(e_RAT)
|
||||||
|
}
|
||||||
|
|||||||
1757
src/number.go
1757
src/number.go
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -27,8 +26,6 @@ var operations = []string{
|
|||||||
"^",
|
"^",
|
||||||
}
|
}
|
||||||
|
|
||||||
var one = newNumber().SetInt64(1)
|
|
||||||
|
|
||||||
type operationType struct {
|
type operationType struct {
|
||||||
operation int
|
operation int
|
||||||
values []any
|
values []any
|
||||||
@@ -74,7 +71,7 @@ func parseOperations(code UNPARSEcode, index int, codelines []UNPARSEcode) (oper
|
|||||||
path: code.path,
|
path: code.path,
|
||||||
}, index, codelines, 0)
|
}, index, codelines, 0)
|
||||||
if !success || err.EXISTS {
|
if !success || err.EXISTS {
|
||||||
return operationType{}, success, err, 0
|
continue
|
||||||
}
|
}
|
||||||
values = append(values, resp)
|
values = append(values, resp)
|
||||||
totalStep += respindex - 1
|
totalStep += respindex - 1
|
||||||
@@ -82,7 +79,7 @@ func parseOperations(code UNPARSEcode, index int, codelines []UNPARSEcode) (oper
|
|||||||
operation: i,
|
operation: i,
|
||||||
values: values,
|
values: values,
|
||||||
line: code.line,
|
line: code.line,
|
||||||
code: code.code,
|
code: code.realcode,
|
||||||
path: code.path,
|
path: code.path,
|
||||||
}, true, ArErr{}, totalStep
|
}, true, ArErr{}, totalStep
|
||||||
}
|
}
|
||||||
@@ -120,9 +117,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
}
|
}
|
||||||
switch o.operation {
|
switch o.operation {
|
||||||
case 4:
|
case 4:
|
||||||
if isAnyNumber(resp) && isAnyNumber(resp2) {
|
if x, ok := resp.(ArObject); ok {
|
||||||
return resp.(number).Cmp(resp2.(number)) <= 0, ArErr{}
|
|
||||||
} else if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__LessThanEqual__"]; ok {
|
if y, ok := x.obj["__LessThanEqual__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -147,9 +142,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
case 5:
|
case 5:
|
||||||
if isAnyNumber(resp) && isAnyNumber(resp2) {
|
if x, ok := resp.(ArObject); ok {
|
||||||
return resp.(number).Cmp(resp2.(number)) >= 0, ArErr{}
|
|
||||||
} else if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__GreaterThanEqual__"]; ok {
|
if y, ok := x.obj["__GreaterThanEqual__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -174,9 +167,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
case 6:
|
case 6:
|
||||||
if isAnyNumber(resp) && isAnyNumber(resp2) {
|
if x, ok := resp.(ArObject); ok {
|
||||||
return resp.(number).Cmp(resp2.(number)) < 0, ArErr{}
|
|
||||||
} else if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__LessThan__"]; ok {
|
if y, ok := x.obj["__LessThan__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -201,9 +192,7 @@ func compareValues(o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
case 7:
|
case 7:
|
||||||
if isAnyNumber(resp) && isAnyNumber(resp2) {
|
if x, ok := resp.(ArObject); ok {
|
||||||
return resp.(number).Cmp(resp2.(number)) > 0, ArErr{}
|
|
||||||
} else if x, ok := resp.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__GreaterThan__"]; ok {
|
if y, ok := x.obj["__GreaterThan__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -253,9 +242,6 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
output := resp
|
output := resp
|
||||||
if isAnyNumber(resp) {
|
|
||||||
output = newNumber().Set(resp.(number))
|
|
||||||
}
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
@@ -265,10 +251,7 @@ func calcNegative(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(output) == "number" && typeof(resp) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
output = output.(number).Sub(output.(number), resp.(number))
|
|
||||||
continue
|
|
||||||
} else if x, ok := output.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__Subtract__"]; ok {
|
if y, ok := x.obj["__Subtract__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -309,33 +292,17 @@ func calcDivide(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
output := resp
|
output := resp
|
||||||
if isAnyNumber(resp) {
|
|
||||||
output = newNumber().Set(resp.(number))
|
|
||||||
}
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
if resp.(number).Cmp(newNumber().SetInt64(0)) == 0 {
|
|
||||||
return nil, ArErr{
|
|
||||||
"Runtime Error",
|
|
||||||
"Cannot divide by zero",
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
o.code,
|
|
||||||
true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output = output.(number).Quo(output.(number), resp.(number))
|
|
||||||
continue
|
|
||||||
} else if x, ok := output.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__Divide__"]; ok {
|
if y, ok := x.obj["__Divide__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -375,9 +342,6 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var output any = resp
|
var output any = resp
|
||||||
if typeof(output) == "number" {
|
|
||||||
output = newNumber().Set(output.(number))
|
|
||||||
}
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
@@ -387,10 +351,7 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(output) == "number" && typeof(resp) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
output = output.(number).Add(output.(number), resp.(number))
|
|
||||||
continue
|
|
||||||
} else if x, ok := output.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__Add__"]; ok {
|
if y, ok := x.obj["__Add__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -400,11 +361,26 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if err.EXISTS {
|
if !err.EXISTS {
|
||||||
return nil, err
|
output = val
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
output = val
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -416,7 +392,7 @@ func calcAdd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
true,
|
true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (output), ArErr{}
|
return output, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
@@ -430,9 +406,6 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var output any = resp
|
var output any = resp
|
||||||
if isAnyNumber(resp) {
|
|
||||||
output = newNumber().Set(resp.(number))
|
|
||||||
}
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
@@ -442,10 +415,7 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(output) == "number" && typeof(resp) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
output = output.(number).Mul(output.(number), resp.(number))
|
|
||||||
continue
|
|
||||||
} else if x, ok := output.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__Multiply__"]; ok {
|
if y, ok := x.obj["__Multiply__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -455,11 +425,26 @@ func calcMul(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
}, stack, stacklevel+1)
|
}, stack, stacklevel+1)
|
||||||
if err.EXISTS {
|
if !err.EXISTS {
|
||||||
return nil, err
|
output = val
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if x, ok := resp.(ArObject); ok {
|
||||||
|
if y, ok := x.obj["__PostMultiply__"]; ok {
|
||||||
|
val, err := runCall(
|
||||||
|
call{
|
||||||
|
y,
|
||||||
|
[]any{output},
|
||||||
|
o.code,
|
||||||
|
o.line,
|
||||||
|
o.path,
|
||||||
|
}, stack, stacklevel+1)
|
||||||
|
if !err.EXISTS {
|
||||||
|
output = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
output = val
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -483,7 +468,7 @@ func calcAnd(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -503,7 +488,7 @@ func calcOr(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -539,7 +524,7 @@ func calcNotIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -624,9 +609,7 @@ func calcIn(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func notequals(a any, b any, o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
func notequals(a any, b any, o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
||||||
if typeof(a) == "number" && typeof(b) == "number" {
|
if x, ok := a.(ArObject); ok {
|
||||||
return a.(number).Cmp(b.(number)) != 0, ArErr{}
|
|
||||||
} else if x, ok := a.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__NotEqual__"]; ok {
|
if y, ok := x.obj["__NotEqual__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -662,9 +645,7 @@ func notequals(a any, b any, o operationType, stack stack, stacklevel int) (bool
|
|||||||
|
|
||||||
func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, ArErr) {
|
||||||
debugPrintln("equals", a, b)
|
debugPrintln("equals", a, b)
|
||||||
if typeof(a) == "number" && typeof(b) == "number" {
|
if x, ok := a.(ArObject); ok {
|
||||||
return a.(number).Cmp(b.(number)) == 0, ArErr{}
|
|
||||||
} else if x, ok := a.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__Equal__"]; ok {
|
if y, ok := x.obj["__Equal__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -680,7 +661,7 @@ func equals(a any, b any, o operationType, stack stack, stacklevel int) (bool, A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if x, ok := b.(ArObject); ok {
|
if x, ok := b.(ArObject); ok {
|
||||||
if y, ok := x.obj["__GreaterThanEqual__"]; ok {
|
if y, ok := x.obj["__Equal__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
y,
|
y,
|
||||||
@@ -708,27 +689,16 @@ func calcMod(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
output := resp
|
output := resp
|
||||||
if isAnyNumber(resp) {
|
|
||||||
output = newNumber().Set(resp.(number))
|
|
||||||
}
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
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 {
|
if y, ok := x.obj["__Modulo__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -767,23 +737,17 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
output := resp
|
output := resp
|
||||||
if isAnyNumber(resp) {
|
|
||||||
output = newNumber().Set(resp.(number))
|
|
||||||
}
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(resp) == "number" && typeof(output) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
output = floor(output.(number).Quo(output.(number), resp.(number)))
|
|
||||||
continue
|
|
||||||
} else if x, ok := output.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__IntDivide__"]; ok {
|
if y, ok := x.obj["__IntDivide__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
@@ -802,7 +766,7 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
"Runtime Error",
|
"Runtime Error",
|
||||||
"Cannot divide type '" + typeof(resp) + "'",
|
"Cannot int divide type '" + typeof(resp) + "'",
|
||||||
o.line,
|
o.line,
|
||||||
o.path,
|
o.path,
|
||||||
o.code,
|
o.code,
|
||||||
@@ -812,93 +776,142 @@ func calcIntDiv(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
return output, ArErr{}
|
return output, ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcPower(o operationType, stack stack, stacklevel int) (number, ArErr) {
|
// func calcPower(o operationType, stack stack, stacklevel int) (number, ArErr) {
|
||||||
|
// resp, err := runVal(
|
||||||
|
// o.values[0],
|
||||||
|
// stack,
|
||||||
|
// stacklevel+1,
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// if err.EXISTS {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// if typeof(resp) != "number" {
|
||||||
|
// return nil, ArErr{
|
||||||
|
// "Runtime Error",
|
||||||
|
// "Cannot calculate power of type '" + typeof(resp) + "'",
|
||||||
|
// o.line,
|
||||||
|
// o.path,
|
||||||
|
// o.code,
|
||||||
|
// true,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// 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(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()
|
||||||
|
// 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,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return output, ArErr{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
func calcPower(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[0],
|
o.values[0],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(resp) != "number" {
|
var output any = resp
|
||||||
return nil, ArErr{
|
|
||||||
"Runtime Error",
|
|
||||||
"Cannot calculate power of type '" + typeof(resp) + "'",
|
|
||||||
o.line,
|
|
||||||
o.path,
|
|
||||||
o.code,
|
|
||||||
true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output := newNumber().Set(resp.(number))
|
|
||||||
for i := 1; i < len(o.values); i++ {
|
for i := 1; i < len(o.values); i++ {
|
||||||
resp, err := runVal(
|
resp, err := runVal(
|
||||||
o.values[i],
|
o.values[i],
|
||||||
stack,
|
stack,
|
||||||
stacklevel+1,
|
stacklevel+1,
|
||||||
)
|
)
|
||||||
resp = ArValidToAny(resp)
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if typeof(resp) == "number" {
|
if x, ok := output.(ArObject); ok {
|
||||||
n := newNumber().Set(resp.(number))
|
if y, ok := x.obj["__Power__"]; ok {
|
||||||
if n.Cmp(newNumber().SetInt64(10)) <= 0 {
|
val, err := runCall(
|
||||||
toOut := newNumber().SetInt64(1)
|
call{
|
||||||
clone := newNumber().Set(output)
|
y,
|
||||||
nAbs := (abs(newNumber().Set(n)))
|
[]any{resp},
|
||||||
j := newNumber()
|
o.code,
|
||||||
for ; j.Cmp(nAbs) < 0; j.Add(j, one) {
|
o.line,
|
||||||
toOut.Mul(toOut, clone)
|
o.path,
|
||||||
|
}, stack, stacklevel+1)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
output = val
|
||||||
nAbs.Sub(nAbs, j)
|
continue
|
||||||
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()
|
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil, ArErr{
|
||||||
|
"Runtime Error",
|
||||||
|
"Cannot power type '" + typeof(resp) + "' to type '" + typeof(output) + "'",
|
||||||
|
o.line,
|
||||||
|
o.path,
|
||||||
|
o.code,
|
||||||
|
true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return output, ArErr{}
|
return (output), ArErr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runOperation(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
func runOperation(o operationType, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
|||||||
@@ -5,14 +5,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var genericImportCompiled = makeRegex(`import( )+(.|\n)+(( )+as( )+([a-zA-Z_]|(\p{L}\p{M}*))([a-zA-Z0-9_]|(\p{L}\p{M}*))*)?( *)`)
|
var genericImportCompiled = makeRegex(`( *)import( )+(.|\n)+(( )+as( )+([a-zA-Z_]|(\p{L}\p{M}*))([a-zA-Z0-9_]|(\p{L}\p{M}*))*)?( *)`)
|
||||||
|
|
||||||
type ArImport struct {
|
type ArImport struct {
|
||||||
FilePath any
|
pretranslated bool
|
||||||
Values any
|
translated translatedImport
|
||||||
Code string
|
FilePath any
|
||||||
Line int
|
Values any
|
||||||
Path string
|
Code string
|
||||||
|
Line int
|
||||||
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func isGenericImport(code UNPARSEcode) bool {
|
func isGenericImport(code UNPARSEcode) bool {
|
||||||
@@ -67,27 +69,54 @@ func parseGenericImport(code UNPARSEcode, index int, codeline []UNPARSEcode) (Ar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ArImport{
|
importOBJ := ArImport{
|
||||||
|
false,
|
||||||
|
translatedImport{},
|
||||||
toImport,
|
toImport,
|
||||||
asStr,
|
asStr,
|
||||||
code.realcode,
|
code.realcode,
|
||||||
code.line,
|
code.line,
|
||||||
code.path,
|
code.path,
|
||||||
}, true, ArErr{}, i
|
}
|
||||||
|
|
||||||
|
if str, ok := toImport.(string); ok {
|
||||||
|
resp, err := translateImport(str, filepath.Dir(filepath.ToSlash(code.path)), false)
|
||||||
|
if !err.EXISTS {
|
||||||
|
importOBJ.translated = resp
|
||||||
|
importOBJ.pretranslated = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return importOBJ, true, ArErr{}, i
|
||||||
}
|
}
|
||||||
|
|
||||||
func runImport(importOBJ ArImport, stack stack, stacklevel int) (any, ArErr) {
|
func runImport(importOBJ ArImport, stack stack, stacklevel int) (any, ArErr) {
|
||||||
val, err := runVal(importOBJ.FilePath, stack, stacklevel+1)
|
var translated = importOBJ.translated
|
||||||
val = ArValidToAny(val)
|
if !importOBJ.pretranslated {
|
||||||
if err.EXISTS {
|
val, err := runVal(importOBJ.FilePath, stack, stacklevel+1)
|
||||||
return nil, err
|
val = ArValidToAny(val)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if typeof(val) != "string" {
|
||||||
|
return nil, ArErr{"Type Error", "import requires a string, got type '" + typeof(val) + "'", importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||||
|
}
|
||||||
|
parent := filepath.Dir(filepath.ToSlash(importOBJ.Path))
|
||||||
|
translated, err = translateImport(val.(string), parent, false)
|
||||||
|
if err.EXISTS {
|
||||||
|
if err.line == 0 {
|
||||||
|
err.line = importOBJ.Line
|
||||||
|
}
|
||||||
|
if err.path == "" {
|
||||||
|
err.path = importOBJ.Path
|
||||||
|
}
|
||||||
|
if err.code == "" {
|
||||||
|
err.code = importOBJ.Code
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if typeof(val) != "string" {
|
stackMap, err := runTranslatedImport(translated, stack[0], false)
|
||||||
return nil, ArErr{"Type Error", "import requires a string, got type '" + typeof(val) + "'", importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
|
||||||
}
|
|
||||||
path := val.(string)
|
|
||||||
parent := filepath.Dir(filepath.ToSlash(importOBJ.Path))
|
|
||||||
stackMap, err := importMod(path, parent, false, stack[0])
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
if err.line == 0 {
|
if err.line == 0 {
|
||||||
err.line = importOBJ.Line
|
err.line = importOBJ.Line
|
||||||
@@ -116,7 +145,7 @@ func runImport(importOBJ ArImport, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
for _, v := range x {
|
for _, v := range x {
|
||||||
val, ok := stackMap.obj[v]
|
val, ok := stackMap.obj[v]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ArErr{"Import Error", "could not find value " + anyToArgon(v, true, false, 3, 0, false, 0) + " in module " + anyToArgon(path, true, false, 3, 0, false, 0), importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
return nil, ArErr{"Import Error", "could not find value " + anyToArgon(v, true, false, 3, 0, false, 0) + " in module " + anyToArgon(translated.path, true, false, 3, 0, false, 0), importOBJ.Line, importOBJ.Path, importOBJ.Code, true}
|
||||||
}
|
}
|
||||||
builtinCall(setindex, []any{v, val})
|
builtinCall(setindex, []any{v, val})
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/path.go
46
src/path.go
@@ -14,7 +14,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "ReadDir argument must be a string, got " + typeof(args[0]),
|
message: "ReadDir argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ var ArPath = Map(
|
|||||||
files, err := os.ReadDir(args[0].(string))
|
files, err := os.ReadDir(args[0].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "exists takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "exists takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "exists argument must be a string, got " + typeof(args[0]),
|
message: "exists argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ var ArPath = Map(
|
|||||||
return false, ArErr{}
|
return false, ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "mkAllDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "mkAllDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "mkAllDir argument must be a string, got " + typeof(args[0]),
|
message: "mkAllDir argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ var ArPath = Map(
|
|||||||
err := os.MkdirAll(args[0].(string), os.ModePerm)
|
err := os.MkdirAll(args[0].(string), os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "mkDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "mkDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "mkDir argument must be a string, got " + typeof(args[0]),
|
message: "mkDir argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ var ArPath = Map(
|
|||||||
err := os.Mkdir(args[0].(string), os.ModePerm)
|
err := os.Mkdir(args[0].(string), os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "remove takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "remove takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "remove argument must be a string, got " + typeof(args[0]),
|
message: "remove argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ var ArPath = Map(
|
|||||||
err := os.Remove(args[0].(string))
|
err := os.Remove(args[0].(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "isDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "isDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "isDir argument must be a string, got " + typeof(args[0]),
|
message: "isDir argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ var ArPath = Map(
|
|||||||
return false, ArErr{}
|
return false, ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ var ArPath = Map(
|
|||||||
x = ArValidToAny(x)
|
x = ArValidToAny(x)
|
||||||
if typeof(x) != "string" {
|
if typeof(x) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "join argument must be an array of strings, got " + typeof(x),
|
message: "join argument must be an array of strings, got " + typeof(x),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ var ArPath = Map(
|
|||||||
return filepath.Join(Path...), ArErr{}
|
return filepath.Join(Path...), ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "join argument must be an array, got " + typeof(args[0]),
|
message: "join argument must be an array, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -225,7 +225,7 @@ var ArPath = Map(
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "parent takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
message: "parent takes exactly 1 argument, got " + fmt.Sprint(len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ var ArPath = Map(
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "string" {
|
if typeof(args[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "runtime",
|
TYPE: "Runtime Error",
|
||||||
message: "parent argument must be a string, got " + typeof(args[0]),
|
message: "parent argument must be a string, got " + typeof(args[0]),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
|
|||||||
108
src/random.go
108
src/random.go
@@ -6,10 +6,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func random() number {
|
var rand_source = rand.New(rand.NewSource(time.Now().UnixMicro()))
|
||||||
return newNumber().SetFloat64(
|
|
||||||
rand.Float64(),
|
func random() ArObject {
|
||||||
)
|
return Number(rand_source.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomRange(args ...any) (any, ArErr) {
|
func randomRange(args ...any) (any, ArErr) {
|
||||||
@@ -33,23 +33,88 @@ func randomRange(args ...any) (any, ArErr) {
|
|||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
min := args[0].(number)
|
min := args[0].(ArObject)
|
||||||
max := args[1].(number)
|
max := args[1].(ArObject)
|
||||||
if min.Cmp(max) > 0 {
|
|
||||||
|
compare_num, err := CompareObjects(min, max)
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
compare, Err := numberToInt64(compare_num)
|
||||||
|
if Err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "Runtime Error",
|
TYPE: "Runtime Error",
|
||||||
message: "takes a min less than max",
|
message: Err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
difference := newNumber().Sub(max, min)
|
|
||||||
|
if compare == 1 {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: "range() num 1 must be less than or equal to num 2",
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num_range, err := runOperation(
|
||||||
|
operationType{
|
||||||
|
operation: 11,
|
||||||
|
values: []any{max, min},
|
||||||
|
},
|
||||||
|
stack{},
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := num_range.(ArObject); !ok {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: "could not subtract the two numbers to calculate the range",
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num_range_obj := num_range.(ArObject)
|
||||||
|
|
||||||
rand := random()
|
rand := random()
|
||||||
rand.Mul(rand, difference)
|
|
||||||
rand.Add(rand, min)
|
multiplier, err := runOperation(
|
||||||
return rand, ArErr{}
|
operationType{
|
||||||
|
operation: 12,
|
||||||
|
values: []any{rand, num_range_obj},
|
||||||
|
},
|
||||||
|
stack{},
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err.EXISTS {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := multiplier.(ArObject); !ok {
|
||||||
|
return nil, ArErr{
|
||||||
|
TYPE: "Runtime Error",
|
||||||
|
message: "could not multiply the random number by the range",
|
||||||
|
EXISTS: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return runOperation(
|
||||||
|
operationType{
|
||||||
|
operation: 10,
|
||||||
|
values: []any{multiplier, min},
|
||||||
|
},
|
||||||
|
stack{},
|
||||||
|
0,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ArRandom = Map(anymap{
|
var ArRandom = ArObject{anymap{
|
||||||
"__call__": builtinFunc{"random", func(args ...any) (any, ArErr) {
|
"__call__": builtinFunc{"random", func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
@@ -83,22 +148,15 @@ var ArRandom = Map(anymap{
|
|||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !a[0].(number).IsInt() {
|
new_seed, err := numberToInt64(a[0].(ArObject))
|
||||||
|
if err != nil {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "Runtime Error",
|
TYPE: "Runtime Error",
|
||||||
message: "takes an integer not a float",
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rand.Seed(
|
rand_source.Seed(new_seed)
|
||||||
a[0].(number).Num().Int64(),
|
|
||||||
)
|
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}},
|
}},
|
||||||
})
|
}}
|
||||||
|
|
||||||
func initRandom() {
|
|
||||||
rand.Seed(
|
|
||||||
time.Now().UnixMicro(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
64
src/run.go
64
src/run.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,38 +57,30 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
return setVariableValue(x, stack, stacklevel+1)
|
return setVariableValue(x, stack, stacklevel+1)
|
||||||
case negative:
|
// case negative:
|
||||||
if stackoverflow {
|
// if stackoverflow {
|
||||||
linenum = x.line
|
// linenum = x.line
|
||||||
path = x.path
|
// path = x.path
|
||||||
code = x.code
|
// code = x.code
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
resp, err := runVal(x.VAL, stack, stacklevel+1)
|
// resp, err := runVal(x.VAL, stack, stacklevel+1)
|
||||||
resp = AnyToArValid(resp)
|
// resp = AnyToArValid(resp)
|
||||||
if err.EXISTS {
|
// if err.EXISTS {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
switch y := resp.(type) {
|
// switch y := resp.(type) {
|
||||||
case number:
|
// case compiledNumber:
|
||||||
if !x.sign {
|
// if !x.sign {
|
||||||
return newNumber().Neg(y), ArErr{}
|
// return Number(compiledNumber{new(big.Rat).Neg(y)}), ArErr{}
|
||||||
}
|
// }
|
||||||
return y, ArErr{}
|
// return y, ArErr{}
|
||||||
}
|
// }
|
||||||
return nil, ArErr{
|
// return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
// TYPE: "Type Error",
|
||||||
message: "cannot negate a non-number",
|
// message: "cannot negate a non-number",
|
||||||
EXISTS: true,
|
// EXISTS: true,
|
||||||
}
|
// }
|
||||||
case brackets:
|
|
||||||
if stackoverflow {
|
|
||||||
linenum = x.line
|
|
||||||
path = x.path
|
|
||||||
code = x.code
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return runVal(x.VAL, stack, stacklevel+1)
|
|
||||||
case operationType:
|
case operationType:
|
||||||
if stackoverflow {
|
if stackoverflow {
|
||||||
linenum = x.line
|
linenum = x.line
|
||||||
@@ -216,7 +209,11 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
return runTryCatch(x, stack, stacklevel+1)
|
return runTryCatch(x, stack, stacklevel+1)
|
||||||
case bool, ArObject, number, nil, Callable, builtinFunc, anymap:
|
case compiledNumber:
|
||||||
|
return Number(x.value), ArErr{}
|
||||||
|
case int64, int, float64, float32, *big.Rat, *big.Int:
|
||||||
|
return Number(x), ArErr{}
|
||||||
|
case bool, ArObject, nil, Callable, builtinFunc, anymap:
|
||||||
return x, ArErr{}
|
return x, ArErr{}
|
||||||
}
|
}
|
||||||
if stackoverflow {
|
if stackoverflow {
|
||||||
@@ -230,6 +227,7 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("unreachable", reflect.TypeOf(line))
|
fmt.Println("unreachable", reflect.TypeOf(line))
|
||||||
|
fmt.Println(line)
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/shell.go
12
src/shell.go
@@ -19,7 +19,7 @@ func shell(global ArObject) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fmt.Print("\x1b[32;5;240mWelcome to the Argon v3!\x1b[0m\n\n")
|
fmt.Print("\x1b[32;5;25mWelcome to the Argon v3!\x1b[25m\n\n")
|
||||||
for {
|
for {
|
||||||
indent := 0
|
indent := 0
|
||||||
previous := 0
|
previous := 0
|
||||||
@@ -27,13 +27,17 @@ func shell(global ArObject) {
|
|||||||
textBefore := ">>>"
|
textBefore := ">>>"
|
||||||
for i := 1; indent > 0 || (previous != indent && indent >= 0) || i == 1; i++ {
|
for i := 1; indent > 0 || (previous != indent && indent >= 0) || i == 1; i++ {
|
||||||
indentStr := strings.Repeat(" ", indent)
|
indentStr := strings.Repeat(" ", indent)
|
||||||
code := indentStr + input("\x1b[38;5;240m"+textBefore+indentStr+" \x1b[0m\x1b[1;5;240m")
|
line, err := input("\x1b[38;5;240m" + textBefore + indentStr + " \x1b[0m\x1b[1;5;25m")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("\x1b[0m\n\x1b[32;5;25mBye :)\x1b[0m")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
code := indentStr + line
|
||||||
fmt.Print("\x1b[0m")
|
fmt.Print("\x1b[0m")
|
||||||
totranslate = append(totranslate, UNPARSEcode{code, code, i, "<shell>"})
|
totranslate = append(totranslate, UNPARSEcode{code, code, i, "<shell>"})
|
||||||
trimmed := strings.TrimSpace(code)
|
trimmed := strings.TrimSpace(code)
|
||||||
split := strings.Split(trimmed, " ")
|
|
||||||
previous = indent
|
previous = indent
|
||||||
if split[len(split)-1] == "do" {
|
if len(trimmed) >= 2 && trimmed[len(trimmed)-2:] == "do" {
|
||||||
indent++
|
indent++
|
||||||
} else if trimmed == "" {
|
} else if trimmed == "" {
|
||||||
indent--
|
indent--
|
||||||
|
|||||||
@@ -10,19 +10,19 @@ import (
|
|||||||
func ArSocketClient(args ...any) (any, ArErr) {
|
func ArSocketClient(args ...any) (any, ArErr) {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket takes exactly 2 arguments",
|
message: "Socket takes exactly 2 arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(args[0]) != "string" {
|
} else if typeof(args[0]) != "string" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket type must be a string",
|
message: "Socket type must be a string",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(args[1]) != "string" {
|
} else if typeof(args[1]) != "string" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket address must be a string",
|
message: "Socket address must be a string",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
conn, err := net.Dial(networktype, address)
|
conn, err := net.Dial(networktype, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: fmt.Sprintf("Socket connection failed: %s", err.Error()),
|
message: fmt.Sprintf("Socket connection failed: %s", err.Error()),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -44,14 +44,14 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.readData() takes exactly 1 argument",
|
message: "Socket.readData() takes exactly 1 argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
n, err := conn.Read(buf)
|
n, err := conn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
|
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -72,14 +72,14 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.readUntil() takes exactly 1 argument",
|
message: "Socket.readUntil() takes exactly 1 argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
value := ArValidToAny(args[0])
|
value := ArValidToAny(args[0])
|
||||||
if typeof(value) != "buffer" {
|
if typeof(value) != "buffer" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
|
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
_, err := reader.Read(buf)
|
_, err := reader.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
|
message: fmt.Sprintf("Socket read failed: %s", err.Error()),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -125,21 +125,21 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("write() takes exactly 1 argument (%d given)", len(args)),
|
message: fmt.Sprintf("write() takes exactly 1 argument (%d given)", len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "buffer" {
|
if typeof(args[0]) != "buffer" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
|
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
args[0] = ArValidToAny(args[0])
|
args[0] = ArValidToAny(args[0])
|
||||||
if typeof(args[0]) != "buffer" {
|
if typeof(args[0]) != "buffer" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
|
message: fmt.Sprintf("write() argument must be a buffer, not %s", typeof(args[0])),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
_, err := conn.Write(args[0].([]byte))
|
_, err := conn.Write(args[0].([]byte))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is already closed",
|
message: "Connection is already closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
err := conn.Close()
|
err := conn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -208,36 +208,37 @@ func ArSocketClient(args ...any) (any, ArErr) {
|
|||||||
func ArSocketServer(args ...any) (any, ArErr) {
|
func ArSocketServer(args ...any) (any, ArErr) {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket takes exactly 2 arguments",
|
message: "Socket takes exactly 2 arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(args[0]) != "string" {
|
} else if typeof(args[0]) != "string" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket type must be a string",
|
message: "Socket type must be a string",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
} else if typeof(args[1]) != "number" {
|
} else if typeof(args[1]) != "number" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket port must be a number",
|
message: "Socket port must be a number",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
networktype := ArValidToAny(args[0]).(string)
|
networktype := ArValidToAny(args[0]).(string)
|
||||||
port := args[1].(number)
|
port_num := args[1].(ArObject)
|
||||||
if port.Denom().Int64() != 1 {
|
port, err := numberToInt64(port_num)
|
||||||
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket port must be an integer",
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ln, err := net.Listen(networktype, ":"+fmt.Sprint(port.Num().Int64()))
|
ln, err := net.Listen(networktype, ":"+fmt.Sprint(port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -248,7 +249,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if ln == nil {
|
if ln == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket is closed",
|
message: "Socket is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -256,7 +257,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
conn, err := ln.Accept()
|
conn, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -267,14 +268,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.readData() takes exactly 1 argument",
|
message: "Socket.readData() takes exactly 1 argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -283,7 +284,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
n, err := conn.Read(buf)
|
n, err := conn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -296,14 +297,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.readUntil() takes exactly 1 argument",
|
message: "Socket.readUntil() takes exactly 1 argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -311,7 +312,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
value := ArValidToAny(args[0])
|
value := ArValidToAny(args[0])
|
||||||
if typeof(value) != "buffer" {
|
if typeof(value) != "buffer" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
|
message: fmt.Sprintf("Socket.readUntil() argument must be a buffer, not %s", typeof(value)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -346,14 +347,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.clearTimeout() takes exactly 0 arguments",
|
message: "Socket.clearTimeout() takes exactly 0 arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -367,21 +368,21 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.setTimeout() takes exactly 1 argument",
|
message: "Socket.setTimeout() takes exactly 1 argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if typeof(args[0]) != "number" {
|
if typeof(args[0]) != "number" {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket timeout must be a number",
|
message: "Socket timeout must be a number",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -389,7 +390,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
timeout := args[0].(number)
|
timeout := args[0].(number)
|
||||||
if timeout.Denom().Int64() != 1 {
|
if timeout.Denom().Int64() != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket timeout must be an integer",
|
message: "Socket timeout must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -397,7 +398,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
err := conn.SetDeadline(time.Now().Add(time.Duration(timeout.Num().Int64()) * time.Millisecond))
|
err := conn.SetDeadline(time.Now().Add(time.Duration(timeout.Num().Int64()) * time.Millisecond))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: err.Error(),
|
message: err.Error(),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -410,14 +411,14 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.writeData() takes exactly 1 argument",
|
message: "Socket.writeData() takes exactly 1 argument",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -429,7 +430,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
for _, v := range x {
|
for _, v := range x {
|
||||||
if typeof(v) != "number" && v.(number).Denom().Int64() != 1 {
|
if typeof(v) != "number" && v.(number).Denom().Int64() != 1 {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.writeData() argument must be a array of integers",
|
message: "Socket.writeData() argument must be a array of integers",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -443,7 +444,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}
|
}
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket.writeData() argument must be a array of numbers",
|
message: "Socket.writeData() argument must be a array of numbers",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -453,7 +454,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is already closed",
|
message: "Connection is already closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -486,7 +487,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Connection is closed",
|
message: "Connection is closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -508,7 +509,7 @@ func ArSocketServer(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if ln == nil {
|
if ln == nil {
|
||||||
return ArObject{}, ArErr{
|
return ArObject{}, ArErr{
|
||||||
TYPE: "SocketError",
|
TYPE: "Socket Error",
|
||||||
message: "Socket is already closed",
|
message: "Socket is already closed",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ func getkeyCache(getKey func(any) (any, ArErr), key any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func compare(a, b any) (bool, error) {
|
func compare(a, b any) (bool, error) {
|
||||||
if isAnyNumber(a) && isAnyNumber(b) {
|
if x, ok := a.(ArObject); ok {
|
||||||
return a.(number).Cmp(b.(number)) < 0, nil
|
|
||||||
} else if x, ok := a.(ArObject); ok {
|
|
||||||
if y, ok := x.obj["__LessThan__"]; ok {
|
if y, ok := x.obj["__LessThan__"]; ok {
|
||||||
resp, err := runCall(
|
resp, err := runCall(
|
||||||
call{
|
call{
|
||||||
|
|||||||
204
src/string.go
204
src/string.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
"golang.org/x/text/cases"
|
"golang.org/x/text/cases"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
@@ -65,7 +66,32 @@ func ArString(str string) ArObject {
|
|||||||
anymap{
|
anymap{
|
||||||
"__value__": str,
|
"__value__": str,
|
||||||
"__name__": "string",
|
"__name__": "string",
|
||||||
"length": newNumber().SetUint64(uint64(len(str))),
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.obj["__string__"] = builtinFunc{
|
||||||
|
"__string__",
|
||||||
|
func(a ...any) (any, ArErr) {
|
||||||
|
return str, ArErr{}
|
||||||
|
}}
|
||||||
|
obj.obj["__repr__"] = builtinFunc{
|
||||||
|
"__repr__",
|
||||||
|
func(a ...any) (any, ArErr) {
|
||||||
|
colored := false
|
||||||
|
if len(a) == 1 {
|
||||||
|
if typeof(a[0]) != "boolean" {
|
||||||
|
return nil, ArErr{"Type Error", "expected boolean, got " + typeof(a[0]), 0, "", "", true}
|
||||||
|
}
|
||||||
|
colored = a[0].(bool)
|
||||||
|
}
|
||||||
|
output := []string{}
|
||||||
|
quoted := strconv.Quote(str)
|
||||||
|
if colored {
|
||||||
|
output = append(output, color.New(33).Sprint(quoted))
|
||||||
|
} else {
|
||||||
|
output = append(output, quoted)
|
||||||
|
}
|
||||||
|
return ArString(strings.Join(output, "")), ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,30 +99,29 @@ func ArString(str string) ArObject {
|
|||||||
"__setindex__",
|
"__setindex__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{"TypeError", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "number" {
|
if typeof(a[0]) != "number" {
|
||||||
return nil, ArErr{"TypeError", "expected number, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected number, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[1]) != "string" {
|
if typeof(a[1]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if len(a[1].(string)) != 1 {
|
if len(a[1].(string)) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected string of length 1, got " + fmt.Sprint(len(a[1].(string))), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string of length 1, got " + fmt.Sprint(len(a[1].(string))), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if !a[0].(number).IsInt() {
|
if !a[0].(number).IsInt() {
|
||||||
return nil, ArErr{"TypeError", "expected integer, got float", 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected integer, got float", 0, "", "", true}
|
||||||
}
|
}
|
||||||
index := a[0].(number).Num().Int64()
|
index := a[0].(number).Num().Int64()
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
index = int64(len(str)) + index
|
index = int64(len(str)) + index
|
||||||
}
|
}
|
||||||
if index < 0 || index >= int64(len(str)) {
|
if index < 0 || index >= int64(len(str)) {
|
||||||
return nil, ArErr{"IndexError", "index out of range", 0, "", "", true}
|
return nil, ArErr{"Index Error", "index out of range", 0, "", "", true}
|
||||||
}
|
}
|
||||||
str = strings.Join([]string{str[:index], a[1].(string), str[index+1:]}, "")
|
str = strings.Join([]string{str[:index], a[1].(string), str[index+1:]}, "")
|
||||||
obj.obj["__value__"] = str
|
obj.obj["__value__"] = str
|
||||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["__getindex__"] = builtinFunc{
|
obj.obj["__getindex__"] = builtinFunc{
|
||||||
@@ -105,8 +130,18 @@ func ArString(str string) ArObject {
|
|||||||
// a[0] is start
|
// a[0] is start
|
||||||
// a[1] is end
|
// a[1] is end
|
||||||
// a[2] is step
|
// a[2] is step
|
||||||
if len(a) > 3 {
|
if len(a) > 3 || len(a) == 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 to 3 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if len(a) == 1 {
|
||||||
|
if typeof(a[0]) == "string" {
|
||||||
|
var name = ArValidToAny(a[0]).(string)
|
||||||
|
if name == "length" {
|
||||||
|
return newNumber().SetInt64(int64(len(str))), ArErr{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
start int = 0
|
start int = 0
|
||||||
@@ -116,14 +151,12 @@ func ArString(str string) ArObject {
|
|||||||
{
|
{
|
||||||
if a[0] == nil {
|
if a[0] == nil {
|
||||||
start = 0
|
start = 0
|
||||||
} else if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
|
} else if x, ok := a[0].(ArObject); ok {
|
||||||
return "", ArErr{
|
start64, err := numberToInt64(x)
|
||||||
TYPE: "TypeError",
|
if err != nil {
|
||||||
message: "slice index must be an integer",
|
return nil, ArErr{"Type Error", err.Error(), 0, "", "", true}
|
||||||
EXISTS: true,
|
|
||||||
}
|
}
|
||||||
} else {
|
start = int(start64)
|
||||||
start = int(a[0].(number).Num().Int64())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(a) > 1 {
|
if len(a) > 1 {
|
||||||
@@ -131,7 +164,7 @@ func ArString(str string) ArObject {
|
|||||||
end = len(str)
|
end = len(str)
|
||||||
} else if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
|
} else if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
|
||||||
return "", ArErr{
|
return "", ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "slice index must be an integer",
|
message: "slice index must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -144,7 +177,7 @@ func ArString(str string) ArObject {
|
|||||||
step = 1
|
step = 1
|
||||||
} else if typeof(a[2]) != "number" || !a[2].(number).IsInt() {
|
} else if typeof(a[2]) != "number" || !a[2].(number).IsInt() {
|
||||||
return "", ArErr{
|
return "", ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "slice index must be an integer",
|
message: "slice index must be an integer",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -184,40 +217,38 @@ func ArString(str string) ArObject {
|
|||||||
"append",
|
"append",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 or more argument, got 0", 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 or more argument, got 0", 0, "", "", true}
|
||||||
}
|
}
|
||||||
output := []string{str}
|
output := []string{str}
|
||||||
for _, v := range a {
|
for _, v := range a {
|
||||||
v = ArValidToAny(v)
|
v = ArValidToAny(v)
|
||||||
if typeof(v) != "string" {
|
if typeof(v) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(v), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(v), 0, "", "", true}
|
||||||
}
|
}
|
||||||
output = append(output, v.(string))
|
output = append(output, v.(string))
|
||||||
}
|
}
|
||||||
str = strings.Join(output, "")
|
str = strings.Join(output, "")
|
||||||
obj.obj["__value__"] = str
|
obj.obj["__value__"] = str
|
||||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["extend"] = builtinFunc{
|
obj.obj["extend"] = builtinFunc{
|
||||||
"extend",
|
"extend",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "array" {
|
if typeof(a[0]) != "array" {
|
||||||
return nil, ArErr{"TypeError", "expected array, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected array, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
output := []string{str}
|
output := []string{str}
|
||||||
for _, v := range a[0].([]any) {
|
for _, v := range a[0].([]any) {
|
||||||
if typeof(v) != "string" {
|
if typeof(v) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(v), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(v), 0, "", "", true}
|
||||||
}
|
}
|
||||||
output = append(output, v.(string))
|
output = append(output, v.(string))
|
||||||
}
|
}
|
||||||
str = strings.Join(output, "")
|
str = strings.Join(output, "")
|
||||||
obj.obj["__value__"] = str
|
obj.obj["__value__"] = str
|
||||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -225,13 +256,13 @@ func ArString(str string) ArObject {
|
|||||||
"insert",
|
"insert",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{"TypeError", "expected 2 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 2 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
|
if typeof(a[0]) != "number" || !a[0].(number).IsInt() {
|
||||||
return nil, ArErr{"TypeError", "expected integer, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected integer, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[1]) != "string" {
|
if typeof(a[1]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
index := int(a[0].(number).Num().Int64())
|
index := int(a[0].(number).Num().Int64())
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
@@ -242,19 +273,18 @@ func ArString(str string) ArObject {
|
|||||||
}
|
}
|
||||||
str = str[:index] + a[1].(string) + str[index:]
|
str = str[:index] + a[1].(string) + str[index:]
|
||||||
obj.obj["__value__"] = str
|
obj.obj["__value__"] = str
|
||||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}}
|
}}
|
||||||
obj.obj["concat"] = builtinFunc{
|
obj.obj["concat"] = builtinFunc{
|
||||||
"concat",
|
"concat",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 or more argument, got 0", 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 or more argument, got 0", 0, "", "", true}
|
||||||
}
|
}
|
||||||
output := []string{str}
|
output := []string{str}
|
||||||
for _, v := range a {
|
for _, v := range a {
|
||||||
if typeof(v) != "string" {
|
if typeof(v) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(v), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(v), 0, "", "", true}
|
||||||
}
|
}
|
||||||
output = append(output, v.(string))
|
output = append(output, v.(string))
|
||||||
}
|
}
|
||||||
@@ -264,10 +294,10 @@ func ArString(str string) ArObject {
|
|||||||
"split",
|
"split",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
splitby := ArValidToAny(a[0]).(string)
|
splitby := ArValidToAny(a[0]).(string)
|
||||||
output := []any{}
|
output := []any{}
|
||||||
@@ -281,13 +311,13 @@ func ArString(str string) ArObject {
|
|||||||
"splitN",
|
"splitN",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{"TypeError", "expected 2 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 2 or more argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
|
if typeof(a[1]) != "number" || !a[1].(number).IsInt() {
|
||||||
return nil, ArErr{"TypeError", "expected integer, got " + typeof(a[1]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected integer, got " + typeof(a[1]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
splitby := ArValidToAny(a[0]).(string)
|
splitby := ArValidToAny(a[0]).(string)
|
||||||
n := int(a[1].(number).Num().Int64())
|
n := int(a[1].(number).Num().Int64())
|
||||||
@@ -302,7 +332,7 @@ func ArString(str string) ArObject {
|
|||||||
"capitalise",
|
"capitalise",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 0 {
|
if len(a) != 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return cases.Title(language.English).String(str), ArErr{}
|
return cases.Title(language.English).String(str), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -310,7 +340,7 @@ func ArString(str string) ArObject {
|
|||||||
"lower",
|
"lower",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 0 {
|
if len(a) != 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.ToLower(str), ArErr{}
|
return strings.ToLower(str), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -318,7 +348,7 @@ func ArString(str string) ArObject {
|
|||||||
"upper",
|
"upper",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 0 {
|
if len(a) != 0 {
|
||||||
return nil, ArErr{"TypeError", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 0 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.ToUpper(str), ArErr{}
|
return strings.ToUpper(str), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -326,13 +356,13 @@ func ArString(str string) ArObject {
|
|||||||
"replace",
|
"replace",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
return nil, ArErr{"TypeError", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 2 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[1]) != "string" {
|
if typeof(a[1]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[1]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
a[1] = ArValidToAny(a[1])
|
a[1] = ArValidToAny(a[1])
|
||||||
@@ -342,10 +372,10 @@ func ArString(str string) ArObject {
|
|||||||
"contains",
|
"contains",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Contains(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
return strings.Contains(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -353,10 +383,10 @@ func ArString(str string) ArObject {
|
|||||||
"startswith",
|
"startswith",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.HasPrefix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
return strings.HasPrefix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -364,10 +394,10 @@ func ArString(str string) ArObject {
|
|||||||
"endswith",
|
"endswith",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.HasSuffix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
return strings.HasSuffix(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -375,10 +405,10 @@ func ArString(str string) ArObject {
|
|||||||
"index",
|
"index",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Index(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
return strings.Index(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -386,10 +416,10 @@ func ArString(str string) ArObject {
|
|||||||
"rindex",
|
"rindex",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.LastIndex(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
return strings.LastIndex(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -398,10 +428,10 @@ func ArString(str string) ArObject {
|
|||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
|
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
return strings.Count(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
return strings.Count(str, a[0].(ArObject).obj["__value__"].(string)), ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -411,7 +441,7 @@ func ArString(str string) ArObject {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) > 2 {
|
if len(args) > 2 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "too many arguments",
|
message: "too many arguments",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -420,7 +450,7 @@ func ArString(str string) ArObject {
|
|||||||
if len(args) >= 1 {
|
if len(args) >= 1 {
|
||||||
if typeof(args[0]) != "boolean" {
|
if typeof(args[0]) != "boolean" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a boolean",
|
message: "argument must be a boolean",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -435,7 +465,7 @@ func ArString(str string) ArObject {
|
|||||||
if len(args) == 2 {
|
if len(args) == 2 {
|
||||||
if typeof(args[1]) != "function" {
|
if typeof(args[1]) != "function" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: "argument must be a function",
|
message: "argument must be a function",
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -454,7 +484,6 @@ func ArString(str string) ArObject {
|
|||||||
bytes[i] = b.(byte)
|
bytes[i] = b.(byte)
|
||||||
}
|
}
|
||||||
str = string(bytes)
|
str = string(bytes)
|
||||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
|
||||||
obj.obj["__value__"] = str
|
obj.obj["__value__"] = str
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}
|
}
|
||||||
@@ -474,7 +503,6 @@ func ArString(str string) ArObject {
|
|||||||
bytes[i] = b.(byte)
|
bytes[i] = b.(byte)
|
||||||
}
|
}
|
||||||
str = string(bytes)
|
str = string(bytes)
|
||||||
obj.obj["length"] = newNumber().SetUint64(uint64(len(str)))
|
|
||||||
obj.obj["__value__"] = str
|
obj.obj["__value__"] = str
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
},
|
},
|
||||||
@@ -483,12 +511,12 @@ func ArString(str string) ArObject {
|
|||||||
"strip",
|
"strip",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) > 1 {
|
if len(a) > 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset := " "
|
cutset := " "
|
||||||
if len(a) == 1 {
|
if len(a) == 1 {
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset = a[0].(ArObject).obj["__value__"].(string)
|
cutset = a[0].(ArObject).obj["__value__"].(string)
|
||||||
}
|
}
|
||||||
@@ -498,12 +526,12 @@ func ArString(str string) ArObject {
|
|||||||
"leftstrip",
|
"leftstrip",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) > 1 {
|
if len(a) > 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset := " "
|
cutset := " "
|
||||||
if len(a) == 1 {
|
if len(a) == 1 {
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset = a[0].(ArObject).obj["__value__"].(string)
|
cutset = a[0].(ArObject).obj["__value__"].(string)
|
||||||
}
|
}
|
||||||
@@ -513,12 +541,12 @@ func ArString(str string) ArObject {
|
|||||||
"rightstrip",
|
"rightstrip",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) > 1 {
|
if len(a) > 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 0 or 1 arguments, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset := " "
|
cutset := " "
|
||||||
if len(a) == 1 {
|
if len(a) == 1 {
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected string, got " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
cutset = a[0].(ArObject).obj["__value__"].(string)
|
cutset = a[0].(ArObject).obj["__value__"].(string)
|
||||||
}
|
}
|
||||||
@@ -528,10 +556,10 @@ func ArString(str string) ArObject {
|
|||||||
"__LessThanOrEqual__",
|
"__LessThanOrEqual__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get less than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot get less than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return str <= a[0].(string), ArErr{}
|
return str <= a[0].(string), ArErr{}
|
||||||
@@ -540,10 +568,10 @@ func ArString(str string) ArObject {
|
|||||||
"__LessThan__",
|
"__LessThan__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get less than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot get less than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return str < a[0].(string), ArErr{}
|
return str < a[0].(string), ArErr{}
|
||||||
@@ -552,10 +580,10 @@ func ArString(str string) ArObject {
|
|||||||
"__GreaterThan__",
|
"__GreaterThan__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get greater than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot get greater than of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return str > a[0].(string), ArErr{}
|
return str > a[0].(string), ArErr{}
|
||||||
@@ -565,10 +593,10 @@ func ArString(str string) ArObject {
|
|||||||
"__GreaterThanEqual__",
|
"__GreaterThanEqual__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot get greater than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot get greater than or equal to of type " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return str >= a[0].(string), ArErr{}
|
return str >= a[0].(string), ArErr{}
|
||||||
@@ -577,7 +605,7 @@ func ArString(str string) ArObject {
|
|||||||
"__Equal__",
|
"__Equal__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return str == a[0], ArErr{}
|
return str == a[0], ArErr{}
|
||||||
@@ -586,7 +614,7 @@ func ArString(str string) ArObject {
|
|||||||
"__NotEqual__",
|
"__NotEqual__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return str != a[0], ArErr{}
|
return str != a[0], ArErr{}
|
||||||
@@ -595,7 +623,7 @@ func ArString(str string) ArObject {
|
|||||||
"__Add__",
|
"__Add__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
@@ -607,7 +635,7 @@ func ArString(str string) ArObject {
|
|||||||
"__PostAdd__",
|
"__PostAdd__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
@@ -619,10 +647,10 @@ func ArString(str string) ArObject {
|
|||||||
"__Multiply__",
|
"__Multiply__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "number" {
|
if typeof(a[0]) != "number" {
|
||||||
return nil, ArErr{"TypeError", "cannot multiply string by " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot multiply string by " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
n := a[0].(number)
|
n := a[0].(number)
|
||||||
if !n.IsInt() {
|
if !n.IsInt() {
|
||||||
@@ -637,10 +665,10 @@ func ArString(str string) ArObject {
|
|||||||
"__NotContains__",
|
"__NotContains__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return !strings.Contains(str, a[0].(string)), ArErr{}
|
return !strings.Contains(str, a[0].(string)), ArErr{}
|
||||||
@@ -649,10 +677,10 @@ func ArString(str string) ArObject {
|
|||||||
"__Contains__",
|
"__Contains__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot check if string contains " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return strings.Contains(str, a[0].(string)), ArErr{}
|
return strings.Contains(str, a[0].(string)), ArErr{}
|
||||||
@@ -661,10 +689,10 @@ func ArString(str string) ArObject {
|
|||||||
"__Subtract__",
|
"__Subtract__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot subtract " + typeof(a[0]) + " from string", 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot subtract " + typeof(a[0]) + " from string", 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
return strings.Replace(str, a[0].(string), "", -1), ArErr{}
|
return strings.Replace(str, a[0].(string), "", -1), ArErr{}
|
||||||
@@ -673,10 +701,10 @@ func ArString(str string) ArObject {
|
|||||||
"__Divide__",
|
"__Divide__",
|
||||||
func(a ...any) (any, ArErr) {
|
func(a ...any) (any, ArErr) {
|
||||||
if len(a) != 1 {
|
if len(a) != 1 {
|
||||||
return nil, ArErr{"TypeError", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
|
||||||
}
|
}
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{"TypeError", "cannot divide string by " + typeof(a[0]), 0, "", "", true}
|
return nil, ArErr{"Type Error", "cannot divide string by " + typeof(a[0]), 0, "", "", true}
|
||||||
}
|
}
|
||||||
a[0] = ArValidToAny(a[0])
|
a[0] = ArValidToAny(a[0])
|
||||||
splitby := a[0].(string)
|
splitby := a[0].(string)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
} else if typeof(args[0]) != "array" {
|
} else if typeof(args[0]) != "array" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("subprocess() argument must be an array, not %s", typeof(args[0])),
|
message: fmt.Sprintf("subprocess() argument must be an array, not %s", typeof(args[0])),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
for _, x := range args[0].([]any) {
|
for _, x := range args[0].([]any) {
|
||||||
if typeof(x) != "string" {
|
if typeof(x) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("subprocess() argument must be an array of strings, not %s", typeof(x)),
|
message: fmt.Sprintf("subprocess() argument must be an array of strings, not %s", typeof(x)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("scan() takes exactly 0 arguments (%d given)", len(args)),
|
message: fmt.Sprintf("scan() takes exactly 0 arguments (%d given)", len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("text() takes exactly 0 arguments (%d given)", len(args)),
|
message: fmt.Sprintf("text() takes exactly 0 arguments (%d given)", len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("err() takes exactly 0 arguments (%d given)", len(args)),
|
message: fmt.Sprintf("err() takes exactly 0 arguments (%d given)", len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ func ArSubprocess(args ...any) (any, ArErr) {
|
|||||||
func(args ...any) (any, ArErr) {
|
func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
TYPE: "TypeError",
|
TYPE: "Type Error",
|
||||||
message: fmt.Sprintf("wait() takes exactly 0 arguments (%d given)", len(args)),
|
message: fmt.Sprintf("wait() takes exactly 0 arguments (%d given)", len(args)),
|
||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ var ArTerm = Map(anymap{
|
|||||||
}
|
}
|
||||||
timingSync.RLock()
|
timingSync.RLock()
|
||||||
if _, ok := timing[id]; !ok {
|
if _, ok := timing[id]; !ok {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot find timer with id '" + fmt.Sprint(id) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot find timer with id '" + fmt.Sprint(id) + "'", EXISTS: true}
|
||||||
}
|
}
|
||||||
timesince := time.Since(timing[id].(time.Time))
|
timesince := time.Since(timing[id].(time.Time))
|
||||||
timingSync.RUnlock()
|
timingSync.RUnlock()
|
||||||
@@ -140,7 +140,11 @@ var ArInput = Map(
|
|||||||
return ArString(resp), ArErr{}
|
return ArString(resp), ArErr{}
|
||||||
}},
|
}},
|
||||||
"__call__": builtinFunc{"input", func(args ...any) (any, ArErr) {
|
"__call__": builtinFunc{"input", func(args ...any) (any, ArErr) {
|
||||||
return input(args...), ArErr{}
|
resp, err := input(args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||||
|
}
|
||||||
|
return ArString(resp), ArErr{}
|
||||||
}},
|
}},
|
||||||
"pause": builtinFunc{"pause", func(args ...any) (any, ArErr) {
|
"pause": builtinFunc{"pause", func(args ...any) (any, ArErr) {
|
||||||
pause()
|
pause()
|
||||||
|
|||||||
@@ -2,50 +2,48 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var threadCount = 0
|
var threadChan = sync.WaitGroup{}
|
||||||
var threadChan = make(chan bool)
|
|
||||||
|
|
||||||
func ArThread(args ...any) (any, ArErr) {
|
func ArThread(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||||
}
|
}
|
||||||
var tocall any
|
var tocall any
|
||||||
switch x := args[0].(type) {
|
switch x := args[0].(type) {
|
||||||
case anymap:
|
case anymap:
|
||||||
if _, ok := x["__call__"]; !ok {
|
if _, ok := x["__call__"]; !ok {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
|
||||||
}
|
}
|
||||||
tocall = x["__call__"]
|
tocall = x["__call__"]
|
||||||
case builtinFunc, Callable:
|
case builtinFunc, Callable:
|
||||||
tocall = x
|
tocall = x
|
||||||
default:
|
default:
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
|
||||||
}
|
}
|
||||||
var resp any
|
var resp any
|
||||||
var err ArErr
|
var err ArErr
|
||||||
|
|
||||||
hasrun := false
|
hasrun := false
|
||||||
joined := false
|
joined := false
|
||||||
var wg = make(chan bool)
|
var wg = sync.WaitGroup{}
|
||||||
threadMap := Map(anymap{
|
threadMap := Map(anymap{
|
||||||
"start": builtinFunc{"start", func(args ...any) (any, ArErr) {
|
"start": builtinFunc{"start", func(args ...any) (any, ArErr) {
|
||||||
if hasrun {
|
if hasrun {
|
||||||
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot start a thread twice", EXISTS: true}
|
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot start a thread twice", EXISTS: true}
|
||||||
}
|
}
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||||
}
|
}
|
||||||
hasrun = true
|
hasrun = true
|
||||||
|
wg.Add(1)
|
||||||
|
threadChan.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
threadCount++
|
|
||||||
resp, err = runCall(call{Callable: tocall, Args: []any{}}, nil, 0)
|
resp, err = runCall(call{Callable: tocall, Args: []any{}}, nil, 0)
|
||||||
wg <- true
|
wg.Done()
|
||||||
threadCount--
|
threadChan.Done()
|
||||||
if threadCount == 0 {
|
|
||||||
threadChan <- true
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
return nil, ArErr{}
|
return nil, ArErr{}
|
||||||
}},
|
}},
|
||||||
@@ -56,10 +54,10 @@ func ArThread(args ...any) (any, ArErr) {
|
|||||||
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot join a thread twice", EXISTS: true}
|
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot join a thread twice", EXISTS: true}
|
||||||
}
|
}
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
|
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||||
}
|
}
|
||||||
joined = true
|
joined = true
|
||||||
<-wg
|
wg.Wait()
|
||||||
return resp, err
|
return resp, err
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -195,7 +194,6 @@ var ArTime = Map(anymap{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"date": builtinFunc{"date", func(a ...any) (any, ArErr) {
|
"date": builtinFunc{"date", func(a ...any) (any, ArErr) {
|
||||||
fmt.Println(a, len(a))
|
|
||||||
if len(a) == 1 {
|
if len(a) == 1 {
|
||||||
if typeof(a[0]) != "string" {
|
if typeof(a[0]) != "string" {
|
||||||
return nil, ArErr{
|
return nil, ArErr{
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,7 +10,7 @@ import (
|
|||||||
"github.com/jwalton/go-supportscolor"
|
"github.com/jwalton/go-supportscolor"
|
||||||
)
|
)
|
||||||
|
|
||||||
func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored bool, plain int) string {
|
func anyToArgon(x any, representive bool, simplify bool, depth int, indent int, colored bool, plain int) string {
|
||||||
output := []string{}
|
output := []string{}
|
||||||
maybenewline := ""
|
maybenewline := ""
|
||||||
if plain == 1 {
|
if plain == 1 {
|
||||||
@@ -29,37 +28,9 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
return strings.Join(output, "")
|
return strings.Join(output, "")
|
||||||
}
|
}
|
||||||
switch x := x.(type) {
|
switch x := x.(type) {
|
||||||
case string:
|
|
||||||
if !quote {
|
|
||||||
output = append(output, x)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
quoted := strconv.Quote(x)
|
|
||||||
if colored {
|
|
||||||
output = append(output, color.New(33).Sprint(quoted))
|
|
||||||
} else {
|
|
||||||
output = append(output, quoted)
|
|
||||||
}
|
|
||||||
case number:
|
|
||||||
if colored {
|
|
||||||
output = append(output, "\x1b[34;5;240m")
|
|
||||||
}
|
|
||||||
num, _ := x.Float64()
|
|
||||||
if math.IsNaN(num) {
|
|
||||||
output = append(output, "NaN")
|
|
||||||
} else if math.IsInf(num, 1) {
|
|
||||||
output = append(output, "infinity")
|
|
||||||
} else if math.IsInf(num, -1) {
|
|
||||||
output = append(output, "-infinity")
|
|
||||||
} else {
|
|
||||||
output = append(output, numberToString(x, simplify))
|
|
||||||
}
|
|
||||||
if colored {
|
|
||||||
output = append(output, "\x1b[0m")
|
|
||||||
}
|
|
||||||
case bool:
|
case bool:
|
||||||
if colored {
|
if colored {
|
||||||
output = append(output, "\x1b[35;5;240m")
|
output = append(output, "\x1b[35;5;25m")
|
||||||
}
|
}
|
||||||
output = append(output, strconv.FormatBool(x))
|
output = append(output, strconv.FormatBool(x))
|
||||||
if colored {
|
if colored {
|
||||||
@@ -67,14 +38,14 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
}
|
}
|
||||||
case nil:
|
case nil:
|
||||||
if colored {
|
if colored {
|
||||||
output = append(output, "\x1b[31;5;240m")
|
output = append(output, "\x1b[31;5;25m")
|
||||||
}
|
}
|
||||||
output = append(output, "null")
|
output = append(output, "null")
|
||||||
if colored {
|
if colored {
|
||||||
output = append(output, "\x1b[0m")
|
output = append(output, "\x1b[0m")
|
||||||
}
|
}
|
||||||
case ArObject:
|
case ArObject:
|
||||||
if callable, ok := x.obj["__string__"]; ok && !quote {
|
if callable, ok := x.obj["__string__"]; ok && !representive {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
Callable: callable,
|
Callable: callable,
|
||||||
@@ -84,24 +55,24 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
if !err.EXISTS {
|
if !err.EXISTS {
|
||||||
output = append(output, anyToArgon(val, false, simplify, depth, indent, colored, plain))
|
output = append(output, fmt.Sprint(ArValidToAny(val)))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else if callable, ok := x.obj["__repr__"]; ok {
|
} else if callable, ok := x.obj["__repr__"]; ok {
|
||||||
val, err := runCall(
|
val, err := runCall(
|
||||||
call{
|
call{
|
||||||
Callable: callable,
|
Callable: callable,
|
||||||
Args: []any{},
|
Args: []any{colored},
|
||||||
},
|
},
|
||||||
stack{},
|
stack{},
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
if !err.EXISTS {
|
if !err.EXISTS {
|
||||||
output = append(output, anyToArgon(val, false, simplify, depth, indent, colored, plain))
|
output = append(output, fmt.Sprint(ArValidToAny(val)))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else if val, ok := x.obj["__value__"]; ok {
|
} else if val, ok := x.obj["__value__"]; ok {
|
||||||
output = append(output, anyToArgon(val, quote, simplify, depth, indent, colored, plain))
|
output = append(output, anyToArgon(val, representive, simplify, depth, indent, colored, plain))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
output = append(output, "<object>")
|
output = append(output, "<object>")
|
||||||
@@ -128,7 +99,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
} else {
|
} else {
|
||||||
outputkeyval := []string{}
|
outputkeyval := []string{}
|
||||||
if colored {
|
if colored {
|
||||||
outputkeyval = append(outputkeyval, "\x1b[36;5;240m")
|
outputkeyval = append(outputkeyval, "\x1b[36;5;25m")
|
||||||
}
|
}
|
||||||
outputkeyval = append(outputkeyval, key.(string))
|
outputkeyval = append(outputkeyval, key.(string))
|
||||||
if colored {
|
if colored {
|
||||||
@@ -148,7 +119,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
output = append(output, anyToArgon(item, true, true, depth-1, indent+1, colored, plain))
|
output = append(output, anyToArgon(item, true, true, depth-1, indent+1, colored, plain))
|
||||||
}
|
}
|
||||||
if colored {
|
if colored {
|
||||||
output = append(output, "\x1b[38;5;240m(...)\x1b[0m")
|
output = append(output, "\x1b[38;5;25m(...)\x1b[0m")
|
||||||
} else {
|
} else {
|
||||||
output = append(output, "(...)")
|
output = append(output, "(...)")
|
||||||
}
|
}
|
||||||
@@ -173,7 +144,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
return "[" + maybenewline + (strings.Repeat(" ", (indent+1)*plain)) + strings.Join(output, ","+maybenewline+(strings.Repeat(" ", (indent+1)*plain))) + maybenewline + (strings.Repeat(" ", indent*plain)) + "]"
|
return "[" + maybenewline + (strings.Repeat(" ", (indent+1)*plain)) + strings.Join(output, ","+maybenewline+(strings.Repeat(" ", (indent+1)*plain))) + maybenewline + (strings.Repeat(" ", indent*plain)) + "]"
|
||||||
case builtinFunc:
|
case builtinFunc:
|
||||||
if colored {
|
if colored {
|
||||||
output = append(output, "\x1b[38;5;240m")
|
output = append(output, "\x1b[38;5;25m")
|
||||||
}
|
}
|
||||||
output = append(output, "<builtin function "+x.name+">")
|
output = append(output, "<builtin function "+x.name+">")
|
||||||
if colored {
|
if colored {
|
||||||
@@ -181,7 +152,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
|
|||||||
}
|
}
|
||||||
case Callable:
|
case Callable:
|
||||||
if colored {
|
if colored {
|
||||||
output = append(output, "\x1b[38;5;240m")
|
output = append(output, "\x1b[38;5;25m")
|
||||||
}
|
}
|
||||||
output = append(output, "<function "+x.name+">")
|
output = append(output, "<function "+x.name+">")
|
||||||
if colored {
|
if colored {
|
||||||
|
|||||||
191
src/translate.go
191
src/translate.go
@@ -11,105 +11,53 @@ type UNPARSEcode struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
var knownFailures = map[string]ArErr{}
|
var QuickKnownFailures = map[string]bool{}
|
||||||
|
|
||||||
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
||||||
if knownErr, ok := knownFailures[code.code]; ok {
|
|
||||||
return nil, false, ArErr{
|
|
||||||
knownErr.TYPE,
|
|
||||||
knownErr.message,
|
|
||||||
code.line,
|
|
||||||
code.path,
|
|
||||||
code.realcode,
|
|
||||||
true,
|
|
||||||
}, 1
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
resp any = nil
|
resp any = nil
|
||||||
worked bool = false
|
worked bool = false
|
||||||
err ArErr = ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}
|
err ArErr = ArErr{"Syntax Error", "invalid syntax", code.line, code.path, code.realcode, true}
|
||||||
i int = 1
|
i int = 1
|
||||||
)
|
)
|
||||||
if isLine == 3 {
|
if isLine >= 3 {
|
||||||
if isComment(code) {
|
if isComment(code) {
|
||||||
resp, worked, err, i = parseComment(code, index, codelines)
|
resp, worked, err, i = parseComment(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
} else if isIfStatement(code) {
|
}
|
||||||
resp, worked, err, i = parseIfStatement(code, index, codelines)
|
if isIfStatement(code) {
|
||||||
if !worked {
|
return parseIfStatement(code, index, codelines)
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isWhileLoop(code) {
|
} else if isWhileLoop(code) {
|
||||||
resp, worked, err, i = parseWhileLoop(code, index, codelines)
|
return parseWhileLoop(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isForeverLoop(code) {
|
} else if isForeverLoop(code) {
|
||||||
resp, worked, err, i = parseForeverLoop(code, index, codelines)
|
return parseForeverLoop(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isForLoop(code) {
|
} else if isForLoop(code) {
|
||||||
resp, worked, err, i = parseForLoop(code, index, codelines)
|
return parseForLoop(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isGenericImport(code) {
|
} else if isGenericImport(code) {
|
||||||
resp, worked, err, i = parseGenericImport(code, index, codelines)
|
return parseGenericImport(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isTryCatch(code) {
|
} else if isTryCatch(code) {
|
||||||
resp, worked, err, i = parseTryCatch(code, index, codelines)
|
return parseTryCatch(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isLine >= 2 {
|
if isLine >= 2 {
|
||||||
if isReturn(code) {
|
if isReturn(code) {
|
||||||
resp, worked, err, i = parseReturn(code, index, codelines)
|
return parseReturn(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
} else if isBreak(code) {
|
||||||
}
|
return parseBreak(code)
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isBreak(code) {
|
} else if isContinue(code) {
|
||||||
resp, worked, err, i = parseBreak(code)
|
return parseContinue(code)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
} else if isDeleteVariable(code) {
|
||||||
}
|
return parseDelete(code, index, codelines)
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isContinue(code) {
|
|
||||||
resp, worked, err, i = parseContinue(code)
|
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isDeleteVariable(code) {
|
|
||||||
resp, worked, err, i = parseDelete(code, index, codelines)
|
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if isLine >= 1 {
|
|
||||||
if isDoWrap(code) {
|
|
||||||
resp, worked, err, i = parseDoWrap(code, index, codelines)
|
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,112 +65,99 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
|||||||
isLine = 1
|
isLine = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if isBoolean(code) {
|
if isDoWrap(code) {
|
||||||
|
return parseDoWrap(code, index, codelines)
|
||||||
|
} else if isBoolean(code) {
|
||||||
return parseBoolean(code)
|
return parseBoolean(code)
|
||||||
} else if isBrackets(code) {
|
} else if !QuickKnownFailures["brackets"+code.code] && isBrackets(code) {
|
||||||
resp, worked, err, i = parseBrackets(code, index, codelines)
|
resp, worked, err, i = parseBrackets(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["brackets"+code.code] = true
|
||||||
}
|
}
|
||||||
if isAbs(code) {
|
if !QuickKnownFailures["abs"+code.code] && isAbs(code) {
|
||||||
resp, worked, err, i = parseAbs(code, index, codelines)
|
resp, worked, err, i = parseAbs(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["abs"+code.code] = true
|
||||||
}
|
}
|
||||||
if isSetVariable(code) {
|
if !QuickKnownFailures["autoasign"+code.code] && isAutoAsignVariable(code) {
|
||||||
resp, worked, err, i = parseSetVariable(code, index, codelines, isLine)
|
|
||||||
if worked {
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isAutoAsignVariable(code) {
|
|
||||||
resp, worked, err, i = parseAutoAsignVariable(code, index, codelines, isLine)
|
resp, worked, err, i = parseAutoAsignVariable(code, index, codelines, isLine)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["autoasign"+code.code] = true
|
||||||
}
|
}
|
||||||
if isNumber(code) {
|
if isSetVariable(code) {
|
||||||
resp, worked, err, i = parseNumber(code)
|
return parseSetVariable(code, index, codelines, isLine)
|
||||||
if !worked {
|
} else if isNumber(code) {
|
||||||
knownFailures[code.code] = err
|
return parseNumber(code)
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isString(code) {
|
} else if isString(code) {
|
||||||
resp, worked, err, i = parseString(code)
|
return parseString(code)
|
||||||
if !worked {
|
} else if !QuickKnownFailures["squareroot"+code.code] && issquareroot(code) {
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if issquareroot(code) {
|
|
||||||
resp, worked, err, i = parseSquareroot(code, index, codelines)
|
resp, worked, err, i = parseSquareroot(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
}
|
QuickKnownFailures["squareroot"+code.code] = true
|
||||||
if isFactorial(code) {
|
|
||||||
resp, worked, err, i = parseFactorial(code, index, codelines)
|
|
||||||
if worked {
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if isVariable(code) {
|
if isVariable(code) {
|
||||||
resp, worked, err, i = parseVariable(code)
|
return parseVariable(code)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
}
|
}
|
||||||
if isArray(code) {
|
if !QuickKnownFailures["array"+code.code] && isArray(code) {
|
||||||
resp, worked, err, i = parseArray(code, index, codelines)
|
resp, worked, err, i = parseArray(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["array"+code.code] = true
|
||||||
} else if isMap(code) {
|
} else if isMap(code) {
|
||||||
resp, worked, err, i = parseMap(code, index, codelines)
|
resp, worked, err, i = parseMap(code, index, codelines)
|
||||||
}
|
}
|
||||||
if isnot(code) {
|
if !QuickKnownFailures["not"+code.code] && isnot(code) {
|
||||||
resp, worked, err, i = parseNot(code, index, codelines, isLine)
|
resp, worked, err, i = parseNot(code, index, codelines, isLine)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["not"+code.code] = true
|
||||||
}
|
}
|
||||||
{
|
if !QuickKnownFailures["operations"+code.code] {
|
||||||
operation, worked, err, step := parseOperations(code, index, codelines)
|
operation, worked, err, step := parseOperations(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return operation, worked, err, step
|
return operation, worked, err, step
|
||||||
} else if err.EXISTS {
|
}
|
||||||
|
QuickKnownFailures["operations"+code.code] = true
|
||||||
|
if err.EXISTS {
|
||||||
return nil, worked, err, step
|
return nil, worked, err, step
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isCall(code) {
|
if !QuickKnownFailures["factorial"+code.code] && isFactorial(code) {
|
||||||
|
resp, worked, err, i = parseFactorial(code, index, codelines)
|
||||||
|
if worked {
|
||||||
|
return resp, worked, err, i
|
||||||
|
}
|
||||||
|
QuickKnownFailures["factorial"+code.code] = true
|
||||||
|
}
|
||||||
|
if !QuickKnownFailures["call"+code.code] && isCall(code) {
|
||||||
resp, worked, err, i = parseCall(code, index, codelines)
|
resp, worked, err, i = parseCall(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["call"+code.code] = true
|
||||||
}
|
}
|
||||||
if isNegative(code) {
|
if isNegative(code) {
|
||||||
resp, worked, err, i = parseNegative(code, index, codelines)
|
return parseNegative(code, index, codelines)
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isMapGet(code) {
|
} else if isMapGet(code) {
|
||||||
resp, worked, err, i = mapGetParse(code, index, codelines)
|
return mapGetParse(code, index, codelines)
|
||||||
if !worked {
|
} else if !QuickKnownFailures["indexget"+code.code] && isIndexGet(code) {
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
|
||||||
} else if isIndexGet(code) {
|
|
||||||
resp, worked, err, i = indexGetParse(code, index, codelines)
|
resp, worked, err, i = indexGetParse(code, index, codelines)
|
||||||
if worked {
|
if worked {
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
QuickKnownFailures["indexget"+code.code] = true
|
||||||
}
|
}
|
||||||
if !worked {
|
|
||||||
knownFailures[code.code] = err
|
|
||||||
}
|
|
||||||
return resp, worked, err, i
|
return resp, worked, err, i
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +172,7 @@ func translate(codelines []UNPARSEcode) ([]any, ArErr) {
|
|||||||
if currentindent != 0 {
|
if currentindent != 0 {
|
||||||
return nil, ArErr{"Syntax Error", "invalid indent", codelines[i].line, codelines[i].path, codelines[i].realcode, true}
|
return nil, ArErr{"Syntax Error", "invalid indent", codelines[i].line, codelines[i].path, codelines[i].realcode, true}
|
||||||
}
|
}
|
||||||
val, _, err, step := translateVal(codelines[i], i, codelines, 3)
|
val, _, err, step := translateVal(codelines[i], i, codelines, 4)
|
||||||
i += step
|
i += step
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
57
src/trig.go
57
src/trig.go
@@ -7,6 +7,18 @@ import (
|
|||||||
|
|
||||||
var PIFloatInaccuracy number = newNumber()
|
var PIFloatInaccuracy number = newNumber()
|
||||||
|
|
||||||
|
type sinCacheValue struct {
|
||||||
|
INPUT number
|
||||||
|
OUTPUT number
|
||||||
|
}
|
||||||
|
|
||||||
|
var sinCache = []sinCacheValue{
|
||||||
|
{newNumber(), newNumber()},
|
||||||
|
{newNumber().Quo(PI_RAT, newNumber().SetInt64(2)), newNumber().SetInt64(1)},
|
||||||
|
{PI_RAT, newNumber()},
|
||||||
|
{newNumber().Add(PI_RAT, newNumber().Quo(PI_RAT, newNumber().SetInt64(2))), newNumber().SetInt64(-1)},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
PIFloatInaccuracy.SetFloat64(math.Asin(1) * 2)
|
PIFloatInaccuracy.SetFloat64(math.Asin(1) * 2)
|
||||||
}
|
}
|
||||||
@@ -25,7 +37,19 @@ var ArSin = builtinFunc{"sin", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, PI)
|
toTrim := newNumber().Mul(PI_RAT, newNumber().SetInt64(2))
|
||||||
|
toTrim.Quo(num, toTrim)
|
||||||
|
toTrim = floor(toTrim)
|
||||||
|
toTrim.Mul(toTrim, newNumber().Mul(PI_RAT, newNumber().SetInt64(2)))
|
||||||
|
num.Sub(num, toTrim)
|
||||||
|
|
||||||
|
for i := 0; i < len(sinCache); i++ {
|
||||||
|
if sinCache[i].INPUT.Cmp(num) == 0 {
|
||||||
|
return sinCache[i].OUTPUT, ArErr{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num.Quo(num, PI_RAT)
|
||||||
num.Mul(num, PIFloatInaccuracy)
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(math.Sin(n))
|
outputnum := newNumber().SetFloat64(math.Sin(n))
|
||||||
@@ -54,7 +78,7 @@ var ArArcsin = builtinFunc{"arcsin", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
outputnum := newNumber().SetFloat64(math.Asin(n))
|
outputnum := newNumber().SetFloat64(math.Asin(n))
|
||||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI_RAT)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -71,12 +95,7 @@ var ArCos = builtinFunc{"cos", func(args ...any) (any, ArErr) {
|
|||||||
EXISTS: true,
|
EXISTS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
return builtinCall(ArSin, []any{newNumber().Add(args[0].(number), newNumber().Quo(PI_RAT, newNumber().SetInt64(2)))})
|
||||||
num.Quo(num, PI)
|
|
||||||
num.Mul(num, PIFloatInaccuracy)
|
|
||||||
n, _ := num.Float64()
|
|
||||||
outputnum := newNumber().SetFloat64(math.Cos(n))
|
|
||||||
return outputnum, ArErr{}
|
|
||||||
}}
|
}}
|
||||||
var ArArccos = builtinFunc{"arccos", func(args ...any) (any, ArErr) {
|
var ArArccos = builtinFunc{"arccos", func(args ...any) (any, ArErr) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
@@ -101,7 +120,7 @@ var ArArccos = builtinFunc{"arccos", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
outputnum := newNumber().SetFloat64(math.Acos(n))
|
outputnum := newNumber().SetFloat64(math.Acos(n))
|
||||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI_RAT)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -119,7 +138,7 @@ var ArTan = builtinFunc{"tan", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, PI)
|
num.Quo(num, PI_RAT)
|
||||||
num.Mul(num, PIFloatInaccuracy)
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(math.Tan(n))
|
outputnum := newNumber().SetFloat64(math.Tan(n))
|
||||||
@@ -142,7 +161,7 @@ var ArArctan = builtinFunc{"arctan", func(args ...any) (any, ArErr) {
|
|||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(math.Atan(n))
|
outputnum := newNumber().SetFloat64(math.Atan(n))
|
||||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI_RAT)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -160,7 +179,7 @@ var ArCosec = builtinFunc{"cosec", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, PI)
|
num.Quo(num, PI_RAT)
|
||||||
num.Mul(num, PIFloatInaccuracy)
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(1 / math.Sin(n))
|
outputnum := newNumber().SetFloat64(1 / math.Sin(n))
|
||||||
@@ -189,7 +208,7 @@ var ArArccosec = builtinFunc{"arccosec", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
outputnum := newNumber().SetFloat64(math.Asin(1 / n))
|
outputnum := newNumber().SetFloat64(math.Asin(1 / n))
|
||||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI_RAT)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -207,7 +226,7 @@ var ArSec = builtinFunc{"sec", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, PI)
|
num.Quo(num, PI_RAT)
|
||||||
num.Mul(num, PIFloatInaccuracy)
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(1 / math.Cos(n))
|
outputnum := newNumber().SetFloat64(1 / math.Cos(n))
|
||||||
@@ -237,7 +256,7 @@ var ArArcsec = builtinFunc{"arcsec", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
outputnum := newNumber().SetFloat64(math.Acos(1 / n))
|
outputnum := newNumber().SetFloat64(math.Acos(1 / n))
|
||||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI_RAT)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -255,7 +274,7 @@ var ArCot = builtinFunc{"cot", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, PI)
|
num.Quo(num, PI_RAT)
|
||||||
num.Mul(num, PIFloatInaccuracy)
|
num.Mul(num, PIFloatInaccuracy)
|
||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(1 / math.Tan(n))
|
outputnum := newNumber().SetFloat64(1 / math.Tan(n))
|
||||||
@@ -279,7 +298,7 @@ var ArArccot = builtinFunc{"arccot", func(args ...any) (any, ArErr) {
|
|||||||
n, _ := num.Float64()
|
n, _ := num.Float64()
|
||||||
outputnum := newNumber().SetFloat64(math.Atan(1 / n))
|
outputnum := newNumber().SetFloat64(math.Atan(1 / n))
|
||||||
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
outputnum.Quo(outputnum, PIFloatInaccuracy)
|
||||||
outputnum.Mul(outputnum, PI)
|
outputnum.Mul(outputnum, PI_RAT)
|
||||||
return outputnum, ArErr{}
|
return outputnum, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -297,7 +316,7 @@ var ArToDeg = builtinFunc{"toDeg", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, PI)
|
num.Quo(num, PI_RAT)
|
||||||
num.Mul(num, newNumber().SetInt64(180))
|
num.Mul(num, newNumber().SetInt64(180))
|
||||||
return num, ArErr{}
|
return num, ArErr{}
|
||||||
}}
|
}}
|
||||||
@@ -317,6 +336,6 @@ var ArToRad = builtinFunc{"toRad", func(args ...any) (any, ArErr) {
|
|||||||
}
|
}
|
||||||
num := newNumber().Set(args[0].(number))
|
num := newNumber().Set(args[0].(number))
|
||||||
num.Quo(num, newNumber().SetInt64(180))
|
num.Quo(num, newNumber().SetInt64(180))
|
||||||
num.Mul(num, PI)
|
num.Mul(num, PI_RAT)
|
||||||
return num, ArErr{}
|
return num, ArErr{}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func isTryCatch(code UNPARSEcode) bool {
|
|||||||
func parseTryCatch(code UNPARSEcode, index int, codelines []UNPARSEcode) (TryCatch, bool, ArErr, int) {
|
func parseTryCatch(code UNPARSEcode, index int, codelines []UNPARSEcode) (TryCatch, bool, ArErr, int) {
|
||||||
trytrimmed := strings.TrimSpace(code.code)
|
trytrimmed := strings.TrimSpace(code.code)
|
||||||
totalIndex := 0
|
totalIndex := 0
|
||||||
tryparsed, worked, err, i := translateVal(UNPARSEcode{trytrimmed[4:], code.realcode, code.line, code.path}, index, codelines, 1)
|
tryparsed, worked, err, i := translateVal(UNPARSEcode{trytrimmed[4:], code.realcode, code.line, code.path}, index, codelines, 3)
|
||||||
if !worked {
|
if !worked {
|
||||||
return TryCatch{}, false, err, i
|
return TryCatch{}, false, err, i
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ func parseTryCatch(code UNPARSEcode, index int, codelines []UNPARSEcode) (TryCat
|
|||||||
catchbracketSplit := strings.SplitN(catchtrimmed, ")", 2)
|
catchbracketSplit := strings.SplitN(catchtrimmed, ")", 2)
|
||||||
errorName := strings.TrimSpace(strings.TrimSpace(catchbracketSplit[0])[1:])
|
errorName := strings.TrimSpace(strings.TrimSpace(catchbracketSplit[0])[1:])
|
||||||
errcode := catchbracketSplit[1]
|
errcode := catchbracketSplit[1]
|
||||||
catchparsed, worked, err, i := translateVal(UNPARSEcode{errcode, code.realcode, code.line, code.path}, index+totalIndex, codelines, 1)
|
catchparsed, worked, err, i := translateVal(UNPARSEcode{errcode, code.realcode, code.line, code.path}, index+totalIndex, codelines, 3)
|
||||||
if !worked {
|
if !worked {
|
||||||
return TryCatch{}, false, err, i
|
return TryCatch{}, false, err, i
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package main
|
|||||||
|
|
||||||
func typeof(val any) string {
|
func typeof(val any) string {
|
||||||
switch x := val.(type) {
|
switch x := val.(type) {
|
||||||
case number:
|
|
||||||
return "number"
|
|
||||||
case nil:
|
case nil:
|
||||||
return "null"
|
return "null"
|
||||||
case bool:
|
case bool:
|
||||||
|
|||||||
@@ -76,12 +76,13 @@ func parseVariable(code UNPARSEcode) (accessVariable, bool, ArErr, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readVariable(v accessVariable, stack stack) (any, ArErr) {
|
func readVariable(v accessVariable, stack stack) (any, ArErr) {
|
||||||
|
name := ArString(v.Name)
|
||||||
for i := len(stack) - 1; i >= 0; i-- {
|
for i := len(stack) - 1; i >= 0; i-- {
|
||||||
callable, ok := stack[i].obj["__Contains__"]
|
callable, ok := stack[i].obj["__Contains__"]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
contains, err := builtinCall(callable, []any{v.Name})
|
contains, err := builtinCall(callable, []any{name})
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,7 @@ func readVariable(v accessVariable, stack stack) (any, ArErr) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return builtinCall(callable, []any{v.Name})
|
return builtinCall(callable, []any{name})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ArErr{"Name Error", "variable \"" + v.Name + "\" does not exist", v.Line, v.Path, v.Code, true}
|
return nil, ArErr{"Name Error", "variable \"" + v.Name + "\" does not exist", v.Line, v.Path, v.Code, true}
|
||||||
@@ -159,7 +160,7 @@ func parseSetVariable(code UNPARSEcode, index int, lines []UNPARSEcode, isLine i
|
|||||||
params = x.params
|
params = x.params
|
||||||
toset = x.toset
|
toset = x.toset
|
||||||
if toset == nil {
|
if toset == nil {
|
||||||
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean to put 'let' before?", code.line, code.path, code.realcode, true}, 1
|
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean '=='?", code.line, code.path, code.realcode, true}, 1
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean '=='?", code.line, code.path, code.realcode, true}, 1
|
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean '=='?", code.line, code.path, code.realcode, true}, 1
|
||||||
@@ -223,7 +224,7 @@ func parseAutoAsignVariable(code UNPARSEcode, index int, lines []UNPARSEcode, is
|
|||||||
toset = x.toset
|
toset = x.toset
|
||||||
default:
|
default:
|
||||||
if i == len(equalsplit)-1 {
|
if i == len(equalsplit)-1 {
|
||||||
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean to put 'let' before?", code.line, code.path, code.realcode, true}, 1
|
return setVariable{}, false, ArErr{"Type Error", "can't set for non variable, did you mean '=='?", code.line, code.path, code.realcode, true}, 1
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func parseWhileLoop(code UNPARSEcode, index int, codeline []UNPARSEcode) (whileL
|
|||||||
},
|
},
|
||||||
index+outindex-1,
|
index+outindex-1,
|
||||||
codeline,
|
codeline,
|
||||||
2,
|
3,
|
||||||
)
|
)
|
||||||
if err.EXISTS || !worked {
|
if err.EXISTS || !worked {
|
||||||
return whileLoop{}, worked, err, step
|
return whileLoop{}, worked, err, step
|
||||||
@@ -96,7 +96,7 @@ func parseForeverLoop(code UNPARSEcode, index int, codeline []UNPARSEcode) (whil
|
|||||||
},
|
},
|
||||||
index,
|
index,
|
||||||
codeline,
|
codeline,
|
||||||
2,
|
3,
|
||||||
)
|
)
|
||||||
return whileLoop{
|
return whileLoop{
|
||||||
condition: true,
|
condition: true,
|
||||||
@@ -108,13 +108,14 @@ func parseForeverLoop(code UNPARSEcode, index int, codeline []UNPARSEcode) (whil
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runWhileLoop(loop whileLoop, stack stack, stacklevel int) (any, ArErr) {
|
func runWhileLoop(loop whileLoop, stack stack, stacklevel int) (any, ArErr) {
|
||||||
|
|
||||||
newstack := append(stack, newscope())
|
newstack := append(stack, newscope())
|
||||||
for {
|
for {
|
||||||
condition, err := runVal(loop.condition, newstack, stacklevel+1)
|
condition, err := runVal(loop.condition, newstack, stacklevel+1)
|
||||||
newbodystack := append(newstack, newscope())
|
|
||||||
if err.EXISTS {
|
if err.EXISTS {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
newbodystack := append(newstack, newscope())
|
||||||
if !anyToBool(condition) {
|
if !anyToBool(condition) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
13
tests/broken_funcCall.ar
Normal file
13
tests/broken_funcCall.ar
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
let x = do
|
||||||
|
let class = {}
|
||||||
|
class.f(path) = do
|
||||||
|
let nice(callback) = do
|
||||||
|
callback()
|
||||||
|
return class
|
||||||
|
let class = {nice:nice}
|
||||||
|
return class
|
||||||
|
class.cool(path, callback) = class.f(path).nice(callback)
|
||||||
|
return class
|
||||||
|
|
||||||
|
|
||||||
|
term.log(x.cool("to", ()=term.log("epic")).nice(()=term.log("test")))
|
||||||
20
tests/chatbot code.ar
Normal file
20
tests/chatbot code.ar
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# This is a comment
|
||||||
|
|
||||||
|
term.log("Hello World!") # Printing to console/output
|
||||||
|
|
||||||
|
value = "Hello" # Declaring a variable
|
||||||
|
|
||||||
|
do # Start of indented block
|
||||||
|
combined = value + " World!"
|
||||||
|
term.log(combined)
|
||||||
|
|
||||||
|
loop = true # Using true condition
|
||||||
|
|
||||||
|
while (loop) do # While loop syntax
|
||||||
|
term.log("Looping...")
|
||||||
|
loop = false # Using false condition
|
||||||
|
|
||||||
|
if (value == "Hello") do # If statement syntax
|
||||||
|
term.log("The value is Hello")
|
||||||
|
else do # else block
|
||||||
|
term.log("The value is not Hello")
|
||||||
2
tests/circular_import.ar
Normal file
2
tests/circular_import.ar
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import "circular_test"
|
||||||
|
term.log("epic wow")
|
||||||
2
tests/circular_test.ar
Normal file
2
tests/circular_test.ar
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import "circular_import"
|
||||||
|
term.log("hello")
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
let zero = 1e-1000
|
let h = 1e-1000
|
||||||
let diff(f) = (x) = (f(x + zero) - f(x)) / zero
|
let diff(f) = (x) = (f(x + h) - f(x)) / h
|
||||||
|
|
||||||
|
|
||||||
let f(x) = x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1
|
let f(x) = x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1
|
||||||
|
|||||||
16
tests/multi_threading.ar
Normal file
16
tests/multi_threading.ar
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
let mythread(threadID) = do
|
||||||
|
term.log(threadID, "start")
|
||||||
|
let mynumber = 10
|
||||||
|
for (i from 0 to 1e4) do
|
||||||
|
mynumber += 1
|
||||||
|
mynumber
|
||||||
|
return term.log(threadID, "done")
|
||||||
|
|
||||||
|
let threads = []
|
||||||
|
term.time("start")
|
||||||
|
for (i from 0 to 100) do
|
||||||
|
threads.append(thread(()=mythread(i)))
|
||||||
|
threads[i].start()
|
||||||
|
for (i from 0 to 100) do
|
||||||
|
threads[i].join()
|
||||||
|
term.timeEnd("start")
|
||||||
2
tests/rng.ar
Normal file
2
tests/rng.ar
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
forever do
|
||||||
|
term.log(random())
|
||||||
1
wasm-build
Executable file
1
wasm-build
Executable file
@@ -0,0 +1 @@
|
|||||||
|
GOOS=js GOARCH=wasm go build -trimpath -ldflags="-s -w" -o ./bin/argon.wasm ./src
|
||||||
Reference in New Issue
Block a user