pcl/interp/proc.go

158 lines
2.4 KiB
Go

package interp
import "fmt"
func proc_proc(p *process_t) error {
/*
p.push_call_frame()
p.set_var("aaa", 10)
p.set_var("bbb", 20)
p.eval_stmt_nodes()
p.pop_call_frame()
*/
var err error
if p.GetNumArgs() != 3 {
err = err_num_args
goto done
}
/*
// procedure name
v1, err = p.interp.eval_arg(p, 0)
if err != nil {
goto done
}
p.set_var(p, v1, v2)*/
done:
return err
}
func proc_set(p *process_t) error {
var (
v1, v2 Value_t
err error
)
if p.GetNumArgs() != 2 {
err = err_num_args
goto done
}
v1, err = p.interp.eval_arg(p, 0)
if err != nil {
goto done
}
v2, err = p.interp.eval_arg(p, 1)
if err != nil {
goto done
}
err = p.interp.set_var(p, v1, v2)
if err != nil {
goto done
}
p.Return(v2)
done:
return err
}
func proc_expr(p *process_t) error {
return nil
}
func proc_if(p *process_t) error {
var (
v Value_t
err error
)
if p.GetNumArgs() < 2 {
err = err_num_args
goto done
}
//v, err = p.interp.EvalText([]rune(*p.GetArg(0)))
v, err = p.interp.eval_arg(p, 0)
if err != nil {
goto done
}
if v.Kind != VALUE_STR {
panic("internal error - screwed conditional value")
}
if *(*string)(v.V) != "" {
//v, err = p.interp.eval_atom_node((*Cnode_t)(p.GetArg(1)))
v, err = p.interp.eval_arg(p, 1)
if err != nil {
goto done
}
p.Return(v)
} else {
// TODO: if elseif else
}
done:
return err
}
func proc_puts(p *process_t) error {
var (
i int
nargs int
v Value_t
err error
)
//fmt.Printf("callee=%s\n", *(p.GetCalleeName()))
//fmt.Printf("callee=%s\n", *(p.GetArg(-1)))
//fmt.Printf("arg count = %d\n", p.GetNumArgs())
nargs = p.GetNumArgs()
for i = 0; i < nargs; i++ {
//fmt.Printf("%s", *p.GetArg(i))
v, err = p.interp.eval_arg_literally(p, i)
if err != nil {
return err
}
// TODO: check if v.kind is VALUE_STR
if v.Kind != VALUE_STR {
panic("internal error... invalid evaluation resutl")
}
fmt.Printf("%s", *(*string)(v.V))
}
if nargs >= 1 {
p.Return(v)
} else {
p.ReturnString("hello")
}
return nil
}
func proc_false(p *process_t) error {
p.ReturnString("false")
return nil
}
func proc_true(p *process_t) error {
p.ReturnString("true")
return nil
}
func proc_null(p *process_t) error {
p.ReturnString("")
return nil
}
func proc_unknown(p *process_t) error {
fmt.Printf("Unknown command - %s\n", *(p.GetCalleeName()))
return nil
}