From 15ba383f96b3def7248566e57654b3d8c6199a90 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 21 Jul 2023 15:36:23 +0900 Subject: [PATCH] updated code --- interp/eval.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++---- interp/feed.go | 19 ++++++-------- interp/pcl.go | 11 ++------ 3 files changed, 72 insertions(+), 26 deletions(-) diff --git a/interp/eval.go b/interp/eval.go index 41bb2d7..1d3b10e 100644 --- a/interp/eval.go +++ b/interp/eval.go @@ -124,7 +124,70 @@ func (p *process_t) pop_context() (node *Cnode_t) { return } +/* +stmt + + text text bracket + stmt: text text + stmt: text TEXT +*/ func (interp *Interp) eval_atom_node(node *Cnode_t) (*string, error) { + var ( + p process_t + v *string + inode *Cnode_t + err error + ) + + p.interp = interp + + for node != nil { + p.push_context(node) + p.push_string_value("") // placeholder for return value + + for inode = node.child; inode != nil; inode = inode.next { + switch inode.code { + case CNODE_BRACKET: + //p.push_context(inode) + //p.push_string_value("") + //node = + + case CNODE_TEXT: + + //fmt.Printf("XXXXXXXXXXXXXXXXXXXx[%s]\n", string(inode.token)) + err = p.push_string_value(string(inode.token)) + if err != nil { + goto oops + } + } + } + + fmt.Printf("CALLING\n") + err = p.call() + if err != nil { + goto oops + } + if p.ctx.parent_ctx != nil { + p.pop_context() + } + + node = node.next + } + + v = (*string)(p.pop_value()) + p.pop_context() + if p.ctx != nil { + err = fmt.Errorf("internal error - dangling process context") + goto oops + } + + return v, nil + +oops: + return nil, err +} + +func (interp *Interp) eval_atom_node_old(node *Cnode_t) (*string, error) { var ( p process_t @@ -186,11 +249,6 @@ func (interp *Interp) eval_atom_node(node *Cnode_t) (*string, error) { goto oops } - case CNODE_SEP: - // skip - case CNODE_EOL: - // skip - default: err = fmt.Errorf("internal error - non-atom node - %d", node.code) goto oops diff --git a/interp/feed.go b/interp/feed.go index e18f823..d932b84 100644 --- a/interp/feed.go +++ b/interp/feed.go @@ -392,7 +392,7 @@ func (inter *Interp) add_cnode_to_feed_struct(feed *feed_struct_t, cnode *Cnode_ } var feed_to_cnode_code_tab [11]cnode_code_t = [11]cnode_code_t{ - FEED_TOP: CNODE_EOL, // this must never be used + FEED_TOP: CNODE_INVALID, // this must never be used FEED_INIT: CNODE_INIT, FEED_BRACKET: CNODE_BRACKET, FEED_BRACE: CNODE_BRACE, @@ -400,9 +400,9 @@ var feed_to_cnode_code_tab [11]cnode_code_t = [11]cnode_code_t{ FEED_DQUOTE: CNODE_DQUOTE, FEED_DQUOTED_TEXT: CNODE_TEXT, FEED_DOLLAR: CNODE_VAR, - FEED_SEP: CNODE_SEP, + FEED_SEP: CNODE_INVALID, FEED_WORD: CNODE_TEXT, - FEED_EOL: CNODE_EOL, + FEED_EOL: CNODE_INVALID, } func (interp *Interp) pop_feed_struct() *feed_struct_t { @@ -445,6 +445,9 @@ func (interp *Interp) pop_feed_struct() *feed_struct_t { parent.cnode_cont = false } else { cnode = &Cnode_t{code: feed_to_cnode_code_tab[feed.state], token: feed.token} + if cnode.code == CNODE_INVALID { + panic("internal error - CNODE INVALID encountered") + } if cnode.code == CNODE_BRACKET || cnode.code == CNODE_BRACE || cnode.code == CNODE_INIT { // popping a container feed struct interp.finalize_feed_struct(feed, true) @@ -452,15 +455,7 @@ func (interp *Interp) pop_feed_struct() *feed_struct_t { } else if cnode.code == CNODE_DQUOTE { interp.finalize_feed_struct(feed, false) cnode.child = feed.cnode_first - } /*else if cnode.code == CNODE_VAR { - fmt.Printf(">>>>\n") - interp.dump_cnodes(parent.cnode_first, true) - fmt.Printf(">>>>\n") - interp.dump_cnodes(parent.cnode_tmp_first, true) - fmt.Printf(">>>>\n") - interp.dump_cnodes(cnode, true) - - }*/ + } // add the current cnode to the parent feed struct interp.add_cnode_to_feed_struct(parent, cnode) diff --git a/interp/pcl.go b/interp/pcl.go index 3ce0bd3..2d2d031 100644 --- a/interp/pcl.go +++ b/interp/pcl.go @@ -54,14 +54,13 @@ type call_frame_t struct { type cnode_code_t int const ( - CNODE_INIT cnode_code_t = iota + CNODE_INVALID cnode_code_t = iota + CNODE_INIT CNODE_BRACKET CNODE_BRACE CNODE_DQUOTE CNODE_VAR CNODE_TEXT - CNODE_SEP - CNODE_EOL CNODE_STMT CNODE_JOIN // merge the two top elements off the stack ) @@ -329,12 +328,6 @@ func (interp *Interp) __dump_cnodes(node *Cnode_t, nl bool, tabs int) { // contained inside other containers, some escaping is required fmt.Printf("%s", string(node.token)) - case CNODE_SEP: - fmt.Printf(" ") - - case CNODE_EOL: - fmt.Printf("\n") - case CNODE_JOIN: // do nothing //fmt.Printf("")