view test/test.c @ 8:8d74ef7fa357

Improved helper macros and added separate Rhope stack in runtime
author Mike Pavone <pavone@retrodev.com>
date Wed, 13 May 2009 23:37:19 -0400
parents d61550e2c001
children 3021dac0d8f5
line wrap: on
line source

#include <stdio.h>
#include "builtin.h"
#include "object.h"
#include "integer.h"
#include "context.h"
#include "func.h"

FuncNoLocals(Main,0)
	call = alloc_cdata(cdata->ct,2);
	call->params[0] = make_Int32(2);
	call->params[1] = make_Int32(3);
	call->num_params = 2;
	ret = call_method(METHOD_ADD, call);
	while(ret == TAIL_RETURN)
		ret = call->tail_func(call);
	if(ret == EXCEPTION_RETURN) {
		Ret(0,call->params[0]);
		return ret;
	}
	call->params[1] = make_Int32(1);
	ret = call_method(METHOD_SUB, call);
	while(ret == TAIL_RETURN)
		ret = call->tail_func(call);
	if(ret == EXCEPTION_RETURN) {
		Ret(0,call->params[0]);
		return ret;
	}
	Ret(0,call->params[0])
EndFunc


int main(int argc, char ** argv)
{
	returntype ret;
	calldata *cdata;
	context * ct;
	register_builtin_types();
	ct = new_context();
	cdata = alloc_cdata(ct, 1);
	cdata->num_params = 0;
	ret = _f_Main(cdata);
	while(ret == TAIL_RETURN)
		ret = cdata->tail_func(cdata);
	if(ret == EXCEPTION_RETURN) {
		puts("Exception!");
		return -1;
	}
	printf("Result: %d\n", ((_t_Int32 *)cdata->params[0])->num);
	return 0;
}