diff options
Diffstat (limited to 'test/colm.d/ext1.lm')
-rw-r--r-- | test/colm.d/ext1.lm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/colm.d/ext1.lm b/test/colm.d/ext1.lm new file mode 100644 index 00000000..9689227f --- /dev/null +++ b/test/colm.d/ext1.lm @@ -0,0 +1,31 @@ +str alphcount( Str: str ) += c_alphcount + +print "[alphcount( " hello friend " )] + +##### CALL ##### +#include <colm/tree.h> +#include <colm/bytecode.h> +#include <stdio.h> +#include <string.h> + +str_t *c_alphcount( program_t *prg, tree_t **sp, str_t *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_t *h = string_alloc_full( prg, strc, strlen( strc ) ); + tree_t *s = construct_string( prg, h ); + colm_tree_upref( prg, s ); + colm_tree_downref( prg, sp, a1 ); + return (str_t*)s; +} +##### EXP ##### +11 |