38 #define RBP(x) (0x18 + (x * sizeof(PN)))
44 #define REG(x) (x == 0 ? 0 : (x == 1 ? 2 : x + 2))
48 #define ARM(ins, a, b, c, d) \
49 ASM((ins << 2) | ((a >> 2) & 0x3)); \
50 ASM((a << 5) | (b & 0x1F)); \
52 #define ARM3(ins, a, b, c) \
53 ARM(ins, a, b, c >> 8, c)
54 #define ARM2(ins, a, b) \
55 ARM(ins, a, 0, b >> 8, b)
56 #define ARMN(ins, a) \
58 ASM(a >> 16); ASM(a >> 8); ASM(a)
60 #define ARM_MOV(a, b) \
61 ARM(31, b, a, (b << 3) | 0x3, 0x78); // or rA,rB,rB
63 ARM(31, REG(op.a), REG(op.a), 0x0e, 0x70); \
64 ARM(31, REG(op.b), REG(op.b), 0x0e, 0x70)
65 #define ARM_MATH(do) \
68 ARM(21, REG(op.a), REG(op.a), 0x08, 0x3c); \
69 ARM3(24, REG(op.a), REG(op.a), 1); \
70 ARM(21, REG(op.b), REG(op.b), 0x08, 0x3c); \
71 ARM3(24, REG(op.b), REG(op.b), 1);
72 #define ARM_CMP(cmp) \
74 ARM(31, 7 << 2, REG(op.a), REG(op.b) << 3, 0x40); \
76 ARM2(14, REG(op.a), PN_TRUE); \
78 ARM2(14, REG(op.a), PN_FALSE);
79 #define TAG_JMP(ins, jpos) \
81 jmps[*jmpc].from = asmp[0]->len; \
83 jmps[*jmpc].to = jpos + 1; \
85 } else if (jpos < pos) { \
86 int off = (offs[jpos + 1] - (asmp[0]->len)); \
87 if (ins == 0x48000000) \
88 ASMI(ins | (off & 0x3FFFFFF)); \
90 ASMI(ins | (off & 0xFFFF)); \
96 ARM3(47, 30, 1, 0xFFF8);
100 rsp = -((rsp+31)&~(15));
115 if (asmj[0] == 0x48) {
116 asmj[0] |= (dist >> 24) & 3;
117 asmj[1] = dist >> 16;
231 ARM(11, 7 << 2,
REG(op.
b), 0, 0);
341 ARM3(46, 30, 1, 0xFFF8);
void potion_arm_named(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
#define ARM3(ins, a, b, c)
#define PN_TUPLE_AT(t, n)
void potion_arm_gte(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
PN asmb
assembled instructions
PN values
numbers, strings, etc.
record labels to be patched
void potion_arm_getpath(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_getlocal(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long regs)
void potion_arm_lte(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_jmp(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, PN_OP *start, PNJumps *jmps, size_t *offs, int *jmpc)
void potion_arm_gettable(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_mult(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_neq(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
#define TAG_JMP(ins, jpos)
void potion_arm_testjmp(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, PN_OP *start, PNJumps *jmps, size_t *offs, int *jmpc)
void potion_arm_setlocal(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long regs)
void potion_arm_cmp(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_gettuple(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
#define REG_TMP
The scratch space, register 3, is referred to as rD in the notation.
void potion_arm_global(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_settable(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_not(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_bitl(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
the Potion VM instruction set (heavily based on Lua's)
void potion_arm_loadk(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_bind(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_ivars(Potion *P, PN ivars, PNAsm *volatile *asmp)
void potion_arm_add(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
#define ARM(ins, a, b, c, d)
void potion_arm_newtuple(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_settuple(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_self(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_stack(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, long rsp)
void potion_arm_newlick(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_getupval(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long lregs)
void potion_arm_message(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_test_asm(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, int test)
void potion_arm_bitn(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_eq(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_sub(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_class(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_test(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_jmpedit(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, unsigned char *asmj, int dist)
void potion_arm_pow(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_div(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_gt(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_finish(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp)
void potion_arm_callset(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_local(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, long reg, long arg)
a prototype is compiled source code, a closure block (lambda) non-volatile.
void potion_arm_rem(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_setup(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp)
#define PN_OP_AT(asmb, n)
int a
< the op. See vm.c http://www.lua.org/doc/jucs05.pdf
the global interpreter state P. currently singleton (not threads yet)
void potion_arm_bitr(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_setpath(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_method(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_OP **pos, long lregs, long start, long regs)
void potion_arm_def(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
#define REG(x)
The EABI reserves GPR1 for a stack pointer, GPR3-GPR7 for function argument passing, and GPR3 for function return values.
void potion_arm_mcache(Potion *P, vPN(Vtable) vt, PNAsm *volatile *asmp)
void potion_arm_call(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
int b
optional arg, the message
void potion_arm_lt(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_search(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_return(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_notjmp(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, PN_OP *start, PNJumps *jmps, size_t *offs, int *jmpc)
void potion_arm_setupval(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long lregs)
void potion_arm_move(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_loadpn(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos)
void potion_arm_upvals(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, long lregs, long start, int upc)
void potion_arm_tailcall(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, PN_SIZE pos, long start)
void potion_arm_registers(Potion *P, struct PNProto *volatile f, PNAsm *volatile *asmp, long start)
PN_OP - a compressed three-address op (as 32bit int bitfield) TODO: expand to 64bit, check jit then.