mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
add while and forever loops
This commit is contained in:
98
src/jumpStatements.go
Normal file
98
src/jumpStatements.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var returnCompile = makeRegex(`( *)return( +)(.|\n)+`)
|
||||
var breakCompile = makeRegex(`( *)break( *)`)
|
||||
|
||||
type CallReturn struct {
|
||||
value any
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
}
|
||||
|
||||
type Return struct {
|
||||
value any
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
}
|
||||
|
||||
type CallBreak struct {
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
}
|
||||
type Break struct {
|
||||
line int
|
||||
code string
|
||||
path string
|
||||
}
|
||||
|
||||
func isReturn(code UNPARSEcode) bool {
|
||||
return returnCompile.MatchString(code.code)
|
||||
}
|
||||
|
||||
func isBreak(code UNPARSEcode) bool {
|
||||
return breakCompile.MatchString(code.code)
|
||||
}
|
||||
|
||||
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 CallReturn{
|
||||
value: resp,
|
||||
line: code.line,
|
||||
code: code.realcode,
|
||||
path: code.path,
|
||||
}, worked, err, i
|
||||
}
|
||||
|
||||
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)
|
||||
if err.EXISTS {
|
||||
return nil, err
|
||||
}
|
||||
val = v
|
||||
}
|
||||
return Return{
|
||||
value: val,
|
||||
line: code.line,
|
||||
code: code.code,
|
||||
path: code.path,
|
||||
}, ArErr{}
|
||||
}
|
||||
|
||||
func openReturn(resp any) any {
|
||||
switch x := resp.(type) {
|
||||
case Return:
|
||||
return x.value
|
||||
default:
|
||||
return resp
|
||||
}
|
||||
}
|
||||
|
||||
func parseBreak(code UNPARSEcode, index int, codeline []UNPARSEcode) (CallBreak, bool, ArErr, int) {
|
||||
return CallBreak{
|
||||
line: code.line,
|
||||
code: code.realcode,
|
||||
path: code.path,
|
||||
}, true, ArErr{}, 1
|
||||
}
|
||||
|
||||
func runBreak(code CallBreak, stack stack, stacklevel int) (any, ArErr) {
|
||||
return Break{
|
||||
line: code.line,
|
||||
code: code.code,
|
||||
path: code.path,
|
||||
}, ArErr{}
|
||||
}
|
||||
Reference in New Issue
Block a user