Compare commits

...
27 Commits
Author SHA1 Message Date
William Bell d4d65d4390 DEPRECATED 2023-03-21 00:37:11 +00:00
Ugric 142dbe5812 fix bug when calling function from another module/file and add indexing 2022-07-11 00:26:07 +02:00
Ugric 1cb3e37e47 fix bugs in maths module (more bug fixes to come), and add indexing to function. 2022-07-09 18:51:29 +02:00
Ugric cbb51bb308 add catchable syntax errors 2022-07-05 11:14:27 +02:00
Ugric 6babfc8949 add try catch with err as error 2022-07-05 01:02:55 +02:00
Ugric 36df037162 edit readme 2022-07-04 21:26:06 +02:00
Ugric dc95a08e81 remove catch.go file 2022-07-04 21:14:27 +02:00
Ugric 6d048d5fd1 get ready for implimentation of error catching, and add infinity and NaN 2022-07-04 21:11:22 +02:00
Ugric 8fb6b2050d fix broken else if when more then one line is used. fix functions being told they are if statements 2022-07-04 17:46:51 +02:00
Ugric 13ba847b94 add local vars to while and if, and remove debug prints 2022-07-04 12:08:19 +02:00
Ugric 873e318ce3 add else if to if statement 2022-07-04 02:04:15 +02:00
Ugric 6693cb9d95 add else if to if statements 2022-07-04 02:04:07 +02:00
Ugric b6e5be7838 add new functions and modules 2022-07-01 01:37:33 +01:00
Ugric a6c3d3deb4 add new functions and modules 2022-07-01 01:37:25 +01:00
Ugric 7f074af8f6 change full import to selective import 2022-06-30 22:27:02 +01:00
Ugric 55a8f0b587 add missing functions to maths readme 2022-06-30 21:57:51 +01:00
Ugric ae5072d1e4 edit readme and add pointer example to example.ar 2022-06-30 21:54:10 +01:00
Ugric 89cc0cefab fix broken function pointer 2022-06-30 21:48:44 +01:00
Ugric 0d07bc1112 add inverse trig functions 2022-06-30 21:18:21 +01:00
William Bell 1498385d6d remove python 2022-06-30 19:53:44 +01:00
Ugric 5306baf21f update todo 2022-06-30 19:48:35 +01:00
Ugric 22db06827c add the ability to import specific variables and modules 2022-06-30 19:45:15 +01:00
Ugric d2aea49006 edit git ignore 2022-06-30 16:55:02 +01:00
Ugric cf1fd5dba7 edit git ignore 2022-06-30 16:54:55 +01:00
Ugric 40cf7aa2f6 import modules with reletive paths 2022-06-30 16:45:05 +01:00
Ugric 89235e35b8 import modules with reletive paths 2022-06-30 16:44:51 +01:00
Ugric 3aa7f0356d work on import modules 2022-06-30 16:29:40 +01:00
36 changed files with 1495 additions and 593 deletions

No files matched your search

