view runtime/builtin.c @ 50:689fb73e7612

Add support for various integer literals and add support for raw pointers to objects and raw pointers to arrays in the FFI
author Mike Pavone <pavone@retrodev.com>
date Fri, 16 Apr 2010 01:57:04 -0400
parents a24eb366195c
children 079200bc3e75
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_Int64(int64_t val)
{
	t_Int64 * obj;
	object * ret = new_object(TYPE_INT64);
	obj = (t_Int64 *)ret;
	obj->Num = val;
	return ret;
}


object * make_Int32(int32_t val)
{
	t_Int32 * obj;
	object * ret = new_object(TYPE_INT32);
	obj = (t_Int32 *)ret;
	obj->Num = val;
	return ret;
}

object * make_Int16(int16_t val)
{
	t_Int16 * obj;
	object * ret = new_object(TYPE_INT16);
	obj = (t_Int16 *)ret;
	obj->Num = val;
	return ret;
}

object * make_Int8(int8_t val)
{
	t_Int8 * obj;
	object * ret = new_object(TYPE_INT8);
	obj = (t_Int8 *)ret;
	obj->Num = val;
	return ret;
}

object * make_UInt64(uint64_t val)
{
	t_UInt64 * obj;
	object * ret = new_object(TYPE_UINT64);
	obj = (t_UInt64 *)ret;
	obj->Num = val;
	return ret;
}

object * make_UInt32(uint32_t val)
{
	t_UInt32 * obj;
	object * ret = new_object(TYPE_UINT32);
	obj = (t_UInt32 *)ret;
	obj->Num = val;
	return ret;
}

object * make_UInt16(uint16_t val)
{
	t_UInt16 * obj;
	object * ret = new_object(TYPE_UINT16);
	obj = (t_UInt16 *)ret;
	obj->Num = val;
	return ret;
}

object * make_UInt8(uint8_t val)
{
	t_UInt8 * obj;
	object * ret = new_object(TYPE_UINT8);
	obj = (t_UInt8 *)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