diff runtime/builtin.c @ 52:079200bc3e75

String literals almost working. Print moved out of C runtime.
author Mike Pavone <pavone@retrodev.com>
date Wed, 28 Apr 2010 01:23:30 -0400
parents 689fb73e7612
children 70af7fa155d0
line wrap: on
line diff
--- a/runtime/builtin.c	Thu Apr 22 02:18:26 2010 -0400
+++ b/runtime/builtin.c	Wed Apr 28 01:23:30 2010 -0400
@@ -3,7 +3,8 @@
 #include "integer.h"
 #include "bool.h"
 #include <stddef.h>
-#include <stdio.h>
+#include <stdio.h>
+#include <string.h>
 
 void register_builtin_type(uint32_t type)
 {
@@ -21,22 +22,7 @@
 	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)
 {
@@ -111,6 +97,35 @@
 	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;
+}
+
 #define lval ((t_Boolean *)(cdata->params[0]))->Val
 
 MethodNoLocals(If,Boolean,