Add a negation operator
[fur] / templates / program.c
index ecabb17..64e0152 100644 (file)
@@ -113,6 +113,85 @@ Object stringLiteral(Runtime* runtime, const char* literal)
   return result;
 }
 
+// TODO Make this conditionally added
+Object builtin$negate(Object input)
+{
+  assert(input.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = -input.instance.integer;
+  return result;
+}
+
+Object builtin$add(Object left, Object right)
+{
+  assert(left.type == INTEGER);
+  assert(right.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = left.instance.integer + right.instance.integer;
+  return result;
+}
+
+Object builtin$subtract(Object left, Object right)
+{
+  assert(left.type == INTEGER);
+  assert(right.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = left.instance.integer - right.instance.integer;
+  return result;
+}
+
+Object builtin$multiply(Object left, Object right)
+{
+  assert(left.type == INTEGER);
+  assert(right.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = left.instance.integer * right.instance.integer;
+  return result;
+}
+
+Object builtin$integerDivide(Object left, Object right)
+{
+  assert(left.type == INTEGER);
+  assert(right.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = left.instance.integer / right.instance.integer;
+  return result;
+}
+
+Object builtin$modularDivide(Object left, Object right)
+{
+  assert(left.type == INTEGER);
+  assert(right.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = left.instance.integer % right.instance.integer;
+  return result;
+}
+
+{% if 'pow' in builtins %}
+Object builtin$pow(Object base, Object exponent)
+{
+  assert(base.type == INTEGER);
+  assert(exponent.type == INTEGER);
+
+  Object result;
+  result.type = INTEGER;
+  result.instance.integer = pow(base.instance.integer, exponent.instance.integer);
+  return result;
+}
+{% endif %}
+
 {% if 'print' in builtins %}
 void builtin$print(Object output)
 {