From 69a68e3fa451f2021da515483ac260d65c8642d3 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 8 Apr 2018 17:35:21 +0000 Subject: [PATCH] added the 'rem' and 'mod' primitive functions --- lib/prim.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/prim.c b/lib/prim.c index 6109734..9a54cc7 100644 --- a/lib/prim.c +++ b/lib/prim.c @@ -612,6 +612,25 @@ static hcl_pfrc_t pf_number_rem (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) return HCL_PF_SUCCESS; } + +static hcl_pfrc_t pf_number_mod (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) +{ + hcl_ooi_t i; + hcl_oop_t arg, ret, rem; + + ret = HCL_STACK_GETARG(hcl, nargs, 0); + for (i = 1; i < nargs; i++) + { + arg = HCL_STACK_GETARG(hcl, nargs, i); + ret = hcl_divints(hcl, ret, arg, 1, &rem); + if (!ret) return HCL_PF_FAILURE; + ret = rem; + } + + HCL_STACK_SETRET (hcl, nargs, ret); + return HCL_PF_SUCCESS; +} + static hcl_pfrc_t pf_number_sqrt (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) { hcl_oop_t ret; @@ -783,7 +802,8 @@ static pf_t builtin_prims[] = { 1, HCL_TYPE_MAX(hcl_oow_t), pf_number_mlt, 3, { 'm','l','t' } }, { 1, HCL_TYPE_MAX(hcl_oow_t), pf_number_div, 1, { '/' } }, { 1, HCL_TYPE_MAX(hcl_oow_t), pf_number_quo, 3, { 'q','u','o' } }, - { 2, HCL_TYPE_MAX(hcl_oow_t), pf_number_rem, 3, { 'm','o','d' } }, + { 2, HCL_TYPE_MAX(hcl_oow_t), pf_number_rem, 3, { 'r','e','m' } }, + { 2, HCL_TYPE_MAX(hcl_oow_t), pf_number_mod, 3, { 'm','o','d' } }, { 1, 1, pf_number_sqrt, 4, { 's','q','r','t' } }, { 1, 1, pf_number_abs, 3, { 'a','b','s' } },