-38
View File
@@ -1,38 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
-20
View File
@@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
+3 -1
View File
@@ -1,2 +1,4 @@
argon.exe
argon
argon
argon-lang/modules/.DS_Store
.DS_Store
+5 -5
View File
@@ -1,6 +1,6 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"files.associations": {
"*.ar": "C"
}
}
"C_Cpp.errorSquiggles": "Disabled",
"files.associations": {
"*.ar": "C"
}
}
+10 -1
View File
@@ -5,6 +5,7 @@ import (
"os"
"regexp"
"strings"
"time"
)
type code struct {
@@ -27,9 +28,17 @@ func makeRegex(str string) *regexp.Regexp {
}
func main() {
ex, err := os.Getwd()
if err != nil {
panic(err)
}
ArgonSetSeed(time.Now().UnixMilli())
if len(os.Args) == 1 {
shell()
} else {
importMod(os.Args[1])
_, err := importMod(os.Args[1], ex, true)
if err != nil {
log.Fatal(err)
}
}
}
+18 -3
View File
@@ -1,4 +1,4 @@
# CURRENTLY IN DEVELOPMENT!
# DEPRECATED
<div align="center">
<p>
@@ -14,7 +14,7 @@
- boolean renamed from true and false to yes and no
- the syntax is very similar to python and javascript
- no floats and ints, only numbers
- **New Feature!** easier operators, e.g. `5^2` can now be `5 to the power of 2`
- easier operators, e.g. `5^2` can now be `5 to the power of 2`
## Examples
@@ -80,6 +80,21 @@ while (yes) [
]
```
Import Modules:
- import the whole module
```javascript
import 'maths'
log(pi)
```
- import specific functions and variables from the module
```javascript
from 'maths' import sqrt, sin, cos, tan, pi, e
log(pi)
```
Items (Lists or Arrays):
```javascript
@@ -186,4 +201,4 @@ Run the shell:
- run the Argon executable without any parameters, (e.g. `$ argon`)
# License
MIT License
MIT License
-1
View File
@@ -1 +0,0 @@
import 'maths'
+1
View File
@@ -0,0 +1 @@
import 'maths/constants'
+1
View File
@@ -0,0 +1 @@
import 'maths/functions'
+1
View File
@@ -0,0 +1 @@
import maths
+1
View File
@@ -0,0 +1 @@
a mirror module of the 'maths' library.
+1
View File
@@ -0,0 +1 @@
import 'maths/trigonometry'
-29
View File
@@ -1,29 +0,0 @@
# make PI variable with PI to 1000 digits (may not be completely parsed)
PI = 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989e-1000
sub factorial(num) [
num = whole(num)
answer = 1
i = 2
while i < num+1 [
answer = answer * i
i = i + 1
]
return answer
]
# currently under development, DO NOT USE IN PRODUCTION!
sub _sine(theta) [
theta = ((theta + PI) % (2 * PI)) - PI
result = 0
termsign = 1
power = 1
i = 0
while i < 100 [
result = result + ((theta ** power) / factorial(power)) * termsign
termsign = 0 - termsign
power = power + 2
]
return result
]
+8
View File
@@ -0,0 +1,8 @@
# constants
# a sub library of maths
pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
e = 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931277361782154249992295763514822082698951936680331825288693984964651058209392398294887933203625094431173012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509961818815930416903515988885193458072738667385894228792284998920868058257492796104841984443634632449684875602336248270419786232090021609902353043699418491463140934317381436405462531520961836908887070167683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354
goldenRatio = (1 + (5 to the power of .5)) / 2
+69
View File
@@ -0,0 +1,69 @@
# functions
# a sub library of maths
from constants import e
sub factorial(num) [
num = whole(num)
answer = 1
i = 2
while i < num+1 [
answer = answer * i
i = i + 1
]
return answer
]
sub mod(x, n) [
return x - n * whole(x / n)
]
sub abs(x) [
if x < 0 [
return 0-x
]
return x
]
sub sqrt(x) [
last_guess = x/2
if x equals 0 [
return 0
]
i = 0
while yes [
if i > 10000 [
error "sqrt: could not find a solution for the square root of " + x
]
guess = (last_guess + x / last_guess) / 2
if abs(guess - last_guess) < 1e-5 [
return guess
]
last_guess = guess
i = i + 1
]
]
sub exp(x) [
return (e**x)
]
sub ln(x) [
n = 1e10
return n * ((x ** (1/n)) - 1)
]
sub logarithm(x) [
return ln(x)/ln(10)
]
sub logarithmX(x,base) [
return ln(x)/ln(base)
]
sub alogarithm(x) [
return 10**x
]
sub alogarithmX(x, base) [
return base**x
]
+51
View File
@@ -0,0 +1,51 @@
# THE MATH LIBRARY
# creation date 30/6/2022
# last modified 1/7/2022
# author: William Bell
# license: MIT
# version: 1.0
# --------------------------------------------------------------------------------------------------------------------
# description:
# This module contains basic math functions for use within Argon.
# The algorithms used are designed to be fast and efficient, however may give inaccurate results with large numbers.
# variables such as pi and e are included in the module have been pre-computed for you, with 1000 digits to make they will work with every use case.
# algorithms such as logarithm give close but not exact results, however the speed of the algorithm is fast. if you want to get more accurate results, you can find other maths modules which are more accurate, or create your own function.
# --------------------------------------------------------------------------------------------------------------------
# functions:
# abs(x)
# ceil(x)
# floor(x)
# round(x)
# sqrt(x)
# sin(x)
# cos(x)
# tan(x)
# exp(x)
# ln(x)
# logarithm(x)
# logarithmX(x, y)
# mod(x, y)
# --------------------------------------------------------------------------------------------------------------------
# trigonometry
import trigonometry
# --------------------------------------------------------------------------------------------------------------------
# math functions
import functions
# --------------------------------------------------------------------------------------------------------------------
# initialize math numbers
import constants
# --------------------------------------------------------------------------------------------------------------------
+27
View File
@@ -0,0 +1,27 @@
# THE MATH LIBRARY
```
creation date 30/6/2022
last modified 1/7/2022
author: William Bell
license: MIT
version: 1.0
```
# description:
- This module contains basic math functions for use within Argon.
- The algorithms used are designed to be fast and efficient, however may give inaccurate results with large numbers.
- However variables such as pi and e are included in the module and have been pre-computed for you, with 1000 digits to make they will work with every use case.
- algorithms such as logarithm give close but not exact results, however the speed of the algorithm is fast. if you want to get more accurate results, you can find other maths modules which are more accurate, or create your own function.
# functions:
- abs(x)
- ceil(x)
- floor(x)
- round(x)
- sqrt(x)
- sin(x)
- cos(x)
- tan(x)
- exp(x)
- ln(x)
- logarithm(x)
- logarithmX(x, y)
- mod(x, y)
+42
View File
@@ -0,0 +1,42 @@
# trigonometry
# a sub library of maths
from functions import abs, sqrt, mod
from constants import pi
# trigonometry
sub sin(theta) [
result = -(mod(theta divided by 180, 1) minus .5) to the power of 2 times 4 plus 1
if theta div 180 div 1 mod 2 is not equal to 0 [
result = result times -1
]
return result
]
sub cos(theta) [
return sin(theta plus 90)
]
sub tan(theta) [
return sin(theta) divided by cos(theta)
]
# inverse trigonometry
sub asin(result) [
return (sqrt(abs(-(result minus 1) divided by 4)) plus .5) times 180
]
sub acos(result) [
return asin(result) - 90
]
# make a inverse tan function
# e.g. atan(tan(x)) = x
# use asin and acos to get theta
# use tan to get result
sub atan(result) [
return asin(result*acos(result))
]
+5
View File
@@ -0,0 +1,5 @@
# constants
# a sub library of physics
c = 299792458
WaterSHC = 4182
+4
View File
@@ -0,0 +1,4 @@
# equations
# a sub library of physics
sub
+8
View File
@@ -0,0 +1,8 @@
# THE RANDOM LIBRARY
# creation date 1/7/2022
# last modified 1/7/2022
# author: William Bell
# license: MIT
# version: 1.0
# --------------------------------------------------------------------------------------------------------------------
+10
View File
@@ -0,0 +1,10 @@
# THE PHYSICS LIBRARY
```
creation date 30/6/2022
last modified 1/7/2022
author: William Bell
license: MIT
version: 1.0
```
# description:
- a module for basic physics equations and constants
+16
View File
@@ -0,0 +1,16 @@
# THE RANDOM LIBRARY
# creation date 1/7/2022
# last modified 1/7/2022
# author: William Bell
# license: MIT
# version: 1.0
# --------------------------------------------------------------------------------------------------------------------
sub randint(a, b) [
return whole(randfloat(a, b+1))
]
sub randfloat(a, b) [
return (random() * (b - a)) + a
]
+10
View File
@@ -0,0 +1,10 @@
# THE RANDOM LIBRARY
```
creation date 1/7/2022
last modified 1/7/2022
author: William Bell
license: MIT
version: 1.0
```
# description:
- a library which uses the built in random function to add features such as randint and randfloat
+1 -1
View File
@@ -1 +1 @@
go build -o argon.exe .
go build -o argon-lang/argon.exe .
+69 -25
View File
@@ -4,32 +4,38 @@ import (
"bufio"
"fmt"
"math"
"math/rand"
"os"
"strings"
"time"
)
func ArgonLog(x ...any) any {
func ArgonLog(x ...any) (any, any) {
output := []any{}
for i := 0; i < len(x); i++ {
output = append(output, anyToArgon(x[i], false))
}
fmt.Println(output...)
return nil
return nil, nil
}
func ArgonNumber(x ...any) any {
func ArgonNumber(x ...any) (any, any) {
return (number(x[0]))
}
func ArgonString(x ...any) any {
return (anyToArgon(x[0], true))
func ArgonString(x ...any) (any, any) {
return (anyToArgon(x[0], true)), nil
}
func ArgonWhole(x ...any) any {
return (math.Floor(number(x[0])))
func ArgonWhole(x ...any) (any, any) {
num, err := number(x[0])
if err != nil {
return nil, err
}
return (math.Floor(num)), nil
}
func ArgonInput(x ...any) any {
func ArgonInput(x ...any) (any, any) {
fmt.Print(x[0])
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
@@ -37,10 +43,10 @@ func ArgonInput(x ...any) any {
if err := scanner.Err(); err != nil {
fmt.Println("Error encountered:", err)
}
return (line)
return (line), nil
}
func ArgonLicense(...any) any {
func ArgonLicense(...any) (any, any) {
fmt.Println(`MIT License
Copyright (c) 2022 William Bell
@@ -62,34 +68,72 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`)
return nil
return nil, nil
}
func exec(x ...any) any {
runStr(x[0].(string))
return nil
func exec(x ...any) (any, any) {
origin := ""
if len(x) > 1 {
origin = x[1].(string)
}
runStr(x[0].(string), origin, map[string]variableValue{})
return nil, nil
}
func eval(x ...any) any {
resp, _ := translateprocess(code{
func eval(x ...any) (any, any) {
resp, _, err := translateprocess(code{
code: x[0].(string),
line: 0,
})
return resp
if err != nil {
return nil, err
}
return resp, nil
}
func ArgonAppend(x ...any) any {
return append(x[0].([]any), x[1])
func ArgonAppend(x ...any) (any, any) {
return append(x[0].([]any), x[1]), nil
}
func ArgonExtend(x ...any) any {
return append(x[0].([]any), x[1].([]any)...)
func ArgonExtend(x ...any) (any, any) {
return append(x[0].([]any), x[1].([]any)...), nil
}
func ArgonLen(x ...any) any {
return len(x[0].([]any))
func ArgonLen(x ...any) (any, any) {
switch value := x[0].(type) {
case []any:
return len(value), nil
case string:
return len(value), nil
case map[any]any:
return len(value), nil
default:
return 0, nil
}
}
func ArgonJoin(x ...any) any {
return strings.Join(x[0].([]string), x[1].(string))
func ArgonJoin(x ...any) (any, any) {
return strings.Join(x[0].([]string), x[1].(string)), nil
}
func ArgonTime(x ...any) (any, any) {
return time.Now().UnixMilli(), nil
}
func ArgonSleep(x ...any) (any, any) {
num, err := number(x[0])
if err != nil {
return nil, err
}
time.Sleep(time.Duration(num) * time.Millisecond)
return nil, nil
}
func ArgonSetSeed(x ...any) (any, any) {
rand.Seed(x[0].(int64))
return nil, nil
}
func ArgonRandom(x ...any) (any, any) {
return rand.Float64(), nil
}
-22
View File
@@ -1,22 +0,0 @@
package main
import "log"
var catch = [](func(any)){}
func err(err string) {
if len(catch) > 0 {
catch[len(catch)-1](err)
catch[len(catch)-1] = nil
} else {
log.Fatal(err)
}
}
func catchError(f func(any)) {
catch = append(catch, f)
}
func endCatch() {
catch = catch[:len(catch)-1]
}
+58 -16
View File
@@ -2,7 +2,7 @@ package main
type opperator struct {
t int
vals []interface{}
vals []any
line int
}
@@ -12,38 +12,50 @@ type variable struct {
}
type funcCallType struct {
name string
args []interface{}
FUNC any
args []any
line int
}
type whileLoop struct {
condition interface{}
code []interface{}
condition any
code []any
}
type variableValue struct {
TYPE string
VAL any
EXISTS any
origin string
FUNC bool
}
type importType struct {
path interface{}
line int
path any
toImport any
line int
}
type iftype struct {
condition any
code []any
}
type ifstatement struct {
condition interface{}
TRUE []interface{}
FALSE []interface{}
statments []iftype
FALSE []any
}
type setVariable struct {
TYPE string
variable string
value interface{}
variable variable
value any
line int
}
type setFunction struct {
name string
args []string
code []interface{}
FUNC callableFunction
line int
}
@@ -65,6 +77,36 @@ type itemsType struct {
line int
}
type closeIndent struct {
line int
type tryType struct {
code []any
catch []any
line int
}
type errorType struct {
val any
}
type deleteType struct {
variable variable
line int
}
type builtinFunc struct {
name string
FUNC func(...any) (any, any)
}
type callableFunction struct {
name any
args []string
code []any
vargroups []map[string]variableValue
line int
}
type indexType struct {
to any
index any
line int
}
-79
View File
@@ -1,79 +0,0 @@
client
proto udp
explicit-exit-notify
remote 212.71.237.189 60005
dev tun
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
verify-x509-name server_wnJuJy53oNsHdwUB name
auth SHA256
auth-nocache
cipher AES-128-GCM
tls-client
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
ignore-unknown-option block-outside-dns
setenv opt block-outside-dns # Prevent Windows 10 DNS leak
verb 3
<ca>
-----BEGIN CERTIFICATE-----
MIIB1zCCAX2gAwIBAgIUb8tI/ox5s8DPwc13FER4ckU0yFQwCgYIKoZIzj0EAwIw
HjEcMBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJSE1qSzAeFw0yMjAzMDcwOTU3MjZa
Fw0zMjAzMDQwOTU3MjZaMB4xHDAaBgNVBAMME2NuX2N1S3lGOThnT2FJSUhNaksw
WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARC7zM+9KYCZIVXl7i38BCK62wYu8W4
LrTFpFOK7DI7uaFcT544rEzDQIz3JY2HYMxN+nOtOybxfioHkZtvUUkao4GYMIGV
MB0GA1UdDgQWBBSj9j7NNN2V1z2MvYTkeRGGDLsndjBZBgNVHSMEUjBQgBSj9j7N
NN2V1z2MvYTkeRGGDLsndqEipCAwHjEcMBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJ
SE1qS4IUb8tI/ox5s8DPwc13FER4ckU0yFQwDAYDVR0TBAUwAwEB/zALBgNVHQ8E
BAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANXx1cZ+WhaXaya/I0Z+XRm3oMq6Jx3W
A65DUw4GKAOJAiBnL44bRCoA74kU755wau0i4IThZC5QLNoY4CJ82CaooQ==
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
MIIB4DCCAYWgAwIBAgIRALja307VuXV/gGvUkGElDBkwCgYIKoZIzj0EAwIwHjEc
MBoGA1UEAwwTY25fY3VLeUY5OGdPYUlJSE1qSzAeFw0yMjA2MjkxNjU0MzZaFw0y
NDEwMDExNjU0MzZaMBcxFTATBgNVBAMMDGdlb3JnZS1waG9uZTBZMBMGByqGSM49
AgEGCCqGSM49AwEHA0IABCslkMIcIiB5E7FaC3dTC7/iapKI9bexr9NahwMjd7aS
L/G4zlh+JCIH8A65y1DCzCazlJ3bYX7Rja9iXx2mRWCjgaowgacwCQYDVR0TBAIw
ADAdBgNVHQ4EFgQUiilqCz4C01AgMbX+j3GRkK6oOfswWQYDVR0jBFIwUIAUo/Y+
zTTdldc9jL2E5HkRhgy7J3ahIqQgMB4xHDAaBgNVBAMME2NuX2N1S3lGOThnT2FJ
SUhNakuCFG/LSP6MebPAz8HNdxREeHJFNMhUMBMGA1UdJQQMMAoGCCsGAQUFBwMC
MAsGA1UdDwQEAwIHgDAKBggqhkjOPQQDAgNJADBGAiEAjrzNh3gFr1EGIcVwzvwH
lWswm8KkIPLHuuQZisqGBokCIQDX4FGUbyDbXmVVD4W5zU9mCQ5Qj37IlEpUMFcM
1Ey1lQ==
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg1lNu8HVoPPre6s9G
/mRZ8uIEFCweqCzVThUPioXHaVehRANCAAQrJZDCHCIgeROxWgt3Uwu/4mqSiPW3
sa/TWocDI3e2ki/xuM5YfiQiB/AOuctQwswms5Sd22F+0Y2vYl8dpkVg
-----END PRIVATE KEY-----
</key>
<tls-crypt>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
b827cd4cb18dc59de1bbd785f513de31
fa2b3bb1d916892b06c2284f139d09d4
6c034d7aeb5f30401a28dce36ded937c
9ed60e0f6c07f577776a72fc6e1d9902
7ff102bf78d43c8600e9a26498ccddbb
e54e7cabc1963cc18df35a4237944094
ceec82ecb6d221bd528b6d49c07ed3b9
689892c542e517a37679cf685bca2638
34db373071aaf06416704287a8ed0ae8
1b893b82f6b2a595f9be96148b03e141
16b683216a8c83c6001eef69a9bff581
10e38b20deae2337ea3a3ce1e5562146
aa4263b7fc79b7fb2dd23ea5d6bac5cf
ee0e70e23097a56244c5bbbf3c91a1f2
c7be0a74cf6b31a5032f2d24cdffeaba
4daa8b7f124018cc946b8cca0d07844b
-----END OpenVPN Static key V1-----
</tls-crypt>
+6 -7
View File
@@ -1,8 +1,7 @@
const aspect = input('aspect ratio: ')
const width = input('width: ') / 25.6
var input = input('text: ')
const height = width / aspect;
const diagonal = (width**2 + height ** 2) ** (1/2)
log(diagonal, 'inches')
i = 0
while i < len(input) [
log(input[i])
i = i + 1
]
+64 -32
View File
@@ -1,13 +1,11 @@
package main
import (
"log"
"fmt"
"os"
"path/filepath"
)
var imported = []any{}
func FileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
@@ -16,44 +14,78 @@ func FileExists(filename string) bool {
return !info.IsDir()
}
func importMod(path string) {
extention := filepath.Ext(path)
var modules = map[string](map[string]variableValue){}
var importing = map[string]any{}
func importMod(realpath string, origin string, main bool) (map[string]variableValue, any) {
extention := filepath.Ext(realpath)
path := realpath
if extention == "" {
path += ".ar"
}
ex, err := os.Getwd()
if err != nil {
panic(err)
return nil, err
}
exPath := ex
p := filepath.Join(exPath, path)
if !FileExists(p) {
ex, err = os.Executable()
if err != nil {
panic(err)
}
exPath = filepath.Dir(ex)
p = filepath.Join(exPath, "modules", path)
if !FileExists(p) {
log.Fatal("Module not found: " + path + " (" + p + ")")
}
}
if xiny(p, imported) {
return
}
imported = append(imported, p)
data, err := os.ReadFile(p)
executable, err := os.Executable()
if err != nil {
log.Fatal(err)
return nil, err
}
runStr(string(data))
executable = filepath.Dir(executable)
pathsToTest := []string{filepath.Join(origin, realpath, "init.ar"), filepath.Join(origin, path), filepath.Join(origin, "modules", path), filepath.Join(origin, "modules", realpath, "init.ar"), filepath.Join(ex, path), filepath.Join(ex, "modules", realpath, "init.ar"), filepath.Join(ex, "modules", path), filepath.Join(executable, "modules", realpath, "init.ar"), filepath.Join(executable, "modules", path)}
var p string
for _, p = range pathsToTest {
if FileExists(p) {
break
}
}
if importing[p] == true {
return nil, fmt.Sprint("Recursive import of ", p, " detected.\n\nHow to fix?\nCurrently this error cannot be pin pointed by Argons error detection, but this can be caused by a circular import or by a module that imports itself. Check .ar files inside ", origin, " for circular imports, or maybe this is an issue with one of the libaries used in the project so maybe get in contact with the library author.")
} else if importing[p] == nil {
importing[p] = true
modules[p] = map[string]variableValue{}
data, err := os.ReadFile(p)
if err != nil {
return nil, err
}
stringdata := string(data)
moduledata := modules[p]
if main {
vars["__main__"] = variableValue{
TYPE: "const",
VAL: p,
EXISTS: true,
origin: p,
FUNC: false,
}
}
_, e := runStr(stringdata, p, moduledata)
if e != nil {
return nil, e
}
importing[p] = false
}
return modules[p], nil
}
func runStr(str string) [][]any {
translated := translate(str)
ty, _, resp := run(translated, []map[string]variableValue{vars})
if ty != nil {
log.Fatal(ty, " at top level")
func runStr(str string, origin string, variables map[string]variableValue) ([][]any, any) {
translated, err := translate(str)
if err != nil {
return nil, err
}
return resp
fileparams := map[string]variableValue{"__file__": {
TYPE: "const",
VAL: origin,
EXISTS: true,
origin: origin,
FUNC: false,
}}
ty, _, resp := run(translated, origin, []map[string]variableValue{vars, fileparams, variables})
if ty != nil {
if ty == "error" {
return nil, resp[len(resp)-1][0]
}
return nil, fmt.Sprint(ty) + " at top level"
}
return resp, nil
}
+484 -146
View File
@@ -2,26 +2,25 @@ package main
import (
"fmt"
"log"
"math"
"reflect"
"path/filepath"
"strconv"
"strings"
)
var runop func(codeseg any, vargroups []map[string]variableValue) (any, any)
var runop func(codeseg any, origin string, vargroups []map[string]variableValue) (any, any)
func init() {
runop = runprocess
}
func run(lines []any, vargroups []map[string]variableValue) (any, any, [][]any) {
func run(lines []any, origin string, vargroups []map[string]variableValue) (any, any, [][]any) {
output := ([][]any{})
for i := 0; i < len(lines); i++ {
if lines[i] != nil {
val, ty := runprocess(lines[i], vargroups)
val, ty := runprocess(lines[i], origin, vargroups)
output = append(output, []any{val, ty})
if ty == "return" || ty == "break" || ty == "continue" {
if ty == "return" || ty == "break" || ty == "continue" || ty == "error" {
return ty, val, output
}
}
@@ -38,7 +37,15 @@ func anyToArgon(x any, quote bool) string {
return strconv.Quote(x)
}
case float64:
return fmt.Sprint(x)
if math.IsNaN(x) {
return "NaN"
} else if math.IsInf(x, 1) {
return "infinity"
} else if math.IsInf(x, -1) {
return "-infinity"
} else {
return strconv.FormatFloat(x, 'f', -1, 64)
}
case bool:
if x {
return "yes"
@@ -53,17 +60,24 @@ func anyToArgon(x any, quote bool) string {
output = append(output, anyToArgon(x[i], true))
}
return "[" + strings.Join(output, ", ") + "]"
case variable:
return x.variable
case builtinFunc:
return fmt.Sprint("<function ", x.name, ">")
case callableFunction:
if x.name != nil {
return fmt.Sprint("<function ", x.name, ">")
} else {
return "<anonymous function>"
}
default:
return fmt.Sprint(x)
}
}
func runprocess(codeseg any, vargroups []map[string]variableValue) (any, any) {
func runprocess(codeseg any, origin string, vargroups []map[string]variableValue) (any, any) {
switch codeseg := codeseg.(type) {
case opperator:
return runOperator(codeseg, vargroups), "opperator"
resp, ty := runOperator(codeseg, vargroups, origin)
return resp, ty
case variable:
var varigroup map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
@@ -77,66 +91,182 @@ func runprocess(codeseg any, vargroups []map[string]variableValue) (any, any) {
myvar = vargroups[len(vargroups)-1][codeseg.variable]
}
if myvar.EXISTS != nil {
if myvar.TYPE != "func" && myvar.TYPE != "init_function" {
return myvar.VAL, "value"
} else {
return codeseg, "value"
}
return myvar.VAL, "value"
}
log.Fatal("undecared variable " + codeseg.variable + " on line " + fmt.Sprint(codeseg.line+1))
return ("undecared variable " + codeseg.variable + ": " + origin + ":" + fmt.Sprint(codeseg.line+1)), "error"
case funcCallType:
return callFunc(codeseg, vargroups), "value"
resp, ty := callFunc(codeseg, vargroups, origin)
return resp, ty
case errorType:
resp, _ := runprocess(codeseg.val, origin, vargroups)
return resp, "error"
case itemsType:
vals := []any{}
for i := 0; i < len(codeseg.vals); i++ {
resp, _ := runprocess(codeseg.vals[i], vargroups)
resp, err := runprocess(codeseg.vals[i], origin, vargroups)
if err != nil {
return "invalid value: " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
}
vals = append(vals, resp)
}
return vals, "value"
case tryType:
ty, resp, _ := run(codeseg.code, origin, append(vargroups, map[string]variableValue{}))
if ty == "error" {
ty, resp, _ := run(codeseg.catch, origin, append(vargroups, map[string]variableValue{"err": {
TYPE: "var",
EXISTS: true,
VAL: resp,
FUNC: false,
}}))
return resp, ty
}
return resp, ty
case whileLoop:
whileloop := codeseg
resp, _ := runop(whileloop.condition, vargroups)
resp, ty := runop(whileloop.condition, origin, vargroups)
if ty == "error" {
return resp, ty
}
vari := append(vargroups, map[string]variableValue{})
for boolean(resp) {
ty, val, _ := run(whileloop.code, vargroups)
ty, val, _ := run(whileloop.code, origin, vari)
if ty == "break" {
break
} else if ty == "continue" {
continue
} else if ty == "return" {
} else if ty == "return" || ty == "error" {
return val, ty
}
resp, _ = runop(whileloop.condition, vargroups)
resp, ty = runop(whileloop.condition, origin, vargroups)
if ty == "error" {
return resp, ty
}
}
return nil, nil
case ifstatement:
vari := append(vargroups, map[string]variableValue{})
iff := codeseg
resp, _ := runop(iff.condition, vargroups)
if boolean(resp) {
ty, val, _ := run(iff.TRUE, vargroups)
return val, ty
} else {
ty, val, _ := run(iff.FALSE, vargroups)
return val, ty
for i := 0; i < len(iff.statments); i++ {
resp, ty := runop(iff.statments[i].condition, origin, vargroups)
if ty == "error" {
return resp, ty
}
if boolean(resp) {
ty, val, _ := run(iff.statments[i].code, origin, vari)
return val, ty
}
}
ty, val, _ := run(iff.FALSE, origin, vari)
return val, ty
case importType:
importMod((codeseg.path).(string))
resp, ty := runop(codeseg.path, origin, vargroups)
if ty == "error" {
return resp, ty
}
importvars, err := importMod(fmt.Sprint(resp), filepath.Dir(origin), false)
if err != nil {
return err, "error"
}
if codeseg.toImport == nil {
for name, val := range importvars {
vargroups[len(vargroups)-1][name] = val
}
} else {
var toImport = codeseg.toImport.([]string)
for i := 0; i < len(toImport); i++ {
vargroups[len(vargroups)-1][toImport[i]] = importvars[toImport[i]]
}
}
return nil, nil
case setVariable:
setVariableVal(codeseg, vargroups)
return nil, nil
value := setVariableVal(codeseg, vargroups, origin)
if value == nil {
return nil, nil
} else {
return value, "error"
}
case setFunction:
setFunctionVal(codeseg, vargroups)
return nil, nil
value := setFunctionVal(codeseg, vargroups, origin)
if value == nil {
return nil, nil
} else {
return value, "error"
}
case indexType:
to, ty := runop(codeseg.to, origin, vargroups)
if ty == "error" {
return to, ty
}
index, ty := runop(codeseg.index, origin, vargroups)
if ty == "error" {
return to, ty
}
switch value := to.(type) {
case string:
index, err := number(index)
if err != nil {
return err, "error"
}
i := int(index)
if i >= len(value) {
return "index out of range on line " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
} else if i < 0 {
i = len(value) + i
}
return string(value[i]), "value"
case []any:
index, err := number(index)
if err != nil {
return err, "error"
}
i := int(index)
if i >= len(value) {
return "index out of range on line " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
} else if i < 0 {
i = len(value) + i
}
return value[i], "value"
case map[string]any:
key := fmt.Sprint(index)
if value[key] == nil {
return "'" + key + "' not in value on line " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
}
return value[key], "value"
default:
return "value not indexable " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
}
case returnType:
var val any = nil
var ty any = "return"
if codeseg.val != nil {
vars, worked := runop(codeseg.val, vargroups)
vars, worked := runop(codeseg.val, origin, vargroups)
if worked == nil {
log.Fatal("return statement must return a value on line " + fmt.Sprint(codeseg.line+1))
return "return statement must return a value: " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
} else if worked == "error" {
return vars, "error"
}
val = vars
}
return val, "return"
return val, ty
case deleteType:
var varigroup map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][codeseg.variable.variable].EXISTS != nil {
varigroup = vargroups[i]
break
}
}
if varigroup[codeseg.variable.variable].EXISTS == nil {
varigroup = vargroups[len(vargroups)-1]
}
if varigroup[codeseg.variable.variable].EXISTS != nil {
delete(varigroup, codeseg.variable.variable)
return nil, nil
}
return "undeclared variable " + codeseg.variable.variable + ": " + origin + ":" + fmt.Sprint(codeseg.line+1), "error"
case breakType:
return nil, "break"
case continueType:
@@ -145,37 +275,25 @@ func runprocess(codeseg any, vargroups []map[string]variableValue) (any, any) {
return codeseg, "value"
}
func callFunc(call funcCallType, vargroups []map[string]variableValue) any {
var variables map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][call.name].EXISTS != nil {
variables = vargroups[i]
break
}
func callFunc(call funcCallType, vargroups []map[string]variableValue, origin string) (any, any) {
resp, ty := runprocess(call.FUNC, origin, vargroups)
if ty == "error" {
return resp, ty
}
if variables[call.name].EXISTS == nil {
log.Fatal("undecared function '" + call.name + "' on line " + fmt.Sprint(call.line+1))
}
callable := call
for variables[callable.name].TYPE != "func" && vars[callable.name].TYPE != "init_function" && fmt.Sprint(reflect.TypeOf(variables[callable.name].VAL)) == "main.variable" {
callable = funcCallType{name: variables[callable.name].VAL.(variable).variable, args: callable.args, line: callable.line}
}
if variables[callable.name].TYPE != "func" && variables[callable.name].TYPE != "init_function" {
log.Fatal("'" + call.name + "' is not a function on line " + fmt.Sprint(call.line+1))
}
if vars[callable.name].FUNC {
argvals := []any{}
for i := 0; i < len(callable.args); i++ {
resp, _ := runprocess(callable.args[i], vargroups)
argvals = append(argvals, resp)
switch variable := resp.(type) {
case callableFunction:
if len(call.args) != len(variable.args) {
return "invalid number of arguments: " + origin + ":" + fmt.Sprint(call.line+1), "error"
}
return vars[callable.name].VAL.(func(...any) any)(argvals...)
} else {
argvars := make(map[string]variableValue)
for i := 0; i < len(callable.args); i++ {
resp, _ := runprocess(callable.args[i], vargroups)
name := variables[callable.name].VAL.(setFunction).args[i]
for i := 0; i < len(variable.args); i++ {
resp, ty := runprocess(call.args[i], origin, vargroups)
if ty == "error" {
return resp, ty
}
name := variable.args[i]
argvars[name] = variableValue{
VAL: resp,
TYPE: "var",
@@ -183,44 +301,98 @@ func callFunc(call funcCallType, vargroups []map[string]variableValue) any {
FUNC: false,
}
}
ty, val, _ := run(vars[callable.name].VAL.(setFunction).code, append(vargroups, argvars))
if ty != "return" && ty != nil {
log.Fatal(ty, " is not allowed in top level of function on line ", (callable.line + 1))
ty, val, _ := run(variable.code, origin, append(variable.vargroups, argvars))
if ty != "return" && ty != "error" && ty != nil {
return fmt.Sprint(ty) + " is not allowed in function: " + origin + ":" + fmt.Sprint(variable.line+1), "error"
} else if ty == "error" {
return val, ty
}
return val
return val, "value"
case builtinFunc:
argvals := []any{}
for i := 0; i < len(call.args); i++ {
resp, ty := runprocess(call.args[i], origin, vargroups)
if ty == "error" {
return resp, ty
}
argvals = append(argvals, resp)
}
val, err := variable.FUNC(argvals...)
if err != nil {
return err, "error"
}
return val, "value"
default:
return ("value is not a function: " + origin + ":" + fmt.Sprint(call.line+1)), "error"
}
}
func setVariableVal(x setVariable, vargroups [](map[string]variableValue)) {
var variable map[string]variableValue = nil
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][x.variable].EXISTS != nil {
variable = vargroups[i]
break
}
func isCallableFunc(x any) bool {
switch x.(type) {
case callableFunction:
return true
default:
return false
}
if variable[x.variable].EXISTS == nil {
resp, _ := runop(x.value, vargroups)
vargroups[len(vargroups)-1][x.variable] = variableValue{
TYPE: x.TYPE,
EXISTS: true,
VAL: resp,
FUNC: false,
}
} else if variable[x.variable].TYPE == "var" {
resp, _ := runop(x.value, vargroups)
variable[x.variable] = variableValue{
TYPE: x.TYPE,
EXISTS: variable[x.variable].EXISTS,
VAL: resp,
FUNC: variable[x.variable].FUNC,
}
func setVariableVal(x setVariable, vargroups [](map[string]variableValue), origin string) any {
var variable map[string]variableValue = nil
if x.TYPE == "preset" {
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][x.variable.variable].EXISTS != nil {
variable = vargroups[i]
break
}
}
} else {
log.Fatal("cannot edit " + variable[x.variable].TYPE + " variable on line " + fmt.Sprint(x.line+1))
variable = vargroups[len(vargroups)-1]
}
if variable[x.variable.variable].EXISTS == nil {
var val any
var TYPE = x.TYPE
if isCallableFunc(x.value) {
val = x.value
} else {
resp, ty := runop(x.value, origin, vargroups)
if ty == "error" {
return resp
}
val = resp
if TYPE == "preset" {
TYPE = "var"
}
}
vargroups[len(vargroups)-1][x.variable.variable] = variableValue{
TYPE: TYPE,
EXISTS: true,
VAL: val,
origin: origin,
FUNC: false,
}
} else if variable[x.variable.variable].TYPE == "var" {
resp, ty := runop(x.value, origin, vargroups)
if ty == "error" {
return resp
}
var TYPE = x.TYPE
if TYPE == "preset" {
TYPE = "var"
}
variable[x.variable.variable] = variableValue{
TYPE: TYPE,
EXISTS: variable[x.variable.variable].EXISTS,
VAL: resp,
origin: origin,
FUNC: variable[x.variable.variable].FUNC,
}
} else {
return ("cannot edit " + variable[x.variable.variable].TYPE + " variable: " + origin + ":" + fmt.Sprint(x.line+1))
}
return nil
}
func setFunctionVal(x setFunction, vargroups []map[string]variableValue) {
func setFunctionVal(x setFunction, vargroups []map[string]variableValue, origin string) any {
var variable map[string]variableValue
for i := len(vargroups) - 1; i >= 0; i-- {
if vargroups[i][x.name].EXISTS != nil {
@@ -228,23 +400,26 @@ func setFunctionVal(x setFunction, vargroups []map[string]variableValue) {
break
}
}
x.FUNC.vargroups = vargroups
if variable[x.name].EXISTS == nil {
vargroups[len(vargroups)-1][x.name] = variableValue{
TYPE: "func",
TYPE: "var",
EXISTS: true,
VAL: x,
VAL: x.FUNC,
FUNC: false,
origin: origin,
}
} else if vars[x.name].TYPE == "func" {
} else if variable[x.name].TYPE == "var" {
vari := variable[x.name]
vari.VAL = x
vari.FUNC = false
} else {
log.Fatal("cannot edit " + vars[x.name].TYPE + " variable on line " + fmt.Sprint(x.line+1))
return ("cannot edit " + variable[x.name].TYPE + " variable: " + origin + ":" + fmt.Sprint(x.line+1))
}
return nil
}
func dynamicAdd(x any, y any) any {
func dynamicAdd(x any, y any) (any, any) {
stringconvert := false
switch x.(type) {
case string:
@@ -255,11 +430,17 @@ func dynamicAdd(x any, y any) any {
stringconvert = true
}
if stringconvert {
return fmt.Sprint(x) + fmt.Sprint(y)
return fmt.Sprint(x) + fmt.Sprint(y), nil
}
xnum := number(x)
ynum := number(y)
return xnum + ynum
xnum, err := number(x)
if err != nil {
return err, "error"
}
ynum, err := number(y)
if err != nil {
return err, "error"
}
return xnum + ynum, nil
}
func xiny(x any, y []any) bool {
@@ -275,36 +456,39 @@ func boolean(x any) bool {
return (x != false && x != nil && x != 0 && x != "")
}
func number(x any) float64 {
func number(x any) (float64, any) {
switch x := x.(type) {
case float64:
return x
return x, nil
case float32:
return float64(x)
return float64(x), nil
case int:
return float64(x)
return float64(x), nil
case bool:
if x {
return 1
return 1, nil
} else {
return 0
return 0, nil
}
default:
num, err := strconv.ParseFloat(fmt.Sprint(x), 64)
if err != nil {
log.Fatal(err)
return 0, (err)
}
return num
return num, nil
}
}
func runOperator(opperation opperator, vargroups []map[string]variableValue) any {
func runOperator(opperation opperator, vargroups []map[string]variableValue, origin string) (any, any) {
var output any
opperationloop:
for i := 0; i < len(opperation.vals); i++ {
switch opperation.t {
case 0:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
@@ -316,124 +500,278 @@ opperationloop:
}
}
case 1:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if boolean(x) {
output = x
break opperationloop
}
case 2:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = xiny(output, x.([]any))
}
case 3:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = !xiny(output, x.([]interface{}))
}
case 4:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (number(output) <= number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out <= in)
}
case 5:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (number(output) >= number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out >= in)
}
case 6:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (number(output) < number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out < in)
}
case 7:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (number(output) > number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out > in)
}
case 8:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (output != x)
}
case 9:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (output == x)
}
case 11:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (number(output) - number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out - in)
}
case 10:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = dynamicAdd(output, x)
val, err := dynamicAdd(output, x)
if err != nil {
return 0, (err)
}
output = val
}
case 12:
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = (number(output) * number(x))
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
case 13:
x, _ := runop(opperation.vals[i], vargroups)
if output == nil {
output = x
} else {
output = math.Floor(number(output) / number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out * in)
}
case 14:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = math.Mod(number(output), number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = math.Floor(out / in)
}
case 13:
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = math.Mod(out, in)
}
case 15:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = (number(output) / number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = (out / in)
}
case 16:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = math.Pow(number(output), 1/number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = math.Pow(out, 1/in)
}
case 17:
x, _ := runop(opperation.vals[i], vargroups)
x, ty := runop(opperation.vals[i], origin, vargroups)
if ty == "error" {
return x, ty
}
if output == nil {
output = x
} else {
output = math.Pow(number(output), number(x))
out, err := number(output)
if err != nil {
return 0, (err)
}
in, err := number(x)
if err != nil {
return 0, (err)
}
output = math.Pow(out, in)
}
}
}
return output
return output, "opperator"
}
+22 -11
View File
@@ -1,28 +1,39 @@
package main
import "fmt"
import (
"fmt"
"os"
)
func shell() {
fmt.Println("Argon Shell\nMIT License\n\nCopyright (c) 2022 William Bell\ncall 'license' for license information\n ")
indent := 0
temp := ""
ex, err := os.Getwd()
if err != nil {
panic(err)
}
variables := map[string]variableValue{}
for {
tempstr := ""
if indent >= 0 {
tempstr = ArgonInput("> ").(string) + "\n"
val, _ := ArgonInput("> ")
tempstr = val.(string)
} else {
tempstr = ArgonInput("... ").(string) + "\n"
val, _ := ArgonInput("... ")
tempstr = val.(string)
}
if !switchCloseCompile.MatchString(tempstr) {
if openCompile.MatchString(tempstr) {
indent--
} else if closeCompile.MatchString(tempstr) {
indent++
}
if opensIndent(tempstr) {
indent--
} else if closeCompile.MatchString(tempstr) {
indent++
}
temp += tempstr
temp += tempstr + "\n"
if indent >= 0 {
resp := runStr(temp)
resp, err := runStr(temp, ex, variables)
if err != nil {
fmt.Println(err)
}
for i := 0; i < len(resp); i++ {
if resp[i][1] != nil {
fmt.Println(anyToArgon(resp[i][0], false))
+13 -4
View File
@@ -7,10 +7,19 @@ completed:
- allow functions parameters to be passed in
- create sub return values
- make local variables that delete after the function finishes
incompleted:
- books (objects)
- add math module
- import
- selective importing
- fix close square bracket not being allowed in open indentation
- items (arrays)
- add else if to if statments
- add try catch
- fix close square bracket not being allowed in open indentation
incompleted:
- books (objects)
- add del to delete variables
- add origin to translate.go
- add edit variable assignment
- allow negetive variables without needing 0 in front (e.g. -x instead of 0-x)
- add index and key to variable assignment and reading
- fix atan function in maths module
+427 -123
View File
@@ -2,36 +2,41 @@ package main
import (
"fmt"
"log"
"strconv"
"strings"
)
var anyAndNewline = "((.)|(\\n))"
var variableOnly = "([a-zA-Z_])([a-zA-Z0-9_])*"
var variableWithIndexes = variableOnly + "(\\[" + anyAndNewline + "+\\]|\\." + variableOnly + ")*"
var stringCompile = makeRegex("(( *)\"((\\\\([a-z\\\"'`]))|[^\\\"])*\"( *))|(( *)'((\\\\([a-z\\'\"`]))|[^\\'])*'( *))|(( *)(`(\\\\[a-z\\\"'`\\n]|[^\\`])*`)( *))")
var numberCompile = makeRegex("( *)(\\-)?(([0-9]+(\\.[0-9]+)?)(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
var numberCompile = makeRegex("( *)(\\-)?(([0-9]*(\\.[0-9]+)?)(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)( *)")
var whileCompile = makeRegex("( *)(while( )+" + anyAndNewline + "+( )+\\[" + anyAndNewline + "*)( *)")
var subCompile = makeRegex("( *)(sub( )+" + variableOnly + "\\(" + anyAndNewline + "*\\)( )+\\[" + anyAndNewline + "*)( *)")
var ifCompile = makeRegex("( *)(if( )+" + anyAndNewline + "+( )+\\[" + anyAndNewline + "*)( *)")
var elseifCompile = makeRegex("( *)(\\] else if " + anyAndNewline + "+ \\[" + anyAndNewline + "*)( *)")
var openCompile = makeRegex("( *)(" + anyAndNewline + "+( )+\\[([^\\]])*)( *)")
var elseCompile = makeRegex("( *)\\] else \\[" + anyAndNewline + "*( *)")
var elseifCompile = makeRegex("( *)(\\]( )+else( )+if( )+" + anyAndNewline + "+( )+\\[" + anyAndNewline + "*)( *)")
var elseCompile = makeRegex("( *)\\]( )+else( )+\\[" + anyAndNewline + "*( *)")
var closeCompile = makeRegex("( *)\\]( *)")
var switchCloseCompile = makeRegex("( *)" + anyAndNewline + "*\\]" + anyAndNewline + "*\\[" + anyAndNewline + "*( *)")
var importCompile = makeRegex("( *)import " + anyAndNewline + "+( *)")
var importCompile = makeRegex("( *)((import " + anyAndNewline + "+)|(from( +)" + anyAndNewline + "+( +)import( +)(( *)" + variableOnly + "( *)(\\,( *)" + variableOnly + "( *))*)))( *)")
var bracketsCompile = makeRegex("( *)\\(" + anyAndNewline + "*\\)( *)")
var functionCompile = makeRegex("( *)" + variableOnly + "\\(" + anyAndNewline + "*\\)( *)")
var variableTextCompile = makeRegex("( *)" + variableOnly + "( *)")
var functionCompile = makeRegex("( *)" + anyAndNewline + "+\\(" + anyAndNewline + "*\\)( *)")
var indexCompile = makeRegex("( *)" + anyAndNewline + "+\\[" + anyAndNewline + "+\\]( *)")
var variableTextCompile = makeRegex("( *)" + variableWithIndexes + "( *)")
var variableonlyCompile = makeRegex(variableOnly)
var setVariableCompile = makeRegex("( *)(((const|var) (" + variableOnly + "( *))=( *).+)|(( *)" + variableOnly + "( *))(( *)=( *).+))( *)")
var setVariableCompile = makeRegex("( *)(((const|var) (" + variableOnly + "( *))=( *)" + anyAndNewline + "+)|(( *)" + variableOnly + "( *))(( *)=( *)" + anyAndNewline + "+))( *)")
var callErrorCompile = makeRegex("( *)(error(( )+" + anyAndNewline + "+))( *)")
var returnStatementCompile = makeRegex("( *)(return(( )+" + anyAndNewline + "*)?)( *)")
var deleteStatmentCompile = makeRegex("( *)(delete( )+" + variableWithIndexes + ")( *)")
var itemsCompiled = makeRegex("( *)(\\[" + anyAndNewline + "*\\])( *)")
var breakStatementCompile = makeRegex("( *)break( *)")
var continueStatementCompile = makeRegex("( *)continue( *)")
var skipCompile = makeRegex("( *)(#(.*))?")
var processfunc func(codeseg code) (interface{}, bool)
var linefunc func(i int, codearray []code) (interface{}, int)
var tryCompile = makeRegex("( *)(try( )+\\[" + anyAndNewline + "*)( *)")
var catchCompile = makeRegex("( *)(\\]( )+catch( )+\\[" + anyAndNewline + "*)( *)")
var negetiveCompile = makeRegex("( *)(\\-" + anyAndNewline + "+)( *)")
var processfunc func(codeseg code) (any, bool, any)
var linefunc func(i int, codearray []code) (any, int, any)
var opperators = [][]string{
{
"&&",
@@ -55,6 +60,7 @@ var opperators = [][]string{
}, {
">=",
" is bigger than or equal to ",
" is greater than or equal to ",
" is more than or equal to ",
}, {
"<",
@@ -63,6 +69,7 @@ var opperators = [][]string{
}, {
">",
" is bigger than ",
" is greater than ",
" is more than ",
}, {
"!=",
@@ -115,19 +122,26 @@ var opperators = [][]string{
"**",
}}
func opensIndent(str string) bool {
return tryCompile.MatchString(str) || ifCompile.MatchString(str) || whileCompile.MatchString(str) || subCompile.MatchString(str)
}
func init() {
processfunc = translateprocess
linefunc = translateline
}
func getValuesFromCommas(str string, line int) ([]any, bool) {
func getValuesFromCommas(str string, line int) ([]any, bool, any) {
output := []any{}
temp := []byte{}
stringlen := len(str)
for i := 0; i < stringlen; i++ {
if str[i] == 44 {
tempstr := string(temp[:])
resp, worked := processfunc(code{code: tempstr, line: 0})
resp, worked, err := processfunc(code{code: tempstr, line: line})
if err != nil {
return nil, false, err
}
if worked {
output = append(output, resp)
temp = []byte{}
@@ -138,14 +152,17 @@ func getValuesFromCommas(str string, line int) ([]any, bool) {
}
tempstr := string(temp[:])
if tempstr != "" {
resp, worked := processfunc(code{code: tempstr, line: 0})
resp, worked, err := processfunc(code{code: tempstr, line: line})
if err != nil {
return nil, false, err
}
if worked {
output = append(output, resp)
} else {
return nil, false
return nil, false, nil
}
}
return output, true
return output, true, nil
}
// make a function that converts backslashes in a string to their correct character
@@ -189,10 +206,11 @@ func unescape(str string) string {
output = append(output, 39)
case 92:
output = append(output, 92)
case 117:
if i+4 < stringlen {
i += 4
output = append(output, byte(int(str[i])*16*16*16+int(str[i+1])*16*16+int(str[i+2])*16+int(str[i+3])))
case 85:
val, err := strconv.Unquote(`"\U` + str[i+1:i+9] + `"`)
if err == nil {
output = append(output, val...)
i += 8
}
}
}
@@ -203,7 +221,7 @@ func unescape(str string) string {
return string(output[:])
}
func getParamNames(str string, line int) []string {
func getParamNames(str string, line int) ([]string, any) {
output := []string{}
temp := []byte{}
stringlen := len(str)
@@ -211,7 +229,7 @@ func getParamNames(str string, line int) []string {
if str[i] == 44 {
tempstr := strings.Trim(string(temp[:]), " ")
if !variableonlyCompile.MatchString(tempstr) {
log.Fatal("invalid param name on line", line+1)
return nil, ("invalid param name on line" + fmt.Sprint(line+1))
}
output = append(output, tempstr)
temp = []byte{}
@@ -223,25 +241,19 @@ func getParamNames(str string, line int) []string {
if variableonlyCompile.MatchString(tempstr) {
output = append(output, tempstr)
}
return output
return output, nil
}
func split_by_semicolon_and_newline(str string) []code {
output := []code{}
temp := []byte{}
split := strings.Split(strings.ReplaceAll(str, "\r", ""), "\n")
splitoutput := []string{}
for i := 0; i < len(split); i++ {
if !(skipCompile.MatchString(split[i])) {
splitoutput = append(splitoutput, split[i])
}
}
str = strings.Join(splitoutput, "\n")
stringlen := len(str)
line := 0
quote := false
backtick := false
speech := false
str = strings.ReplaceAll(str, "\r", "")
stringlen := len(str)
for i := 0; i < stringlen; i++ {
if str[i] == 34 && (len(temp) == 0 || str[i-1] != 92) && !speech && !backtick {
@@ -265,31 +277,35 @@ func split_by_semicolon_and_newline(str string) []code {
return output
}
var getCodeInIndent = func(i int, codearray []code, isIf bool) ([]code, int) {
var getCodeInIndent = func(i int, codearray []code, TYPE string) ([]code, int, any) {
var result []code
indent := 0
start := codearray[i]
result = append(result, code{
code: strings.SplitN(codearray[i].code, "[", 2)[1],
line: codearray[i].line,
})
i++
for {
if (closeCompile.MatchString(codearray[i].code) && !switchCloseCompile.MatchString(codearray[i].code)) || (isIf && (elseCompile.MatchString(codearray[i].code) || elseifCompile.MatchString(codearray[i].code))) {
if i == len(codearray) {
return nil, 0, ("invalid opening brackets starting on line " + fmt.Sprint(start.line+1) + ": " + start.code)
}
if (TYPE != "try" && closeCompile.MatchString(codearray[i].code) && !setVariableCompile.MatchString(codearray[i].code) && !switchCloseCompile.MatchString(codearray[i].code)) || (TYPE == "if" && (elseCompile.MatchString(codearray[i].code) || elseifCompile.MatchString(codearray[i].code)) || (TYPE == "try" && catchCompile.MatchString(codearray[i].code))) {
indent--
if indent < 0 {
break
}
} else if openCompile.MatchString(codearray[i].code) && !switchCloseCompile.MatchString(codearray[i].code) {
} else if opensIndent(codearray[i].code) {
indent++
}
result = append(result, codearray[i])
i++
}
i++
return result, i
return result, i, nil
}
var translateprocess = func(codeseg code) (interface{}, bool) {
var translateprocess = func(codeseg code) (any, bool, any) {
for i := 0; i < len(opperators); i++ {
for j := 0; j < len(opperators[i]); j++ {
split := strings.Split(codeseg.code, opperators[i][j])
@@ -298,7 +314,7 @@ var translateprocess = func(codeseg code) (interface{}, bool) {
current := 0
for k := 0; k < len(split); k++ {
currentstr := strings.Join(split[current:k], opperators[i][j])
val, worked := processfunc(code{
val, worked, _ := processfunc(code{
code: currentstr,
line: codeseg.line,
})
@@ -309,10 +325,13 @@ var translateprocess = func(codeseg code) (interface{}, bool) {
}
if len(vals) >= 1 {
currentstr := strings.Join(split[current:], opperators[i][j])
val, worked := processfunc(code{
val, worked, err := processfunc(code{
code: currentstr,
line: codeseg.line,
})
if err != nil {
return nil, false, err
}
if worked {
vals = append(vals, val)
@@ -320,69 +339,158 @@ var translateprocess = func(codeseg code) (interface{}, bool) {
t: i,
vals: vals,
line: codeseg.line,
}, true
} else if len(opperators) == i+1 {
return nil, false
}, true, nil
}
}
}
}
}
if stringCompile.MatchString(codeseg.code) {
return unescape(stringencode(codeseg.code)), true
return unescape(stringencode(codeseg.code)), true, nil
} else if negetiveCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
val, worked, err := processfunc(code{
code: str[1:],
line: codeseg.line,
})
if err != nil {
return val, worked, err
}
if !worked {
return nil, false, "invalid value on line " + fmt.Sprint(codeseg.line+1)
}
return opperator{
t: 11,
vals: []any{0, val},
line: codeseg.line,
}, true, nil
} else if functionCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
bracketsplit := strings.SplitN(str, "(", 2)
funcname := strings.Trim(bracketsplit[0], " ")
params := bracketsplit[1][:len(bracketsplit[1])-1]
paramstranslated, worked := getValuesFromCommas(params, codeseg.line)
indent := 0
output := []byte{}
for i := len(str) - 2; i >= 0; i-- {
if str[i] == ')' {
indent++
} else if str[i] == '(' {
indent--
if indent < 0 {
break
}
}
output = append([]byte{str[i]}, output...)
}
params := string(output[:])
paramstranslated, worked, err := getValuesFromCommas(params, codeseg.line)
if !worked {
return nil, false, "invalid params on line " + fmt.Sprint(codeseg.line+1)
}
if err != nil {
return nil, false, err
}
FUNC, worked, err := processfunc(code{
code: str[:len(str)-len(params)-2],
line: codeseg.line,
})
if !worked {
return nil, false, "invalid value on line " + fmt.Sprint(codeseg.line+1)
}
if err != nil {
return nil, false, err
}
if worked {
return funcCallType{
name: funcname,
FUNC: FUNC,
args: paramstranslated,
line: codeseg.line,
}, true
}, true, nil
}
} else if bracketsCompile.MatchString(codeseg.code) {
shorter := strings.Trim(codeseg.code, " ")
shorter = shorter[1 : len(shorter)-1]
brackets, ran := processfunc(code{
brackets, ran, err := processfunc(code{
code: shorter,
line: codeseg.line,
})
return brackets, ran
return brackets, ran, err
} else if itemsCompiled.MatchString(codeseg.code) {
inside := strings.Trim(codeseg.code, " ")[1 : len(strings.Trim(codeseg.code, " "))-1]
vals, worked := getValuesFromCommas(inside, codeseg.line)
vals, worked, err := getValuesFromCommas(inside, codeseg.line)
if err != nil {
return nil, false, err
}
if worked {
return itemsType{
vals: vals,
line: codeseg.line,
}, true
}, true, nil
}
} else if indexCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
indent := 0
output := []byte{}
for i := len(str) - 2; i >= 0; i-- {
if str[i] == ']' {
indent++
} else if str[i] == '[' {
indent--
if indent < 0 {
break
}
}
output = append([]byte{str[i]}, output...)
}
value := string(output[:])
resp, worked, err := processfunc(code{
code: value,
line: codeseg.line,
})
if !worked {
return nil, false, "invalid index value on line " + fmt.Sprint(codeseg.line+1)
}
if err != nil {
return nil, false, err
}
index := resp
resp, worked, err = processfunc(code{
code: str[:len(str)-len(value)-2],
line: codeseg.line,
})
if !worked {
return nil, false, "invalid value on line " + fmt.Sprint(codeseg.line+1)
}
if err != nil {
return nil, false, err
}
return indexType{
to: resp,
index: index,
line: codeseg.line,
}, true, nil
} else if numberCompile.MatchString(codeseg.code) {
if s, err := strconv.ParseFloat(strings.Trim(codeseg.code, " "), 64); err == nil {
return s, true
return s, true, nil
} else {
log.Fatal(err)
return nil, false, err
}
} else if variableTextCompile.MatchString(codeseg.code) {
return variable{
variable: strings.Trim(codeseg.code, " "),
line: codeseg.line,
}, true
}, true, nil
}
return nil, false
return nil, false, nil
}
var translateline = func(i int, codearray []code) (interface{}, int) {
var translateline = func(i int, codearray []code) (any, int, any) {
codeseg := codearray[i]
if returnStatementCompile.MatchString(codeseg.code) {
var val any = strings.Trim(codeseg.code, " ")[6:]
if val != "" {
respval, worked := translateprocess(code{code: val.(string), line: codeseg.line})
if !worked {
log.Fatal("invalid value on line ", codeseg.line+1)
respval, worked, err := translateprocess(code{code: val.(string), line: codeseg.line})
if !worked || err != nil {
return nil, 0, ("invalid value on line " + fmt.Sprint(codeseg.line+1))
}
val = respval
} else {
@@ -391,99 +499,232 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
return returnType{
val: val,
line: codeseg.line,
}, i + 1
}, i + 1, nil
} else if breakStatementCompile.MatchString(codeseg.code) {
return breakType{
line: codeseg.line,
}, i + 1
}, i + 1, nil
} else if continueStatementCompile.MatchString(codeseg.code) {
return continueType{
line: codeseg.line,
}, i + 1
}
resp, worked := translateprocess(codeseg)
if worked {
return resp, i + 1
}, i + 1, nil
} else if skipCompile.MatchString(codeseg.code) {
return nil, i + 1, nil
} else if setVariableCompile.MatchString(codeseg.code) {
VAR := strings.Split(codeseg.code, "=")
firstSplit := strings.Split(strings.Trim(VAR[0], " "), " ")
TYPE := "var"
TYPE := "preset"
if len(firstSplit) > 1 {
TYPE = firstSplit[0]
}
variable := firstSplit[len(firstSplit)-1]
resp, worked := translateprocess(code{code: VAR[1],
vari := firstSplit[len(firstSplit)-1]
resp, worked, err := translateprocess(code{code: VAR[1],
line: codeseg.line})
if err != nil {
return nil, 0, err
}
if !worked {
log.Fatal("invalid value")
return nil, 0, ("invalid value on line " + fmt.Sprint(codeseg.line+1) + ": " + VAR[1])
}
return setVariable{
TYPE: TYPE,
variable: variable,
value: resp,
line: codeseg.line,
}, i + 1
TYPE: TYPE,
variable: variable{
variable: vari,
line: codeseg.line,
},
value: resp,
line: codeseg.line,
}, i + 1, nil
}
resp, worked, err := translateprocess(codeseg)
if err != nil {
return nil, 0, err
}
if worked {
return resp, i + 1, nil
} else if deleteStatmentCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
return deleteType{
variable: variable{
variable: str[7:],
line: codeseg.line,
},
line: codeseg.line,
}, i + 1, nil
} else if whileCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
strlen := len(str)
str = str[5:strlen]
split := strings.SplitN(str, "[", 2)
condition, worked := translateprocess(code{code: split[0],
condition, worked, err := translateprocess(code{code: split[0],
line: codeseg.line})
if !worked {
log.Fatal("invalid value on line", codeseg.line+1)
if err != nil {
return nil, 0, err
}
codedata, x := getCodeInIndent(i, codearray, false)
codeoutput := []interface{}{}
if !worked {
return nil, 0, ("invalid value on line " + fmt.Sprint(codeseg.line+1))
}
codedata, x, err := getCodeInIndent(i, codearray, "none")
if err != nil {
return nil, 0, err
}
codeoutput := []any{}
codelen := len(codedata)
for i := 0; i < codelen; {
resp, x := linefunc(i, codedata)
resp, x, err := linefunc(i, codedata)
if err != nil {
return nil, 0, err
}
i = x
codeoutput = append(codeoutput, resp)
if resp != nil {
codeoutput = append(codeoutput, resp)
}
}
return whileLoop{
condition: condition,
code: codeoutput,
}, x
}, x, nil
} else if tryCompile.MatchString(codeseg.code) {
codedata, x, err := getCodeInIndent(i, codearray, "try")
if err != nil {
return nil, 0, err
}
codeoutput := []any{}
codelen := len(codedata)
for i := 0; i < codelen; {
resp, x, err := linefunc(i, codedata)
if err != nil {
return nil, 0, err
}
i = x
if resp != nil {
codeoutput = append(codeoutput, resp)
}
}
catchdata, x, err := getCodeInIndent(x-1, codearray, "none")
if err != nil {
return nil, 0, err
}
catchoutput := []any{}
catchlen := len(catchdata)
for i := 0; i < catchlen; {
resp, x, err := linefunc(i, catchdata)
if err != nil {
return nil, 0, err
}
i = x
if resp != nil {
catchoutput = append(catchoutput, resp)
}
}
return tryType{
code: codeoutput,
catch: catchoutput,
line: codeseg.line,
}, x, nil
} else if ifCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
strlen := len(str)
str = str[2:strlen]
split := strings.SplitN(str, "[", 2)
condition, worked := translateprocess(code{code: split[0],
condition, worked, err := translateprocess(code{code: split[0],
line: codeseg.line})
if !worked {
log.Fatal("invalid value on line", codeseg.line+1)
if err != nil {
return nil, 0, err
}
codedata, x := getCodeInIndent(i, codearray, true)
codeoutput := []interface{}{}
if !worked {
return nil, 0, ("invalid value on line " + fmt.Sprint(codeseg.line+1) + ": " + split[0])
}
codedata, x, err := getCodeInIndent(i, codearray, "if")
if err != nil {
return nil, 0, err
}
codeoutput := []any{}
codelen := len(codedata)
for i := 0; i < codelen; {
resp, x := linefunc(i, codedata)
resp, x, err := linefunc(i, codedata)
if err != nil {
return nil, 0, err
}
i = x
codeoutput = append(codeoutput, resp)
if resp != nil {
codeoutput = append(codeoutput, resp)
}
}
ifstatementcode := []iftype{
{
condition: condition,
code: codeoutput,
},
}
elsecode := []any{}
elsecodelen := 0
for {
if elseifCompile.MatchString(codearray[x-1].code) {
str := strings.Trim(codearray[x-1].code, " ")
str = strings.SplitN(str[1:len(str)-1], "if", 2)[1]
condition, worked, err = translateprocess(code{code: str,
line: codearray[x-1].line})
if err != nil {
return nil, 0, err
}
if !worked {
return nil, 0, "invalid value on line " + fmt.Sprint(codearray[x-1].line+1) + ": " + split[0]
}
codedata, j, err := getCodeInIndent(x-1, codearray, "if")
if err != nil {
return nil, 0, err
}
codeoutput := []any{}
x = j
codelen := len(codedata)
for i := 0; i < codelen; {
resp, x, err := linefunc(i, codedata)
if err != nil {
return nil, 0, err
}
i = x
if resp != nil {
codeoutput = append(codeoutput, resp)
}
}
ifstatementcode = append(ifstatementcode,
iftype{
condition: condition,
code: codeoutput,
})
} else {
break
}
}
if elseCompile.MatchString(codearray[x-1].code) {
codedata, x := getCodeInIndent(x-1, codearray, false)
elsecodelen = x - 3
codedata, j, err := getCodeInIndent(x-1, codearray, "none")
if err != nil {
return nil, 0, err
}
x += j - 3
codelen := len(codedata)
for i := 0; i < codelen; {
resp, x := linefunc(i, codedata)
resp, x, err := linefunc(i, codedata)
if err != nil {
return nil, 0, err
}
i = x
elsecode = append(elsecode, resp)
if resp != nil {
elsecode = append(elsecode, resp)
}
}
}
return ifstatement{
condition: condition,
TRUE: codeoutput,
statments: ifstatementcode,
FALSE: elsecode,
}, x + elsecodelen
}, x, nil
} else if subCompile.MatchString(codeseg.code) {
sub := strings.Trim(codeseg.code, " ")
sub = sub[4:]
@@ -492,48 +733,111 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
functionname := functioninfo[0]
argstr := functioninfo[1]
argstr = argstr[:len(argstr)-1]
args := getParamNames(argstr, codeseg.line)
codedata, x := getCodeInIndent(i, codearray, true)
codeoutput := []interface{}{}
args, err := getParamNames(argstr, codeseg.line)
if err != nil {
return nil, 0, err
}
codedata, x, err := getCodeInIndent(i, codearray, "none")
if err != nil {
return nil, 0, err
}
codeoutput := []any{}
codelen := len(codedata)
for i := 0; i < codelen; {
resp, x := linefunc(i, codedata)
resp, x, err := linefunc(i, codedata)
if err != nil {
return nil, 0, err
}
i = x
codeoutput = append(codeoutput, resp)
if resp != nil {
codeoutput = append(codeoutput, resp)
}
}
return setFunction{
name: functionname,
args: args,
code: codeoutput,
}, x
FUNC: callableFunction{
name: functionname,
args: args,
code: codeoutput,
line: codeseg.line,
},
line: codeseg.line,
}, x, nil
} else if importCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
path, worked := processfunc(code{code: str[7:], line: codeseg.line})
if !worked {
log.Fatal("invalid import path on line ", codeseg.line+1)
var toImport any = nil
var path any
if strings.HasPrefix(str, "import") {
if variableonlyCompile.MatchString(strings.Trim(str[7:], " ")) {
path = strings.Trim(str[7:], " ")
} else {
p, worked, err := processfunc(code{code: str[7:], line: codeseg.line})
if err != nil {
return nil, 0, err
}
path = p
if !worked {
return nil, 0, "invalid import path on line " + fmt.Sprint(codeseg.line+1)
}
}
} else {
info := strings.SplitN(str[5:], " import ", 2)
if variableonlyCompile.MatchString(strings.Trim(info[0], " ")) {
path = strings.Trim(info[0], " ")
} else {
p, worked, err := processfunc(code{code: info[0], line: codeseg.line})
if err != nil {
return nil, 0, err
}
path = p
if !worked {
return nil, 0, "invalid import path on line " + fmt.Sprint(codeseg.line+1)
}
}
toImport, err = getParamNames(info[1], codeseg.line)
if err != nil {
return nil, 0, err
}
}
return importType{
path: path,
line: codeseg.line,
}, i + 1
} else if skipCompile.MatchString(codeseg.code) {
path: path,
toImport: toImport,
line: codeseg.line,
}, i + 1, nil
} else if callErrorCompile.MatchString(codeseg.code) {
str := strings.Trim(codeseg.code, " ")
val, worked, err := processfunc(code{code: str[6:], line: codeseg.line})
if err != nil {
return nil, 0, err
}
if worked {
return errorType{
val,
}, i + 1, nil
} else {
return nil, 0, "invalid error value on line " + fmt.Sprint(codeseg.line+1)
}
} else {
err := "Invalid syntax on line "
log.Fatal("\n\nLine " + fmt.Sprint(codeseg.line+1) + ": " + codeseg.code + "\n" + err + "\n\n")
return nil, 0, ("\n\nLine " + fmt.Sprint(codeseg.line+1) + ": " + codeseg.code + "\n" + err + "\n\n")
}
return nil, i + 1
}
var translate = func(str string) []interface{} {
var translate = func(str string) ([]any, any) {
code := split_by_semicolon_and_newline(str)
codelen := len(code)
output := []interface{}{}
output := []any{}
i := 0
for i < codelen {
resp, x := translateline(i, code)
resp, x, err := translateline(i, code)
if err != nil {
return nil, err
}
i = x
output = append(output, resp)
if resp != nil {
output = append(output, resp)
}
}
return output
return output, nil
}
+60 -29
View File
@@ -1,25 +1,20 @@
package main
type variableValue struct {
TYPE string
VAL interface{}
EXISTS interface{}
FUNC bool
}
import "math"
var vars = make(map[string]variableValue)
func init() {
vars["log"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonLog,
VAL: builtinFunc{"log", ArgonLog},
FUNC: true,
}
vars["input"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonInput,
VAL: builtinFunc{"input", ArgonInput},
FUNC: true,
}
vars["yes"] = variableValue{
@@ -34,6 +29,18 @@ func init() {
VAL: false,
FUNC: false,
}
vars["infinity"] = variableValue{
TYPE: "init",
EXISTS: true,
VAL: math.Inf(1),
FUNC: false,
}
vars["NaN"] = variableValue{
TYPE: "init",
EXISTS: true,
VAL: math.NaN(),
FUNC: false,
}
vars["unknown"] = variableValue{
TYPE: "init",
EXISTS: true,
@@ -41,64 +48,88 @@ func init() {
FUNC: false,
}
vars["number"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonNumber,
VAL: builtinFunc{"number", ArgonNumber},
FUNC: true,
}
vars["whole"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonWhole,
VAL: builtinFunc{"whole", ArgonWhole},
FUNC: true,
}
vars["string"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonString,
VAL: builtinFunc{"string", ArgonString},
FUNC: true,
}
vars["license"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonLicense,
VAL: builtinFunc{"license", ArgonLicense},
FUNC: true,
}
vars["exec"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: exec,
VAL: builtinFunc{"exec", exec},
FUNC: true,
}
vars["eval"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: eval,
VAL: builtinFunc{"eval", eval},
FUNC: true,
}
vars["append"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonAppend,
VAL: builtinFunc{"append", ArgonAppend},
FUNC: true,
}
vars["extend"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonExtend,
FUNC: true,
}
vars["len"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonLen,
VAL: builtinFunc{"len", ArgonLen},
FUNC: true,
}
vars["join"] = variableValue{
TYPE: "init_function",
TYPE: "init",
EXISTS: true,
VAL: ArgonJoin,
VAL: builtinFunc{"join", ArgonJoin},
FUNC: true,
}
vars["random"] = variableValue{
TYPE: "init",
EXISTS: true,
VAL: builtinFunc{"random", ArgonRandom},
FUNC: true,
}
vars["randomSetSeed"] = variableValue{
TYPE: "init",
EXISTS: true,
VAL: builtinFunc{"randomSetSeed", ArgonSetSeed},
FUNC: true,
}
vars["time"] = variableValue{
TYPE: "init",
EXISTS: true,
VAL: builtinFunc{"time", ArgonTime},
FUNC: true,
}
vars["sleep"] = variableValue{
TYPE: "init",
EXISTS: true,
VAL: builtinFunc{"sleep", ArgonSleep},
FUNC: true,
}
}