]> granicus.if.org Git - jq/commitdiff
Remove duplicate TOP insertions, drop unused defs. 532/head
authorWilliam Langford <wlangfor@gmail.com>
Tue, 5 Aug 2014 04:46:10 +0000 (00:46 -0400)
committerWilliam Langford <wlangfor@gmail.com>
Tue, 5 Aug 2014 04:46:10 +0000 (00:46 -0400)
compile.c
parser.y

index 03d03c3ed63e5fea2ca39086c5f2d296f001fee4..cc5a8d0925f2ad79ec698bc2f6701ede58d81a7b 100644 (file)
--- a/compile.c
+++ b/compile.c
@@ -399,7 +399,7 @@ block block_drop_unreferenced(block body) {
   int drop;
   do {
     drop = 0;
-    while((curr = block_take(&body)) && curr->op != TOP) {
+    while ((curr = block_take(&body)) && curr->op != TOP) {
       block b = inst_block(curr);
       if (block_count_refs(b,refd) + block_count_refs(b,body) == 0) {
         unrefd = BLOCK(unrefd, b);
@@ -593,7 +593,11 @@ block gen_definedor(block a, block b) {
 }
 
 int block_has_main(block top) {
-  return top.first && top.first->op == TOP;
+  for (inst *c = top.first; c; c = c->next) {
+    if (c->op == TOP)
+      return 1;
+  }
+  return 0;
 }
 
 int block_is_funcdef(block b) {
index 0117e1a2c1733768d2e0d329ab51f04dffd79fcd..72e2b28ffa87933d8844f0dd752a702934c07d44 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -278,10 +278,7 @@ FuncDef FuncDefs {
 
 Exp:
 FuncDef Exp %prec ';' {
-  if (block_is_funcdef($2))
-    $$ = block_bind($1, $2, OP_IS_CALL_PSEUDO);
-  else
-    $$ = block_bind($1, BLOCK(gen_op_simple(TOP), $2), OP_IS_CALL_PSEUDO);
+  $$ = block_bind_referenced($1, $2, OP_IS_CALL_PSEUDO);
 } |
 
 Term "as" '$' IDENT '|' Exp {