diff options
author | Adrian Thurston <thurston@complang.org> | 2015-04-03 15:09:15 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-04-03 15:09:15 -0400 |
commit | fa5f9a998a4138abed01557eadb577d316e3482d (patch) | |
tree | b1850d9de695e083a12f1d607afe81e1b31691c8 /test | |
parent | 9a03234d26ede0dda117b7b03cd5849834f17614 (diff) | |
download | colm-fa5f9a998a4138abed01557eadb577d316e3482d.tar.gz |
fixes for host-code function calls, added a couple test cases
Calls into colm programs was broken since recent changes to calling
conventions. Fixed and added a test case. Also added a test case for C
extensions to colm programs.
Diffstat (limited to 'test')
-rw-r--r-- | test/ext1.lm | 24 | ||||
-rw-r--r-- | test/extfunc1.c | 23 | ||||
-rw-r--r-- | test/load1.lm | 40 | ||||
-rw-r--r-- | test/runtests.sh | 55 |
4 files changed, 108 insertions, 34 deletions
diff --git a/test/ext1.lm b/test/ext1.lm index 20a7ae39..3d2c40c8 100644 --- a/test/ext1.lm +++ b/test/ext1.lm @@ -4,6 +4,28 @@ str alphcount( Str: str ) print "[alphcount( " hello friend " )] ##### CALL ##### -extfunc1.c +#include <colm/tree.h> +#include <colm/bytecode.h> +#include <stdio.h> +#include <string.h> + +Str *c_alphcount( Program *prg, Tree **sp, Str *a1 ) +{ + int p, count = 0; + for ( p = 0; p < a1->value->length; p++ ) { + char c = a1->value->data[p]; + if ( 'a' <= c && c <= 'z' ) + count++; + } + + char strc[64]; + sprintf( strc, "%d", count ); + + Head *h = stringAllocFull( prg, strc, strlen( strc ) ); + Tree *s = constructString( prg, h ); + treeUpref( s ); + treeDownref( prg, sp, a1 ); + return (Str*)s; +} ##### EXP ##### 11 diff --git a/test/extfunc1.c b/test/extfunc1.c deleted file mode 100644 index 7a6a3e15..00000000 --- a/test/extfunc1.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <colm/tree.h> -#include <colm/bytecode.h> -#include <stdio.h> -#include <string.h> - -Str *c_alphcount( Program *prg, Tree **sp, Str *a1 ) -{ - int p, count = 0; - for ( p = 0; p < a1->value->length; p++ ) { - char c = a1->value->data[p]; - if ( 'a' <= c && c <= 'z' ) - count++; - } - - char strc[64]; - sprintf( strc, "%d", count ); - - Head *h = stringAllocFull( prg, strc, strlen( strc ) ); - Tree *s = constructString( prg, h ); - treeUpref( s ); - treeDownref( prg, sp, a1 ); - return (Str*)s; -} diff --git a/test/load1.lm b/test/load1.lm new file mode 100644 index 00000000..5ac3a924 --- /dev/null +++ b/test/load1.lm @@ -0,0 +1,40 @@ + +print "this is the program + +def foo + Str: str + [] + +export foo f( Str: str ) +{ + cons Foo: foo[] + Foo.Str = Str + return Foo +} + +##### HOST ##### + +#include <colm/colm.h> +#include <colm/tree.h> +#include <errno.h> +#include "working/load1.if.h" +#include <iostream> + +extern colm_sections colm_object; + +int main( int argc, const char **argv ) +{ + colm_program *program = colm_new_program( &colm_object ); + colm_set_debug( program, 1 ); + colm_run_program( program, argc, argv ); + + foo F = f( program, "passthrouh" ); + + std::cout << F.Str().text() << std::endl; + + colm_delete_program( program ); + return 0; +} +##### EXP ##### +this is the program +passthrough diff --git a/test/runtests.sh b/test/runtests.sh index c95e1b40..8223890d 100644 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -57,6 +57,22 @@ function sig_exit() exit 1; } +function echo_cmd() +{ + echo $@ + $@ +} + +function check_compilation() +{ + if [ $1 != 0 ]; then + echo "ERROR: $TST cannot be run: compilation error" + ERRORS=$(( ERRORS + 1 )) + continue + return 1 + fi +} + trap sig_exit SIGINT trap sig_exit SIGQUIT trap sig_exit SIGTERM @@ -151,6 +167,8 @@ function runtests() ARGS=$WORKING/$ROOT.args IN=$WORKING/$ROOT.in EXP=$WORKING/$ROOT.exp + HOST=$WORKING/$ROOT.host.cc + CALL=$WORKING/$ROOT.call.c section LM 0 $TST $LM @@ -165,19 +183,36 @@ function runtests() continue fi + section CALL 0 $TST $CALL + section HOST 0 $TST $HOST + COLM_ADDS="" - for a in `cat_section CALL 0 $TST`; do - COLM_ADDS="$COLM_ADDS -a $a" - done + if test -f $CALL; then + COLM_ADDS="-a $CALL" + fi + if test -f $HOST; then + PARSE=$WORKING/$ROOT.parse + IF=$WORKING/$ROOT.if - # Compilation. - echo $COLM $COLM_ADDS $TST - $COLM $COLM_ADDS $LM &> $LOG - if [ $? != 0 ]; then - echo "ERROR: $TST cannot be run: compilation error" - ERRORS=$(( ERRORS + 1 )) - continue + echo_cmd $COLM -c -o $PARSE.c -e $IF.h -x $IF.cc $LM + if ! check_compilation $?; then + continue + fi + + echo_cmd gcc -c -I../src/include -L../src -o $PARSE.o $PARSE.c + echo_cmd g++ -I. -I../src/include -L../src -o $WORKING/$ROOT \ + $IF.cc $HOST $PARSE.o -lcolmd + + if ! check_compilation $?; then + continue + fi + else + # Compilation. + echo_cmd $COLM $COLM_ADDS $LM &> $LOG + if ! check_compilation $?; then + continue + fi fi Nth=0 |