Table of Contents
The EulerLisp VM is stack-based and has one operand register.
Arithmetic primitives work by assigning
to the result of
using the given primitive.
(+ a b)
<Code for b> PUSH_VAULE <Code for a> POP_ARG1 ADD
Arguments are evaluated from right to left and pushed to the stack,
then popped to
one by one. This is important for primitives
that are not commutative, e.g.
This easily extends to an arbitrary number of arguments.
(+ a b c d)
which compiles to
<Code for d> PUSH_VAULE <Code for c> PUSH_VAULE <Code for b> PUSH_VAULE <Code for a> POP_ARG1 ADD POP_ARG1 ADD POP_ARG1 ADD
Previously, primitives with more than two arguments were implemented using builtin functions. The changes in performance are negligible since arithmetic primitives with more than two arguments are rarely used.
Running Project Euler Problems 1 to 50: Before: 29.446s / 30.340s / 29.978s After: 28.455s / 28.356s / 29.118s