mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
about to start implimentation of if statments, and add not
This commit is contained in:
@@ -56,7 +56,7 @@ func runDoWrap(d dowrap, stack stack, stacklevel int) (any, ArErr) {
|
||||
return nil, err
|
||||
}
|
||||
switch x := val.(type) {
|
||||
case PassBackJumpStatment:
|
||||
case Return:
|
||||
return x, ArErr{}
|
||||
}
|
||||
}
|
||||
|
||||
1
src/ifstatment.go
Normal file
1
src/ifstatment.go
Normal file
@@ -0,0 +1 @@
|
||||
package main
|
||||
@@ -4,16 +4,14 @@ import "strings"
|
||||
|
||||
var returnCompile = makeRegex(`( *)return( +)(.|\n)+`)
|
||||
|
||||
type CallJumpStatment struct {
|
||||
TYPE string
|
||||
type CallReturn struct {
|
||||
value any
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
}
|
||||
|
||||
type PassBackJumpStatment struct {
|
||||
TYPE string
|
||||
type Return struct {
|
||||
value any
|
||||
line int
|
||||
code string
|
||||
@@ -24,15 +22,14 @@ func isReturn(code UNPARSEcode) bool {
|
||||
return returnCompile.MatchString(code.code)
|
||||
}
|
||||
|
||||
func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallJumpStatment, bool, ArErr, int) {
|
||||
func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallReturn, bool, ArErr, int) {
|
||||
resp, worked, err, i := translateVal(UNPARSEcode{
|
||||
code: strings.TrimSpace(code.code)[6:],
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codeline, 1)
|
||||
return CallJumpStatment{
|
||||
TYPE: "return",
|
||||
return CallReturn{
|
||||
value: resp,
|
||||
line: code.line,
|
||||
code: code.realcode,
|
||||
@@ -40,7 +37,7 @@ func parseReturn(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallJumpS
|
||||
}, worked, err, i
|
||||
}
|
||||
|
||||
func runJumpStatment(code CallJumpStatment, stack stack, stacklevel int) (any, ArErr) {
|
||||
func runReturn(code CallReturn, stack stack, stacklevel int) (any, ArErr) {
|
||||
var val any
|
||||
if code.value != nil {
|
||||
v, err := runVal(code.value, stack, stacklevel+1)
|
||||
@@ -49,8 +46,7 @@ func runJumpStatment(code CallJumpStatment, stack stack, stacklevel int) (any, A
|
||||
}
|
||||
val = v
|
||||
}
|
||||
return PassBackJumpStatment{
|
||||
TYPE: code.TYPE,
|
||||
return Return{
|
||||
value: val,
|
||||
line: code.line,
|
||||
code: code.code,
|
||||
@@ -60,7 +56,7 @@ func runJumpStatment(code CallJumpStatment, stack stack, stacklevel int) (any, A
|
||||
|
||||
func openJump(resp any) any {
|
||||
switch x := resp.(type) {
|
||||
case PassBackJumpStatment:
|
||||
case Return:
|
||||
return x.value
|
||||
default:
|
||||
return resp
|
||||
|
||||
40
src/not.go
Normal file
40
src/not.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import "strings"
|
||||
|
||||
var notCompiled = makeRegex(`( *)not (.|\n)+`)
|
||||
|
||||
type not struct {
|
||||
value any
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
}
|
||||
|
||||
func isnot(code UNPARSEcode) bool {
|
||||
return notCompiled.MatchString(code.code)
|
||||
}
|
||||
|
||||
func parseNot(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine int) (any, bool, ArErr, int) {
|
||||
trimmed := strings.TrimSpace(code.code)
|
||||
trimmed = trimmed[4:]
|
||||
|
||||
val, worked, err, step := translateVal(UNPARSEcode{
|
||||
code: trimmed,
|
||||
realcode: code.realcode,
|
||||
line: code.line,
|
||||
path: code.path,
|
||||
}, index, codelines, isLine)
|
||||
return not{
|
||||
value: val,
|
||||
line: code.line,
|
||||
code: code.realcode,
|
||||
path: code.path,
|
||||
}, worked, err, step
|
||||
}
|
||||
|
||||
func runNot(n not, stack stack, stacklevel int) (bool, ArErr) {
|
||||
val, err := runVal(n.value, stack, stacklevel+1)
|
||||
boolean := !anyToBool(val)
|
||||
return boolean, err
|
||||
}
|
||||
@@ -55,10 +55,12 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
|
||||
return runOperation(x, stack, stacklevel+1)
|
||||
case dowrap:
|
||||
return runDoWrap(x, stack, stacklevel+1)
|
||||
case CallJumpStatment:
|
||||
return runJumpStatment(x, stack, stacklevel+1)
|
||||
case CallReturn:
|
||||
return runReturn(x, stack, stacklevel+1)
|
||||
case ArDelete:
|
||||
return runDelete(x, stack, stacklevel+1)
|
||||
case not:
|
||||
return runNot(x, stack, stacklevel+1)
|
||||
}
|
||||
fmt.Println("unreachable", reflect.TypeOf(line))
|
||||
panic("unreachable")
|
||||
|
||||
@@ -40,6 +40,8 @@ func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine i
|
||||
if worked {
|
||||
return bracket, worked, err, step
|
||||
}
|
||||
} else if isnot(code) {
|
||||
return parseNot(code, index, codelines, isLine)
|
||||
}
|
||||
if isSetVariable(code) {
|
||||
setvar, worked, err, step := parseSetVariable(code, index, codelines, isLine)
|
||||
@@ -97,7 +99,7 @@ func translate(codelines []UNPARSEcode) ([]any, ArErr) {
|
||||
}
|
||||
val, _, err, step := translateVal(codelines[i], i, codelines, 2)
|
||||
switch val.(type) {
|
||||
case CallJumpStatment:
|
||||
case CallReturn:
|
||||
return nil, ArErr{"Runtime Error", "Jump statment at top level", codelines[i].line, codelines[i].path, codelines[i].realcode, true}
|
||||
}
|
||||
i += step
|
||||
|
||||
@@ -27,6 +27,9 @@ var blockedVariableNames = map[string]bool{
|
||||
"false": true,
|
||||
"null": true,
|
||||
"delete": true,
|
||||
"not": true,
|
||||
"and": true,
|
||||
"or": true,
|
||||
}
|
||||
|
||||
type accessVariable struct {
|
||||
|
||||
10
test.ar
10
test.ar
@@ -1,13 +1,15 @@
|
||||
let ln(x) = do
|
||||
let maths = map()
|
||||
|
||||
maths.ln(x) = do
|
||||
let n = 1e10
|
||||
return n * ((x^(1/n)) - 1)
|
||||
|
||||
let __ln10cache = ln(10)
|
||||
|
||||
let log(x) = do
|
||||
maths.log(x) = do
|
||||
return ln(x) / __ln10cache
|
||||
|
||||
let logN(n,x) = do
|
||||
maths.logN(n,x) = do
|
||||
return ln(x) / ln(n)
|
||||
|
||||
term.log(log(1000))
|
||||
term.log(maths.log(10000), array(maths))
|
||||
Reference in New Issue
Block a user