view runtime/builtin.c @ 49:3e20ed8959c4

Added initial FFI implementation, Array type and 64-bit integers
author Mike Pavone <pavone@retrodev.com>
date Thu, 08 Apr 2010 01:02:18 -0400
parents a24eb366195c
children 689fb73e7612
line wrap: on
line source

#include "builtin.h"
#include "object.h"
#include "integer.h"
#include "bool.h"
#include <stddef.h>
#include <stdio.h>

void register_builtin_type(uint32_t type)
{
	blueprint * bp;
	switch(type)
	{
	case TYPE_BLUEPRINT:
		bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL);
		break;
	}
}

void register_builtin_types()
{
	uint32_t i;
	for(i = 0; i < TYPE_FIRST_USER; ++i)
		register_builtin_type(i);
}

//TODO: Remove this when it's possible to write Print in Rhope
FuncNoLocals(Print,
	NumParams 1,
	CallSpace 0)
	
	if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32))
	{
		printf("%d\n", ((t_Int32 *)(cdata->params[0]))->Num);
	} else {
		puts("Don't know how to print this type");
	}
	release_ref(cdata->params[0]);
	Ret(0, make_Int32(0))
EndFunc
object * make_Int32(int32_t val)
{
	t_Int32 * obj;
	object * ret = new_object(TYPE_INT32);
	obj = (t_Int32 *)ret;
	obj->Num = val;
	return ret;
}

#define lval ((t_Boolean *)(cdata->params[0]))->Val

MethodNoLocals(If,Boolean,
	NumParams 1,
	CallSpace 1)
	
	Param(0, TYPE_BOOLEAN)
	
	if(lval)
	{
		Ret(1, NULL)
	} else {
		Ret(1, cdata->params[0]);
		Ret(0, NULL)
	}
EndFunc