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

#include "error.h"
#include "func.h"
#include "number.h"
#include "object.h"
#include "vm.h"
#include <stdio.h>

static void test_number(VmState state) {
	Object numA = number_create(5);
	Object numB = number_create(3);
	vm_stack_push(state, NULL);
	vm_stack_push(state, numB);
	numB = NULL;
	vm_call(state, numA, "Add", 2);
	Object numC = vm_stack_pop(state);
	printf("numC value is %i\n", number_value(numC));
	abort_if(number_value(numC) != 8, "add return value is not 8");
	object_drop(&numA);
	object_drop(&numC);
}

static void test_func(VmState state) {
	Object funcA = func_create();
	vm_stack_push(state, NULL);
	vm_call(state, funcA, "Call", 1);
	Object numA = vm_stack_pop(state);
	printf("code return value is %i\n", number_value(numA));
	abort_if(number_value(numA) != 1234, "code return value is not 1234");
	object_drop(&numA);
	object_drop(&funcA);
}

int lang_main(void) {
	VmState state = vm_create();
	test_number(state);
	test_func(state);
	vm_destroy(&state);
	return 0;
}