potion  0.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
asm.h
Go to the documentation of this file.
1 
13 #ifndef POTION_ASM_H
14 #define POTION_ASM_H
15 
16 #define ASM_UNIT 512
17 #define ASM_TPL_IMM 1024 // bitflag for immediate gettuple op.b value
18 
20 typedef struct {
21  size_t from;
23 } PNJumps;
24 
25 #define MAKE_TARGET(arch) PNTarget potion_target_##arch = { \
26  .setup = potion_##arch##_setup, \
27  .stack = potion_##arch##_stack, \
28  .registers = potion_##arch##_registers, \
29  .local = potion_##arch##_local, \
30  .upvals = potion_##arch##_upvals, \
31  .jmpedit = potion_##arch##_jmpedit, \
32  .op = { \
33  (OP_F)NULL, \
34  (OP_F)potion_##arch##_move, \
35  (OP_F)potion_##arch##_loadk, \
36  (OP_F)potion_##arch##_loadpn, \
37  (OP_F)potion_##arch##_self, \
38  (OP_F)potion_##arch##_newtuple, \
39  (OP_F)potion_##arch##_gettuple, \
40  (OP_F)potion_##arch##_settuple, \
41  (OP_F)potion_##arch##_getlocal, \
42  (OP_F)potion_##arch##_setlocal, \
43  (OP_F)potion_##arch##_getupval, \
44  (OP_F)potion_##arch##_setupval, \
45  (OP_F)potion_##arch##_global, \
46  (OP_F)potion_##arch##_gettable, \
47  (OP_F)potion_##arch##_settable, \
48  (OP_F)potion_##arch##_newlick, \
49  (OP_F)potion_##arch##_getpath, \
50  (OP_F)potion_##arch##_setpath, \
51  (OP_F)potion_##arch##_add, \
52  (OP_F)potion_##arch##_sub, \
53  (OP_F)potion_##arch##_mult, \
54  (OP_F)potion_##arch##_div, \
55  (OP_F)potion_##arch##_rem, \
56  (OP_F)potion_##arch##_pow, \
57  (OP_F)potion_##arch##_not, \
58  (OP_F)potion_##arch##_cmp, \
59  (OP_F)potion_##arch##_eq, \
60  (OP_F)potion_##arch##_neq, \
61  (OP_F)potion_##arch##_lt, \
62  (OP_F)potion_##arch##_lte, \
63  (OP_F)potion_##arch##_gt, \
64  (OP_F)potion_##arch##_gte, \
65  (OP_F)potion_##arch##_bitn, \
66  (OP_F)potion_##arch##_bitl, \
67  (OP_F)potion_##arch##_bitr, \
68  (OP_F)potion_##arch##_def, \
69  (OP_F)potion_##arch##_bind, \
70  (OP_F)potion_##arch##_message, \
71  (OP_F)potion_##arch##_jmp, \
72  (OP_F)potion_##arch##_test, \
73  (OP_F)potion_##arch##_testjmp, \
74  (OP_F)potion_##arch##_notjmp, \
75  (OP_F)potion_##arch##_named, \
76  (OP_F)potion_##arch##_call, \
77  (OP_F)potion_##arch##_callset, \
78  (OP_F)potion_##arch##_tailcall, \
79  (OP_F)potion_##arch##_return, \
80  (OP_F)potion_##arch##_method, \
81  (OP_F)potion_##arch##_class \
82  }, \
83  .finish = potion_##arch##_finish, \
84  .mcache = potion_##arch##_mcache, \
85  .ivars = potion_##arch##_ivars \
86  }
87 
88 #define PN_HAS_UPVALS(v) \
89  int v = 0; \
90  if (PN_TUPLE_LEN(f->protos) > 0) { \
91  PN_TUPLE_EACH(f->protos, i, proto2, { \
92  if (PN_TUPLE_LEN(PN_PROTO(proto2)->upvals) > 0) { \
93  v = 1; \
94  } \
95  }); \
96  }
97 
98 #define ASM(ins) *asmp = potion_asm_put(P, *asmp, (PN)(ins), sizeof(u8))
99 #define ASM2(pn) *asmp = potion_asm_put(P, *asmp, (PN)(pn), 2)
100 #define ASMI(pn) *asmp = potion_asm_put(P, *asmp, (PN)(pn), sizeof(int))
101 #define ASMN(pn) *asmp = potion_asm_put(P, *asmp, (PN)(pn), sizeof(PN))
102 #define ASMS(cstr) *asmp = potion_asm_write(P, *asmp, cstr, sizeof(cstr)-1)
103 
106 PNAsm *potion_asm_put(Potion *, PNAsm *, PN, size_t);
107 PNAsm *potion_asm_op(Potion *, PNAsm *, u8, int, int);
108 PNAsm *potion_asm_write(Potion *, PNAsm *, char *, size_t);
109 
110 #endif
PNAsm * potion_asm_clear(Potion *, PNAsm *)
Definition: asm.c:19
record labels to be patched
Definition: asm.h:20
PNAsm * potion_asm_new(Potion *)
Definition: asm.c:13
PNAsm * potion_asm_write(Potion *, PNAsm *, char *, size_t)
Definition: asm.c:56
PNAsm * potion_asm_op(Potion *, PNAsm *, u8, int, int)
Definition: asm.c:43
Definition: potion.h:577
PN_SIZE to
Definition: asm.h:22
unsigned int PN_SIZE
Definition: potion.h:79
unsigned char u8
Definition: internal.h:8
the global interpreter state P. currently singleton (not threads yet)
Definition: potion.h:644
volatile _PN PN
Definition: potion.h:81
size_t from
Definition: asm.h:21
PNAsm * potion_asm_put(Potion *, PNAsm *, PN, size_t)
Definition: asm.c:25