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

#include "func.h"
#include "number.h"
#include <stdio.h>

static void test_number(void) {
	struct object *numA = number_create(5);
	struct object *numB = number_create(3);
	struct object *args[] = {numB};
	dispatch_call(numA, "Add", 1, &args[0]);
	struct object *numC = args[0];
	printf("numC value is %i\n", number_value(numC));
	printf("numA is %p\n", (void *)numA);
	printf("numB is %p\n", (void *)numB);
	printf("numC is %p\n", (void *)numC);
	object_drop(&numA);
	object_drop(&numB);
	object_drop(&numC);
	printf("numA is %p\n", (void *)numA);
	printf("numB is %p\n", (void *)numB);
	printf("numC is %p\n", (void *)numC);
}

static void test_func(void) {
	struct object *funcA = func_create();
	// args must have space for a stack
	struct object *args[8] = {NULL, NULL};
	dispatch_call(funcA, "Call", 0, &args[0]);
	printf("funcA is %p\n", (void *)funcA);
	object_drop(&funcA);
	printf("funcA is %p\n", (void *)funcA);
	struct object *numA = args[0];
	printf("numA is %p\n", (void *)numA);
	printf("code return value is %i\n", number_value(numA));
	object_drop(&numA);
	printf("numA is %p\n", (void *)numA);
}

int lang_main(void) {
	printf("Hello world!\n");
	test_number();
	test_func();
	return 0;
}