diff options
author | Adrian Thurston <thurston@complang.org> | 2015-04-19 15:04:33 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-04-19 15:04:33 -0400 |
commit | 0333335160ed6b9c00c5ede9502d7cd2174cf12f (patch) | |
tree | eb96eed1ea87c2897196508006e695a2603c94b2 | |
parent | 0d5bc74ba923313d1192693937c050557edca563 (diff) | |
download | colm-0333335160ed6b9c00c5ede9502d7cd2174cf12f.tar.gz |
fixed missing downref in the logical operators
-rw-r--r-- | src/bytecode.c | 36 | ||||
-rw-r--r-- | src/bytecode.h | 6 | ||||
-rw-r--r-- | src/synthesis.cc | 4 | ||||
-rw-r--r-- | test/logical1.lm | 18 |
4 files changed, 27 insertions, 37 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 25218cad..59a8e0dc 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1710,8 +1710,8 @@ again: treeDownref( prg, sp, o2 ); break; } - case IN_TST_LOGICAL_AND_VAL: { - debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_AND_VAL\n" ); + case IN_TST_LOGICAL_AND: { + debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_AND\n" ); Value o2 = vm_pop_value(); Value o1 = vm_pop_value(); @@ -1719,22 +1719,8 @@ again: vm_push_value( val ); break; } - case IN_TST_LOGICAL_AND_TREE: { - debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_AND_TREE\n" ); - - Tree *o2 = vm_pop_tree(); - Tree *o1 = vm_pop_tree(); - long v2 = !testFalse( prg, o2 ); - long v1 = !testFalse( prg, o1 ); - Word r = v1 && v2; - Value val = r ? TRUE_VAL : FALSE_VAL; - vm_push_value( val ); - treeDownref( prg, sp, o1 ); - treeDownref( prg, sp, o2 ); - break; - } - case IN_TST_LOGICAL_OR_VAL: { - debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_OR_VAL\n" ); + case IN_TST_LOGICAL_OR: { + debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_OR\n" ); Value o2 = vm_pop_value(); Value o1 = vm_pop_value(); @@ -1742,25 +1728,13 @@ again: vm_push_value( val ); break; } - case IN_TST_LOGICAL_OR_TREE: { - debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_OR_TREE\n" ); - - Tree *o2 = vm_pop_tree(); - Tree *o1 = vm_pop_tree(); - long v2 = !testFalse( prg, o2 ); - long v1 = !testFalse( prg, o1 ); - Value val = v1 || v2 ? TRUE_VAL : FALSE_VAL; - vm_push_value( val ); - treeDownref( prg, sp, o1 ); - treeDownref( prg, sp, o2 ); - break; - } case IN_TST_NZ_TREE: { debug( prg, REALM_BYTECODE, "IN_TST_NZ_TREE\n" ); Tree *tree = vm_pop_tree(); long r = !testFalse( prg, tree ); + treeDownref( prg, sp, tree ); vm_push_value( r ); break; } diff --git a/src/bytecode.h b/src/bytecode.h index ae5fa72a..f73fdcb5 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -67,10 +67,8 @@ typedef unsigned long colm_value_t; #define IN_TST_LESS_EQL_TREE 0xc0 #define IN_TST_GRTR_EQL_VAL 0x11 #define IN_TST_GRTR_EQL_TREE 0xcd -#define IN_TST_LOGICAL_AND_VAL 0x12 -#define IN_TST_LOGICAL_AND_TREE 0xce -#define IN_TST_LOGICAL_OR_VAL 0x13 -#define IN_TST_LOGICAL_OR_TREE 0xcf +#define IN_TST_LOGICAL_AND 0x12 +#define IN_TST_LOGICAL_OR 0x13 #define IN_TST_NZ_TREE 0xd1 diff --git a/src/synthesis.cc b/src/synthesis.cc index 8285957d..99d130e1 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -2004,7 +2004,7 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const if ( !rut->val() ) code.append( IN_TST_NZ_TREE ); - code.append( IN_TST_LOGICAL_AND_VAL ); + code.append( IN_TST_LOGICAL_AND ); /* Set the distance of the jump. */ long distance = code.length() - jump - 3; @@ -2031,7 +2031,7 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const if ( !rut->val() ) code.append( IN_TST_NZ_TREE ); - code.append( IN_TST_LOGICAL_OR_VAL ); + code.append( IN_TST_LOGICAL_OR ); /* Set the distance of the jump. */ long distance = code.length() - jump - 3; diff --git a/test/logical1.lm b/test/logical1.lm new file mode 100644 index 00000000..b3f29be7 --- /dev/null +++ b/test/logical1.lm @@ -0,0 +1,18 @@ + +if 1 && 1 + print "true + +if "a" && "b" + print "true + +if 1 || 1 + print "true + +if "a" || "b" + print "true + +##### EXP ##### +true +true +true +true |