summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-02-01 18:29:40 +0000
committerDamien George <damien.p.george@gmail.com>2014-02-01 18:29:40 +0000
commitfb083ea986d758c7426fda091c4899f0511aaa8c (patch)
treef63392368dc5140441ab3f0d8a04ec1ca9585871 /py/emitbc.c
parent87413a4d0c579ec491cf52ab8d6520430df64c7d (diff)
downloadmicropython-fb083ea986d758c7426fda091c4899f0511aaa8c.tar.gz
micropython-fb083ea986d758c7426fda091c4899f0511aaa8c.zip
py: mp_execute_byte_code has 2 arg arrays, for more efficient default params.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index 10a93d5b6e..117a08cda5 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -107,6 +107,22 @@ static void emit_write_byte_code_byte_byte(emit_t* emit, byte b1, uint b2) {
c[1] = b2;
}
+static void emit_write_byte_code_uint(emit_t* emit, uint num) {
+ if (num <= 127) { // fits in 0x7f
+ // fit argument in single byte
+ byte* c = emit_get_cur_to_write_byte_code(emit, 1);
+ c[0] = num;
+ } else if (num <= 16383) { // fits in 0x3fff
+ // fit argument in two bytes
+ byte* c = emit_get_cur_to_write_byte_code(emit, 2);
+ c[0] = (num >> 8) | 0x80;
+ c[1] = num;
+ } else {
+ // larger numbers not implemented/supported
+ assert(0);
+ }
+}
+
// integers (for small ints) are stored as 24 bits, in excess
static void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t num) {
num += 0x800000;
@@ -118,26 +134,21 @@ static void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t n
c[3] = num >> 16;
}
-static void emit_write_byte_code_byte_uint(emit_t* emit, byte b1, uint num) {
- if (num <= 127) { // fits in 0x7f
- // fit argument in single byte
- byte* c = emit_get_cur_to_write_byte_code(emit, 2);
- c[0] = b1;
- c[1] = num;
- } else if (num <= 16383) { // fits in 0x3fff
- // fit argument in two bytes
- byte* c = emit_get_cur_to_write_byte_code(emit, 3);
- c[0] = b1;
- c[1] = (num >> 8) | 0x80;
- c[2] = num;
- } else {
- // larger numbers not implemented/supported
- assert(0);
- }
+static void emit_write_byte_code_byte_uint(emit_t* emit, byte b, uint num) {
+ emit_write_byte_code_byte(emit, b);
+ emit_write_byte_code_uint(emit, num);
}
-static void emit_write_byte_code_byte_qstr(emit_t* emit, byte b1, qstr qstr) {
- emit_write_byte_code_byte_uint(emit, b1, qstr);
+/* currently unused
+static void emit_write_byte_code_byte_uint_uint(emit_t* emit, byte b, uint num1, uint num2) {
+ emit_write_byte_code_byte(emit, b);
+ emit_write_byte_code_byte_uint(emit, num1);
+ emit_write_byte_code_byte_uint(emit, num2);
+}
+*/
+
+static void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) {
+ emit_write_byte_code_byte_uint(emit, b, qstr);
}
// unsigned labels are relative to ip following this instruction, stored as 16 bits
@@ -665,13 +676,13 @@ static void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) {
static void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
assert(n_dict_params == 0);
- if (n_default_params != 0) {
+ if (n_default_params == 0) {
+ emit_pre(emit, 1);
+ emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id);
+ } else {
emit_bc_build_tuple(emit, n_default_params);
emit_pre(emit, 0);
emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION_DEFARGS, scope->unique_code_id);
- } else {
- emit_pre(emit, 1);
- emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id);
}
}