diff options
| author | Paul Buetow <paul@buetow.org> | 2008-11-09 11:28:26 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-11-09 11:28:26 +0000 |
| commit | 0c69b76e7d7cbc50d4f87e41766a2de1394a6cad (patch) | |
| tree | 5b9d1d27af7470ce54cb9b1fa6af48869f103efa /src/core/function.c | |
| parent | ec175fe6a038171c4a24c9089e146a28a4343450 (diff) | |
len and ind implemented
Diffstat (limited to 'src/core/function.c')
| -rw-r--r-- | src/core/function.c | 31 |
1 files changed, 31 insertions, 0 deletions
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"); |
