aboutsummaryrefslogtreecommitdiffstats
path: root/awkgram.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2011-01-30 21:55:59 +0200
committerArnold D. Robbins <arnold@skeeve.com>2011-01-30 21:55:59 +0200
commit318b7ac345d0e78502ac0674a8ebb467997174f3 (patch)
treed21662d1435c3c768cf2d2a2cc9ee7114912d9de /awkgram.c
parenta7dd34e347fecd3a09be19c9c2b9fe99e1bbbcd7 (diff)
downloadegawk-318b7ac345d0e78502ac0674a8ebb467997174f3.tar.gz
egawk-318b7ac345d0e78502ac0674a8ebb467997174f3.tar.bz2
egawk-318b7ac345d0e78502ac0674a8ebb467997174f3.zip
Add isarray built-in function.
Diffstat (limited to 'awkgram.c')
-rw-r--r--awkgram.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/awkgram.c b/awkgram.c
index f1fa9dd2..c97684f3 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4513,6 +4513,7 @@ static const struct token tokentab[] = {
{"include", Op_symbol, LEX_INCLUDE, GAWKX, 0},
{"index", Op_builtin, LEX_BUILTIN, A(2), do_index},
{"int", Op_builtin, LEX_BUILTIN, A(1), do_int},
+{"isarray", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_isarray},
{"length", Op_builtin, LEX_LENGTH, A(0)|A(1), do_length},
{"log", Op_builtin, LEX_BUILTIN, A(1), do_log},
{"lshift", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_lshift},
@@ -6152,7 +6153,6 @@ snode(INSTRUCTION *subn, INSTRUCTION *r)
if (subn != NULL) {
INSTRUCTION *tp;
for (tp = subn->nexti; tp; tp = tp->nexti) {
- /* assert(tp->opcode == Op_list); */
tp = tp->lasti;
nexp++;
}
@@ -6172,15 +6172,24 @@ snode(INSTRUCTION *subn, INSTRUCTION *r)
/* special case processing for a few builtins */
if (r->builtin == do_length) {
if (nexp == 0) {
- INSTRUCTION *list; /* no args. Use $0 */
+ /* no args. Use $0 */
+ INSTRUCTION *list;
r->expr_count = 1;
list = list_create(r);
(void) list_prepend(list, instruction(Op_field_spec));
(void) list_prepend(list, instruction(Op_push_i));
list->nexti->memory = mk_number((AWKNUM) 0.0, (PERM|NUMCUR|NUMBER));
return list;
- }
+ } else {
+ arg = subn->nexti;
+ if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
+ arg->nexti->opcode = Op_push_arg; /* argument may be array */
+ }
+ } else if (r->builtin == do_isarray) {
+ arg = subn->nexti;
+ if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
+ arg->nexti->opcode = Op_push_arg; /* argument may be array */
} else if (r->builtin == do_match) {
static short warned = FALSE;