summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-21 23:48:04 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-21 23:48:04 +0000
commit600ae734cf3d0ca5274086b897f1ebaf20cf9d20 (patch)
tree5d05831a589eb5dd614a23dfae01c0fae74f0b93 /py/vm.c
parent2c302563820d18be5fcfed406582ea5edaa6b39f (diff)
downloadmicropython-600ae734cf3d0ca5274086b897f1ebaf20cf9d20.tar.gz
micropython-600ae734cf3d0ca5274086b897f1ebaf20cf9d20.zip
py: Implement break and continue byte codes, and add tests.
Also fixes a bug in the for-in-range optimiser. I hope to remove break and continue byte codes in the future and just use jump (if possible).
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/py/vm.c b/py/vm.c
index c41146ac8f..b6db0bb87f 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -326,6 +326,18 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
break;
*/
+ // TODO this might need more sophisticated handling when breaking from within an except
+ case MP_BC_BREAK_LOOP:
+ DECODE_ULABEL;
+ ip += unum;
+ break;
+
+ // TODO this might need more sophisticated handling when breaking from within an except
+ case MP_BC_CONTINUE_LOOP:
+ DECODE_ULABEL;
+ ip += unum;
+ break;
+
// matched against: POP_BLOCK or POP_EXCEPT (anything else?)
case MP_BC_SETUP_EXCEPT:
DECODE_ULABEL; // except labels are always forward
@@ -366,7 +378,7 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
exc_sp -= 2; // pop back to previous exception handler
break;
- // matched againts: SETUP_EXCEPT
+ // matched against: SETUP_EXCEPT
case MP_BC_POP_EXCEPT:
// TODO need to work out how blocks work etc
// pops block, checks it's an exception block, and restores the stack, saving the 3 exception values to local threadstate