comparison 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
comparison
equal deleted inserted replaced
51:7d6a6906b648 52:079200bc3e75
2 #include "object.h" 2 #include "object.h"
3 #include "integer.h" 3 #include "integer.h"
4 #include "bool.h" 4 #include "bool.h"
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h>
7 8
8 void register_builtin_type(uint32_t type) 9 void register_builtin_type(uint32_t type)
9 { 10 {
10 blueprint * bp; 11 blueprint * bp;
11 switch(type) 12 switch(type)
20 { 21 {
21 uint32_t i; 22 uint32_t i;
22 for(i = 0; i < TYPE_FIRST_USER; ++i) 23 for(i = 0; i < TYPE_FIRST_USER; ++i)
23 register_builtin_type(i); 24 register_builtin_type(i);
24 } 25 }
25
26 //TODO: Remove this when it's possible to write Print in Rhope
27 FuncNoLocals(Print,
28 NumParams 1,
29 CallSpace 0)
30
31 if(get_blueprint(cdata->params[0]) == get_blueprint_byid(TYPE_INT32))
32 {
33 printf("%d\n", ((t_Int32 *)(cdata->params[0]))->Num);
34 } else {
35 puts("Don't know how to print this type");
36 }
37 release_ref(cdata->params[0]);
38 Ret(0, make_Int32(0))
39 EndFunc
40 26
41 object * make_Int64(int64_t val) 27 object * make_Int64(int64_t val)
42 { 28 {
43 t_Int64 * obj; 29 t_Int64 * obj;
44 object * ret = new_object(TYPE_INT64); 30 object * ret = new_object(TYPE_INT64);
109 obj = (t_UInt8 *)ret; 95 obj = (t_UInt8 *)ret;
110 obj->Num = val; 96 obj->Num = val;
111 return ret; 97 return ret;
112 } 98 }
113 99
100 object * make_String(char * text)
101 {
102 returntype ret;
103 context * ct;
104 calldata * cdata;
105 object * retobj;
106 t_Array * arr = (t_Array *)_internal_array_allocnaked(strlen(text), make_Blueprint(TYPE_UINT8));
107 arr->payload.Length = arr->payload.Storage;
108 memcpy(((char *)arr) + sizeof(t_Array), text, arr->payload.Length);
109
110 //This is really ugly, but I don't see a good way around it at the moment
111 ct = new_context();
112 cdata = alloc_cdata(ct, 1);
113 cdata->params[0] = (object *)arr;
114 cdata->num_params = 1;
115 cdata->resume = 0;
116 ret = f_String(cdata);
117 while(ret == TAIL_RETURN)
118 ret = cdata->tail_func(cdata);
119 if(ret == EXCEPTION_RETURN)
120 {
121 puts("Exception while building string literal!");
122 exit(-1);
123 }
124 retobj = cdata->params[0];
125 free_context(ct);
126 return retobj;
127 }
128
114 #define lval ((t_Boolean *)(cdata->params[0]))->Val 129 #define lval ((t_Boolean *)(cdata->params[0]))->Val
115 130
116 MethodNoLocals(If,Boolean, 131 MethodNoLocals(If,Boolean,
117 NumParams 1, 132 NumParams 1,
118 CallSpace 1) 133 CallSpace 1)