summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-01-27 16:59:22 -0500
committerAdrian Thurston <thurston@complang.org>2015-01-27 16:59:22 -0500
commit6f9c7f12e3888c525a4b9be7712294929d690790 (patch)
treed53632c5fd2ee42df1f0ef45ab824e896e000d88
parent09c75e4b10915cb32786d2482af6727841659b80 (diff)
downloadcolm-6f9c7f12e3888c525a4b9be7712294929d690790.tar.gz
first cut of value-based ints, test cases pass
-rw-r--r--src/bytecode.c254
-rw-r--r--src/bytecode.h42
-rw-r--r--src/colm.lm4
-rw-r--r--src/compiler.cc2
-rw-r--r--src/compiler.h2
-rw-r--r--src/declare.cc13
-rw-r--r--src/loadcolm.cc8
-rw-r--r--src/map.c20
-rw-r--r--src/parsetree.cc3
-rw-r--r--src/parsetree.h9
-rw-r--r--src/pdabuild.cc34
-rw-r--r--src/program.c22
-rw-r--r--src/string.c4
-rw-r--r--src/synthesis.cc129
-rw-r--r--src/tree.c94
-rw-r--r--test/exit6.lm4
-rw-r--r--test/superid.lm8
17 files changed, 429 insertions, 223 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 346e0d04..f9430b93 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -346,7 +346,7 @@ break; }
static Tree *stream_pull_bc( Program *prg, Tree **sp, PdaRun *pdaRun,
Stream *stream, Tree *length )
{
- long len = ((Int*)length)->value;
+ long len = ((long)length);
StreamImpl *impl = streamToImpl( stream );
Head *tokdata = streamPull( prg, sp, pdaRun, impl, len );
return constructString( prg, tokdata );
@@ -688,13 +688,13 @@ again:
}
case IN_LOAD_TRUE: {
debug( prg, REALM_BYTECODE, "IN_LOAD_TRUE\n" );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
break;
}
case IN_LOAD_FALSE: {
debug( prg, REALM_BYTECODE, "IN_LOAD_FALSE\n" );
- treeUpref( prg->falseVal );
+ //treeUpref( prg->falseVal );
vm_push( prg->falseVal );
break;
}
@@ -705,7 +705,7 @@ again:
debug( prg, REALM_BYTECODE, "IN_LOAD_INT %d\n", i );
Tree *tree = constructInteger( prg, i );
- treeUpref( tree );
+ //treeUpref( tree );
vm_push( tree );
break;
}
@@ -1071,6 +1071,7 @@ again:
Tree *val = vm_local(field);
vm_push( val );
+ debug( prg, REALM_BYTECODE, "val: %ld\n", (long)val );
break;
}
case IN_SET_LOCAL_VAL_WC: {
@@ -1527,7 +1528,7 @@ again:
Tree *str = constructString( prg, res );
treeUpref( str );
vm_push( str );
- treeDownref( prg, sp, integer );
+ //treeDownref( prg, sp, integer );
treeDownref( prg, sp, format );
break;
}
@@ -1535,11 +1536,11 @@ again:
debug( prg, REALM_BYTECODE, "IN_INT_TO_STR\n" );
Int *i = (Int*)vm_pop();
- Head *res = intToStr( prg, i->value );
+ Head *res = intToStr( prg, (long)i );
Tree *str = constructString( prg, res );
treeUpref( str );
vm_push( str );
- treeDownref( prg, sp, (Tree*) i );
+// treeDownref( prg, sp, (Tree*) i );
break;
}
case IN_TREE_TO_STR: {
@@ -1592,7 +1593,7 @@ again:
Str *str = (Str*)vm_pop();
long len = stringLength( str->value );
Tree *res = constructInteger( prg, len );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
treeDownref( prg, sp, (Tree*)str );
break;
@@ -1639,7 +1640,7 @@ again:
debug( prg, REALM_BYTECODE, "IN_JMP_TRUE_VAL %d\n", dist );
Tree *tree = vm_pop();
- if ( !tree != 0 )
+ if ( tree != 0 )
instr += dist;
break;
}
@@ -1667,8 +1668,8 @@ again:
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
long r = cmpTree( prg, o1, o2 );
- Tree *val = r ? prg->falseVal : prg->trueVal;
- treeUpref( val );
+ Tree *val = r == 0 ? prg->trueVal : prg->falseVal;
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
@@ -1680,7 +1681,7 @@ again:
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
Tree *val = o1 == o2 ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
break;
}
@@ -1691,7 +1692,7 @@ again:
Tree *o1 = vm_pop();
long r = cmpTree( prg, o1, o2 );
Tree *val = r ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
@@ -1703,63 +1704,120 @@ again:
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
Tree *val = o1 != o2 ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
break;
}
- case IN_TST_LESS: {
- debug( prg, REALM_BYTECODE, "IN_TST_LESS\n" );
+ case IN_TST_LESS_VAL: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LESS_VAL\n" );
+
+ Tree *o2 = vm_pop();
+ Tree *o1 = vm_pop();
+ Tree *val = (long)o1 < (long)o2 ? prg->trueVal : prg->falseVal;
+ vm_push( val );
+ break;
+ }
+ case IN_TST_LESS_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LESS_TREE\n" );
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
long r = cmpTree( prg, o1, o2 );
Tree *val = r < 0 ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
break;
}
- case IN_TST_LESS_EQL: {
- debug( prg, REALM_BYTECODE, "IN_TST_LESS_EQL\n" );
+ case IN_TST_LESS_EQL_VAL: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LESS_EQL_VAL\n" );
+
+ Tree *o2 = vm_pop();
+ Tree *o1 = vm_pop();
+ Tree *val = (long)o1 <= (long)o2 ? prg->trueVal : prg->falseVal;
+ vm_push( val );
+ }
+ case IN_TST_LESS_EQL_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LESS_EQL_TREE\n" );
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
long r = cmpTree( prg, o1, o2 );
Tree *val = r <= 0 ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
}
- case IN_TST_GRTR: {
- debug( prg, REALM_BYTECODE, "IN_TST_GRTR\n" );
+ case IN_TST_GRTR_VAL: {
+ debug( prg, REALM_BYTECODE, "IN_TST_GRTR_VAL\n" );
+
+ Tree *o2 = vm_pop();
+ Tree *o1 = vm_pop();
+ Tree *val = (long)o1 > (long)o2 ? prg->trueVal : prg->falseVal;
+ vm_push( val );
+ break;
+ }
+ case IN_TST_GRTR_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_GRTR_TREE\n" );
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
long r = cmpTree( prg, o1, o2 );
Tree *val = r > 0 ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
break;
}
- case IN_TST_GRTR_EQL: {
- debug( prg, REALM_BYTECODE, "IN_TST_GRTR_EQL\n" );
+ case IN_TST_GRTR_EQL_VAL: {
+
+ Tree *o2 = (Tree*)vm_pop();
+ Tree *o1 = (Tree*)vm_pop();
+
+ debug( prg, REALM_BYTECODE, "IN_TST_GRTR_EQL_VAL %ld %ld\n", (long)o1, (long)o2 );
+
+ //long r = cmpTree( prg, o1, o2 );
+ //Tree *val = r >= 0 ? prg->trueVal : prg->falseVal;
+ Tree *val = (long)o1 >= (long)o2 ? prg->trueVal : prg->falseVal;
+ //treeUpref( val );
+ vm_push( val );
+ //treeDownref( prg, sp, o1 );
+ //treeDownref( prg, sp, o2 );
+ break;
+ }
+ case IN_TST_GRTR_EQL_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_GRTR_EQL_TREE\n" );
Tree *o2 = (Tree*)vm_pop();
Tree *o1 = (Tree*)vm_pop();
long r = cmpTree( prg, o1, o2 );
Tree *val = r >= 0 ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
break;
}
- case IN_TST_LOGICAL_AND: {
- debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_AND\n" );
+ case IN_TST_LOGICAL_AND_VAL: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_AND_VAL\n" );
+
+ Tree *o2 = vm_pop();
+ Tree *o1 = vm_pop();
+// long v2 = !testFalse( prg, o2 );
+// long v1 = !testFalse( prg, o1 );
+ Word r = o1 && o2;
+ Tree *val = r ? prg->trueVal : prg->falseVal;
+ //treeUpref( val );
+ vm_push( val );
+// treeDownref( prg, sp, o1 );
+// treeDownref( prg, sp, o2 );
+ break;
+ }
+ case IN_TST_LOGICAL_AND_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_AND_TREE\n" );
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
@@ -1767,14 +1825,29 @@ again:
long v1 = !testFalse( prg, o1 );
Word r = v1 && v2;
Tree *val = r ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
break;
}
- case IN_TST_LOGICAL_OR: {
- debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_OR\n" );
+ case IN_TST_LOGICAL_OR_VAL: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_OR_VAL\n" );
+
+ Tree *o2 = vm_pop();
+ Tree *o1 = vm_pop();
+// long v2 = !testFalse( prg, o2 );
+// long v1 = !testFalse( prg, o1 );
+ Word r = o1 || o2;
+ Tree *val = r ? prg->trueVal : prg->falseVal;
+ //treeUpref( val );
+ vm_push( val );
+// treeDownref( prg, sp, o1 );
+// treeDownref( prg, sp, o2 );
+ break;
+ }
+ case IN_TST_LOGICAL_OR_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_LOGICAL_OR_TREE\n" );
Tree *o2 = vm_pop();
Tree *o1 = vm_pop();
@@ -1782,19 +1855,41 @@ again:
long v1 = !testFalse( prg, o1 );
Word r = v1 || v2;
Tree *val = r ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, o1 );
treeDownref( prg, sp, o2 );
break;
}
- case IN_NOT: {
- debug( prg, REALM_BYTECODE, "IN_NOT\n" );
+
+ case IN_TST_NZ_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_TST_NZ_TREE\n" );
+
+ Tree *tree = (Tree*)vm_pop();
+ long r = !testFalse( prg, tree );
+ vm_push_val( r );
+ break;
+ }
+
+ case IN_NOT_VAL: {
+ debug( prg, REALM_BYTECODE, "IN_NOT_VAL\n" );
+
+ Tree *tree = (Tree*)vm_pop();
+// long r = testFalse( prg, tree );
+ Tree *val = tree == 0 ? prg->trueVal : prg->falseVal;
+ //treeUpref( val );
+ vm_push( val );
+ //treeDownref( prg, sp, tree );
+ break;
+ }
+
+ case IN_NOT_TREE: {
+ debug( prg, REALM_BYTECODE, "IN_NOT_TREE\n" );
Tree *tree = (Tree*)vm_pop();
long r = testFalse( prg, tree );
Tree *val = r ? prg->trueVal : prg->falseVal;
- treeUpref( val );
+ //treeUpref( val );
vm_push( val );
treeDownref( prg, sp, tree );
break;
@@ -1805,12 +1900,12 @@ again:
Int *o2 = (Int*)vm_pop();
Int *o1 = (Int*)vm_pop();
- long r = o1->value + o2->value;
+ long r = (long)o1 + (long)o2;
Tree *tree = constructInteger( prg, r );
- treeUpref( tree );
+// treeUpref( tree );
vm_push( tree );
- treeDownref( prg, sp, (Tree*)o1 );
- treeDownref( prg, sp, (Tree*)o2 );
+// treeDownref( prg, sp, (Tree*)o1 );
+// treeDownref( prg, sp, (Tree*)o2 );
break;
}
case IN_MULT_INT: {
@@ -1818,12 +1913,12 @@ again:
Int *o2 = (Int*)vm_pop();
Int *o1 = (Int*)vm_pop();
- long r = o1->value * o2->value;
+ long r = (long)o1 * (long)o2;
Tree *tree = constructInteger( prg, r );
- treeUpref( tree );
+// treeUpref( tree );
vm_push( tree );
- treeDownref( prg, sp, (Tree*)o1 );
- treeDownref( prg, sp, (Tree*)o2 );
+// treeDownref( prg, sp, (Tree*)o1 );
+// treeDownref( prg, sp, (Tree*)o2 );
break;
}
case IN_DIV_INT: {
@@ -1831,12 +1926,12 @@ again:
Int *o2 = (Int*)vm_pop();
Int *o1 = (Int*)vm_pop();
- long r = o1->value / o2->value;
+ long r = (long)o1 / (long)o2;
Tree *tree = constructInteger( prg, r );
- treeUpref( tree );
+// treeUpref( tree );
vm_push( tree );
- treeDownref( prg, sp, (Tree*)o1 );
- treeDownref( prg, sp, (Tree*)o2 );
+// treeDownref( prg, sp, (Tree*)o1 );
+// treeDownref( prg, sp, (Tree*)o2 );
break;
}
case IN_SUB_INT: {
@@ -1844,12 +1939,12 @@ again:
Int *o2 = (Int*)vm_pop();
Int *o1 = (Int*)vm_pop();
- long r = o1->value - o2->value;
+ long r = (long)o1 - (long)o2;
Tree *tree = constructInteger( prg, r );
- treeUpref( tree );
+// treeUpref( tree );
vm_push( tree );
- treeDownref( prg, sp, (Tree*)o1 );
- treeDownref( prg, sp, (Tree*)o2 );
+// treeDownref( prg, sp, (Tree*)o1 );
+// treeDownref( prg, sp, (Tree*)o2 );
break;
}
case IN_TOP_SWAP: {
@@ -1970,7 +2065,7 @@ again:
TreeIter *iter = (TreeIter*) vm_plocal(field);
Tree *res = treeIterAdvance( prg, &sp, iter );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
break;
}
@@ -1982,7 +2077,7 @@ again:
TreeIter *iter = (TreeIter*) vm_plocal(field);
Tree *res = treeIterNextChild( prg, &sp, iter );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
break;
}
@@ -1994,7 +2089,7 @@ again:
RevTreeIter *iter = (RevTreeIter*) vm_plocal(field);
Tree *res = treeRevIterPrevChild( prg, &sp, iter );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
break;
}
@@ -2006,7 +2101,7 @@ again:
TreeIter *iter = (TreeIter*) vm_plocal(field);
Tree *res = treeIterNextRepeat( prg, &sp, iter );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
break;
}
@@ -2018,7 +2113,7 @@ again:
TreeIter *iter = (TreeIter*) vm_plocal(field);
Tree *res = treeIterPrevRepeat( prg, &sp, iter );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
break;
}
@@ -2562,7 +2657,7 @@ again:
rcode_word( exec, (Word) string );
rcode_unit_term( exec );
- treeDownref( prg, sp, len );
+ //treeDownref( prg, sp, len );
break;
}
@@ -2576,7 +2671,7 @@ again:
treeUpref( string );
vm_push( string );
- treeDownref( prg, sp, len );
+ //treeDownref( prg, sp, len );
break;
}
case IN_INPUT_PULL_BKT: {
@@ -2727,7 +2822,7 @@ again:
arg[i] = vm_pop();
Tree *result = constructToken( prg, arg, nargs );
- for ( i = 0; i < nargs; i++ )
+ for ( i = 1; i < nargs; i++ )
treeDownref( prg, sp, arg[i] );
vm_push( result );
break;
@@ -2744,7 +2839,7 @@ again:
arg[i] = vm_pop();
Tree *result = makeTree( prg, arg, nargs );
- for ( i = 0; i < nargs; i++ )
+ for ( i = 1; i < nargs; i++ )
treeDownref( prg, sp, arg[i] );
vm_push( result );
@@ -2961,7 +3056,7 @@ again:
Tree *integer = 0;
if ( tree->tokdata->location ) {
integer = constructInteger( prg, tree->tokdata->location->byte );
- treeUpref( integer );
+ //treeUpref( integer );
}
vm_push( integer );
treeDownref( prg, sp, tree );
@@ -2974,7 +3069,7 @@ again:
Tree *integer = 0;
if ( tree->tokdata->location ) {
integer = constructInteger( prg, tree->tokdata->location->line );
- treeUpref( integer );
+ //treeUpref( integer );
}
vm_push( integer );
treeDownref( prg, sp, tree );
@@ -2985,7 +3080,7 @@ again:
Tree *integer = constructInteger( prg,
stringLength(exec->parser->pdaRun->tokdata) );
- treeUpref( integer );
+ //treeUpref( integer );
vm_push( integer );
break;
}
@@ -3005,7 +3100,7 @@ again:
long len = colm_list_length( list );
Tree *res = constructInteger( prg, len );
treeDownref( prg, sp, (Tree*)list );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
break;
}
@@ -3119,7 +3214,7 @@ again:
Tree *obj = vm_pop();
long len = mapLength( (Map*)obj );
Tree *res = constructInteger( prg, len );
- treeUpref( res );
+ //treeUpref( res );
vm_push( res );
treeDownref( prg, sp, obj );
@@ -3255,7 +3350,7 @@ again:
/* Return the yield result on the top of the stack. */
Tree *result = uiter->ref.kid != 0 ? prg->trueVal : prg->falseVal;
- treeUpref( result );
+ //treeUpref( result );
vm_push( result );
}
break;
@@ -3426,7 +3521,7 @@ again:
treeDownref( prg, sp, (Tree*)cmd );
Tree *result = constructInteger( prg, r );
- treeUpref( result );
+ //treeUpref( result );
vm_push( result );
break;
}
@@ -3440,7 +3535,7 @@ again:
Str *str = (Str*)vm_pop();
Word res = strAtoi( str->value );
Tree *integer = constructInteger( prg, res );
- treeUpref( integer );
+ //treeUpref( integer );
vm_push( integer );
treeDownref( prg, sp, (Tree*)str );
break;
@@ -3451,7 +3546,7 @@ again:
Str *str = (Str*)vm_pop();
Word res = strUord8( str->value );
Tree *tree = constructInteger( prg, res );
- treeUpref( tree );
+ //treeUpref( tree );
vm_push( tree );
treeDownref( prg, sp, (Tree*)str );
break;
@@ -3462,7 +3557,7 @@ again:
Str *str = (Str*)vm_pop();
Word res = strUord16( str->value );
Tree *tree = constructInteger( prg, res );
- treeUpref( tree );
+ //treeUpref( tree );
vm_push( tree );
treeDownref( prg, sp, (Tree*)str );
break;
@@ -3522,7 +3617,7 @@ again:
ListEl *listEl = colm_struct_to_list_el( prg, s, genId );
colm_list_prepend( list, listEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
break;
}
@@ -3538,7 +3633,7 @@ again:
ListEl *listEl = colm_struct_to_list_el( prg, s, genId );
colm_list_prepend( list, listEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
/* Set up reverse code. Needs no args. */
@@ -3566,7 +3661,7 @@ again:
ListEl *listEl = colm_struct_to_list_el( prg, s, genId );
colm_list_append( list, listEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
break;
}
@@ -3582,7 +3677,7 @@ again:
ListEl *listEl = colm_struct_to_list_el( prg, s, genId );
colm_list_append( list, listEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
/* Set up reverse code. Needs no args. */
@@ -3736,7 +3831,7 @@ again:
colm_map_insert( prg, map, mapEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
break;
}
@@ -3753,7 +3848,7 @@ again:
MapEl *inserted = colm_map_insert( prg, map, mapEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
rcode_code( exec, IN_FN );
@@ -3798,7 +3893,7 @@ again:
colm_map_detach( prg, map, mapEl );
- treeUpref( prg->trueVal );
+ //treeUpref( prg->trueVal );
vm_push( prg->trueVal );
break;
}
@@ -3848,9 +3943,9 @@ again:
Tree *global = vm_pop();
Int *status = (Int*)vm_pop();
- prg->exitStatus = status->value;
+ prg->exitStatus = (long)status;//->value;
prg->induceExit = 1;
- treeDownref( prg, sp, (Tree*)status );
+ //treeDownref( prg, sp, (Tree*)status );
while ( true ) {
FrameInfo *fi = &prg->rtd->frameInfo[exec->frameId];
@@ -3873,6 +3968,7 @@ again:
vm_popn( fi->argSize );
vm_pop();
+ /* Problem here. */
treeDownref( prg, sp, retVal );
}
diff --git a/src/bytecode.h b/src/bytecode.h
index a41c3cd7..5c029ec6 100644
--- a/src/bytecode.h
+++ b/src/bytecode.h
@@ -41,6 +41,7 @@ typedef unsigned long colm_value_t;
/*
*/
+
#define IN_LOAD_INT 0x01
#define IN_LOAD_STR 0x02
#define IN_LOAD_NIL 0x03
@@ -54,19 +55,32 @@ typedef unsigned long colm_value_t;
#define IN_MULT_INT 0x0a
#define IN_DIV_INT 0x0b
-#define IN_TST_EQL_TREE 0x0c
#define IN_TST_EQL_VAL 0x59
-#define IN_TST_EQL 0x0c
+#define IN_TST_EQL_TREE 0x0c
+//#define IN_TST_EQL 0x0c
#define IN_TST_NOT_EQL_TREE 0x0d
#define IN_TST_NOT_EQL_VAL 0x5f
-#define IN_TST_LESS 0x0e
-#define IN_TST_GRTR 0x0f
-#define IN_TST_LESS_EQL 0x10
-#define IN_TST_GRTR_EQL 0x11
-#define IN_TST_LOGICAL_AND 0x12
-#define IN_TST_LOGICAL_OR 0x13
-
-#define IN_NOT 0x14
+#define IN_TST_LESS_VAL 0x0e
+#define IN_TST_LESS_TREE 0xbd
+#define IN_TST_GRTR_VAL 0x0f
+#define IN_TST_GRTR_TREE 0xbf
+#define IN_TST_LESS_EQL_VAL 0x10
+#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_NZ_TREE 0xd1
+
+//0xd3
+//0xd4
+//0xd5
+
+#define IN_NOT_VAL 0x14
+#define IN_NOT_TREE 0xd2
#define IN_JMP 0x15
#define IN_JMP_FALSE_TREE 0x16
@@ -370,6 +384,8 @@ enum TYPE
TYPE_ITER = 0x04,
TYPE_STRUCT = 0x05,
TYPE_GENERIC = 0x06,
+ TYPE_INT = 0x07,
+ TYPE_BOOL = 0x08,
};
/* Types of Generics. */
@@ -385,10 +401,8 @@ enum GEN {
enum LEL_ID {
LEL_ID_PTR = 1,
LEL_ID_VOID = 2,
- LEL_ID_BOOL = 3,
- LEL_ID_INT = 4,
- LEL_ID_STR = 5,
- LEL_ID_IGNORE = 6
+ LEL_ID_STR = 3,
+ LEL_ID_IGNORE = 4
};
/*
diff --git a/src/colm.lm b/src/colm.lm
index cd449372..9a7b6d2e 100644
--- a/src/colm.lm
+++ b/src/colm.lm
@@ -49,6 +49,8 @@ lex
token SWITCH / 'switch' /
token CASE / 'case' /
token DEFAULT / 'default' /
+ token INT / 'int' /
+ token BOOL / 'bool' /
token MAKE_TOKEN / 'make_token' /
token MAKE_TREE / 'make_tree' /
@@ -561,6 +563,8 @@ def code_factor
def type_ref
[region_qual id opt_repeat] :Id
+| [INT] :Int
+| [BOOL] :Bool
| [PARSER LT type_ref GT] :Parser
| [LIST LT type_ref GT] :List
| [MAP LT KeyType: type_ref ElType: type_ref GT] :Map
diff --git a/src/compiler.cc b/src/compiler.cc
index e66473c5..9192f290 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -364,8 +364,6 @@ Compiler::Compiler( )
//tokenStruct(0),
ptrLangEl(0),
- boolLangEl(0),
- intLangEl(0),
strLangEl(0),
anyLangEl(0),
rootLangEl(0),
diff --git a/src/compiler.h b/src/compiler.h
index d8219054..56e4a446 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -868,8 +868,6 @@ struct Compiler
LangEl *ptrLangEl;
LangEl *voidLangEl;
- LangEl *boolLangEl;
- LangEl *intLangEl;
LangEl *strLangEl;
LangEl *anyLangEl;
LangEl *rootLangEl;
diff --git a/src/declare.cc b/src/declare.cc
index d59e83d0..8c551c89 100644
--- a/src/declare.cc
+++ b/src/declare.cc
@@ -29,8 +29,8 @@ void Compiler::initUniqueTypes( )
uniqueTypeNil = new UniqueType( TYPE_NIL );
uniqueTypeVoid = new UniqueType( TYPE_TREE, voidLangEl );
uniqueTypePtr = new UniqueType( TYPE_TREE, ptrLangEl );
- uniqueTypeBool = new UniqueType( TYPE_TREE, boolLangEl );
- uniqueTypeInt = new UniqueType( TYPE_TREE, intLangEl );
+ uniqueTypeBool = new UniqueType( TYPE_BOOL );
+ uniqueTypeInt = new UniqueType( TYPE_INT );
uniqueTypeStr = new UniqueType( TYPE_TREE, strLangEl );
uniqueTypeIgnore = new UniqueType( TYPE_TREE, ignoreLangEl );
uniqueTypeAny = new UniqueType( TYPE_TREE, anyLangEl );
@@ -310,8 +310,8 @@ void Compiler::declareBaseLangEls()
ptrLangEl = declareLangEl( this, rootNamespace, "ptr", LangEl::Term );
voidLangEl = declareLangEl( this, rootNamespace, "void", LangEl::Term );
- boolLangEl = declareLangEl( this, rootNamespace, "bool", LangEl::Term );
- intLangEl = declareLangEl( this, rootNamespace, "int", LangEl::Term );
+// boolLangEl = declareLangEl( this, rootNamespace, "bool", LangEl::Term );
+// intLangEl = declareLangEl( this, rootNamespace, "int", LangEl::Term );
strLangEl = declareLangEl( this, rootNamespace, "str", LangEl::Term );
ignoreLangEl = declareLangEl( this, rootNamespace, "il", LangEl::Term );
@@ -749,7 +749,7 @@ void Compiler::addThis( ObjectDef *frame )
void Compiler::declareIntFields( )
{
intObj = ObjectDef::cons( ObjectDef::BuiltinType, "int", nextObjectId++ );
- intLangEl->objectDef = intObj;
+// intLangEl->objectDef = intObj;
initFunction( uniqueTypeStr, intObj, "to_string", IN_INT_TO_STR, IN_INT_TO_STR, true );
}
@@ -828,6 +828,7 @@ ObjectField *Compiler::makePosEl()
el->isConst = true;
el->inGetR = IN_GET_TOKEN_POS_R;
+ el->inGetValR = IN_GET_TOKEN_POS_R;
return el;
}
@@ -840,6 +841,7 @@ ObjectField *Compiler::makeLineEl()
el->isConst = true;
el->inGetR = IN_GET_TOKEN_LINE_R;
+ el->inGetValR = IN_GET_TOKEN_LINE_R;
return el;
}
@@ -853,6 +855,7 @@ void Compiler::addLengthField( ObjectDef *objDef, Code getLength )
ObjectField::InbuiltFieldType, typeRef, "length" );
el->isConst = true;
el->inGetR = getLength;
+ el->inGetValR = getLength;
objDef->rootScope->insertField( el->name, el );
}
diff --git a/src/loadcolm.cc b/src/loadcolm.cc
index 4405e334..f6d82284 100644
--- a/src/loadcolm.cc
+++ b/src/loadcolm.cc
@@ -894,6 +894,14 @@ struct LoadColm
tr = TypeRef::cons( typeRef.id().loc(), nspaceQual, id, repeatType );
break;
}
+ case type_ref::Int: {
+ tr = TypeRef::cons( internal, pd->uniqueTypeInt );
+ break;
+ }
+ case type_ref::Bool: {
+ tr = TypeRef::cons( internal, pd->uniqueTypeBool );
+ break;
+ }
case type_ref::Parser: {
TypeRef *type = walkTypeRef( typeRef._type_ref() );
tr = TypeRef::cons( typeRef.loc(), TypeRef::Parser, 0, type, 0 );
diff --git a/src/map.c b/src/map.c
index 92ce8b27..78e9d7ff 100644
--- a/src/map.c
+++ b/src/map.c
@@ -552,6 +552,20 @@ MapEl *mapCopyBranch( Program *prg, Map *map, MapEl *el, Kid *oldNextDown, Kid *
return newEl;
}
+static long map_cmp( Program *prg, Map *map, const Tree *tree1, const Tree *tree2 )
+{
+ if ( map->genericInfo->keyType == 0x7 ) {
+ if ( (long)tree1 < (long)tree2 )
+ return -1;
+ else if ( (long)tree1 > (long)tree2)
+ return 1;
+ return 0;
+ }
+ else {
+ return cmpTree( prg, tree1, tree2 );
+ }
+}
+
MapEl *mapInsertEl( Program *prg, Map *map, MapEl *element, MapEl **lastFound )
{
long keyRelation;
@@ -569,7 +583,7 @@ MapEl *mapInsertEl( Program *prg, Map *map, MapEl *element, MapEl **lastFound )
return element;
}
- keyRelation = cmpTree( prg,
+ keyRelation = map_cmp( prg, map,
element->key, curEl->key );
/* Do we go left? */
@@ -611,7 +625,7 @@ MapEl *mapInsertKey( Program *prg, Map *map, Tree *key, MapEl **lastFound )
return element;
}
- keyRelation = cmpTree( prg, key, curEl->key );
+ keyRelation = map_cmp( prg, map, key, curEl->key );
/* Do we go left? */
if ( keyRelation < 0 ) {
@@ -659,7 +673,7 @@ MapEl *mapImplFind( Program *prg, Map *map, Tree *key )
long keyRelation;
while ( curEl != 0 ) {
- keyRelation = cmpTree( prg, key, curEl->key );
+ keyRelation = map_cmp( prg, map, key, curEl->key );
/* Do we go left? */
if ( keyRelation < 0 )
diff --git a/src/parsetree.cc b/src/parsetree.cc
index 6f838c26..cc9c6bc6 100644
--- a/src/parsetree.cc
+++ b/src/parsetree.cc
@@ -119,7 +119,10 @@ int CmpUniqueType::compare( const UniqueType &ut1, const UniqueType &ut2 )
return 1;
break;
case TYPE_NIL:
+ case TYPE_INT:
+ case TYPE_BOOL:
break;
+
case TYPE_STRUCT:
if ( ut1.structEl < ut2.structEl )
return -1;
diff --git a/src/parsetree.h b/src/parsetree.h
index 0e60dc4e..6f3f78c1 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -1871,6 +1871,13 @@ struct UniqueType : public AvlTreeEl<UniqueType>
bool ptr()
{ return typeId == TYPE_STRUCT || typeId == TYPE_GENERIC; }
+
+ bool val() {
+ return typeId == TYPE_STRUCT ||
+ typeId == TYPE_GENERIC ||
+ typeId == TYPE_INT ||
+ typeId == TYPE_BOOL;
+ }
};
struct CmpUniqueType
@@ -1970,6 +1977,8 @@ struct TypeRef
MapEl,
Parser,
Ref,
+ Int,
+ Bool
};
TypeRef()
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index 6b177853..234c83f5 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -206,8 +206,8 @@ void Compiler::makeLangElIds()
}
assert( ptrLangEl->id == LEL_ID_PTR );
- assert( boolLangEl->id == LEL_ID_BOOL );
- assert( intLangEl->id == LEL_ID_INT );
+// assert( boolLangEl->id == LEL_ID_BOOL );
+// assert( intLangEl->id == LEL_ID_INT );
assert( strLangEl->id == LEL_ID_STR );
assert( ignoreLangEl->id == LEL_ID_IGNORE );
}
@@ -243,20 +243,20 @@ void Compiler::makeLangElNames()
lel->xmlTag = "void";
}
- else if ( lel->id == LEL_ID_INT ) {
- lel->fullName = "_int";
- lel->fullLit = "_int";
- lel->refName = "_int";
- lel->declName = "_int";
- lel->xmlTag = "int";
- }
- else if ( lel->id == LEL_ID_BOOL ) {
- lel->fullName = "_bool";
- lel->fullLit = "_bool";
- lel->refName = "_bool";
- lel->declName = "_bool";
- lel->xmlTag = "bool";
- }
+// else if ( lel->id == LEL_ID_INT ) {
+// lel->fullName = "_int";
+// lel->fullLit = "_int";
+// lel->refName = "_int";
+// lel->declName = "_int";
+// lel->xmlTag = "int";
+// }
+// else if ( lel->id == LEL_ID_BOOL ) {
+// lel->fullName = "_bool";
+// lel->fullLit = "_bool";
+// lel->refName = "_bool";
+// lel->declName = "_bool";
+// lel->xmlTag = "bool";
+// }
else {
lel->fullName = lel->name;
lel->fullLit = lel->lit;
@@ -1653,7 +1653,7 @@ void Compiler::makeRuntimeData()
runtimeData->firstNonTermId = firstNonTermId;
/* Special trees. */
- runtimeData->integerId = intLangEl->id;
+ runtimeData->integerId = -1; //intLangEl->id;
runtimeData->stringId = strLangEl->id;
runtimeData->anyId = anyLangEl->id;
runtimeData->eofId = 0; //eofLangEl->id;
diff --git a/src/program.c b/src/program.c
index 83ad04e4..cdd0f335 100644
--- a/src/program.c
+++ b/src/program.c
@@ -188,15 +188,15 @@ Program *colm_new_program( RuntimeData *rtd )
initPoolAlloc( &prg->headPool, sizeof(Head) );
initPoolAlloc( &prg->locationPool, sizeof(Location) );
- Int *trueInt = (Int*) treeAllocate( prg );
- trueInt->id = LEL_ID_BOOL;
- trueInt->refs = 1;
- trueInt->value = 1;
-
- Int *falseInt = (Int*) treeAllocate( prg );
- falseInt->id = LEL_ID_BOOL;
- falseInt->refs = 1;
- falseInt->value = 0;
+ Int *trueInt = (Int*) 1; //treeAllocate( prg );
+// trueInt->id = LEL_ID_BOOL;
+// trueInt->refs = 1;
+// trueInt->value = 1;
+//
+ Int *falseInt = (Int*) 0; //treeAllocate( prg );
+// falseInt->id = LEL_ID_BOOL;
+// falseInt->refs = 1;
+// falseInt->value = 0;
prg->trueVal = (Tree*)trueInt;
prg->falseVal = (Tree*)falseInt;
@@ -297,8 +297,8 @@ int colm_delete_program( Program *prg )
treeDownref( prg, sp, prg->returnVal );
colm_clear_heap( prg, sp );
- treeDownref( prg, sp, prg->trueVal );
- treeDownref( prg, sp, prg->falseVal );
+// treeDownref( prg, sp, prg->trueVal );
+// treeDownref( prg, sp, prg->falseVal );
treeDownref( prg, sp, prg->error );
diff --git a/src/string.c b/src/string.c
index 31472e21..6b85673f 100644
--- a/src/string.c
+++ b/src/string.c
@@ -238,9 +238,9 @@ Head *makeLiteral( Program *prg, long offset )
Head *stringSprintf( Program *prg, Str *format, Int *integer )
{
Head *formatHead = format->value;
- long written = snprintf( 0, 0, stringData(formatHead), integer->value );
+ long written = snprintf( 0, 0, stringData(formatHead), (long)integer );
Head *head = initStrSpace( written+1 );
- written = snprintf( (char*)head->data, written+1, stringData(formatHead), integer->value );
+ written = snprintf( (char*)head->data, written+1, stringData(formatHead), (long)integer );
head->length -= 1;
return head;
}
diff --git a/src/synthesis.cc b/src/synthesis.cc
index e720d631..3cd7462c 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -271,7 +271,7 @@ UniqueType *LangVarRef::loadField( Compiler *pd, CodeVect &code,
UniqueType *elUT = el->typeRef->uniqueType;
- if ( elUT->typeId == TYPE_STRUCT || elUT->typeId == TYPE_GENERIC ) {
+ if ( elUT->val() ) {
if ( forWriting ) {
/* The instruction, depends on whether or not we are reverting. */
if ( pd->revertOn && revert )
@@ -583,7 +583,7 @@ void LangVarRef::setField( Compiler *pd, CodeVect &code,
/* Ensure that the field is referenced. */
inObject->referenceField( pd, el );
- if ( exprUT->typeId == TYPE_STRUCT || exprUT->typeId == TYPE_GENERIC ) {
+ if ( exprUT->val() ) {
if ( pd->revertOn && revert )
code.append( el->inSetValWV );
else
@@ -1317,6 +1317,9 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
continue;
}
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
+
if ( ut == pd->uniqueTypeStream )
isStream = true;
@@ -1429,6 +1432,9 @@ void ConsItemList::evaluateSendStream( Compiler *pd, CodeVect &code )
code.append( IN_POP );
continue;
}
+
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
break;
}
@@ -1493,6 +1499,9 @@ void LangTerm::evaluateSendParser( Compiler *pd, CodeVect &code, bool strings )
if ( ut == pd->uniqueTypeStream )
isStream = true;
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
+
if ( strings && ut->typeId == TYPE_TREE &&
ut->langEl != pd->strLangEl && ut != pd->uniqueTypeStream )
{
@@ -1597,6 +1606,9 @@ UniqueType *LangTerm::evaluateEmbedString( Compiler *pd, CodeVect &code ) const
case ConsItem::ExprType: {
UniqueType *ut = item->expr->evaluate( pd, code );
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
+
if ( ut->typeId == TYPE_TREE &&
ut->langEl != pd->strLangEl && ut != pd->uniqueTypeStream )
{
@@ -1788,7 +1800,7 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const
if ( lt != rt )
error(loc) << "comparison of different types" << endp;
- if ( lt->ptr() )
+ if ( lt->val() )
code.append( IN_TST_EQL_VAL );
else
code.append( IN_TST_EQL_TREE );
@@ -1801,7 +1813,7 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const
if ( lt != rt )
error(loc) << "comparison of different types" << endp;
- if ( lt->ptr() )
+ if ( lt->val() )
code.append( IN_TST_NOT_EQL_VAL );
else
code.append( IN_TST_NOT_EQL_TREE );
@@ -1809,49 +1821,80 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const
return pd->uniqueTypeBool;
}
case '<': {
- left->evaluate( pd, code );
- right->evaluate( pd, code );
+ UniqueType *lt = left->evaluate( pd, code );
+ UniqueType *rt = right->evaluate( pd, code );
- code.append( IN_TST_LESS );
+ if ( lt != rt )
+ error(loc) << "comparison of different types" << endp;
+
+ if ( lt->val() )
+ code.append( IN_TST_LESS_VAL );
+ else
+ code.append( IN_TST_LESS_TREE );
return pd->uniqueTypeBool;
}
case '>': {
- left->evaluate( pd, code );
- right->evaluate( pd, code );
+ UniqueType *lt = left->evaluate( pd, code );
+ UniqueType *rt = right->evaluate( pd, code );
+
+ if ( lt != rt )
+ error(loc) << "comparison of different types" << endp;
+
+ if ( lt->val() )
+ code.append( IN_TST_GRTR_VAL );
+ else
+ code.append( IN_TST_GRTR_TREE );
- code.append( IN_TST_GRTR );
return pd->uniqueTypeBool;
}
case OP_LessEql: {
- left->evaluate( pd, code );
- right->evaluate( pd, code );
+ UniqueType *lt = left->evaluate( pd, code );
+ UniqueType *rt = right->evaluate( pd, code );
+
+ if ( lt != rt )
+ error(loc) << "comparison of different types" << endp;
+
+ if ( lt->val() )
+ code.append( IN_TST_LESS_EQL_VAL );
+ else
+ code.append( IN_TST_LESS_EQL_TREE );
- code.append( IN_TST_LESS_EQL );
return pd->uniqueTypeBool;
}
case OP_GrtrEql: {
- left->evaluate( pd, code );
- right->evaluate( pd, code );
+ UniqueType *lt = left->evaluate( pd, code );
+ UniqueType *rt = right->evaluate( pd, code );
+
+ if ( lt != rt )
+ error(loc) << "comparison of different types" << endp;
+
+ if ( lt->val() )
+ code.append( IN_TST_GRTR_EQL_VAL );
+ else
+ code.append( IN_TST_GRTR_EQL_TREE );
- code.append( IN_TST_GRTR_EQL );
return pd->uniqueTypeBool;
}
case OP_LogicalAnd: {
/* Evaluate the left and duplicate it. */
UniqueType *lut = left->evaluate( pd, code );
- code.append( IN_DUP_TREE );
+ if ( !lut->val() )
+ code.append( IN_TST_NZ_TREE );
+ code.append( IN_DUP_VAL );
/* Jump over the right if false, leaving the original left
* result on the top of the stack. We don't know the
* distance yet so record the position of the jump. */
long jump = code.length();
- Half jinstr = lut->tree() ? IN_JMP_FALSE_TREE : IN_JMP_FALSE_VAL;
- code.append( jinstr );
+ code.append( IN_JMP_FALSE_VAL );
code.appendHalf( 0 );
/* Evauluate the right, add the test. Store it separately. */
- right->evaluate( pd, code );
- code.append( IN_TST_LOGICAL_AND );
+ UniqueType *rut = right->evaluate( pd, code );
+ if ( !rut->val() )
+ code.append( IN_TST_NZ_TREE );
+
+ code.append( IN_TST_LOGICAL_AND_VAL );
/* Set the distance of the jump. */
long distance = code.length() - jump - 3;
@@ -1862,19 +1905,23 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const
case OP_LogicalOr: {
/* Evaluate the left and duplicate it. */
UniqueType *lut = left->evaluate( pd, code );
- code.append( IN_DUP_TREE );
+ if ( !lut->val() )
+ code.append( IN_TST_NZ_TREE );
+ code.append( IN_DUP_VAL );
/* Jump over the right if true, leaving the original left
* result on the top of the stack. We don't know the
* distance yet so record the position of the jump. */
long jump = code.length();
- Half jinstr = lut->tree() ? IN_JMP_TRUE_TREE : IN_JMP_TRUE_VAL;
- code.append( jinstr );
+ code.append( IN_JMP_TRUE_VAL );
code.appendHalf( 0 );
/* Evauluate the right, add the test. */
- right->evaluate( pd, code );
- code.append( IN_TST_LOGICAL_OR );
+ UniqueType *rut = right->evaluate( pd, code );
+ if ( !rut->val() )
+ code.append( IN_TST_NZ_TREE );
+
+ code.append( IN_TST_LOGICAL_OR_VAL );
/* Set the distance of the jump. */
long distance = code.length() - jump - 3;
@@ -1891,19 +1938,29 @@ UniqueType *LangExpr::evaluate( Compiler *pd, CodeVect &code ) const
switch ( op ) {
case '!': {
/* Evaluate the left and duplicate it. */
- right->evaluate( pd, code );
- code.append( IN_NOT );
+ UniqueType *ut = right->evaluate( pd, code );
+ if ( ut->val() )
+ code.append( IN_NOT_VAL );
+ else
+ code.append( IN_NOT_TREE );
return pd->uniqueTypeBool;
}
case '$': {
- right->evaluate( pd, code );
+ UniqueType *ut = right->evaluate( pd, code );
+
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
+
code.append( IN_TREE_TO_STR_TRIM );
return pd->uniqueTypeStr;
}
case '%': {
- right->evaluate( pd, code );
- code.append( IN_TREE_TO_STR );
+ UniqueType *ut = right->evaluate( pd, code );
+ if ( ut->typeId == TYPE_INT || ut->typeId == TYPE_BOOL )
+ code.append( IN_INT_TO_STR );
+ else
+ code.append( IN_TREE_TO_STR );
return pd->uniqueTypeStr;
}
case '^': {
@@ -2027,7 +2084,7 @@ void LangStmt::compileForIterBody( Compiler *pd,
/* Test: jump past the while block if false. Note that we don't have the
* distance yet. */
long jumpFalse = code.length();
- code.append( IN_JMP_FALSE_TREE );
+ code.append( IN_JMP_FALSE_VAL );
code.appendHalf( 0 );
/*
@@ -2181,8 +2238,14 @@ void LangStmt::compile( Compiler *pd, CodeVect &code ) const
UniqueType **types = new UniqueType*[exprPtrVect->length()];
/* Push the args backwards. */
- for ( CallArgVect::Iter pex = exprPtrVect->first(); pex.lte(); pex++ )
+ for ( CallArgVect::Iter pex = exprPtrVect->first(); pex.lte(); pex++ ) {
types[pex.pos()] = (*pex)->expr->evaluate( pd, code );
+ if ( types[pex.pos()]->typeId == TYPE_INT ||
+ types[pex.pos()]->typeId == TYPE_BOOL )
+ {
+ code.append( IN_INT_TO_STR );
+ }
+ }
/* Run the printing forwards. */
if ( type == PrintType ) {
diff --git a/src/tree.c b/src/tree.c
index 29d041ce..fa3c15cb 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -181,11 +181,7 @@ Kid *kidListConcat( Kid *list1, Kid *list2 )
Tree *constructInteger( Program *prg, long i )
{
- Int *integer = (Int*) treeAllocate( prg );
- integer->id = LEL_ID_INT;
- integer->value = i;
-
- return (Tree*)integer;
+ return (Tree*)i;
}
Tree *constructString( Program *prg, Head *s )
@@ -591,7 +587,7 @@ Tree *constructToken( Program *prg, Tree **args, long nargs )
Int *idInt = (Int*)args[0];
Str *textStr = (Str*)args[1];
- long id = idInt->value;
+ long id = (long)idInt;//->value;
Head *tokdata = stringCopy( prg, textStr->value );
LangElInfo *lelInfo = prg->rtd->lelInfo;
@@ -716,7 +712,7 @@ Tree *makeTree( Program *prg, Tree **args, long nargs )
{
Int *idInt = (Int*)args[0];
- long id = idInt->value;
+ long id = (long)idInt;//->value;
LangElInfo *lelInfo = prg->rtd->lelInfo;
Tree *tree = treeAllocate( prg );
@@ -749,8 +745,8 @@ int testFalse( Program *prg, Tree *tree )
{
int flse = (
tree == 0 ||
- tree == prg->falseVal ||
- ( tree->id == LEL_ID_INT && ((Int*)tree)->value == 0 ) );
+ tree == prg->falseVal /* ||
+ ( tree->id == LEL_ID_INT && ((Int*)tree)->value == 0 ) */ );
return flse;
}
@@ -923,10 +919,10 @@ Tree *copyTree( Program *prg, Tree *tree, Kid *oldNextDown, Kid **newNextDown )
// assert(false);
if ( tree->id == LEL_ID_PTR )
assert(false);
- else if ( tree->id == LEL_ID_BOOL )
- assert(false);
- else if ( tree->id == LEL_ID_INT )
- assert(false);
+// else if ( tree->id == LEL_ID_BOOL )
+// assert(false);
+// else if ( tree->id == LEL_ID_INT )
+// assert(false);
else if ( tree->id == LEL_ID_STR )
assert(false);
// else if ( tree->id == LEL_ID_STREAM )
@@ -975,8 +971,8 @@ free_tree:
// assert( genericId == 0 );
switch ( tree->id ) {
- case LEL_ID_BOOL:
- case LEL_ID_INT:
+// case LEL_ID_BOOL:
+// case LEL_ID_INT:
case LEL_ID_PTR:
treeFree( prg, tree );
break;
@@ -1049,11 +1045,11 @@ free_tree:
treeFree( prg, tree );
break;
}
- case LEL_ID_BOOL:
- case LEL_ID_INT: {
- treeFree( prg, tree );
- break;
- }
+// case LEL_ID_BOOL:
+// case LEL_ID_INT: {
+// treeFree( prg, tree );
+// break;
+// }
case LEL_ID_PTR: {
treeFree( prg, tree );
break;
@@ -1338,12 +1334,12 @@ long cmpTree( Program *prg, const Tree *tree1, const Tree *tree2 )
else if ( ((Pointer*)tree1)->value > ((Pointer*)tree2)->value )
return 1;
}
- else if ( tree1->id == LEL_ID_INT ) {
- if ( ((Int*)tree1)->value < ((Int*)tree2)->value )
- return -1;
- else if ( ((Int*)tree1)->value > ((Int*)tree2)->value )
- return 1;
- }
+// else if ( tree1->id == LEL_ID_INT ) {
+// if ( ((Int*)tree1)->value < ((Int*)tree2)->value )
+// return -1;
+// else if ( ((Int*)tree1)->value > ((Int*)tree2)->value )
+// return 1;
+// }
else if ( tree1->id == LEL_ID_STR ) {
cmpres = cmpString( ((Str*)tree1)->value, ((Str*)tree2)->value );
if ( cmpres != 0 )
@@ -2063,18 +2059,18 @@ void colm_print_term_tree( Program *prg, Tree **sp, struct colm_print_args *prin
{
debug( prg, REALM_PRINT, "printing term %p\n", kid->tree );
- if ( kid->tree->id == LEL_ID_INT ) {
- char buf[INT_SZ];
- sprintf( buf, "%ld", ((Int*)kid->tree)->value );
- printArgs->out( printArgs, buf, strlen(buf) );
- }
- else if ( kid->tree->id == LEL_ID_BOOL ) {
- if ( ((Int*)kid->tree)->value )
- printArgs->out( printArgs, "true", 4 );
- else
- printArgs->out( printArgs, "false", 5 );
- }
- else if ( kid->tree->id == LEL_ID_PTR ) {
+// if ( kid->tree->id == LEL_ID_INT ) {
+// char buf[INT_SZ];
+// sprintf( buf, "%ld", ((Int*)kid->tree)->value );
+// printArgs->out( printArgs, buf, strlen(buf) );
+// }
+// else if ( kid->tree->id == LEL_ID_BOOL ) {
+// if ( ((Int*)kid->tree)->value )
+// printArgs->out( printArgs, "true", 4 );
+// else
+// printArgs->out( printArgs, "false", 5 );
+// }
+ if ( kid->tree->id == LEL_ID_PTR ) {
char buf[INT_SZ];
printArgs->out( printArgs, "#", 1 );
sprintf( buf, "%p", (void*) ((Pointer*)kid->tree)->value );
@@ -2134,17 +2130,17 @@ void printTermXml( Program *prg, Tree **sp, struct colm_print_args *printArgs, K
sprintf( ptr, "%p\n", (void*)((Pointer*)kid->tree)->value );
printArgs->out( printArgs, ptr, strlen(ptr) );
}
- else if ( kid->tree->id == LEL_ID_BOOL ) {
- if ( ((Int*)kid->tree)->value )
- printArgs->out( printArgs, "true", 4 );
- else
- printArgs->out( printArgs, "false", 5 );
- }
- else if ( kid->tree->id == LEL_ID_INT ) {
- char ptr[32];
- sprintf( ptr, "%ld", ((Int*)kid->tree)->value );
- printArgs->out( printArgs, ptr, strlen(ptr) );
- }
+// else if ( kid->tree->id == LEL_ID_BOOL ) {
+// if ( ((Int*)kid->tree)->value )
+// printArgs->out( printArgs, "true", 4 );
+// else
+// printArgs->out( printArgs, "false", 5 );
+// }
+// else if ( kid->tree->id == LEL_ID_INT ) {
+// char ptr[32];
+// sprintf( ptr, "%ld", ((Int*)kid->tree)->value );
+// printArgs->out( printArgs, ptr, strlen(ptr) );
+// }
else if ( kid->tree->id == LEL_ID_STR ) {
Head *head = (Head*) ((Str*)kid->tree)->value;
diff --git a/test/exit6.lm b/test/exit6.lm
index ec43c399..a87f4383 100644
--- a/test/exit6.lm
+++ b/test/exit6.lm
@@ -699,8 +699,8 @@ send Output
iter i()
{
- I: int = 1
- yield I
+ S: str = "1"
+ yield S
}
int indepToHost( Indep: ref<section*> )
diff --git a/test/superid.lm b/test/superid.lm
index ba9383a4..6b9f2443 100644
--- a/test/superid.lm
+++ b/test/superid.lm
@@ -66,10 +66,10 @@ print( '\n' )
##### IN #####
!a b b a;
##### EXP #####
-old_id = NIL
-new_id = 12
-old_id = NIL
-new_id = 11
+old_id = 0
+new_id = 10
+old_id = 0
+new_id = 9
this is item2
<si::start><si::item2><si::e2></si::e2><si::_literal_0001>!</si::_literal_0001><si::_literal_0003>a</si::_literal_0003><si::super_id>b</si::super_id><si::super_id>b</si::super_id><si::_literal_0003>a</si::_literal_0003></si::item2><si::SEMI_NL>;
</si::SEMI_NL></si::start>