diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-07-10 16:32:44 -0700 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-07-10 16:32:44 -0700 |
commit | df2eaea6a92c7d89d604d0a4e885d064678ce3ed (patch) | |
tree | 127610b11382d876d1be2ebce2f770d60147788b /awkgram.c | |
parent | 21606db0d06b91332b1514f6662f7bc6d414e54e (diff) | |
download | egawk-df2eaea6a92c7d89d604d0a4e885d064678ce3ed.tar.gz egawk-df2eaea6a92c7d89d604d0a4e885d064678ce3ed.tar.bz2 egawk-df2eaea6a92c7d89d604d0a4e885d064678ce3ed.zip |
Add div() function for integer division & remainder.
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -4199,6 +4199,7 @@ static const struct token tokentab[] = { {"dcngettext", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3)|A(4)|A(5), do_dcngettext, 0}, {"default", Op_K_default, LEX_DEFAULT, GAWKX, 0, 0}, {"delete", Op_K_delete, LEX_DELETE, NOT_OLD, 0, 0}, +{"div", Op_builtin, LEX_BUILTIN, GAWKX|A(3), do_div, MPF(div)}, {"do", Op_K_do, LEX_DO, NOT_OLD|BREAK|CONTINUE, 0, 0}, {"else", Op_K_else, LEX_ELSE, 0, 0, 0}, {"eval", Op_symbol, LEX_EVAL, 0, 0, 0}, @@ -6244,7 +6245,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) } #ifdef HAVE_MPFR - /* N.B.: There isn't any special processing for an alternate function below */ + /* N.B.: If necessary, add special processing for alternate builtin, below */ if (do_mpfr && tokentab[idx].ptr2) r->builtin = tokentab[idx].ptr2; else @@ -6273,6 +6274,15 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) 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_div +#ifdef HAVE_MPFR + || r->builtin == MPF(div) +#endif + ) { + arg = subn->nexti->lasti->nexti->lasti->nexti; /* 3rd arg list */ + ip = arg->lasti; + if (ip->opcode == Op_push) + ip->opcode = Op_push_array; } else if (r->builtin == do_match) { static bool warned = false; |