Commit 4975eb5b authored by Duncan White's avatar Duncan White

tested experimental free support (added "-" dontfree hints in cdata.in, and...

tested experimental free support (added "-" dontfree hints in cdata.in, and tackled pointer sharing problems in ctest.c)
parent 455c12e5
...@@ -15,6 +15,7 @@ extern int lengthil( illist ); ...@@ -15,6 +15,7 @@ extern int lengthil( illist );
GLOBAL { GLOBAL {
#include <mem.h>
@@ @@
...@@ -60,7 +61,7 @@ first = a | b | c | d | e; ...@@ -60,7 +61,7 @@ first = a | b | c | d | e;
second = a( int aa ); second = a( int aa );
third = a | b; third = a | b;
fourth = a | b | c(char cc) | d | e; fourth = a | b | c(char cc) | d | e;
fifth = a | b | c(BOOL cc) | d( string dd) | e; fifth = a | b | c(BOOL cc) | d( -string dd) | e;
sixth = a(int aa, BOOL ab, -string ac) | b | c | d | e; sixth = a(int aa, BOOL ab, -string ac) | b | c | d | e;
intlist = nil "nil" intlist = nil "nil"
...@@ -68,10 +69,10 @@ intlist = nil "nil" ...@@ -68,10 +69,10 @@ intlist = nil "nil"
; ;
illist = nil "nil" illist = nil "nil"
| cons( intlist first, illist next ) "[ " 1 " ] , " 2 | cons( -intlist first, illist next ) "[ " 1 " ] , " 2
; ;
idtree = leaf( string id, intlist l ) "leaf( '" 1 "', " 2 ")" idtree = leaf( -string id, -intlist l ) "leaf( '" 1 "', " 2 ")"
| node( idtree left, idtree right ) "( " 1 " , " 2 " )" | node( idtree left, idtree right ) "node( " 1 " , " 2 " )"
; ;
} }
#include <stdio.h> #include <stdio.h>
#include <mem.h>
#include "cx.h" #include "cx.h"
...@@ -7,10 +8,6 @@ intlist int1, int2, int3; ...@@ -7,10 +8,6 @@ intlist int1, int2, int3;
void test_intlist( void ) void test_intlist( void )
{ {
int1 = intlist_nil();
int2 = intlist_cons( 11, int1 );
int3 = intlist_cons( 20, int2 );
printf( "intlists:\n" ); printf( "intlists:\n" );
printf( "\n int1: len %d, ", length(int1) ); printf( "\n int1: len %d, ", length(int1) );
print_intlist( stdout, int1 ); print_intlist( stdout, int1 );
...@@ -27,9 +24,9 @@ void test_illist( void ) ...@@ -27,9 +24,9 @@ void test_illist( void )
illist il1, il2, il3, il4; illist il1, il2, il3, il4;
il1 = illist_nil(); il1 = illist_nil();
il2 = illist_cons( int1, il1 ); il2 = illist_cons( int1, illist_nil() );
il3 = illist_cons( int2, il2 ); il3 = illist_cons( int2, illist_cons( int1, illist_nil() ) );
il4 = illist_cons( int3, il3 ); il4 = illist_cons( int3, illist_cons( int2, illist_cons( int1, illist_nil() ) ) );
printf( "illists:\n" ); printf( "illists:\n" );
printf( "\n il1: len %d, ", lengthil(il1) ); print_illist( stdout, il1 ); printf( "\n il1: len %d, ", lengthil(il1) ); print_illist( stdout, il1 );
...@@ -37,19 +34,23 @@ void test_illist( void ) ...@@ -37,19 +34,23 @@ void test_illist( void )
printf( "\n il3: len %d, ", lengthil(il3) ); print_illist( stdout, il3 ); printf( "\n il3: len %d, ", lengthil(il3) ); print_illist( stdout, il3 );
printf( "\n il4: len %d, ", lengthil(il4) ); print_illist( stdout, il4 ); printf( "\n il4: len %d, ", lengthil(il4) ); print_illist( stdout, il4 );
printf( "\n\n" ); printf( "\n\n" );
free_illist( il1 );
free_illist( il2 );
free_illist( il3 );
free_illist( il4 );
} }
void test_idtree( void ) void test_idtree( void )
{ {
idtree id1, id2, id3, id4, id5, id6; idtree id1, id2, id3, id4, id5;
id1 = idtree_leaf( "hello", int1 ); id1 = idtree_leaf( "hello", int1 );
id2 = idtree_leaf( "there", int2 ); id2 = idtree_leaf( "there", int2 );
id3 = idtree_node( id1, id2 ); id3 = idtree_leaf( "wotcher", int3 );
id4 = idtree_node( id3, id1 ); id4 = idtree_node( id1, id2 );
id5 = idtree_leaf( "zebedee", int3 ); id5 = idtree_node( id3, id4 );
id6 = idtree_node( id4, id5 );
printf( "idtrees:\n" ); printf( "idtrees:\n" );
printf( "\n id1: " ); print_idtree( stdout, id1 ); printf( "\n id1: " ); print_idtree( stdout, id1 );
...@@ -57,16 +58,34 @@ void test_idtree( void ) ...@@ -57,16 +58,34 @@ void test_idtree( void )
printf( "\n id3: " ); print_idtree( stdout, id3 ); printf( "\n id3: " ); print_idtree( stdout, id3 );
printf( "\n id4: " ); print_idtree( stdout, id4 ); printf( "\n id4: " ); print_idtree( stdout, id4 );
printf( "\n id5: " ); print_idtree( stdout, id5 ); printf( "\n id5: " ); print_idtree( stdout, id5 );
printf( "\n id6: " ); print_idtree( stdout, id6 );
printf( "\n\n" ); printf( "\n\n" );
//free_idtree( id1 );
//free_idtree( id2 );
//free_idtree( id3 );
//free_idtree( id4 );
free_idtree( id5 );
} }
int main( void ) int main( void )
{ {
init_cx(); init_cx();
int1 = intlist_nil();
int2 = intlist_cons( 11, intlist_nil() );
int3 = intlist_cons( 20, intlist_cons( 11, intlist_nil() ) );
test_intlist(); test_intlist();
test_illist(); test_illist();
test_idtree(); test_idtree();
free_intlist( int1 );
free_intlist( int2 );
free_intlist( int3 );
exit(0);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment