diff runtime/builtin.c @ 63:04baa003de5a

Merged latest changes with better C branch
author Mike Pavone <pavone@retrodev.com>
date Wed, 05 May 2010 22:12:23 -0400
parents d2f9b0a9403d 70af7fa155d0
children d4b44ae2e34a
line wrap: on
line diff
--- a/runtime/builtin.c	Sat Oct 10 16:43:37 2009 -0400
+++ b/runtime/builtin.c	Wed May 05 22:12:23 2010 -0400
@@ -3,35 +3,18 @@
 #include "integer.h"
 #include "bool.h"
 #include <stddef.h>
-#include <stdio.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 void register_builtin_type(uint32_t type)
 {
 	blueprint * bp;
 	switch(type)
 	{
-	case TYPE_INT32:
-		bp = register_type_byid(TYPE_INT32, sizeof(int32_t), NULL, NULL, NULL);
-/*		add_method(bp, METHOD_ADD, MethodName(_PL_,Int32));
-		add_method(bp, METHOD_SUB, MethodName(_MN_,Int32));
-		add_method(bp, METHOD_MUL, MethodName(_TM_,Int32));
-		add_method(bp, METHOD_DIV, MethodName(_DV_,Int32));
-		add_method(bp, METHOD_LSHIFT, MethodName(LShift,Int32));
-		add_method(bp, METHOD_RSHIFT, MethodName(RShift,Int32));
-		add_method(bp, METHOD_LESS, MethodName(_LT_,Int32));
-		add_method(bp, METHOD_GREATER, MethodName(_GT_,Int32)); */
+	case TYPE_BLUEPRINT:
+		bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL);
 		break;
-	case TYPE_BOOLEAN:
-		bp = register_type_byid(TYPE_BOOLEAN, sizeof(int32_t), NULL, NULL, NULL);
-		//add_method(bp, METHOD_IF, MethodName(If,Boolean));
-		val_yes = (t_Boolean *)new_object(TYPE_BOOLEAN);
-		val_yes->val = 1;
-		val_no = (t_Boolean *)new_object(TYPE_BOOLEAN);
-		val_no->val = 0;
-		break;
-/*	case TYPE_BLUEPRINT:
-		bp = register_type_byid(TYPE_BLUEPRINT, sizeof(blueprint *), NULL, NULL, NULL);
-		break;*/
 	}
 }
 
@@ -40,5 +23,107 @@
 	uint32_t i;
 	for(i = 0; i < TYPE_FIRST_USER; ++i)
 		register_builtin_type(i);
-}
+}
+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;
+}
+
+object * make_String(char * text)
+{
+	returntype ret;
+	context * ct;
+	calldata * cdata;
+	object * retobj;
+	t_Array * arr = (t_Array *)_internal_array_allocnaked(strlen(text), make_Blueprint(TYPE_UINT8));
+	arr->payload.Length = arr->payload.Storage;
+	memcpy(((char *)arr) + sizeof(t_Array), text, arr->payload.Length);
+	
+	//This is really ugly, but I don't see a good way around it at the moment
+	ct = new_context();
+	cdata = alloc_cdata(ct, 1);
+	cdata->params[0] = (object *)arr;
+	cdata->num_params = 1;
+	cdata->resume = 0;
+	ret = f_String(cdata);
+	while(ret == TAIL_RETURN)
+		ret = cdata->tail_func(cdata);
+	if(ret == EXCEPTION_RETURN)
+	{
+		puts("Exception while building string literal!");
+		exit(-1);
+	}
+	retobj = cdata->params[0];
+	free_context(ct);
+	return retobj;
+}
+
+