Newer
Older
Tardis / lang / func.c
// SPDX-License-Identifier: MIT
// Copyright (c) 2023 John Watts and the LuminaSensum contributors

#include "bytecode.h"
#include "error.h"
#include "object.h"
#include <stddef.h>

static struct object_class func_class;

Object func_create(void) {
	Object obj = object_create(&func_class, 1);
	abort_if(!obj, "unable to allocate func");
	return obj;
}

static void func_cleanup(Object obj) { (void)obj; }

static void func_call(VmState state, Object obj) {
	(void)obj;
	int arg_count = vm_stack_depth(state);
	abort_if(arg_count != 1, "func_add called with more than 1 argument");
	bytecode_run(state);
}

static struct object_call calls[] = {
	{.name = "Call", .handler = func_call}, {.name = NULL, /* end */}};

static struct object_class func_class = {
	.cleanup = func_cleanup,
	.calls = &calls[0],
};