aboutsummaryrefslogtreecommitdiff
path: root/patches/sauer
blob: ce846e857b71d179945bc01356ae714a610fef8f (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
diff --git a/patches/README b/patches/README
--- a/patches/README
+++ b/patches/README
@@ -4,7 +4,7 @@
 
   ln -s patches .hg/patches
 
-After doing so, |hg qpush| sauer, and then running |python tests/runner.py| will run only sauer, using v8, and without optimizations or relooping.
+After doing so, |hg qpush| sauer, and then running |python tests/runner.py| will run only sauer, using v8, and without relooping.
 
 Note to patch queue maintainer: You need to manually copy from .hg/patches into this directory, after |qrefresh|ing the patch.
 
diff --git a/src/settings.js b/src/settings.js
--- a/src/settings.js
+++ b/src/settings.js
@@ -1,5 +1,5 @@
 OPTIMIZE = 1;
-RELOOP = 1;
-SAFE_HEAP = 0;
+RELOOP = 0;
+SAFE_HEAP = 1;
 LABEL_DEBUG = 0;
 
diff --git a/tests/runner.py b/tests/runner.py
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -85,6 +85,7 @@
           if output is not None and 'Traceback' in output: print output; assert (0) # 'generating JavaScript failed'
           if DEBUG: print "\nGenerated JavaScript:\n\n===\n\n%s\n\n===\n\n" % output
   #        if not DEBUG:
+        raise Exception("Moshe");
         js_output = timeout_run(Popen([JS_ENGINE] + JS_ENGINE_OPTS + [filename + '.o.js'] + args, stdout=PIPE, stderr=STDOUT), 20, 'Execution')
         if output_nicerizer is not None:
             js_output = output_nicerizer(js_output)
@@ -148,7 +149,7 @@
              print "Expected to NOT find '%s' in '%s'" % (value, string)
              self.assertTrue(value not in string)
 
-    def test_hello_world(self):
+    def zzztest_hello_world(self):
         src = '''
           #include <stdio.h>
           int main()
@@ -159,7 +160,7 @@
         '''
         self.do_test(src, 'hello, world!')
 
-    def test_intvars(self):
+    def zzztest_intvars(self):
         src = '''
           #include <stdio.h>
           int global = 20;
@@ -188,7 +189,7 @@
         '''
         self.do_test(src, '*5,23,10,19,121,1,37,1,0*')
 
-    def test_floatvars(self):
+    def zzztest_floatvars(self):
         src = '''
           #include <stdio.h>
           int main()
@@ -202,7 +203,7 @@
         '''
         self.do_test(src, '*1,10,10.5,1,1.2339')
 
-    def test_if(self):
+    def zzztest_if(self):
         src = '''
           #include <stdio.h>
           int main()
@@ -216,7 +217,7 @@
         '''
         self.do_test(src, '*yes*')
 
-    def test_loop(self):
+    def zzztest_loop(self):
         src = '''
           #include <stdio.h>
           int main()
@@ -230,7 +231,7 @@
         '''
         self.do_test(src, '*3600*')
 
-    def test_strings(self):
+    def zzztest_strings(self):
         src = '''
           #include <stdio.h>
           #include <stdlib.h>
@@ -245,7 +246,7 @@
         '''
         self.do_test(src, '*4*wowie*too*76*', ['wowie', 'too', '74'], lambda x: x.replace('\n', '*'))
 
-    def test_funcs(self):
+    def zzztest_funcs(self):
         src = '''
           #include <stdio.h>
           int funcy(int x)
@@ -260,7 +261,7 @@
         '''
         self.do_test(src, '*72,90*')
 
-    def test_structs(self):
+    def zzztest_structs(self):
         src = '''
           #include <stdio.h>
           struct S
@@ -304,13 +305,13 @@
           }
     '''
 
-    def test_mallocstruct(self):
+    def zzztest_mallocstruct(self):
         self.do_test(self.gen_struct_src.replace('{{gen_struct}}', '(S*)malloc(ES_SIZEOF(S))').replace('{{del_struct}}', 'free'), '*51,62*')
 
-    def test_newstruct(self):
+    def zzztest_newstruct(self):
         self.do_test(self.gen_struct_src.replace('{{gen_struct}}', 'new S').replace('{{del_struct}}', 'delete'), '*51,62*')
 
-    def test_addr_of_stacked(self):
+    def zzztest_addr_of_stacked(self):
         src = '''
           #include <stdio.h>
           void alter(int *y)
@@ -327,7 +328,7 @@
         '''
         self.do_test(src, '*7*')
 
-    def test_linked_list(self):
+    def zzztest_linked_list(self):
         src = '''
           #include <stdio.h>
           struct worker_args {
@@ -372,7 +373,7 @@
         '''
         self.do_test(src, '*1410,0*')
 
-    def test_assert(self):
+    def zzztest_assert(self):
         src = '''
           #include <stdio.h>
           #include <assert.h>
@@ -384,7 +385,7 @@
         '''
         self.do_test(src, 'Assertion failed: 1 == false')
 
-    def test_class(self):
+    def zzztest_class(self):
         src = '''
           #include <stdio.h>
           struct Random {
@@ -413,7 +414,7 @@
         '''
         self.do_test(src, '*0*')
 
-    def test_inherit(self):
+    def zzztest_inherit(self):
         src = '''
           #include <stdio.h>
           struct Parent {
@@ -441,7 +442,7 @@
         '''
         self.do_test(src, '*51,87,78,550,100,78,550*')
 
-    def test_polymorph(self):
+    def zzztest_polymorph(self):
         src = '''
           #include <stdio.h>
           struct Parent {
@@ -460,7 +461,7 @@
         '''
         self.do_test(src, '*11,74*')
 
-    def test_emptyclass(self):
+    def zzztest_emptyclass(self):
         src = '''
         #include <stdio.h>
 
@@ -501,7 +502,7 @@
           '''
         self.do_test(src, '*97,15,3*')
 
-    def test_conststructs(self):
+    def zzztest_conststructs(self):
         src = '''
           #include <stdio.h>
           struct IUB {
@@ -524,7 +525,7 @@
           '''
         self.do_test(src, '*97,15,3,3029*')
 
-    def test_ptrtoint(self):
+    def zzztest_ptrtoint(self):
         src = '''
           #include <stdio.h>
 
@@ -546,7 +547,7 @@
             runner.assertEquals(filter(lambda line: 'Warning' in line, output.split('\n')).__len__(), 4)
         self.do_test(src, '*5*', output_processor=check_warnings)
 
-    def test_sizeof(self):
+    def zzztest_sizeof(self):
         src = '''
           #include <stdio.h>
           #include <string.h>
@@ -582,7 +583,7 @@
           '''
         self.do_test(src, '*2,2,5,8,8*\n*8,8,5,8,8*\n*7,2,6,990,7,2*')
 
-    def test_llvmswitch(self):
+    def zzztest_llvmswitch(self):
         src = '''
           #include <stdio.h>
           #include <string.h>
@@ -607,7 +608,7 @@
           '''
         self.do_test(src, '*96,97,98,101,101*')
 
-    def test_varargs(self):
+    def zzztest_varargs(self):
         src = '''
           #include <stdio.h>
           #include "stdarg.h"
@@ -629,7 +630,7 @@
           '''
         self.do_test(src, '*cheez: 10+24*')
 
-    def test_atexit(self):
+    def zzztest_atexit(self):
         src = '''
           #include <stdio.h>
           #include <stdlib.h>
@@ -646,13 +647,13 @@
           '''
         self.do_test(src, '*cleaned*')
 
-    def test_fannkuch(self):
+    def zzztest_fannkuch(self):
         results = [ (1,0), (2,1), (3,2), (4,4), (5,7), (6,10), (7, 16), (8,22) ]
         for i, j in results:
           src = open(path_from_root(['tests', 'fannkuch.cpp']), 'r').read()
           self.do_test(src, 'Pfannkuchen(%d) = %d.' % (i,j), [str(i)], no_build=i>1)
 
-    def test_fasta(self):
+    def zzztest_fasta(self):
         results = [ (1,'''GG*ctt**tgagc**'''), (20,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tacgtgtagcctagtgtttgtgttgcgttatagtctatttgtggacacagtatggtcaaa**tgacgtcttttgatctgacggcgttaacaaagatactctg**'''),
 (50,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA*TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACAT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa**NtactMcSMtYtcMgRtacttctWBacgaa**agatactctgggcaacacacatacttctctcatgttgtttcttcggacctttcataacct**ttcctggcacatggttagctgcacatcacaggattgtaagggtctagtggttcagtgagc**ggaatatcattcgtcggtggtgttaatctatctcggtgtagcttataaatgcatccgtaa**gaatattatgtttatttgtcggtacgttcatggtagtggtgtcgccgatttagacgtaaa**ggcatgtatg**''') ]
         for i, j in results:
@@ -661,7 +662,7 @@
 
     # XXX Warning: Running this in SpiderMonkey can lead to an extreme amount of memory being
     #              used, see Mozilla bug 593659.
-    def zzztest_sauer(self):
+    def test_sauer(self):
       self.do_test(path_from_root(['tests', 'sauer']), 'Hello sauer world!', main_file='command.cpp')
 
 if __name__ == '__main__':
diff --git a/tests/sauer/command.cpp b/tests/sauer/command.cpp
--- a/tests/sauer/command.cpp
+++ b/tests/sauer/command.cpp
@@ -1,6 +1,8 @@
 // command.cpp: implements the parsing and execution of a tiny script language which
 // is largely backwards compatible with the quake console language.
 
+// XXX Emscripten: changed all sizeof to ES_SIZEOF
+
 // XXX Emscripten
   #define STANDALONE
 
@@ -1312,7 +1314,7 @@
 void conoutfv(int type, const char *fmt, va_list args)
 {
     static char buf[CONSTRLEN];
-    vformatstring(buf, fmt, args, sizeof(buf));
+    vformatstring(buf, fmt, args, ES_SIZEOF(char)*CONSTRLEN); // XXX Emscripten?
     conline(type, buf);
     //filtertext(buf, buf); // XXX Emscripten
     puts(buf);
@@ -1404,6 +1406,11 @@
 {
   execute("echo Hello from sauer");
 
+  ident moshe, david;
+  printf("cheezme1 %d,%d\n", int(&moshe), int(&(moshe.type)));
+  moshe = david;
+  printf("cheezme2\n");
+
   return 0;
 }
 
diff --git a/tests/sauer/command.h b/tests/sauer/command.h
--- a/tests/sauer/command.h
+++ b/tests/sauer/command.h
@@ -84,7 +84,7 @@
 
     virtual ~ident() {}        
 
-    ident &operator=(const ident &o) { memcpy(this, &o, sizeof(ident)); return *this; }        // force vtable copy, ugh
+    ident &operator=(const ident &o) { memcpy(this, &o, ES_SIZEOF(ident)); return *this; }        // force vtable copy, ugh
     
     virtual void changed() { if(fun) fun(); }
 };
diff --git a/tests/sauer/tools.h b/tests/sauer/tools.h
--- a/tests/sauer/tools.h
+++ b/tests/sauer/tools.h
@@ -3,6 +3,8 @@
 #ifndef _TOOLS_H
 #define _TOOLS_H
 
+#include "emscripten.h" // XXX Emscripten
+
 #ifdef NULL
 #undef NULL
 #endif
@@ -173,7 +175,7 @@
     void put(const T *vals, int numvals)
     {
         if(maxlen-len<numvals) flags |= OVERWROTE;
-        memcpy(&buf[len], vals, min(maxlen-len, numvals)*sizeof(T));
+        memcpy(&buf[len], vals, min(maxlen-len, numvals)*ES_SIZEOF(T));
         len += min(maxlen-len, numvals);
     }
 
@@ -181,7 +183,7 @@
     {
         int read = min(maxlen-len, numvals);
         if(read<numvals) flags |= OVERREAD;
-        memcpy(vals, &buf[len], read*sizeof(T));
+        memcpy(vals, &buf[len], read*ES_SIZEOF(T));
         len += read;
         return read;
     }
@@ -207,7 +209,7 @@
 template<class T, class U>
 static inline void quicksort(T *buf, int n, int (__cdecl *func)(U *, U *))
 {
-    qsort(buf, n, sizeof(T), (int (__cdecl *)(const void *,const void *))func);
+    qsort(buf, n, ES_SIZEOF(T), (int (__cdecl *)(const void *,const void *))func);
 }
 
 template <class T> struct vector
@@ -268,7 +270,7 @@
         else
         {
             growbuf(ulen+v.ulen);
-            if(v.ulen) memcpy(&buf[ulen], v.buf, v.ulen*sizeof(T));
+            if(v.ulen) memcpy(&buf[ulen], v.buf, v.ulen*ES_SIZEOF(T));
             ulen += v.ulen;
             v.ulen = 0;
         }
@@ -309,10 +311,10 @@
         if(!alen) alen = max(MINSIZE, sz);
         else while(alen < sz) alen *= 2;
         if(alen <= olen) return;
-        uchar *newbuf = new uchar[alen*sizeof(T)];
+        uchar *newbuf = new uchar[alen*ES_SIZEOF(T)];
         if(olen > 0)
         {
-            memcpy(newbuf, buf, olen*sizeof(T));
+            memcpy(newbuf, buf, olen*ES_SIZEOF(T));
             delete[] (uchar *)buf;
         }
         buf = (T *)newbuf;
@@ -515,6 +517,7 @@
         numelems = 0;
         chunks = NULL;
         unused = NULL;
+        printf("unused is at %d : %d\n", int(&unused), int(unused));
         chains = new chain *[size];
         loopi(size) chains[i] = NULL;
     }
@@ -527,6 +530,7 @@
 
     chain *insert(uint h)
     {
+        printf("Insert. Unused: %d, addr of next is offset to: %d\n", int(unused), int(&(unused->next)));
         if(!unused)
         {
             chainchunk *chunk = new chainchunk;
@@ -535,9 +539,13 @@
             loopi(CHUNKSIZE-1) chunk->chains[i].next = &chunk->chains[i+1];
             chunk->chains[CHUNKSIZE-1].next = unused;
             unused = chunk->chains;
+            loopi(CHUNKSIZE) printf("chunk %d is at %d, and points to %d\n", i, int(&(chunk->chains[i])), int(chunk->chains[i].next));
+          printf("PRE YO unused is NOW at %d : %d, %d, %d\n", int(&unused), int(unused), int(unused->next), int(unused->next->next));
         }
         chain *c = unused;
+        //printf("unused PRE:      %d : %d, %d, %d\n", int(&unused), int(unused), int(unused->next), int(unused->next->next));
         unused = unused->next;
+        //printf("unused POST:     %d : %d, %d, %d\n", int(&unused), int(unused), int(unused->next), int(unused->next->next));
         c->next = chains[h];
         chains[h] = c;
         numelems++;
@@ -545,11 +553,11 @@
     }
      
     #define HTFIND(key, success, fail) \
-        uint h = hthash(key)&(this->size-1); \
+        printf("HTFIND a\n"); uint h = hthash(key)&(this->size-1); \
         for(chain *c = this->chains[h]; c; c = c->next) \
-        { \
+        { printf("HTFIND b\n"); \
             if(htcmp(key, c->elem)) return (success); \
-        } \
+        } printf("HTFIND c\n"); \
         return (fail);
 
     template<class K>
@@ -644,7 +652,9 @@
 
     entry &insert(const K &key, uint h)
     {
+        printf("hashTABLE insert\n");
         chain *c = hashset<entry>::insert(h);
+        printf("hashTABLE insert moving on\n");
         c->elem.key = key;
         return c->elem;
     }
@@ -863,11 +873,11 @@
     virtual int printf(const char *fmt, ...) { return -1; }
     virtual uint getcrc() { return 0; }
 
-    template<class T> bool put(T n) { return write(&n, sizeof(n)) == sizeof(n); }
+    template<class T> bool put(T n) { return write(&n, ES_SIZEOV(n)) == ES_SIZEOV(n); }
     template<class T> bool putlil(T n) { return put<T>(lilswap(n)); }
     template<class T> bool putbig(T n) { return put<T>(bigswap(n)); }
 
-    template<class T> T get() { T n; return read(&n, sizeof(n)) == sizeof(n) ? n : 0; }
+    template<class T> T get() { T n; return read(&n, ES_SIZEOV(n)) == ES_SIZEOV(n) ? n : 0; }
     template<class T> T getlil() { return lilswap(get<T>()); }
     template<class T> T getbig() { return bigswap(get<T>()); }
 };
diff --git a/tests/settings.py b/tests/settings.py
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -9,7 +9,7 @@
 JS_ENGINE_OPTS=[]#['-j']
 PARSER_ENGINE=SPIDERMONKEY_SHELL
 PARSER_OPTS=[]#['-j']
-#PARSER_ENGINE=V8_ENGINE
+PARSER_ENGINE=V8_ENGINE
 #PARSER_OPTS = []
 #JS_ENGINE=V8_ENGINE
 JS_COMPILER=path_from_root(['src', 'parser.js'])