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 "vm.h"
#include <stddef.h>

// clang-format off
static const unsigned char bytecode[] = {
0x09, 0x01, 0x05, 0x05, 0x05, 0x01, 0x6a, 0x02, 0x00, 0x00,
0x07, 0x01, 0x05, 0x06, 0x01, 0x06, 0x01, 0x04, 0x02, 0x41,
0x64, 0x64, 0x00, 0x09, 0x05, 0x07, 0x02, 0x05, 0x01, 0x02,
0x00, 0x00, 0x00, 0x06, 0x02, 0x04, 0x02, 0x4d, 0x69, 0x6e,
0x75, 0x73, 0x00, 0x09, 0x05, 0x07, 0x03, 0x06, 0x03, 0x07,
0x00, 0x08, 0x03, 0x03,
};
// clang-format on

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 *priv) {
	(void)obj;
	bytecode_run(state, (const unsigned char *)priv);
}

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

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