From 0c69b76e7d7cbc50d4f87e41766a2de1394a6cad Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 9 Nov 2008 11:28:26 +0000 Subject: len and ind implemented --- NEW | 4 ++++ docs/stats.txt | 2 +- fype | Bin 456844 -> 457100 bytes src/build.h | 2 +- src/core/function.c | 31 +++++++++++++++++++++++++++++++ src/data/array.c | 2 -- src/data/array.h | 1 + 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/NEW b/NEW index 47e74e0..b0dbb82 100644 --- a/NEW +++ b/NEW @@ -1,2 +1,6 @@ keywords: refs + +functions: + ind + len diff --git a/docs/stats.txt b/docs/stats.txt index e885347..80adb30 100644 --- a/docs/stats.txt +++ b/docs/stats.txt @@ -1,4 +1,4 @@ ===> Num of C source files : 44 -===> Num of C source lines : 8002 +===> Num of C source lines : 8032 ===> Num of Fype source examples : 14 ===> Num of Fype source lines : 362 diff --git a/fype b/fype index 855003e..4746410 100755 Binary files a/fype and b/fype differ diff --git a/src/build.h b/src/build.h index c192ce4..242be89 100644 --- a/src/build.h +++ b/src/build.h @@ -35,7 +35,7 @@ #ifndef BUILD_H #define BUILD_H -#define BUILDNR 9623 +#define BUILDNR 9627 #define OS_FREEBSD #endif diff --git a/src/core/function.c b/src/core/function.c index 0df0b65..e21b029 100644 --- a/src/core/function.c +++ b/src/core/function.c @@ -596,9 +596,15 @@ function_is_buildin(Token *p_token_ident) { if (strcmp("incr", token_get_val(p_token_ident)) == 0) return (true); + if (strcmp("ind", token_get_val(p_token_ident)) == 0) + return (true); + if (strcmp("integer", token_get_val(p_token_ident)) == 0) return (true); + if (strcmp("len", token_get_val(p_token_ident)) == 0) + return (true); + if (strcmp("ln", token_get_val(p_token_ident)) == 0) return (true); @@ -639,6 +645,17 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident, Token *p_token = stack_top(p_stack_args); if (token_get_tt(p_token) == TT_ARRAY) { + if (strcmp("len", token_get_val(p_token_ident)) == 0) { + stack_pop(p_stack_args); + stack_push(p_stack_args, + token_new_integer(array_get_used(p_token->p_array))); + + } else if (strcmp("ind", token_get_val(p_token_ident)) == 0) { + stack_pop(p_stack_args); + stack_push(p_stack_args, + token_new_integer(array_get_ind(p_token->p_array))); + + } else { ArrayIterator *p_iter = arrayiterator_new(p_token->p_array); while (arrayiterator_has_next(p_iter)) { @@ -649,6 +666,7 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident, } arrayiterator_delete(p_iter); + } return; } @@ -737,6 +755,9 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident, NO_DEFAULT; } + } else if (strcmp("ind", token_get_val(p_token_ident)) == 0) { + _FUNCTION_ERROR("Expected array", p_token_ident); + } else if (strcmp("integer", token_get_val(p_token_ident)) == 0) { if (0 == stack_size(p_stack_args)) _FUNCTION_ERROR("No argument given", p_token_ident); @@ -745,6 +766,16 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident, convert_to_integer(p_token); stack_push(p_stack_args, p_token); + } else if (strcmp("len", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = token_new_copy(stack_pop(p_stack_args)); + convert_to_string(p_token); + token_set_tt(p_token, TT_INTEGER); + token_set_ival(p_token, strlen(token_get_val(p_token))); + stack_push(p_stack_args, p_token); + } else if (strcmp("ln", token_get_val(p_token_ident)) == 0) { printf("\n"); diff --git a/src/data/array.c b/src/data/array.c index ba9cf2a..21e941d 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -115,7 +115,6 @@ array_set(Array *p_array, int i_index, void *p_val) { void array_set_used(Array *p_array, int i_used) { - //printf("foo %d",i_used); p_array->i_used = i_used; } @@ -193,7 +192,6 @@ array_resize(Array *p_array, int i_size) { p_array->pp_ae[i] = arrayelement_new(NULL); p_array->i_size = i_size; - //printf("[%d > %d]", p_array->i_used, i_size); if (p_array->i_used > i_size) array_set_used(p_array, i_size); } diff --git a/src/data/array.h b/src/data/array.h index eb935e9..a56082f 100644 --- a/src/data/array.h +++ b/src/data/array.h @@ -42,6 +42,7 @@ #define array_get_size(a) a->i_size #define array_get_used(a) a->i_used +#define array_get_ind(a) (a->i_used - 1) #define array_empty(a) a->i_size == 0 #define array_clear(a) array_resize(a, 0) #define array_get_first(a) array_get(a, 0) -- cgit v1.2.3