repos / gbc

GBC - Go B Compiler
git clone https://github.com/xplshn/gbc.git

gbc / tests
xplshn  ·  2025-08-13

rvalue_call.b

B
 1foo() {
 2    extrn printf;
 3    printf("Foo\n");
 4}
 5
 6bar() {
 7    extrn printf;
 8    printf("Bar\n");
 9}
10
11baz() {
12    extrn printf;
13    printf("Baz\n");
14}
15
16main() {
17    extrn printf, malloc, exit;
18
19    auto W;
20    W = &0[1];
21
22    auto funs, i, n;
23    n = 4;
24    funs = malloc(n * W);
25    i = 0;
26    funs[i++] = &foo;
27    funs[i++] = &bar;
28    funs[i++] = &baz;
29    funs[i++] = &exit;
30
31    i = 0; while (i < n) funs[i++](0);
32}