8000 update compiler to align with latest changes on master, v1.7 · godlygeek/circuitpython@be020eb · GitHub
[go: up one dir, main page]

Skip to content

Commit be020eb

Browse files
committed
update compiler to align with latest changes on master, v1.7
1 parent 1c0343f commit be020eb

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

py/compile2.c

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,11 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, const byte *n_pre, const
17021702
compile_node(comp, p_body);
17031703
} else {
17041704
uint l_end = comp_next_label(comp);
1705+
if (MICROPY_EMIT_NATIVE && comp->scope_cur->emit_options != MP_EMIT_OPT_BYTECODE) {
1706+
// we need to allocate an extra label for the native emitter
1707+
// it will use l_end+1 as an auxiliary label
1708+
comp_next_label(comp);
1709+
}
17051710
if (pt_is_rule(n_pre, PN_with_item)) {
17061711
// this pre-bit is of the form "a as b"
17071712
const byte *p = pt_rule_first(n_pre);
@@ -1719,10 +1724,7 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, const byte *n_pre, const
17191724
// compile additional pre-bits and the body
17201725
compile_with_stmt_helper(comp, n_pre, p_body);
17211726
// finish this with block
1722-
EMIT(pop_block);
1723-
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
1724-
EMIT_ARG(label_assign, l_end);
1725-
EMIT(with_cleanup);
1727+
EMIT_ARG(with_cleanup, l_end);
17261728
compile_decrease_except_level(comp);
17271729
EMIT(end_finally);
17281730
}
@@ -2073,6 +2075,10 @@ STATIC void compile_power(compiler_t *comp, const byte *p, const byte *ptop) {
20732075
comp->func_arg_is_super = pt_is_id(p, MP_QSTR_super);
20742076

20752077
compile_generic_all_nodes(comp, p, ptop);
2078+
2079+
if (pt_num_nodes(p, ptop) == 3) {
2080+
EMIT_ARG(binary_op, MP_BINARY_OP_POWER);
2081+
}
20762082
}
20772083

20782084
// if p_arglist==NULL then there are no arguments
@@ -2205,12 +2211,6 @@ STATIC void compile_power_trailers(compiler_t *comp, const byte *p, const byte *
22052211
}
22062212
}
22072213

2208-
STATIC void compile_power_dbl_star(compiler_t *comp, const byte *p, const byte *ptop) {
2209-
(void)ptop;
2210-
compile_node(comp, p);
2211-
EMIT_ARG(binary_op, MP_BINARY_OP_POWER);
2212-
}
2213-
22142214
// p needs to point to 2 successive nodes, first is lhs of comprehension, second is PN_comp_for node
22152215
STATIC void compile_comprehension(compiler_t *comp, const byte *p, scope_kind_t kind) {
22162216
const byte *p_comp_for = pt_next(p);
@@ -2493,7 +2493,23 @@ STATIC const byte *compile_node(compiler_t *comp, const byte *p) {
24932493
} else if (pt_is_small_int(p)) {
24942494
mp_int_t arg;
24952495
p = pt_get_small_int(p, &arg);
2496+
#if MICROPY_DYNAMIC_COMPILER
2497+
mp_uint_t sign_mask = -(1 << (mp_dynamic_compiler.small_int_bits - 1));
2498+
if ((arg & sign_mask) == 0 || (arg & sign_mask) == sign_mask) {
2499+
// integer fits in target runtime's small-int
2500+
EMIT_ARG(load_const_small_int, arg);
2501+
} else {
2502+
// integer doesn't fit, so create a multi-precision int object
2503+
// (but only create the actual object on the last pass)
2504+
if (comp->pass != MP_PASS_EMIT) {
2505+
EMIT_ARG(load_const_obj, mp_const_none);
2506+
} else {
2507+
EMIT_ARG(load_const_obj, mp_obj_new_int_from_ll(arg));
2508+
}
2509+
}
2510+
#else
24962511
EMIT_ARG(load_const_small_int, arg);
2512+
#endif
24972513
return p;
24982514
} else if (pt_is_any_tok(p)) {
24992515
byte tok;
@@ -2970,7 +2986,25 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
29702986
}
29712987

29722988
p = pt_next(p); // skip the parameter list
2973-
p = pt_next(p); // skip the return type
2989+
2990+
// function return annotation is in the next node
2991+
mp_uint_t type_sig = MP_NATIVE_TYPE_INT;
2992+
if (!pt_is_null(p)) {
2993+
if (pt_is_any_id(p)) {
2994+
qstr ret_type;
2995+
pt_extract_id(p, &ret_type);
2996+
switch (ret_type) {
2997+
case MP_QSTR_object: type_sig = MP_NATIVE_TYPE_OBJ; break;
2998+
case MP_QSTR_bool: type_sig = MP_NATIVE_TYPE_BOOL; break;
2999+
case MP_QSTR_int: type_sig = MP_NATIVE_TYPE_INT; break;
3000+
case MP_QSTR_uint: type_sig = MP_NATIVE_TYPE_UINT; break;
3001+
default: compile_syntax_error(comp, p, "unknown type"); return;
3002+
}
3003+
} else {
3004+
compile_syntax_error(comp, p, "return annotation must be an identifier");
3005+
}
3006+
}
3007+
p = pt_next(p); // move past function return annotation
29743008

29753009
// get the list of statements within the body of the function
29763010
const byte *ptop = mp_parse_node_extract_list(&p, PN_suite_block_stmts);
@@ -3077,7 +3111,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
30773111
}
30783112

30793113
if (comp->pass > MP_PASS_SCOPE) {
3080-
EMIT_INLINE_ASM_ARG(end_pass, 0);
3114+
EMIT_INLINE_ASM_ARG(end_pass, type_sig);
30813115
}
30823116

30833117
if (comp->compile_error != MP_OBJ_NULL) {

0 commit comments

Comments
 (0)
0