enum Type
{
BOOLEAN,
+ CLOSURE,
INTEGER,
STRING
};
union Instance
{
bool boolean;
+ Object (*closure)(size_t, Object*);
int32_t integer;
const char* string;
};
}
// TODO Make this conditionally added
-Object builtin$negate(Object input)
+Object operator$negate(Object input)
{
assert(input.type == INTEGER);
return result;
}
-Object builtin$add(Object left, Object right)
+Object operator$add(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$subtract(Object left, Object right)
+Object operator$subtract(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$multiply(Object left, Object right)
+Object operator$multiply(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$integerDivide(Object left, Object right)
+Object operator$integerDivide(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$modularDivide(Object left, Object right)
+Object operator$modularDivide(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$equals(Object left, Object right)
+Object operator$equals(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$notEquals(Object left, Object right)
+Object operator$notEquals(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$greaterThan(Object left, Object right)
+Object operator$greaterThan(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$lessThan(Object left, Object right)
+Object operator$lessThan(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$greaterThanOrEqual(Object left, Object right)
+Object operator$greaterThanOrEqual(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$lessThanOrEqual(Object left, Object right)
+Object operator$lessThanOrEqual(Object left, Object right)
{
assert(left.type == INTEGER);
assert(right.type == INTEGER);
return result;
}
-Object builtin$and(Object left, Object right)
+Object operator$and(Object left, Object right)
{
assert(left.type == BOOLEAN);
assert(right.type == BOOLEAN);
return result;
}
-Object builtin$or(Object left, Object right)
+Object operator$or(Object left, Object right)
{
assert(left.type == BOOLEAN);
assert(right.type == BOOLEAN);
}
{% if 'pow' in builtins %}
-Object builtin$pow(size_t argc, Object args[])
+Object builtin$pow$implementation(size_t argc, Object* args)
{
assert(argc == 2);
result.instance.integer = pow(base.instance.integer, exponent.instance.integer);
return result;
}
+
+Object builtin$pow = { CLOSURE, (Instance)builtin$pow$implementation };
{% endif %}
{% if 'print' in builtins %}
-void builtin$print(size_t argc, Object args[])
+Object builtin$print$implementation(size_t argc, Object* args)
{
for(size_t i = 0; i < argc; i++)
{
assert(false);
}
}
+
+ // TODO Return something better
+ return FALSE;
}
+
+Object builtin$print = { CLOSURE, (Instance)builtin$print$implementation };
{% endif %}
int main(int argc, char** argv)