9 Commits

22 changed files with 320 additions and 112 deletions

View File

@@ -1,2 +1,2 @@
@echo off @echo off
go build -trimpath -ldflags="-s -w" -o bin/argon.exe ./src go build -trimpath -ldflags="-s -w" -tags WINDOWS -o bin/argon.exe ./src

View File

@@ -3,4 +3,4 @@
:: run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments :: run the go run command passing the path to the main.go file, with the working directory set to the bin folder. pass in the arguments
set __ARGON_DEBUG__=true set __ARGON_DEBUG__=true
go run ./src %* go run -tags WINDOWS ./src %*

12
go.mod
View File

@@ -7,7 +7,15 @@ 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/go-ole/go-ole v1.2.6 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/shirou/gopsutil v2.21.11+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
)
require ( require (
github.com/gabriel-vasile/mimetype v1.4.2 github.com/gabriel-vasile/mimetype v1.4.2
@@ -18,7 +26,7 @@ require (
github.com/jwalton/go-supportscolor v1.1.0 github.com/jwalton/go-supportscolor v1.1.0
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-isatty v0.0.17 // indirect
golang.org/x/sys v0.6.0 // indirect golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.6.0 golang.org/x/term v0.6.0
golang.org/x/text v0.8.0 golang.org/x/text v0.8.0
) )

18
go.sum
View File

@@ -1,7 +1,13 @@
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=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ= github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
@@ -11,19 +17,31 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/shirou/gopsutil v2.21.11+incompatible h1:lOGOyCG67a5dv2hq5Z1BLDUqqKp3HkbjPcz5j6XMS0U=
github.com/shirou/gopsutil v2.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
github.com/wadey/go-rounding v1.1.0 h1:RAs9dMkB/uUHFv9ljlbRFC8/kBrQ5jhwt1GQq+2cciY= github.com/wadey/go-rounding v1.1.0 h1:RAs9dMkB/uUHFv9ljlbRFC8/kBrQ5jhwt1GQq+2cciY=
github.com/wadey/go-rounding v1.1.0/go.mod h1:/uD953tCL6Fea2Yp+LZBBp8d60QSObkMJxY6SPOJ5QE= github.com/wadey/go-rounding v1.1.0/go.mod h1:/uD953tCL6Fea2Yp+LZBBp8d60QSObkMJxY6SPOJ5QE=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= 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-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=

View File

@@ -17,7 +17,12 @@ ARGON 3 is a math-driven programming language designed to make code easy to read
- 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.
## 💻 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)`. ### Windows
As of now, Argon 3 does not have a windows installer. Feel free to clone this repo and run the `build.bat` file. the build will be found in `bin\argon.exe`.
If you want to also use the isotope package manager, you can find the source code [here](https://github.com/open-argon/isotope).
### UNIX based (macOS and Linux)
Unix based operating systems can use the argon installer script found at [https://argon.wbell.dev/](https://argon.wbell.dev/). The script should run on all modern linux distros, and should also work on macOS with limited support. It may also work on other Unix based operating systems such at FreeBSD, but those are untested but are supported if you have issues.
## 📖 Usage ## 📖 Usage
To use Argon 3, you can create a file with the .ar extension and write your code in it. Then, you can run your code using the interpreter. For example, if you have a file called example.ar, you can run it using the following command: To use Argon 3, you can create a file with the .ar extension and write your code in it. Then, you can run your code using the interpreter. For example, if you have a file called example.ar, you can run it using the following command:

9
server_test/app.ar Normal file
View 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()

View File

@@ -61,6 +61,29 @@ func ArArray(arr []any) ArObject {
return nil, ArErr{} return nil, ArErr{}
}, },
} }
val.obj["__Multiply__"] = builtinFunc{
"__Multiply__",
func(a ...any) (any, ArErr) {
if len(a) != 1 {
return nil, ArErr{"Type Error", "expected 1 argument, got " + fmt.Sprint(len(a)), 0, "", "", true}
}
if typeof(a[0]) != "number" {
return nil, ArErr{"Type Error", "cannot multiply array by " + typeof(a[0]), 0, "", "", true}
}
n := a[0].(number)
if !n.IsInt() {
return nil, ArErr{"Value Error", "cannot multiply array by float", 0, "", "", true}
}
if n.Sign() < 0 {
return nil, ArErr{"Value Error", "cannot multiply array by negative number", 0, "", "", true}
}
size := int(n.Num().Int64())
retval := make([]any, 0, len(arr)*size)
for i := 0; i < size; i++ {
retval = append(retval, arr...)
}
return ArArray(retval), ArErr{}
}}
val.obj["__getindex__"] = builtinFunc{ val.obj["__getindex__"] = builtinFunc{
"__getindex__", "__getindex__",
func(a ...any) (any, ArErr) { func(a ...any) (any, ArErr) {

View File

@@ -9,6 +9,7 @@ func makeGlobal() ArObject {
var vars = anymap{} var vars = anymap{}
vars["global"] = vars vars["global"] = vars
vars["env"] = env vars["env"] = env
vars["platform"] = platform
vars["term"] = ArTerm vars["term"] = ArTerm
vars["ArgonVersion"] = ArString(VERSION) vars["ArgonVersion"] = ArString(VERSION)
vars["ArgonVersionNumber"] = newNumber().SetInt64(VERSION_NUM) vars["ArgonVersionNumber"] = newNumber().SetInt64(VERSION_NUM)
@@ -266,7 +267,7 @@ func makeGlobal() ArObject {
switch x := a[0].(type) { switch x := a[0].(type) {
case string: case string:
if len(x) != 1 { if len(x) != 1 {
return nil, ArErr{TYPE: "ord", message: "ord takes a string with only one character, got " + fmt.Sprint(len(a)), EXISTS: true} return nil, ArErr{TYPE: "ord", message: "ord takes a string with only one character, got " + fmt.Sprint(len(x)), EXISTS: true}
} }
return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{} return floor(newNumber().SetInt64(int64([]rune(x)[0]))), ArErr{}
} }

View File

@@ -156,6 +156,7 @@ func translateImport(realpath string, origin string, topLevelOnly bool) (transla
importing[p] = true importing[p] = true
translated, translationerr := translate(codelines) translated, translationerr := translate(codelines)
debugPrintln(translated...)
importing[p] = false importing[p] = false
if translationerr.EXISTS { if translationerr.EXISTS {

View File

@@ -1,63 +1,13 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
"golang.org/x/term" "golang.org/x/term"
) )
func input(args ...any) string { var tempFilePath = os.TempDir() + "/argon_input_history.tmp"
output := []any{}
for i := 0; i < len(args); i++ {
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
}
fmt.Print(output...)
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
input := scanner.Text()
return input
}
func getPassword(args ...any) (string, error) {
output := []any{}
for i := 0; i < len(args); i++ {
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
}
fmt.Print(output...)
password := []byte{}
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer term.Restore(int(os.Stdin.Fd()), oldState)
for {
char := make([]byte, 1)
_, 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 string(password), nil
}
func pause() { func pause() {
fmt.Print("Press Enter to continue...") fmt.Print("Press Enter to continue...")

55
src/input_unix.go Normal file
View File

@@ -0,0 +1,55 @@
//go:build !WINDOWS
// +build !WINDOWS
package main
import (
"fmt"
"log"
"github.com/chzyer/readline"
)
func input(args ...any) (string, error) {
output := []any{}
for i := 0; i < len(args); i++ {
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
}
message := fmt.Sprint(output...)
rl, err := readline.NewEx(&readline.Config{
Prompt: message,
HistoryFile: tempFilePath,
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) {
output := []any{}
for i := 0; i < len(args); i++ {
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
}
message := fmt.Sprint(output...)
rl, err := readline.NewEx(&readline.Config{
Prompt: message,
MaskRune: '*',
EnableMask: 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
}

63
src/input_windows.go Normal file
View File

@@ -0,0 +1,63 @@
//go:build WINDOWS
// +build WINDOWS
package main
import (
"bufio"
"fmt"
"os"
"golang.org/x/term"
)
func input(args ...any) (string, error) {
output := []any{}
for i := 0; i < len(args); i++ {
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
}
fmt.Print(output...)
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
input := scanner.Text()
return input, nil
}
func getPassword(args ...any) (string, error) {
output := []any{}
for i := 0; i < len(args); i++ {
output = append(output, anyToArgon(args[i], false, true, 3, 0, true, 0))
}
fmt.Print(output...)
password := []byte{}
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer term.Restore(int(os.Stdin.Fd()), oldState)
for {
char := make([]byte, 1)
_, 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 string(password), nil
}

View File

@@ -10,8 +10,8 @@ var Args = os.Args[1:]
type stack = []ArObject type stack = []ArObject
const VERSION = "3.0.8" const VERSION = "3.0.11"
const VERSION_NUM = 6 const VERSION_NUM = 9
func newscope() ArObject { func newscope() ArObject {
return Map(anymap{}) return Map(anymap{})

View File

@@ -20,8 +20,8 @@ var operations = []string{
"==", "==",
"+", "+",
"-", "-",
"*",
"%", "%",
"*",
"//", "//",
"/", "/",
"^", "^",
@@ -918,9 +918,9 @@ func runOperation(o operationType, stack stack, stacklevel int) (any, ArErr) {
case 11: case 11:
return calcNegative(o, stack, stacklevel+1) return calcNegative(o, stack, stacklevel+1)
case 12: case 12:
return calcMul(o, stack, stacklevel+1)
case 13:
return calcMod(o, stack, stacklevel+1) return calcMod(o, stack, stacklevel+1)
case 13:
return calcMul(o, stack, stacklevel+1)
case 14: case 14:
return calcIntDiv(o, stack, stacklevel+1) return calcIntDiv(o, stack, stacklevel+1)
case 15: case 15:

49
src/platform.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"fmt"
"runtime"
"time"
"github.com/shirou/gopsutil/cpu"
)
var platform = Map(
anymap{
"os": ArString(runtime.GOOS),
"cpu": Map(anymap{
"count": newNumber().SetInt64((int64)(runtime.NumCPU())),
"usage": builtinFunc{"usage", func(args ...any) (any, ArErr) {
if len(args) != 2 {
return nil, ArErr{
TYPE: "Runtime Error",
message: "usage takes 2 arguments, got " + fmt.Sprint(len(args)),
EXISTS: true,
}
}
if !isAnyNumber(args[0]) {
return nil, ArErr{
TYPE: "Runtime Error",
message: "first argument is meant to be a number, got " + fmt.Sprint(typeof(args[0])),
EXISTS: true,
}
}
var Number = newNumber().Mul(args[0].(number), newNumber().SetInt64(1000)).Num().Int64()
avgPercent, err := cpu.Percent(time.Duration(Number)*time.Millisecond, anyToBool(args[1]))
if err != nil {
return nil, ArErr{
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
}
var ArAvgPercent = []any{}
for i := 0; i < len(avgPercent); i++ {
ArAvgPercent = append(ArAvgPercent, newNumber().SetFloat64(avgPercent[i]))
}
return ArArray(ArAvgPercent), ArErr{}
}},
}),
},
)

View File

@@ -14,12 +14,12 @@ func shell(global ArObject) {
go func() { go func() {
for sig := range c { for sig := range c {
if sig == os.Interrupt { if sig == os.Interrupt {
fmt.Println("\x1b[0m\n\x1b[32;5;240mBye :)\x1b[0m") fmt.Println("\x1b[0m\n\x1b[32;240mBye :)\x1b[0m")
os.Exit(0) os.Exit(0)
} }
} }
}() }()
fmt.Print("\x1b[32;5;240mWelcome to the Argon v3!\x1b[0m\n\n") fmt.Print("\x1b[32;240mWelcome to the Argon v3!\x1b[0m\n\n")
for { for {
indent := 0 indent := 0
previous := 0 previous := 0
@@ -27,7 +27,12 @@ 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") inp, err := input("\x1b[38;240m" + textBefore + indentStr + " \x1b[0m")
if err != nil {
fmt.Println("\x1b[0m\n\x1b[32;240mBye :)\x1b[0m")
os.Exit(0)
}
code := indentStr + inp
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)

View File

@@ -140,7 +140,15 @@ 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{} inp, err := input(args...)
if err != nil {
return nil, ArErr{
TYPE: "Runtime Error",
message: err.Error(),
EXISTS: true,
}
}
return ArString(inp), ArErr{}
}}, }},
"pause": builtinFunc{"pause", func(args ...any) (any, ArErr) { "pause": builtinFunc{"pause", func(args ...any) (any, ArErr) {
pause() pause()

View File

@@ -42,7 +42,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
} }
case number: case number:
if colored { if colored {
output = append(output, "\x1b[34;5;240m") output = append(output, "\x1b[34;240m")
} }
num, _ := x.Float64() num, _ := x.Float64()
if math.IsNaN(num) { if math.IsNaN(num) {
@@ -59,7 +59,7 @@ func anyToArgon(x any, quote bool, simplify bool, depth int, indent int, colored
} }
case bool: case bool:
if colored { if colored {
output = append(output, "\x1b[35;5;240m") output = append(output, "\x1b[35;240m")
} }
output = append(output, strconv.FormatBool(x)) output = append(output, strconv.FormatBool(x))
if colored { if colored {
@@ -67,7 +67,7 @@ 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;240m")
} }
output = append(output, "null") output = append(output, "null")
if colored { if colored {
@@ -128,7 +128,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;240m")
} }
outputkeyval = append(outputkeyval, key.(string)) outputkeyval = append(outputkeyval, key.(string))
if colored { if colored {
@@ -148,7 +148,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;240m(...)\x1b[0m")
} else { } else {
output = append(output, "(...)") output = append(output, "(...)")
} }
@@ -173,7 +173,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;240m")
} }
output = append(output, "<builtin function "+x.name+">") output = append(output, "<builtin function "+x.name+">")
if colored { if colored {
@@ -181,7 +181,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;240m")
} }
output = append(output, "<function "+x.name+">") output = append(output, "<function "+x.name+">")
if colored { if colored {

View File

@@ -139,6 +139,9 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
return nil, worked, err, step return nil, worked, err, step
} }
} }
if isNegative(code) {
return parseNegative(code, index, codelines)
}
if !QuickKnownFailures["call"+code.code] && isCall(code) { 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 {
@@ -146,9 +149,7 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
} }
QuickKnownFailures["call"+code.code] = true QuickKnownFailures["call"+code.code] = true
} }
if isNegative(code) { if isMapGet(code) {
return parseNegative(code, index, codelines)
} else if isMapGet(code) {
return mapGetParse(code, index, codelines) return mapGetParse(code, index, codelines)
} else if !QuickKnownFailures["indexget"+code.code] && isIndexGet(code) { } else if !QuickKnownFailures["indexget"+code.code] && isIndexGet(code) {
resp, worked, err, i = indexGetParse(code, index, codelines) resp, worked, err, i = indexGetParse(code, index, codelines)

View File

@@ -1,33 +1,45 @@
let interpret(code) = do let brainfuck(INPUT) = do
memory = map() memory = [0] * 30*1000
pointer = 0 pointer = 0
code_ptr = 0 output = ""
loops = [] i = 0
while (i < INPUT.length) do
if (INPUT[i] == ">") do
pointer += 1
else if (INPUT[i] == "<") do
pointer -= 1
else if (INPUT[i] == "+") do
memory[pointer] += 1
else if (INPUT[i] == "-") do
memory[pointer] -= 1
else if (INPUT[i] == ".") do
output += chr(memory[pointer])
else if (INPUT[i] == ",") do
memory[pointer] = ord(input())
else if (INPUT[i] == "[") do
if (memory[pointer] == 0) do
count = 1
while (count > 0) do
i += 1
if (INPUT[i] == "[") do
count += 1
else if (INPUT[i] == "]") do
count -= 1
else if (INPUT[i] == "]") do
if (memory[pointer] != 0) do
count = 1
while (count > 0) do
i -= 1
if (INPUT[i] == "]") do
count += 1
else if (INPUT[i] == "[") do
count -= 1
else do
pass
i += 1
term.print(memory)
return output
while (code_ptr < code.length) do term.time("brainfuck")
command = code[code_ptr] term.plain.oneLine(brainfuck(input()))
term.timeEnd("brainfuck")
if (command == '>') pointer = pointer + 1
else if (command == '<') pointer = pointer - 1
else if (command == '+') do
if (pointer not in memory) memory[pointer] = 0
memory[pointer] = memory[pointer] + 1
else if (command == '-') do
if (pointer not in memory) memory[pointer] = 0
memory[pointer] = memory[pointer] - 1
else if (command == '.') term.log((memory.get(pointer, 0)))
else if (command == ',') memory[pointer] = ord(input())
else if (command == '[') do
if (memory.get(pointer, 0) == 0) do
loop_depth = 1
while (loop_depth > 0) do
code_ptr = code_ptr + 1
if (code[code_ptr] == '[') loop_depth = loop_depth + 1
else if (code[code_ptr] == ']') loop_depth = loop_depth - 1
else loops.append(code_ptr)
else if (command == ']') do
if (memory.get(pointer, 0) != 0) code_ptr = loops[-1]
else loops.pop()
code_ptr = code_ptr + 1
interpret('>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.>++++++++++.')