247 // (module
248 // (memory 1)
249 // (func $fac (export "fac") (param i64) (result i64)
250 // (if (i64.eqz (get_local 0))
251 // (return (i64.const 1))
252 // )
253 // (return (i64.mul (get_local 0) (call $fac (i64.sub (get_local 0) (i64.const 1)))))
254 // )
255 // )
256 Vector<uint8_t> vector = {
257 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x86, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40,
258 0x01, 0x02, 0x01, 0x02, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x05, 0x83, 0x80, 0x80,
259 0x80, 0x00, 0x01, 0x00, 0x01, 0x07, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x03, 0x66, 0x61, 0x63,
260 0x00, 0x00, 0x0a, 0x9e, 0x80, 0x80, 0x80, 0x00, 0x01, 0x98, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14,
261 0x00, 0x11, 0x00, 0x68, 0x03, 0x00, 0x11, 0x01, 0x09, 0x0f, 0x14, 0x00, 0x14, 0x00, 0x11, 0x01,
262 0x5c, 0x16, 0x00, 0x5d, 0x09, 0x0f
263 };
264
265 Plan plan(*vm, vector);
266 if (plan.result.size() != 1 || !plan.result[0]) {
267 dataLogLn("Module failed to compile correctly.");
268 CRASH();
269 }
270
271 // Test this doesn't crash.
272 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(0) }), 1);
273 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(1) }), 1);
274 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(2) }), 2);
275 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(4) }), 24);
276 }
277
278 {
279 // Generated from:
280 // (module
281 // (memory 1)
282 // (func (export "double") (param i64) (result i64) (return (call 1 (get_local 0) (get_local 0))))
283 // (func $sum (param i64) (param i64) (result i64) (return (i64.add (get_local 0) (get_local 1))))
284 // )
285 Vector<uint8_t> vector = {
286 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x8c, 0x80, 0x80, 0x80, 0x00, 0x02, 0x40,
287 0x01, 0x02, 0x01, 0x02, 0x40, 0x02, 0x02, 0x02, 0x01, 0x02, 0x03, 0x83, 0x80, 0x80, 0x80, 0x00,
288 0x02, 0x00, 0x01, 0x05, 0x83, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x01, 0x07, 0x8a, 0x80, 0x80,
289 0x80, 0x00, 0x01, 0x06, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x00, 0x00, 0x0a, 0x9c, 0x80, 0x80,
290 0x80, 0x00, 0x02, 0x89, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x16, 0x01, 0x09,
291 0x0f, 0x88, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x5b, 0x09, 0x0f
292 };
293
294 Plan plan(*vm, vector);
295 if (plan.result.size() != 2 || !plan.result[0] || !plan.result[1]) {
296 dataLogLn("Module failed to compile correctly.");
297 CRASH();
298 }
299
300 // Test this doesn't crash.
301 CHECK_EQ(invoke<int>(*plan.result[1]->jsEntryPoint, { box(0), box(0) }), 0);
302 CHECK_EQ(invoke<int>(*plan.result[1]->jsEntryPoint, { box(100), box(0) }), 100);
303 CHECK_EQ(invoke<int>(*plan.result[1]->jsEntryPoint, { box(1), box(15) }), 16);
304 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(0) }), 0);
305 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(100) }), 200);
306 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(1) }), 2);
307 }
308
309 {
310 // Generated from:
311 // (module
312 // (memory 1)
313 // (func $id (param $value i32) (result i32) (return (get_local $value)))
314 // (func (export "id-call") (param $value i32) (result i32) (return (call $id (get_local $value))))
315 // )
316 Vector<uint8_t> vector = {
317 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x86, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40,
318 0x01, 0x01, 0x01, 0x01, 0x03, 0x83, 0x80, 0x80, 0x80, 0x00, 0x02, 0x00, 0x00, 0x05, 0x83, 0x80,
319 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x07, 0x8b, 0x80, 0x80, 0x80, 0x00, 0x01, 0x07, 0x69, 0x64,
320 0x2d, 0x63, 0x61, 0x6c, 0x6c, 0x00, 0x01, 0x0a, 0x97, 0x80, 0x80, 0x80, 0x00, 0x02, 0x85, 0x80,
321 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x09, 0x0f, 0x87, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00,
322 0x16, 0x00, 0x09, 0x0f
323 };
324
325 Plan plan(*vm, vector);
326 if (plan.result.size() != 2 || !plan.result[0] || !plan.result[1]) {
327 dataLogLn("Module failed to compile correctly.");
328 CRASH();
329 }
330
331 // Test this doesn't crash.
332 CHECK_EQ(invoke<int>(*plan.result[1]->jsEntryPoint, { box(0) }), 0);
333 CHECK_EQ(invoke<int>(*plan.result[1]->jsEntryPoint, { box(100) }), 100);
334 CHECK_EQ(invoke<int>(*plan.result[1]->jsEntryPoint, { box(1) }), 1);
335 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(0) }), 0);
336 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(100) }), 100);
337 CHECK_EQ(invoke<int>(*plan.result[0]->jsEntryPoint, { box(1) }), 1);
338 }
339
340 {
341 // Generated from: