webruby 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webruby/environment.rb +4 -0
  3. data/lib/webruby/rake/files.rake +2 -1
  4. data/lib/webruby/rake/mruby.rake +4 -2
  5. data/modules/emscripten/AUTHORS +1 -0
  6. data/modules/emscripten/cmake/Platform/Emscripten.cmake +2 -0
  7. data/modules/emscripten/emcc +96 -40
  8. data/modules/emscripten/emrun +301 -136
  9. data/modules/emscripten/emscripten.py +5 -45
  10. data/modules/emscripten/src/analyzer.js +11 -1
  11. data/modules/emscripten/src/compiler.js +1 -1
  12. data/modules/emscripten/src/emrun_postjs.js +2 -2
  13. data/modules/emscripten/src/emrun_prejs.js +5 -0
  14. data/modules/emscripten/src/emscripten-source-map.min.js +31 -0
  15. data/modules/emscripten/src/library.js +187 -0
  16. data/modules/emscripten/src/library_egl.js +20 -0
  17. data/modules/emscripten/src/library_sdl.js +1 -0
  18. data/modules/emscripten/src/preamble.js +4 -0
  19. data/modules/emscripten/src/relooper/Relooper.cpp +33 -15
  20. data/modules/emscripten/src/relooper/Relooper.h +20 -14
  21. data/modules/emscripten/src/relooper/fuzzer.py +6 -0
  22. data/modules/emscripten/src/relooper/test.cpp +28 -0
  23. data/modules/emscripten/src/relooper/test.txt +211 -166
  24. data/modules/emscripten/src/relooper/test2.txt +20 -20
  25. data/modules/emscripten/src/relooper/test3.txt +41 -41
  26. data/modules/emscripten/src/relooper/test4.txt +26 -26
  27. data/modules/emscripten/src/relooper/test5.txt +52 -52
  28. data/modules/emscripten/src/relooper/test6.txt +19 -19
  29. data/modules/emscripten/src/relooper/test_dead.txt +1 -1
  30. data/modules/emscripten/src/relooper/test_debug.txt +31 -31
  31. data/modules/emscripten/src/relooper/test_fuzz1.txt +50 -50
  32. data/modules/emscripten/src/relooper/test_fuzz2.txt +21 -21
  33. data/modules/emscripten/src/relooper/test_fuzz3.txt +18 -18
  34. data/modules/emscripten/src/relooper/test_fuzz4.txt +28 -28
  35. data/modules/emscripten/src/relooper/test_fuzz5.txt +61 -61
  36. data/modules/emscripten/src/relooper/test_fuzz6.txt +179 -179
  37. data/modules/emscripten/src/relooper/test_inf.txt +846 -846
  38. data/modules/emscripten/src/relooper/testit.sh +15 -15
  39. data/modules/emscripten/system/include/emscripten/emscripten.h +64 -0
  40. data/modules/emscripten/tools/eliminator/asm-eliminator-test-output.js +8 -2
  41. data/modules/emscripten/tools/eliminator/asm-eliminator-test.js +9 -1
  42. data/modules/emscripten/tools/eliminator/eliminator-test-output.js +11 -0
  43. data/modules/emscripten/tools/eliminator/eliminator-test.js +16 -1
  44. data/modules/emscripten/tools/file_packager.py +59 -49
  45. data/modules/emscripten/tools/js-optimizer.js +47 -8
  46. data/modules/emscripten/tools/shared.py +3 -3
  47. data/modules/emscripten/tools/test-js-optimizer-asm-pre-output.js +5 -3
  48. data/modules/emscripten/tools/test-js-optimizer-asm-pre.js +4 -0
  49. data/modules/mruby/INSTALL +11 -6
  50. data/modules/mruby/include/mrbconf.h +0 -3
  51. data/modules/mruby/include/mruby/khash.h +34 -36
  52. data/modules/mruby/include/mruby/string.h +3 -0
  53. data/modules/mruby/include/mruby.h +3 -3
  54. data/modules/mruby/mrblib/string.rb +3 -0
  55. data/modules/mruby/src/class.c +12 -12
  56. data/modules/mruby/src/codegen.c +18 -11
  57. data/modules/mruby/src/hash.c +12 -12
  58. data/modules/mruby/src/kernel.c +3 -3
  59. data/modules/mruby/src/load.c +29 -14
  60. data/modules/mruby/src/numeric.c +1 -1
  61. data/modules/mruby/src/object.c +14 -2
  62. data/modules/mruby/src/state.c +13 -10
  63. data/modules/mruby/src/string.c +1 -3
  64. data/modules/mruby/src/symbol.c +44 -18
  65. data/modules/mruby/src/variable.c +6 -6
  66. data/modules/mruby/test/t/class.rb +34 -0
  67. data/modules/mruby/test/t/module.rb +1 -1
  68. data/modules/mruby/test/t/syntax.rb +28 -0
  69. metadata +5 -13
  70. data/modules/emscripten/src/relooper.js +0 -11516
  71. data/modules/emscripten/src/relooper.js.raw.js +0 -11511
  72. data/modules/emscripten/tools/__init__.pyc +0 -0
  73. data/modules/emscripten/tools/cache.pyc +0 -0
  74. data/modules/emscripten/tools/gen_struct_info.pyc +0 -0
  75. data/modules/emscripten/tools/js_optimizer.pyc +0 -0
  76. data/modules/emscripten/tools/jsrun.pyc +0 -0
  77. data/modules/emscripten/tools/response_file.pyc +0 -0
  78. data/modules/emscripten/tools/shared.pyc +0 -0
  79. data/modules/emscripten/tools/tempfiles.pyc +0 -0
