File: test_inlinejs3.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (40 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright 2016 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

#include <stdio.h>
#include <emscripten.h>

void loop_iter() {
  EM_ASM(out('loop iter!'));
}

int main(int argc, char **argv) {
  EM_ASM(out('hello dere1'));
  EM_ASM("out('hello dere2');");
  emscripten_debugger(); // does nothing in shells; check for validation error though
  for (int i = 0; i < 3; i++) {
    EM_ASM(out('hello dere3'); out('hello dere' + 4););
  }
  EM_ASM({ out('hello input ' + $0) }, 123);
  int sum = 0;
  for (int i = 0; i < argc * 3; i++) {
    sum += EM_ASM_INT({
                        out('i: ' + [ $0, ($1).toFixed(2) ]);
                        return $0 * 2;
                      },
                      i, (double)i / 12);
  }
  EM_ASM_INT({ globalVar = $0 }, sum); // no outputs, just input
  sum = 0;
  sum = EM_ASM_INT(return globalVar); // no inputs, just output
  printf("sum: %d\n", sum);
  printf("|%.2f|\n", EM_ASM_DOUBLE({
    return $0; // return double properly
  }, 1.2));
  for (int i = 0; i < argc*2; i++) loop_iter();
  return 0;
}