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

static void test_number(void) {
	struct object *stack[16] = {0};
	struct vm_state state;
	state.stack_next = (struct object **)&stack;
	state.stack_base = state.stack_next;
	struct object *numA = number_create(5);
	struct object *numB = number_create(3);
	vm_stack_push(&state, NULL);
	vm_stack_push(&state, numB);
	numB = NULL;
	vm_call(numA, "Add", 2, &state);
	struct object *numC = vm_stack_get(&state, 0);
	printf("numC value is %i\n", number_value(numC));
	vm_stack_drop(&state, 2);
	object_drop(&numA);
	object_drop(&numC);
}

static void test_func(void) {
	struct object *stack[16] = {0};
	struct vm_state state;
	state.stack_next = (struct object **)&stack;
	state.stack_base = state.stack_next;
	struct object *funcA = func_create();
	vm_stack_push(&state, NULL);
	vm_call(funcA, "Call", 1, &state);
	struct object *numA = vm_stack_pop(&state);
	printf("code return value is %i\n", number_value(numA));
	object_drop(&numA);
	object_drop(&funcA);
}

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