aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/multiple_heaps.diff
blob: 1b451b01989e7c97d446fd81847fb8bc6c237c4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
diff -r e90280547f0d enzymatic/parser.js
--- a/enzymatic/parser.js	Mon Aug 16 20:31:28 2010 -0700
+++ b/enzymatic/parser.js	Tue Aug 17 21:00:45 2010 -0700
@@ -1250,20 +1250,22 @@
 
   function makePointer(slab, pos) {
 // XXX hardcoded ptr impl
+    if (slab == 'HEAP') return pos;
+    return 'Pointer_make(' + slab + ', ' + (pos ? pos : 0) + ')';
 //    return '{ slab: ' + slab + ', pos: ' + (pos ? pos : 0) + ' }';
-    return '[' + slab + ', ' + (pos ? pos : 0) + ']';
+//    return '[' + slab + ', ' + (pos ? pos : 0) + ']';
   }
 
   function makeGetSlab(ptr) {
 // XXX hardcoded ptr impl
 //    return ptr + '.slab';
-    return ptr + '[0]';
+    return 'HEAP';
   }
 
   function makeGetPos(ptr) {
 // XXX hardcoded ptr impl
 //    return ptr + '.pos';
-    return ptr + '[1]';
+    return ptr;
   }
 
   function makeGetValue(ptr, pos, noNeedFirst) {
@@ -1275,14 +1277,13 @@
   }
 
   function makeEmptyStruct(type) {
-//    print('// ???? ' + type + ' : ' + (new Error().stack) + dump(TYPES));
-    return TYPES[type].fields.map(function(field) {
-      if (isPointerType(field)) {
-        return makePointer('null');
-      } else {
-        return 0;
-      }
-    });
+//    print('// ???? ' + type + ' : ' + dump(TYPES));
+// XXX hardcoded ptr impl
+    var ret = [];
+    for (var i = 0; i < TYPES[type].flatSize; i++) {
+      ret.push(0);
+    }
+    return ret;
   }
 
   // globalVariable
diff -r e90280547f0d enzymatic/postamble.js
--- a/enzymatic/postamble.js	Mon Aug 16 20:31:28 2010 -0700
+++ b/enzymatic/postamble.js	Tue Aug 17 21:00:45 2010 -0700
@@ -3,7 +3,7 @@
 
 function run(args) {
   var argc = args.length+1;
-  var argv = [intArrayFromString("/bin/this.program") ];
+  var argv = [Pointer_make(intArrayFromString("/bin/this.program")) ];
   for (var i = 0; i < argc-1; i = i + 1) {
     argv.push(Pointer_make(intArrayFromString(args[i])));
   }
diff -r e90280547f0d enzymatic/preamble.js
--- a/enzymatic/preamble.js	Mon Aug 16 20:31:28 2010 -0700
+++ b/enzymatic/preamble.js	Tue Aug 17 21:00:45 2010 -0700
@@ -6,6 +6,9 @@
 
 UNDEFINED = null; // None in python; good for pypy
 
+HEAP = [];
+HEAPTOP = 0;
+
 function abort(text) {
   text = "ABORT: " + text;
   print(text + "\n");
@@ -15,16 +18,24 @@
 }
 
 function Pointer_niceify(ptr) {
-  if (!ptr.slab)
-    return { slab: ptr[0], pos: ptr[1] };
-  else
-    return ptr;
+// XXX hardcoded ptr impl
+  return { slab: HEAP, pos: ptr };
+//  if (!ptr.slab)
+//    return { slab: ptr[0], pos: ptr[1] };
+//  else
+//    return ptr;
 }
 
 function Pointer_make(slab, pos) {
+  pos = pos ? pos : 0;
 // XXX hardcoded ptr impl
+  if (slab === HEAP) return pos;
+  var ret = _malloc(Math.max(slab.length - pos, 1));
+  for (var i = 0; i < slab.length - pos; i++) {
+    HEAP[ret + i] = slab[pos + i];
+  }
+  return ret;
 //  return { slab: slab, pos: pos ? pos : 0 };
-  return [slab, pos ? pos : 0];
 }
 
 function Pointer_stringify(ptr) {
@@ -47,20 +58,24 @@
 NULL = Pointer_make([]);
 
 function _malloc(size) {
+// XXX hardcoded ptr impl
+  var ret = HEAPTOP;
+  HEAPTOP += size;
+  return ret;
   // We don't actually do new Array(size) - memory is uninitialized anyhow
-  return Pointer_make([]);
+//  return Pointer_make([]);
 }
 
 __Znwj = _malloc; // Mangled "new"
 __Znaj = _malloc; // Mangled "new"
 
 function _free(ptr) {
+// XXX hardcoded ptr impl
   // Nothing needs to be done! But we mark the pointer
   // as invalid. Note that we should do it for all other
   // pointers of this slab too.
-// XXX hardcoded ptr impl
 //  ptr.slab = null;
-  ptr[0] = null;
+//  ptr[0] = null;
 }
 
 __ZdlPv = _free; // Mangled "delete"
@@ -90,8 +105,12 @@
 }
 
 function _strlen(p) {
-  p = Pointer_niceify(p);
-  return p.slab.length; // XXX might want to find the null terminator...
+// XXX hardcoded ptr impl
+  var q = p;
+  while (HEAP[q] != 0) q++;
+  return q - p;
+//  p = Pointer_niceify(p);
+//  return p.slab.length; // XXX might want to find the null terminator...
 }
 
 // stdlib.h
@@ -102,9 +121,13 @@
 }
 
 function _llvm_memcpy_i32(dest, src, num, idunno) {
-  dest = Pointer_niceify(dest);
-  src = Pointer_niceify(src);
-  dest.slab = src.slab.slice(src.pos);
+// XXX hardcoded ptr impl
+  for (var i = 0; i < num; i++) {
+    HEAP[dest + i] = HEAP[src + i];
+  }
+//  dest = Pointer_niceify(dest);
+//  src = Pointer_niceify(src);
+//  dest.slab = src.slab.slice(src.pos);
 }
 
 // Tools
@@ -131,6 +154,7 @@
     ret.push(stringy.charCodeAt(i));
     i = i + 1;
   }
+  ret.push(0);
   return ret;
 }