mirror of
https://github.com/Open-Argon/argon-v2.git
synced 2026-10-28 09:44:03 +00:00
work on import modules
This commit is contained in:
1 parent
235cddafa0
commit
3aa7f0356d
13 files changed
+206
-62
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type code struct {
|
||||
@@ -27,6 +28,7 @@ func makeRegex(str string) *regexp.Regexp {
|
||||
}
|
||||
|
||||
func main() {
|
||||
ArgonSetSeed(time.Now().UnixMilli())
|
||||
if len(os.Args) == 1 {
|
||||
shell()
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import math
|
||||
|
||||
def my_sin(theta):
|
||||
theta = math.fmod(theta + math.pi, 2 * math.pi) - math.pi
|
||||
print(theta)
|
||||
result = 0
|
||||
termsign = 1
|
||||
power = 1
|
||||
|
||||
for i in range(10):
|
||||
result += (math.pow(theta, power) / math.factorial(power)) * termsign
|
||||
termsign *= -1
|
||||
power += 2
|
||||
return result
|
||||
|
||||
print(my_sin(101))
|
||||
Vendored
BIN
Binary file not shown.
@@ -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
|
||||
]
|
||||
@@ -0,0 +1,110 @@
|
||||
# THE MATH LIBRARY
|
||||
# creation date 30/6/2022
|
||||
# last modified 30/6/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)
|
||||
# logarithm(x)
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# trigonometry functions
|
||||
|
||||
sub sin(theta) [
|
||||
x = ((theta)/180) mod 1
|
||||
result = 0-(((x - 0.5)**2) * 4) + 1
|
||||
if ((theta div 180) div 1) % 2 != 0 [
|
||||
result = result * -1
|
||||
]
|
||||
return result
|
||||
]
|
||||
|
||||
sub cos(theta) [
|
||||
return sin(theta + 90)
|
||||
]
|
||||
|
||||
sub tan(theta) [
|
||||
return sin(theta) / cos(theta)
|
||||
]
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# math functions
|
||||
|
||||
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
|
||||
]
|
||||
while yes [
|
||||
guess = (last_guess + x / last_guess) / 2
|
||||
if abs(guess - last_guess) < 1e-5 [
|
||||
return guess
|
||||
]
|
||||
last_guess = guess
|
||||
]
|
||||
]
|
||||
|
||||
sub exp(x) [
|
||||
return (e**x)
|
||||
]
|
||||
|
||||
sub logarithm(x) [
|
||||
n = 1e10
|
||||
return n * ((x ** (1/n)) - 1)
|
||||
]
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# initialize math numbers
|
||||
|
||||
pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
|
||||
|
||||
e = 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907632338298807531952510190115738341879307021540891499348841675092447614606680822648001684774118537423454424371075390777449920695517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416928368190255151086574637721112523897844250569536967707854499699679468644549059879316368892300987931277361782154249992295763514822082698951936680331825288693984964651058209392398294887933203625094431173012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509961818815930416903515988885193458072738667385894228792284998920868058257492796104841984443634632449684875602336248270419786232090021609902353043699418491463140934317381436405462531520961836908887070167683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354
|
||||
|
||||
goldenRatio = (1 + sqrt(5)) / 2
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,22 @@
|
||||
# THE MATH LIBRARY
|
||||
creation date 30/6/2022
|
||||
last modified 30/6/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)
|
||||
- logarithm(x)
|
||||
+20
-1
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -87,9 +88,27 @@ func ArgonExtend(x ...any) any {
|
||||
}
|
||||
|
||||
func ArgonLen(x ...any) any {
|
||||
return len(x[0].([]any))
|
||||
switch value := x[0].(type) {
|
||||
case []any:
|
||||
return len(value)
|
||||
case string:
|
||||
return len(value)
|
||||
case map[any]any:
|
||||
return len(value)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func ArgonJoin(x ...any) any {
|
||||
return strings.Join(x[0].([]string), x[1].(string))
|
||||
}
|
||||
|
||||
func ArgonSetSeed(x ...any) any {
|
||||
rand.Seed(x[0].(int64))
|
||||
return nil
|
||||
}
|
||||
|
||||
func ArgonRandom(x ...any) any {
|
||||
return rand.Float64()
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
import "math"
|
||||
|
||||
log(sin(65))
|
||||
|
||||
const aspect = input('aspect ratio: ')
|
||||
const width = input('width: ') / 25.6
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -16,8 +17,10 @@ func FileExists(filename string) bool {
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
||||
func importMod(path string) {
|
||||
extention := filepath.Ext(path)
|
||||
func importMod(realpath string) {
|
||||
origin := realpath
|
||||
extention := filepath.Ext(realpath)
|
||||
path := realpath
|
||||
if extention == "" {
|
||||
path += ".ar"
|
||||
}
|
||||
@@ -25,17 +28,17 @@ func importMod(path string) {
|
||||
if err != nil {
|
||||
panic(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 + ")")
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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)}
|
||||
fmt.Println(pathsToTest)
|
||||
var p string
|
||||
for _, p = range pathsToTest {
|
||||
if FileExists(p) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if xiny(p, imported) {
|
||||
|
||||
@@ -119,7 +119,8 @@ func runprocess(codeseg any, vargroups []map[string]variableValue) (any, any) {
|
||||
return val, ty
|
||||
}
|
||||
case importType:
|
||||
importMod((codeseg.path).(string))
|
||||
resp, _ := runop(codeseg.path, vargroups)
|
||||
importMod(resp.(string))
|
||||
return nil, nil
|
||||
case setVariable:
|
||||
setVariableVal(codeseg, vargroups)
|
||||
@@ -398,14 +399,14 @@ opperationloop:
|
||||
} else {
|
||||
output = (number(output) * number(x))
|
||||
}
|
||||
case 13:
|
||||
case 14:
|
||||
x, _ := runop(opperation.vals[i], vargroups)
|
||||
if output == nil {
|
||||
output = x
|
||||
} else {
|
||||
output = math.Floor(number(output) / number(x))
|
||||
}
|
||||
case 14:
|
||||
case 13:
|
||||
x, _ := runop(opperation.vals[i], vargroups)
|
||||
if output == nil {
|
||||
output = x
|
||||
|
||||
@@ -7,10 +7,11 @@ completed:
|
||||
- allow functions parameters to be passed in
|
||||
- create sub return values
|
||||
- make local variables that delete after the function finishes
|
||||
- add math module
|
||||
|
||||
incompleted:
|
||||
- books (objects)
|
||||
- items (arrays)
|
||||
- add else if to if statments
|
||||
- add try catch
|
||||
- fix close square bracket not being allowed in open indentation
|
||||
- fix close square bracket not being allowed in open indentation
|
||||
+10
-15
@@ -127,7 +127,7 @@ func getValuesFromCommas(str string, line int) ([]any, bool) {
|
||||
for i := 0; i < stringlen; i++ {
|
||||
if str[i] == 44 {
|
||||
tempstr := string(temp[:])
|
||||
resp, worked := processfunc(code{code: tempstr, line: 0})
|
||||
resp, worked := processfunc(code{code: tempstr, line: line})
|
||||
if worked {
|
||||
output = append(output, resp)
|
||||
temp = []byte{}
|
||||
@@ -138,7 +138,7 @@ func getValuesFromCommas(str string, line int) ([]any, bool) {
|
||||
}
|
||||
tempstr := string(temp[:])
|
||||
if tempstr != "" {
|
||||
resp, worked := processfunc(code{code: tempstr, line: 0})
|
||||
resp, worked := processfunc(code{code: tempstr, line: line})
|
||||
if worked {
|
||||
output = append(output, resp)
|
||||
} else {
|
||||
@@ -227,21 +227,15 @@ func getParamNames(str string, line int) []string {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -400,6 +394,8 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
return continueType{
|
||||
line: codeseg.line,
|
||||
}, i + 1
|
||||
} else if skipCompile.MatchString(codeseg.code) {
|
||||
return nil, i + 1
|
||||
}
|
||||
resp, worked := translateprocess(codeseg)
|
||||
if worked {
|
||||
@@ -415,7 +411,7 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
resp, worked := translateprocess(code{code: VAR[1],
|
||||
line: codeseg.line})
|
||||
if !worked {
|
||||
log.Fatal("invalid value")
|
||||
log.Fatal("invalid value on line ", codeseg.line+1, ": ", VAR[1])
|
||||
}
|
||||
return setVariable{
|
||||
TYPE: TYPE,
|
||||
@@ -431,7 +427,7 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
condition, worked := translateprocess(code{code: split[0],
|
||||
line: codeseg.line})
|
||||
if !worked {
|
||||
log.Fatal("invalid value on line", codeseg.line+1)
|
||||
log.Fatal("invalid value on line ", codeseg.line+1)
|
||||
}
|
||||
codedata, x := getCodeInIndent(i, codearray, false)
|
||||
codeoutput := []interface{}{}
|
||||
@@ -455,7 +451,7 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
condition, worked := translateprocess(code{code: split[0],
|
||||
line: codeseg.line})
|
||||
if !worked {
|
||||
log.Fatal("invalid value on line", codeseg.line+1)
|
||||
log.Fatal("invalid value on line ", codeseg.line+1, ": ", split[0])
|
||||
}
|
||||
codedata, x := getCodeInIndent(i, codearray, true)
|
||||
codeoutput := []interface{}{}
|
||||
@@ -517,7 +513,6 @@ var translateline = func(i int, codearray []code) (interface{}, int) {
|
||||
path: path,
|
||||
line: codeseg.line,
|
||||
}, i + 1
|
||||
} else if skipCompile.MatchString(codeseg.code) {
|
||||
} else {
|
||||
err := "Invalid syntax on line "
|
||||
log.Fatal("\n\nLine " + fmt.Sprint(codeseg.line+1) + ": " + codeseg.code + "\n" + err + "\n\n")
|
||||
|
||||
Reference in new issue
Block a user