]> git.sesse.net Git - interpreter_trials/blob - bytecode.cpp
Add a tail-call variant with state as global variables in locked registers.
[interpreter_trials] / bytecode.cpp
1 #include "bytecode.h"
2
3
4 uint8_t cycle_table[8] = {
5     1,
6     2,
7     2,
8     2,
9     6,
10     2,
11     2,
12 };
13
14
15 uint8_t fibonacci[] = {
16
17     // initializer
18
19     OP_MOV, REGS(X3, X0),
20     OP_MOVI, REGS(X0, 0), IMM(0),
21     OP_MOVI, REGS(X1, 0), IMM(1),
22     OP_MOV, REGS(X4, X1),
23
24     OP_SUB, REGS(X3, X0),
25     OP_BNZ, 1,
26     OP_RETURN, // early-out for fibonacci(0)
27
28
29     // loop start
30     OP_MOV, REGS(X2, X0),
31     OP_MOV, REGS(X0, X1),
32     OP_ADD, REGS(X1, X2),
33     OP_SUB, REGS(X3, X4),
34     OP_BNZ, uint8_t(-10),
35
36     OP_RETURN,
37 };