mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 20:30:28 +02:00
add1 and sub1 instructions
* libguile/vm-i-scheme.c: Add add1 and sub1 instructions. * module/language/tree-il/compile-glil.scm: Compile 1+ and 1- to add1 and sub1. * module/language/tree-il/primitives.scm (define-primitive-expander): Add support for `if' statements in the consequent. (+, -): Compile (- x 1), (+ x 1), and (+ 1 x) to 1- or 1+ as appropriate. (1-): Remove this one. Seems we forgot 1+ before, but we weren't compiling it nicely anyway. * test-suite/tests/tree-il.test ("void"): Fix expected compilation of (+ (void) 1) to allow for add1.
This commit is contained in:
parent
f4863880f5
commit
7382f23e58
4 changed files with 52 additions and 6 deletions
|
@ -215,11 +215,37 @@ VM_DEFINE_FUNCTION (120, add, "add", 2)
|
|||
FUNC2 (+, scm_sum);
|
||||
}
|
||||
|
||||
VM_DEFINE_FUNCTION (167, add1, "add1", 1)
|
||||
{
|
||||
ARGS1 (x);
|
||||
if (SCM_I_INUMP (x))
|
||||
{
|
||||
scm_t_int64 n = SCM_I_INUM (x) + 1;
|
||||
if (SCM_FIXABLE (n))
|
||||
RETURN (SCM_I_MAKINUM (n));
|
||||
}
|
||||
SYNC_REGISTER ();
|
||||
RETURN (scm_sum (x, SCM_I_MAKINUM (1)));
|
||||
}
|
||||
|
||||
VM_DEFINE_FUNCTION (121, sub, "sub", 2)
|
||||
{
|
||||
FUNC2 (-, scm_difference);
|
||||
}
|
||||
|
||||
VM_DEFINE_FUNCTION (168, sub1, "sub1", 1)
|
||||
{
|
||||
ARGS1 (x);
|
||||
if (SCM_I_INUMP (x))
|
||||
{
|
||||
scm_t_int64 n = SCM_I_INUM (x) - 1;
|
||||
if (SCM_FIXABLE (n))
|
||||
RETURN (SCM_I_MAKINUM (n));
|
||||
}
|
||||
SYNC_REGISTER ();
|
||||
RETURN (scm_difference (x, SCM_I_MAKINUM (1)));
|
||||
}
|
||||
|
||||
VM_DEFINE_FUNCTION (122, mul, "mul", 2)
|
||||
{
|
||||
ARGS2 (x, y);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue