diff --git a/interp/eval.go b/interp/eval.go index 25a859d..749e6e4 100644 --- a/interp/eval.go +++ b/interp/eval.go @@ -2,7 +2,6 @@ package interp import ( "fmt" - "unsafe" ) var debug bool = false @@ -60,7 +59,7 @@ func (p *process_t) merge_top_values() error { new_val = *v1 + *v2 p.vsp-- p.vstack[p.vsp] = nil - p.vstack[p.vsp-1] = unsafe.Pointer(&new_val) + p.vstack[p.vsp-1] = &new_val p.ctx.count-- if debug { @@ -121,6 +120,10 @@ func (p *process_t) GetNumArgs() int { return p.ctx.count - 2 } +func (p *process_t) ReturnString(val string) { + p.vstack[p.vsp-p.ctx.count] = &val +} + func (p *process_t) Return(val Value_t) { p.vstack[p.vsp-p.ctx.count] = val } @@ -178,7 +181,7 @@ func (interp *Interp) dump_vstack(p *process_t) { }*/ switch t := p.vstack[i].(type) { case *string: - fmt.Printf(" %d => [%s]\n", i, t) + fmt.Printf(" %d => [%s]\n", i, *t) case *Cnode_t: fmt.Printf(" %d => ", i) interp.dump_cnodes(t, false) diff --git a/interp/proc.go b/interp/proc.go index 16a3960..5116091 100644 --- a/interp/proc.go +++ b/interp/proc.go @@ -74,22 +74,22 @@ func proc_puts(p *process_t) error { if nargs >= 1 { p.Return(v) } else { - p.Return("hello") + p.ReturnString("hello") } return nil } func proc_false(p *process_t) error { - p.Return("false") + p.ReturnString("false") return nil } func proc_true(p *process_t) error { - p.Return("true") + p.ReturnString("true") return nil } func proc_null(p *process_t) error { - p.Return("") + p.ReturnString("") return nil }