#include <{{standard_library}}>
{% endfor %}
-struct String;
-typedef struct String String;
enum Type;
typedef enum Type Type;
union Instance;
typedef union Instance Instance;
struct Object;
typedef struct Object Object;
-struct Runtime;
-typedef struct Runtime Runtime;
-const char * const SYMBOL_LIST[] = {
+const char* const STRING_LITERAL_LIST[] = {
+{% for string_literal in string_literal_list %}
+ "{{ string_literal }}",
+{% endfor %}
+};
+
+const char* const SYMBOL_LIST[] = {
{% for symbol in symbol_list %}
"{{ symbol }}",
{% endfor %}
{
bool boolean;
int32_t integer;
- char* string;
+ const char* string;
};
struct Object
EnvironmentNode* next;
for(EnvironmentNode* node = self->root; node != NULL; node = next)
{
- // We don't need to destruct the permanent strings, because those will be destructed at the end when the Runtime is destructed
- // The above comment represents all heap-allocated objects currently, so we don't need to destruct Objects (yet)
+ // No objects are allocated on the heap (yet!) so we don't need to free anything else
next = node->next;
free(node);
}
{
for(EnvironmentNode* node = self->root; node != NULL; node = node->next)
{
- // We can compare pointers because pointers are unique in the SYMBOLS_LIST
+ // We can compare pointers because pointers are unique in the SYMBOL_LIST
if(node->key == symbol)
{
return node->value;
return result;
}
-Object stringLiteral(char* literal)
+Object stringLiteral(const char* literal)
{
Object result;
result.type = STRING;
}
{% if 'pow' in builtins %}
-Object builtin$pow(Object base, Object exponent)
+Object builtin$pow(size_t argc, Object args[])
{
+ assert(argc == 2);
+
+ Object base = args[0];
+ Object exponent = args[1];
+
assert(base.type == INTEGER);
assert(exponent.type == INTEGER);
{% endif %}
{% if 'print' in builtins %}
-void builtin$print(Object output)
+void builtin$print(size_t argc, Object args[])
{
- switch(output.type)
+ for(size_t i = 0; i < argc; i++)
{
- case BOOLEAN:
- fputs(output.instance.boolean ? "true" : "false", stdout);
- break;
+ Object output = args[i];
+ switch(output.type)
+ {
+ case BOOLEAN:
+ fputs(output.instance.boolean ? "true" : "false", stdout);
+ break;
- case INTEGER:
- printf("%" PRId32, output.instance.integer);
- break;
+ case INTEGER:
+ printf("%" PRId32, output.instance.integer);
+ break;
- case STRING:
- // Using fwrite instead of printf to handle size_t length
- printf("%s", output.instance.string);
- break;
+ case STRING:
+ // Using fwrite instead of printf to handle size_t length
+ printf("%s", output.instance.string);
+ break;
- default:
- assert(false);
+ default:
+ assert(false);
+ }
}
}
{% endif %}