first commit

This commit is contained in:
cozis
2021-10-31 04:17:57 +00:00
commit 7a5d0d1dcb
55 changed files with 5204 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
#include <assert.h>
#include "../utils/defs.h"
#include "../objects/objects.h"
#include "runtime.h"
typedef struct {
Object base;
Runtime *runtime;
Executable *exe;
int index;
} FunctionObject;
static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap, Error *error);
static const Type t_func = {
.base = (Object) { .type = &t_type, .flags = Object_STATIC },
.name = "function",
.size = sizeof (FunctionObject),
.call = call,
};
static Object *call(Object *self, Object **argv, unsigned int argc, Heap *heap, Error *error)
{
assert(self != NULL);
assert(heap != NULL);
assert(error != NULL);
FunctionObject *func = (FunctionObject*) self;
assert(func->exe != NULL);
assert(func->index >= 0);
return run(func->runtime, error, func->exe, func->index, argv, argc);
}
Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, Heap *heap, Error *error)
{
assert(runtime != NULL);
assert(exe != NULL);
assert(index >= 0);
assert(heap != NULL);
assert(error != NULL);
FunctionObject *func = (FunctionObject*) Heap_Malloc(heap, &t_func, error);
if(func == NULL)
return NULL;
func->runtime = runtime;
func->exe = exe;
func->index = index;
return (Object*) func;
}