1 | // |
2 | // m3_exec_defs.h |
3 | // |
4 | // Created by Steven Massey on 5/1/19. |
5 | // Copyright © 2019 Steven Massey. All rights reserved. |
6 | // |
7 | |
8 | #ifndef m3_exec_defs_h |
9 | #define m3_exec_defs_h |
10 | |
11 | #include "m3_core.h" |
12 | |
13 | d_m3BeginExternC |
14 | |
15 | # define m3MemData(mem) (u8*)(((M3MemoryHeader*)(mem))+1) |
16 | # define m3MemRuntime(mem) (((M3MemoryHeader*)(mem))->runtime) |
17 | # define m3MemInfo(mem) (&(((M3MemoryHeader*)(mem))->runtime->memory)) |
18 | |
19 | # define d_m3BaseOpSig pc_t _pc, m3stack_t _sp, M3MemoryHeader * _mem, m3reg_t _r0 |
20 | # define d_m3BaseOpArgs _sp, _mem, _r0 |
21 | # define d_m3BaseOpAllArgs _pc, _sp, _mem, _r0 |
22 | # define d_m3BaseOpDefaultArgs 0 |
23 | # define d_m3BaseClearRegisters _r0 = 0; |
24 | |
25 | # define d_m3ExpOpSig(...) d_m3BaseOpSig, __VA_ARGS__ |
26 | # define d_m3ExpOpArgs(...) d_m3BaseOpArgs, __VA_ARGS__ |
27 | # define d_m3ExpOpAllArgs(...) d_m3BaseOpAllArgs, __VA_ARGS__ |
28 | # define d_m3ExpOpDefaultArgs(...) d_m3BaseOpDefaultArgs, __VA_ARGS__ |
29 | # define d_m3ExpClearRegisters(...) d_m3BaseClearRegisters; __VA_ARGS__ |
30 | |
31 | # if d_m3HasFloat |
32 | # define d_m3OpSig d_m3ExpOpSig (f64 _fp0) |
33 | # define d_m3OpArgs d_m3ExpOpArgs (_fp0) |
34 | # define d_m3OpAllArgs d_m3ExpOpAllArgs (_fp0) |
35 | # define d_m3OpDefaultArgs d_m3ExpOpDefaultArgs (0.) |
36 | # define d_m3ClearRegisters d_m3ExpClearRegisters (_fp0 = 0.;) |
37 | # else |
38 | # define d_m3OpSig d_m3BaseOpSig |
39 | # define d_m3OpArgs d_m3BaseOpArgs |
40 | # define d_m3OpAllArgs d_m3BaseOpAllArgs |
41 | # define d_m3OpDefaultArgs d_m3BaseOpDefaultArgs |
42 | # define d_m3ClearRegisters d_m3BaseClearRegisters |
43 | # endif |
44 | |
45 | typedef m3ret_t (vectorcall * IM3Operation) (d_m3OpSig); |
46 | |
47 | #define d_m3RetSig static inline m3ret_t vectorcall |
48 | #define d_m3Op(NAME) M3_NO_UBSAN d_m3RetSig op_##NAME (d_m3OpSig) |
49 | |
50 | #define nextOpImpl() ((IM3Operation)(* _pc))(_pc + 1, d_m3OpArgs) |
51 | #define jumpOpImpl(PC) ((IM3Operation)(* PC))( PC + 1, d_m3OpArgs) |
52 | |
53 | #define nextOpDirect() return nextOpImpl() |
54 | #define jumpOpDirect(PC) return jumpOpImpl((pc_t)(PC)) |
55 | |
56 | d_m3RetSig RunCode (d_m3OpSig) |
57 | { |
58 | nextOpDirect(); |
59 | } |
60 | |
61 | d_m3EndExternC |
62 | |
63 | #endif // m3_exec_defs_h |
64 | |