• R/O
  • SSH

quipu: Commit

quipu mercurial repository


Commit MetaInfo

Revisioned020b7852ee820d4227cf5d741b96e03ba7894c (tree)
Time2018-07-13 06:41:45
AuthorAgustina Arzille <avarzille@rise...>
CommiterAgustina Arzille

Log Message

Inline bytecode accessors

Change Summary

Incremental Difference

diff -r 5bba00932321 -r ed020b7852ee bytecode.cpp
--- a/bytecode.cpp Thu Jul 12 16:34:22 2018 -0300
+++ b/bytecode.cpp Thu Jul 12 18:41:45 2018 -0300
@@ -10,9 +10,6 @@
1010
1111 QP_DECLS_BEGIN
1212
13-static const int BC_FLG_FBIT = 2;
14-static const int BC_OPS_MASK = (1 << BC_FLG_FBIT) - 1;
15-
1613 static const char OPC_NAMES[] =
1714 "nop\0dup\0pop\0ret\0is\0not\0cons\0list\0car\0cdr\0cadr\0nputcar\0"
1815 "nputcdr\0apply\0tapply\0loadt\0loadnil\0load0\0load1\0loadi8\0loada0\0"
@@ -26,15 +23,11 @@
2623 "irtjmp\0irtjmp.l\0optargs\0optargs.l\0brbound\0brbound.l\0kwargs\0"
2724 "kwargs.l";
2825
29-#define F_(n) 1 << (BC_FLG_FBIT + n)
30-
31-static const int BC_CALL_FORM = F_(0);
32-static const int BC_LOAD_FORM = F_(1);
33-static const int BC_BRANCH_FORM = F_(2);
34-static const int BC_LONG_FORM = F_(3);
35-static const int BC_PURE_FORM = F_(4);
36-
37-#undef F_
26+#define BC_CALL_FORM bcode_instr::BC_CALL_FORM
27+#define BC_LOAD_FORM bcode_instr::BC_LOAD_FORM
28+#define BC_BRANCH_FORM bcode_instr::BC_BRANCH_FORM
29+#define BC_LONG_FORM bcode_instr::BC_LONG_FORM
30+#define BC_PURE_FORM bcode_instr::BC_PURE_FORM
3831
3932 static const bcode_instr BCODE_INSTR[] =
4033 {
@@ -130,6 +123,12 @@
130123 { 0, 0 }
131124 };
132125
126+#undef BC_CALL_FORM
127+#undef BC_LOAD_FORM
128+#undef BC_BRANCH_FORM
129+#undef BC_LONG_FORM
130+#undef BC_PURE_FORM
131+
133132 const bcode_instr* bcode_get (int opc)
134133 {
135134 return (&BCODE_INSTR[opc]);
@@ -145,56 +144,6 @@
145144 return (OPC_NAMES + this->name_off);
146145 }
147146
148-int bcode_instr::nops () const
149-{
150- return (this->flg_ex & BC_OPS_MASK);
151-}
152-
153-bool bcode_instr::branch_p () const
154-{
155- return ((this->flg_ex & BC_BRANCH_FORM) != 0);
156-}
157-
158-bool bcode_instr::long_p () const
159-{
160- return ((this->flg_ex & BC_LONG_FORM) != 0);
161-}
162-
163-bool bcode_instr::loadf_p () const
164-{
165- return ((this->flg_ex & BC_LOAD_FORM) != 0);
166-}
167-
168-bool bcode_instr::callf_p () const
169-{
170- return ((this->flg_ex & BC_CALL_FORM) != 0);
171-}
172-
173-bool bcode_instr::pure_p () const
174-{
175- return ((this->flg_ex & BC_PURE_FORM) != 0);
176-}
177-
178-int bcode_instr::argsize () const
179-{
180- return ((this->flg_ex & BC_LONG_FORM) ?
181- sizeof (int32_t) : (this->flg_ex & BC_BRANCH_FORM) ?
182- sizeof (int16_t) : 1);
183-}
184-
185-int bcode_instr::getarg (const void *ptr) const
186-{
187- switch (this->argsize ())
188- {
189- case sizeof (int32_t):
190- return ((int32_t)get32 (ptr));
191- case sizeof (int16_t):
192- return ((int16_t)get16 (ptr));
193- default:
194- return (*(int8_t *)ptr);
195- }
196-}
197-
198147 static void disasm_aux (interpreter *, object, stream *, int);
199148
200149 static void
diff -r 5bba00932321 -r ed020b7852ee bytecode.h
--- a/bytecode.h Thu Jul 12 16:34:22 2018 -0300
+++ b/bytecode.h Thu Jul 12 18:41:45 2018 -0300
@@ -105,16 +105,70 @@
105105 uint16_t name_off;
106106 uint16_t flg_ex;
107107
108+ static const int BC_FLG_FBIT = 2;
109+ static const int BC_OPS_MASK = (1 << BC_FLG_FBIT) - 1;
110+
111+#define F_(n) (1 << (BC_FLG_FBIT + n))
112+
113+ static const int BC_CALL_FORM = F_(0);
114+ static const int BC_LOAD_FORM = F_(1);
115+ static const int BC_BRANCH_FORM = F_(2);
116+ static const int BC_LONG_FORM = F_(3);
117+ static const int BC_PURE_FORM = F_(4);
118+
119+#undef F_
120+
108121 int opcode () const;
109122 const char* name () const;
110- int nops () const;
111- bool branch_p () const;
112- bool long_p () const;
113- bool loadf_p () const;
114- bool callf_p () const;
115- bool pure_p () const;
116- int argsize () const;
117- int getarg (const void *__ptr) const;
123+
124+ int nops () const
125+ {
126+ return (this->flg_ex & BC_OPS_MASK);
127+ }
128+
129+ bool branch_p () const
130+ {
131+ return ((this->flg_ex & BC_BRANCH_FORM) != 0);
132+ }
133+
134+ bool long_p () const
135+ {
136+ return ((this->flg_ex & BC_LONG_FORM) != 0);
137+ }
138+
139+ bool loadf_p () const
140+ {
141+ return ((this->flg_ex & BC_LOAD_FORM) != 0);
142+ }
143+
144+ bool callf_p () const
145+ {
146+ return ((this->flg_ex & BC_CALL_FORM) != 0);
147+ }
148+
149+ bool pure_p () const
150+ {
151+ return ((this->flg_ex & BC_PURE_FORM) != 0);
152+ }
153+
154+ int argsize () const
155+ {
156+ return (this->long_p () ? sizeof (int32_t) :
157+ (this->branch_p () ? sizeof (int16_t) : 1));
158+ }
159+
160+ int getarg (const void *__ptr) const
161+ {
162+ switch (this->argsize ())
163+ {
164+ case sizeof (int32_t):
165+ return ((int32_t)get32 (__ptr));
166+ case sizeof (int16_t):
167+ return ((int16_t)get16 (__ptr));
168+ default:
169+ return (*(int8_t *)__ptr);
170+ }
171+ }
118172 };
119173
120174 QP_EXPORT const bcode_instr* bcode_get (int __opc) __attribute__ ((pure));
diff -r 5bba00932321 -r ed020b7852ee defs.h
--- a/defs.h Thu Jul 12 16:34:22 2018 -0300
+++ b/defs.h Thu Jul 12 18:41:45 2018 -0300
@@ -102,7 +102,7 @@
102102 * 8 bytes, and use the least 3 significant bits for similar
103103 * purposes as described above. */
104104
105- // Get a pointer from a varobj, masking type and sign bits.
105+ // Get a pointer from a varobj, masking type and extra bits.
106106 inline void* maskp (object __obj)
107107 {
108108 return ((void *)(__obj & ~7));
Show on old repository browser