Notebooks · lib/cc/tests/corpus
lib/ cc/ tests/ corpus.viv
lib/cc/tests/corpus.viv · 1 code cellOpen in the workbenchDownload .vivLook inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.
[1]lines 1–551
# The C corpus of tests/cc compiled by lib/cc and run on lib/rv32's # simulator, against clang -O0 on the host: written by # tools/cc/corpus.py, which ran each program natively for the expected # output and exit status. Generated: do not edit. from cc.driver import run_c EXIT_MOD: Int = 256 # a host process reports the low 8 bits of main's value SRC_ACKERMANN = """/* SPDX-License-Identifier: MIT */ /* SPDX-FileCopyrightText: 2019 Rui Ueyama */ /* SPDX-FileCopyrightText: 2026 The Viv authors */ /* The Ackermann function: deep recursion through two parameters. */ int ack(int m, int n) { if (m == 0) return n + 1; if (n == 0) return ack(m - 1, 1); return ack(m - 1, ack(m, n - 1)); } int main() { int m; int n; for (m = 0; m <= 2; m = m + 1) for (n = 0; n <= 3; n = n + 1) print_int(ack(m, n)); return ack(2, 3); } """ test "ackermann.c: the output and exit status clang -O0 gives" { m = run_c(SRC_ACKERMANN) assert_true(m.halted) assert_true(m.output == "1\n2\n3\n4\n2\n3\n4\n5\n3\n5\n7\n9\n") assert_true(m.exit_code % EXIT_MOD == 9) } SRC_ARITH = """/* SPDX-License-Identifier: MIT */ /* SPDX-FileCopyrightText: 2019 Rui Ueyama */ /* SPDX-FileCopyrightText: 2026 The Viv authors */ /* Arithmetic, precedence and comparisons: expressions from chibicc's * test.sh and tests/arith.c (github.com/rui314/chibicc). */ int main() { print_int(5 + 20 - 4); print_int(5 + 6 * 7); print_int(5 * (9 - 6)); print_int((3 + 5) / 2); print_int(-10 + 20); print_int(- -10); print_int(17 % 6); print_int(-17 % 6); print_int(-17 / 6); print_int(0 == 1); print_int(42 != 42); print_int(1 >= 1); print_int(!0 + !5); print_int(0 || (2 - 2) || 5); print_int((2 - 2) && 5); return 21; } """