updated wrong handling of Value_t, not using unsafe.Pointer

This commit is contained in:
hyung-hwan 2023-08-07 22:32:42 +09:00
parent 3cae246546
commit 6ffe32a9df
2 changed files with 10 additions and 7 deletions

View File

@ -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)

View File

@ -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
}