added the debug variable for easy toggling of debug messages

This commit is contained in:
chunghh 2023-08-03 00:56:42 +09:00
parent 760f9a7114
commit 85a6092363

View File

@ -5,6 +5,8 @@ import (
"unsafe"
)
var debug bool = false
var err_num_args *error_t = &error_t{msg: "wrong number of arguments"}
/*
@ -154,6 +156,26 @@ func (interp *Interp) dump_vstack(p *process_t) {
}
}
}
/*
[STMT]
[TEXT] [DQUOTE] [TEXT]
[STMT]
[BRACKET] [TEXT]
[STMT]
[TEXT] [TEXT] [TEXT]
[STMT]
[TEXT] [TEXT]
"pu[null 1]ts" 10 20
[STMT]
[DQUOTE] [TEXT|10] [TEXT|20]
[TEXT|pu] [BRACKET] [JOIN] [TEXT|ts] [JOIN]
[STMT]
[TEXT|null] [TEXT|1]
*/
func (interp *Interp) eval_stmt_nodes(container_node *Cnode_t) (*string, error) {
var (
p process_t
@ -193,9 +215,11 @@ func (interp *Interp) eval_stmt_nodes(container_node *Cnode_t) (*string, error)
stmt_node = inner_node.child // first statement inside []
p.push_context(stmt_node, inner_node)
p.push_string_value("") // for return value
if debug {
fmt.Printf("going to start over\n")
interp.dump_cnodes(stmt_node, true)
fmt.Printf("\n--\n")
}
goto start_over
} else {
// no statements inside []. treat it like an empty string
@ -207,9 +231,11 @@ func (interp *Interp) eval_stmt_nodes(container_node *Cnode_t) (*string, error)
p.push_context(stmt_node, inner_node)
//p.push_string_value("") // no placeholder for return value is needed
inner_node = inner_node.child
if debug {
fmt.Printf("going to start over\n")
interp.dump_cnodes(stmt_node, true)
fmt.Printf("\n--\n")
}
goto resume
} else {
// no statements inside []. treat it like an empty string
@ -236,11 +262,15 @@ func (interp *Interp) eval_stmt_nodes(container_node *Cnode_t) (*string, error)
inner_node = inner_node.next
}
if debug {
interp.dump_vstack(&p)
}
//fmt.Printf("p.ctx.parent_node.code %d p.ctx.container_node.code %d CNODE_STMT %d CNODE_DQUOTE %d\n", p.ctx.parent_node.code, p.ctx.container_node.code, CNODE_STMT, CNODE_DQUOTE)
//if p.ctx.parent_node.code == CNODE_STMT {
if p.ctx.container_node == nil || (p.ctx.container_node.code == CNODE_STMT || p.ctx.container_node.code == CNODE_BRACKET) {
if debug {
fmt.Printf("calling..... [%s]\n", *p.GetCalleeName())
}
err = p.call()
if err != nil {
goto oops
@ -248,13 +278,13 @@ func (interp *Interp) eval_stmt_nodes(container_node *Cnode_t) (*string, error)
stmt_node, inner_node = p.pop_context(true)
} else {
// join the all
stmt_node, inner_node = p.pop_context(false)
}
if inner_node != nil {
if debug {
fmt.Printf("resuming... %d\n", p.vsp)
}
inner_node = inner_node.next
goto resume
}
@ -263,8 +293,10 @@ func (interp *Interp) eval_stmt_nodes(container_node *Cnode_t) (*string, error)
stmt_node = stmt_node.next
}
if debug {
interp.dump_vstack(&p)
fmt.Printf("END p.sp = %d\n", p.vsp)
}
return v, nil
oops: