prototype repl

This commit is contained in:
Aidan 2020-06-21 01:30:54 -07:00
parent 30481d4f78
commit c40aea7326
No known key found for this signature in database
GPG key ID: 327711E983899316
7 changed files with 233 additions and 35 deletions

View file

@ -17,6 +17,8 @@
package ast
import "git.callpipe.com/aidan/shs/log"
func (t *Token) Eval(funcs FuncTable, vars VarTable) *Token {
if t == nil {
return nil
@ -53,7 +55,9 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) *Token {
f := funcs.GetFunction(ret.Inner.(string))
if f == nil {
if !eligibleForSystemCall {
// TODO: log error
log.Log(log.DEBUG,
"could not find definition for symbol " + ret.Inner.(string),
"eval")
return nil
}
@ -61,7 +65,7 @@ func (t *Token) Eval(funcs FuncTable, vars VarTable) *Token {
return nil // TODO: Thats gotta change
}
return (*f).CallFunction(ret.Next)
return (*f).CallFunction(ret.Next, vars, funcs)
}
return ret

View file

@ -21,6 +21,7 @@ type Operation func(*Token) *Token
type Function struct {
function Operation
name string
timesCalled int
args int // TODO: Make this a list of expected types (TAGs)
}
@ -40,7 +41,9 @@ func (f Function) ParseFunction(args *Token) bool {
}
if i != 0 {
// TODO: log error here
log.Log(log.ERR,
"Incorrect number of arguments",
"eval")
return false
}
@ -49,6 +52,9 @@ func (f Function) ParseFunction(args *Token) bool {
func (f Function) CallFunction(args *Token) *Token {
if !f.ParseFunction(args) {
log.Log(log.Err,
"Couldnt call " + f.name,
"eval")
return nil
}
@ -59,6 +65,9 @@ func (f Function) CallFunction(args *Token) *Token {
func (table FuncTable) GetFunction(arg string) *Function {
target, ok := table[arg]
if !ok {
log.Log(log.DEBUG,
"function " + arg + " not found",
"eval")
return nil
}

View file

@ -164,11 +164,17 @@ error:
// TODO: Hook into error module
// TODO: Finalize and GC alloced tokens
if start_pos == -1 {
println("[-] Unmatched string delimiter in input. discarding.")
log.Log(log.ERR,
"Unmatched string delimiter in input. discarding.",
"lex")
} else if start_pos == -2 {
println("[-] Unmatched list delimiter in input. discarding.")
log.Log(log.ERR,
"Unmatched list delimiter in input. discarding.",
"lex")
} else {
println("[-] Unknown error in input. discarding.")
log.Log(log.ERR,
"Unknown error in input. discarding.",
"lex")
}
return nil