14 lines
522 B
C
14 lines
522 B
C
/* modulo de exemplo compilado para wasm32 (sem libc) */
|
|
__attribute__((visibility("default"))) int add(int a, int b) { return a + b; }
|
|
__attribute__((visibility("default"))) int sum_to(int n) {
|
|
int s = 0;
|
|
for (int i = 1; i <= n; i++) s += i;
|
|
return s;
|
|
}
|
|
__attribute__((visibility("default"))) int fact(int n) { return n <= 1 ? 1 : n * fact(n - 1); }
|
|
__attribute__((visibility("default"))) int fib(int n) {
|
|
int a = 0, b = 1;
|
|
for (int i = 0; i < n; i++) { int t = a + b; a = b; b = t; }
|
|
return a;
|
|
}
|