Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c4b3c34e6c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 43 lines (35 sloc) 1.296 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
//// compiled primitives for numbers

COMPILE_FN(+, compiledFn_add, "($x $y)",
  Cell* x = lookup("$x"); Cell* y = lookup("$y");
  if (x->type == FLOAT || y->type == FLOAT)
    return mkref(newNum(toFloat(x) + toFloat(y)));
  else
    return mkref(newNum(toInt(x) + toInt(y)));
)

COMPILE_FN(-, compiledFn_subtract, "($x $y)",
  Cell* x = lookup("$x"); Cell* y = lookup("$y");
  if (x->type == FLOAT || y->type == FLOAT)
    return mkref(newNum(toFloat(x) - toFloat(y)));
  else
    return mkref(newNum(toInt(x) - toInt(y)));
)

COMPILE_FN(*, compiledFn_multiply, "($x $y)",
  Cell* x = lookup("$x"); Cell* y = lookup("$y");
  if (x->type == FLOAT || y->type == FLOAT)
    return mkref(newNum(toFloat(x) * toFloat(y)));
  else
    return mkref(newNum(toInt(x) * toInt(y)));
)

COMPILE_FN(/, compiledFn_divide, "($x $y)",
  Cell* x = lookup("$x"); Cell* y = lookup("$y");
  return mkref(newNum(toFloat(x) / toFloat(y)));
)

COMPILE_FN(%, compiledFn_modulo, "($x $y)",
  return mkref(newNum(toInt(lookup("$x")) % toInt(lookup("$y")))); // what does modulo of floats mean?
)

COMPILE_FN(<, compiledFn_lesser, "($x $y)",
  return toFloat(lookup("$x")) < toFloat(lookup("$y")) ? mkref(lookup("$x")) : nil;
)

COMPILE_FN(int, compiledFn_integer, "($x)",
  return mkref(newNum(toInt(lookup("$x"))));
)
Something went wrong with that request. Please try again.