2023-07-21 09:32:51 +00:00
|
|
|
package interp
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
func proc_expr(p *process_t) error {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func proc_if(p *process_t) error {
|
|
|
|
var (
|
2023-08-04 09:41:30 +00:00
|
|
|
v Value_t
|
|
|
|
vv *string
|
|
|
|
ok bool
|
2023-07-21 09:32:51 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-08-04 09:41:30 +00:00
|
|
|
vv, ok = v.(*string)
|
|
|
|
if !ok {
|
|
|
|
panic("internal error - screwed conditional value")
|
|
|
|
}
|
|
|
|
if *vv != "" {
|
2023-07-21 09:32:51 +00:00
|
|
|
//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
|
|
|
|
}
|
|
|
|
|
2023-08-04 09:41:30 +00:00
|
|
|
p.Return(v)
|
2023-07-21 09:32:51 +00:00
|
|
|
} else {
|
|
|
|
// TODO: if elseif else
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func proc_puts(p *process_t) error {
|
|
|
|
var (
|
|
|
|
i int
|
|
|
|
nargs int
|
2023-08-04 09:41:30 +00:00
|
|
|
v Value_t
|
|
|
|
vv *string
|
2023-07-21 09:32:51 +00:00
|
|
|
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
|
|
|
|
}
|
2023-08-04 09:41:30 +00:00
|
|
|
|
|
|
|
vv, _ = v.(*string)
|
|
|
|
fmt.Printf("%s", *vv)
|
2023-07-21 09:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nargs >= 1 {
|
2023-08-04 09:41:30 +00:00
|
|
|
p.Return(v)
|
2023-07-21 09:32:51 +00:00
|
|
|
} else {
|
2023-08-07 13:32:42 +00:00
|
|
|
p.ReturnString("hello")
|
2023-07-21 09:32:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-03 13:34:42 +00:00
|
|
|
func proc_false(p *process_t) error {
|
2023-08-07 13:32:42 +00:00
|
|
|
p.ReturnString("false")
|
2023-08-03 13:34:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func proc_true(p *process_t) error {
|
2023-08-07 13:32:42 +00:00
|
|
|
p.ReturnString("true")
|
2023-08-03 13:34:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func proc_null(p *process_t) error {
|
2023-08-07 13:32:42 +00:00
|
|
|
p.ReturnString("")
|
2023-08-03 13:34:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-21 09:32:51 +00:00
|
|
|
func proc_unknown(p *process_t) error {
|
|
|
|
fmt.Printf("Unknown command - %s\n", *(p.GetCalleeName()))
|
|
|
|
return nil
|
|
|
|
}
|