@@ -57,7 +57,7 @@ struct Block {
57
57
  BlockBranchMap ProcessedBranchesOut;
58
58
  BlockSet ProcessedBranchesIn;
59
59
  Shape *Parent; // The shape we are directly inside
60
- int Id; // A unique identifier
60
+ int Id; // A unique identifier, defined when added to relooper
61
61
  const char *Code; // The string representation of the code in this block. Owning pointer (we copy the input)
62
62
  const char *BranchVar; // If we have more than one branch out, the variable whose value determines where we go
63
63
  bool IsCheckedMultipleEntry; // If true, we are a multiple entry, so reaching us requires setting the label variable
@@ -69,9 +69,6 @@ struct Block {
69
69
 
70
70
  // Prints out the instructions code and branchings
71
71
  void Render(bool InLoop);
72
-
73
- // INTERNAL
74
- static int IdCounter;
75
72
  };
76
73
 
77
74
  // Represents a structured control flow shape, one of
@@ -96,20 +93,22 @@ class SimpleShape;
96
93
  class LabeledShape;
97
94
  class MultipleShape;
98
95
  class LoopShape;
96
+ class EmulatedShape;
99
97
 
100
98
  struct Shape {
101
- int Id; // A unique identifier. Used to identify loops, labels are Lx where x is the Id.
99
+ int Id; // A unique identifier. Used to identify loops, labels are Lx where x is the Id. Defined when added to relooper
102
100
  Shape *Next; // The shape that will appear in the code right after this one
103
101
  Shape *Natural; // The shape that control flow gets to naturally (if there is Next, then this is Next)
104
102
 
105
103
  enum ShapeType {
106
104
  Simple,
107
105
  Multiple,
108
- Loop
106
+ Loop,
107
+ Emulated
109
108
  };
110
109
  ShapeType Type;
111
110
 
112
- Shape(ShapeType TypeInit) : Id(Shape::IdCounter++), Next(NULL), Type(TypeInit) {}
111
+ Shape(ShapeType TypeInit) : Id(-1), Next(NULL), Type(TypeInit) {}
113
112
  virtual ~Shape() {}
114
113
 
115
114
  virtual void Render(bool InLoop) = 0;
@@ -118,9 +117,7 @@ struct Shape {
118
117
  static MultipleShape *IsMultiple(Shape *It) { return It && It->Type == Multiple ? (MultipleShape*)It : NULL; }
119
118
  static LoopShape *IsLoop(Shape *It) { return It && It->Type == Loop ? (LoopShape*)It : NULL; }
120
119
  static LabeledShape *IsLabeled(Shape *It) { return IsMultiple(It) || IsLoop(It) ? (LabeledShape*)It : NULL; }
121
-
122
- // INTERNAL
123
- static int IdCounter;
120
+ static EmulatedShape *IsEmulated(Shape *It) { return It && It->Type == Emulated ? (EmulatedShape*)It : NULL; }
124
121
  };
125
122
 
126
123
  struct SimpleShape : public Shape {
@@ -162,12 +159,15 @@ struct LoopShape : public LabeledShape {
162
159
  void Render(bool InLoop);
163
160
  };
164
161
 
165
- /*
166
- struct EmulatedShape : public Shape {
167
- std::deque<Block*> Blocks;
162
+ // TODO EmulatedShape is only partially functional. Currently it can be used for the
163
+ // entire set of blocks being relooped, but not subsets.
164
+ struct EmulatedShape : public LabeledShape {
165
+ Block *Entry;
166
+ BlockSet Blocks;
167
+
168
+ EmulatedShape() : LabeledShape(Emulated) { Labeled = true; }
168
169
  void Render(bool InLoop);
169
170
  };
170
- */
171
171
 
172
172
  // Implements the relooper algorithm for a function's blocks.
173
173
  //
@@ -184,6 +184,9 @@ struct Relooper {
184
184
  std::deque<Block*> Blocks;
185
185
  std::deque<Shape*> Shapes;
186
186
  Shape *Root;
187
+ bool Emulate;
188
+ int BlockIdCounter;
189
+ int ShapeIdCounter;
187
190
 
188
191
  Relooper();
189
192
  ~Relooper();
@@ -204,6 +207,9 @@ struct Relooper {
204
207
 
205
208
  // Sets asm.js mode on or off (default is off)
206
209
  static void SetAsmJSMode(int On);
210
+
211
+ // Sets whether we must emulate everything with switch-loop code
212
+ void SetEmulate(int E) { Emulate = E; }
207
213
  };
208
214
 
209
215
  typedef std::map<Block*, BlockSet> BlockBlockSetMap;
@@ -87,6 +87,12 @@ int main() {
87
87
  Relooper r;
88
88
  '''
89
89
 
90
+ if random.random() < 0.1:
91
+ print 'emulate'
92
+ fast += '''
93
+ r.SetEmulate(true);
94
+ '''
95
+
90
96
  for i in range(num):
91
97
  fast += ''' r.AddBlock(b%d);
92
98
  ''' % i
@@ -258,5 +258,33 @@ int main() {
258
258
 
259
259
  puts(buffer);
260
260
  }
261
+
262
+ if (1) {
263
+ Relooper::SetOutputBuffer(buffer, sizeof(buffer));
264
+
265
+ printf("\n\n-- If pattern, emulated --\n\n", "the_var");
266
+
267
+ Block *b_a = new Block("// block A\n", NULL);
268
+ Block *b_b = new Block("// block B\n", "b_check()");
269
+ Block *b_c = new Block("// block C\n", NULL);
270
+
271
+ b_a->AddBranchTo(b_b, "check == 10", "atob();");
272
+ b_a->AddBranchTo(b_c, NULL, "atoc();");
273
+
274
+ b_b->AddBranchTo(b_c, "case 17:", "btoc();");
275
+ b_b->AddBranchTo(b_a, NULL, NULL);
276
+
277
+ Relooper r;
278
+ r.SetEmulate(true);
279
+ r.AddBlock(b_a);
280
+ r.AddBlock(b_b);
281
+ r.AddBlock(b_c);
282
+
283
+ r.Calculate(b_a);
284
+ printf("\n\n", "the_var");
285
+ r.Render();
286
+
287
+ puts(buffer);
288
+ }
261
289
  }
262
290
 
@@ -4,23 +4,23 @@
4
4
 
5
5
 
6
6
 
7
- // block A
8
- switch (the_var) {
9
- check == 10 {
10
- atob();
11
- // block B
7
+ // block A
12
8
  switch (the_var) {
9
+ check == 10 {
10
+ atob();
11
+ // block B
12
+ switch (the_var) {
13
+ default: {
14
+ btoc();
15
+ }
16
+ }
17
+ break;
18
+ }
13
19
  default: {
14
- btoc();
20
+ atoc();
15
21
  }
16
22
  }
17
- break;
18
- }
19
- default: {
20
- atoc();
21
- }
22
- }
23
- // block C
23
+ // block C
24
24
 
25
25
 
26
26
 
@@ -28,25 +28,25 @@ default: {
28
28
 
29
29
 
30
30
 
31
- // block A
32
- switch (the_var) {
33
- check == 15 {
34
- // block B
31
+ // block A
35
32
  switch (the_var) {
36
- default: {
37
- }
33
+ check == 15 {
34
+ // block B
35
+ switch (the_var) {
36
+ default: {
37
+ }
38
+ }
39
+ break;
38
40
  }
39
- break;
40
- }
41
- default: {
42
- // block C
43
- switch (the_var) {
44
41
  default: {
42
+ // block C
43
+ switch (the_var) {
44
+ default: {
45
+ }
46
+ }
45
47
  }
46
48
  }
47
- }
48
- }
49
- // block D
49
+ // block D
50
50
 
51
51
 
52
52
 
@@ -54,81 +54,81 @@ default: {
54
54
 
55
55
 
56
56
 
57
- L9: while(1) {
58
- // block A
59
- var check = maybe();
60
- switch (the_var) {
61
- default: {
62
- }
63
- }
64
- // block B
65
- switch (the_var) {
66
- check == 41 {
67
- break;
68
- }
69
- default: {
70
- break L9;
71
- }
57
+ L0: while(1) {
58
+ // block A
59
+ var check = maybe();
60
+ switch (the_var) {
61
+ default: {
62
+ }
63
+ }
64
+ // block B
65
+ switch (the_var) {
66
+ check == 41 {
67
+ break;
68
+ }
69
+ default: {
70
+ break L0;
71
+ }
72
+ }
72
73
  }
73
- }
74
- // block C
74
+ // block C
75
75
 
76
76
 
77
77
 
78
78
  -- Loop with phi to head
79
79
 
80
- // code 1
81
- switch (the_var) {
82
- default: {
83
- var $i_0 = 0;var $x_0 = 5;
84
- }
85
- }
86
- L14: while(1) {
87
- // code 2
80
+ // code 1
88
81
  switch (the_var) {
89
- $2 {
90
- break;
91
- }
92
82
  default: {
93
- var $x_1 = $x_0;
94
- label = 18;
95
- break L14;
83
+ var $i_0 = 0;var $x_0 = 5;
84
+ }
85
+ }
86
+ L1: while(1) {
87
+ // code 2
88
+ switch (the_var) {
89
+ $2 {
90
+ break;
91
+ }
92
+ default: {
93
+ var $x_1 = $x_0;
94
+ label = -1;
95
+ break L1;
96
+ }
97
+ }
98
+ // code 3
99
+ switch (the_var) {
100
+ $6 {
101
+ break L1;
102
+ break;
103
+ }
104
+ default: {
105
+ var $i_0 = $7;var $x_0 = $5;
106
+ }
107
+ }
96
108
  }
109
+ if (label == -1) {
110
+ // code 7
97
111
  }
98
- // code 3
112
+ // code 4
99
113
  switch (the_var) {
100
- $6 {
101
- break L14;
114
+ $10 {
115
+ // code 5
116
+ switch (the_var) {
117
+ default: {
118
+ }
119
+ }
102
120
  break;
103
121
  }
104
122
  default: {
105
- var $i_0 = $7;var $x_0 = $5;
106
123
  }
107
124
  }
108
- }
109
- if (label == 18) {
110
- // code 7
111
- }
112
- // code 4
113
- switch (the_var) {
114
- $10 {
115
- // code 5
125
+ // code 6
116
126
  switch (the_var) {
117
127
  default: {
128
+ var $x_1 = $13;
118
129
  }
119
130
  }
120
- break;
121
- }
122
- default: {
123
- }
124
- }
125
- // code 6
126
- switch (the_var) {
127
- default: {
128
- var $x_1 = $13;
129
- }
130
- }
131
- // code 7
131
+ // code 7
132
132
 
133
133
 
134
134
 
@@ -136,30 +136,30 @@ default: {
136
136
 
137
137
 
138
138
 
139
- // block A...................................................................................................
140
- switch (the_var) {
141
- chak() {
142
- atob();
143
- // block B...................................................................................................
139
+ // block A...................................................................................................
144
140
  switch (the_var) {
145
- default: {
146
- btod();
147
- }
141
+ chak() {
142
+ atob();
143
+ // block B...................................................................................................
144
+ switch (the_var) {
145
+ default: {
146
+ btod();
147
+ }
148
+ }
149
+ // block D
150
+ break;
148
151
  }
149
- // block D
150
- break;
151
- }
152
- default: {
153
- atoc();
154
- // block C...................................................................................................
155
- switch (the_var) {
156
152
  default: {
157
- ctod2();
153
+ atoc();
154
+ // block C...................................................................................................
155
+ switch (the_var) {
156
+ default: {
157
+ ctod2();
158
+ }
159
+ }
160
+ // block D
158
161
  }
159
162
  }
160
- // block D
161
- }
162
- }
163
163
 
164
164
 
165
165
 
@@ -167,27 +167,27 @@ default: {
167
167
 
168
168
 
169
169
 
170
- // block A
171
- switch (the_var) {
172
- check == 10 {
173
- break;
174
- }
175
- default: {
176
- return C;
177
- }
178
- }
179
- while(1) {
180
- // block B
170
+ // block A
181
171
  switch (the_var) {
182
- default: {
183
- }
172
+ check == 10 {
173
+ break;
184
174
  }
185
- // block D
186
- switch (the_var) {
187
175
  default: {
176
+ return C;
188
177
  }
189
178
  }
190
- }
179
+ while(1) {
180
+ // block B
181
+ switch (the_var) {
182
+ default: {
183
+ }
184
+ }
185
+ // block D
186
+ switch (the_var) {
187
+ default: {
188
+ }
189
+ }
190
+ }
191
191
 
192
192
 
193
193
 
@@ -195,51 +195,51 @@ while(1) {
195
195
 
196
196
 
197
197
 
198
- // block A
199
- L37: do {
200
- switch (the_var) {
201
- expensive() {
202
- label = 33;
203
- break;
204
- }
205
- default: {
206
- // block B
198
+ // block A
199
+ L1: do {
207
200
  switch (the_var) {
208
- expensive2() {
209
- label = 33;
210
- break L37;
201
+ expensive() {
202
+ label = 3;
211
203
  break;
212
204
  }
213
205
  default: {
206
+ // block B
207
+ switch (the_var) {
208
+ expensive2() {
209
+ label = 3;
210
+ break L1;
211
+ break;
212
+ }
213
+ default: {
214
+ }
215
+ }
216
+ // block D
217
+ switch (the_var) {
218
+ default: {
219
+ }
220
+ }
214
221
  }
215
222
  }
216
- // block D
223
+ } while(0);
224
+ if (label == 3) {
225
+ // block C;
217
226
  switch (the_var) {
218
227
  default: {
219
228
  }
220
229
  }
221
230
  }
231
+ while(1) {
232
+ // block E
233
+ switch (the_var) {
234
+ default: {
235
+ }
236
+ }
237
+ // block F
238
+ switch (the_var) {
239
+ default: {
240
+ }
241
+ }
222
242
  }
223
- } while(0);
224
- if (label == 33) {
225
- // block C;
226
- switch (the_var) {
227
- default: {
228
- }
229
- }
230
- }
231
- while(1) {
232
- // block E
233
- switch (the_var) {
234
- default: {
235
- }
236
- }
237
- // block F
238
- switch (the_var) {
239
- default: {
240
- }
241
- }
242
- }
243
243
 
244
244
 
245
245
 
@@ -247,26 +247,71 @@ while(1) {
247
247
 
248
248
 
249
249
 
250
- // block A
251
- L46: do {
252
- switch (the_var) {
253
- shouldLoop() {
254
- while(1) {
255
- // block B
256
- switch (the_var) {
257
- moarLoop() {
250
+ // block A
251
+ L1: do {
252
+ switch (the_var) {
253
+ shouldLoop() {
254
+ while(1) {
255
+ // block B
256
+ switch (the_var) {
257
+ moarLoop() {
258
+ break;
259
+ }
260
+ default: {
261
+ break L1;
262
+ }
263
+ }
264
+ }
265
+ break;
266
+ }
267
+ default: {
268
+ }
269
+ }
270
+ } while(0);
271
+ // block C
272
+
273
+
274
+
275
+ -- If pattern, emulated --
276
+
277
+
278
+
279
+ label = 1;
280
+ L0: while(1) {
281
+ switch(label|0) {
282
+ case 3: {
283
+ // block C
258
284
  break;
259
285
  }
260
- default: {
261
- break L46;
286
+ case 1: {
287
+ // block A
288
+ if (check == 10) {
289
+ atob();
290
+ label = 2;
291
+ continue L0;
292
+ } else {
293
+ atoc();
294
+ label = 3;
295
+ continue L0;
296
+ }
297
+ break;
262
298
  }
299
+ case 2: {
300
+ // block B
301
+ switch (b_check()) {
302
+ case 17: {
303
+ btoc();
304
+ label = 3;
305
+ continue L0;
306
+ break;
307
+ }
308
+ default: {
309
+ label = 1;
310
+ continue L0;
311
+ }
312
+ }
313
+ break;
263
314
  }
264
315
  }
265
- break;
266
- }
267
- default: {
268
- }
269
316
  }
270
- } while(0);
271
- // block C
272
317
 
@@ -1,26 +1,26 @@
1
- ep
2
- L1: do {
3
- switch (var) {
4
- ep -> LBB1 {
5
- LBB1
6
- switch (the_var) {
7
- LBB1 -> LBB2 {
1
+ ep
2
+ L1: do {
3
+ switch (var) {
4
+ ep -> LBB1 {
5
+ LBB1
6
+ switch (the_var) {
7
+ LBB1 -> LBB2 {
8
+ break;
9
+ }
10
+ default: {
11
+ break L1;
12
+ }
13
+ }
14
+ LBB2
15
+ switch (the_var) {
16
+ default: {
17
+ }
18
+ }
8
19
  break;
9
20
  }
10
21
  default: {
11
- break L1;
12
22
  }
13
23
  }
14
- LBB2
15
- switch (the_var) {
16
- default: {
17
- }
18
- }
19
- break;
20
- }
21
- default: {
22
- }
23
- }
24
- } while(0);
25
- LBB3
24
+ } while(0);
25
+ LBB3
26
26