summaryrefslogtreecommitdiff
path: root/py/nlrthumb.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-12-28 16:46:30 +1100
committerDamien George <damien.p.george@gmail.com>2017-12-28 16:46:30 +1100
commitb25f92160b318a096c516c430afde5472a944c19 (patch)
tree18022d1de245f9fca253f2a8076c4e8c79f6fca8 /py/nlrthumb.c
parent5bf8e85fc828974199d469db711aa2f9649c467b (diff)
py/nlr: Factor out common NLR code to macro and generic funcs in nlr.c.
Each NLR implementation (Thumb, x86, x64, xtensa, setjmp) duplicates a lot of the NLR code, specifically that dealing with pushing and popping the NLR pointer to maintain the linked-list of NLR buffers. This patch factors all of that code out of the specific implementations into generic functions in nlr.c, along with a helper macro in nlr.h. This eliminates duplicated code.
Diffstat (limited to 'py/nlrthumb.c')
-rw-r--r--py/nlrthumb.c25
1 files changed, 2 insertions, 23 deletions
diff --git a/py/nlrthumb.c b/py/nlrthumb.c
index cc081e3ff..fb0a92236 100644
--- a/py/nlrthumb.c
+++ b/py/nlrthumb.c
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2013-2016 Damien P. George
+ * Copyright (c) 2013-2017 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -82,29 +82,8 @@ __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
#endif
}
-__attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr) {
- nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
- nlr->prev = *top;
- MP_NLR_SAVE_PYSTACK(nlr);
- *top = nlr;
- return 0; // normal return
-}
-
-void nlr_pop(void) {
- nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
- *top = (*top)->prev;
-}
-
NORETURN void nlr_jump(void *val) {
- nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top);
- nlr_buf_t *top = *top_ptr;
- if (top == NULL) {
- nlr_jump_fail(val);
- }
-
- top->ret_val = val;
- MP_NLR_RESTORE_PYSTACK(top);
- *top_ptr = top->prev;
+ MP_NLR_JUMP_HEAD(val, top)
__asm volatile (
"mov r0, %0 \n" // r0 points to nlr_buf