Add a negation operator
[fur] / templates / program.c
index 274aa33..64e0152 100644 (file)
@@ -114,6 +114,16 @@ Object stringLiteral(Runtime* runtime, const char* literal)
 }
 
 // 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);
@@ -169,6 +179,19 @@ Object builtin$modularDivide(Object left, Object right)
   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)
 {