3737
3838#if defined(_WIN32) || defined(__CYGWIN__)
3939#define NLR_OS_WINDOWS
40+ #endif
41+
42+ #if defined(__APPLE__) && defined(__MACH__)
43+ #define NLR_OS_MAC
44+ #endif
45+
46+ #if defined(NLR_OS_WINDOWS) || defined(NLR_OS_MAC)
4047#define NLR_TOP (_mp_state_ctx + NLR_TOP_OFFSET)
48+ #define MP_THREAD_GET_STATE _mp_thread_get_state
4149#else
4250#define NLR_TOP (mp_state_ctx + NLR_TOP_OFFSET)
51+ #define MP_THREAD_GET_STATE mp_thread_get_state
4352#endif
4453
4554// offset of nlr_top within mp_state_thread_t structure
5564 .globl _nlr_push
5665 .def _nlr_push; .scl 2 ; .type 32 ; .endef
5766_nlr_push:
67+ #elif defined(NLR_OS_MAC)
68+ .globl _nlr_push
69+ _nlr_push:
5870#else
5971 .globl nlr_push
6072 .type nlr_push, @function
@@ -75,7 +87,7 @@ nlr_push:
7587 mov %edx , NLR_TOP # stor new nlr_buf (to make linked list)
7688#else
7789 // to check: stack is aligned to 16-byte boundary before this call
78- call mp_thread_get_state # get mp_state_thread ptr into eax
90+ call MP_THREAD_GET_STATE # get mp_state_thread ptr into eax
7991 mov 4 (%esp ), %edx # load nlr_buf argument into edx (edx clobbered by call)
8092 mov NLR_TOP_TH_OFF(%eax ), %ecx # get thread.nlr_top (last nlr_buf)
8193 mov %ecx , (%edx ) # store it
@@ -84,7 +96,7 @@ nlr_push:
8496
8597 xor %eax , %eax # return 0, normal return
8698 ret # return
87- #if !defined(NLR_OS_WINDOWS)
99+ #if !defined(NLR_OS_WINDOWS) && !defined(NLR_OS_MAC)
88100 .size nlr_push, .-nlr_push
89101#endif
90102
@@ -95,6 +107,9 @@ nlr_push:
95107 .globl _nlr_pop
96108 .def _nlr_pop; .scl 2 ; .type 32 ; .endef
97109_nlr_pop:
110+ #elif defined(NLR_OS_MAC)
111+ .globl _nlr_pop
112+ _nlr_pop:
98113#else
99114 .globl nlr_pop
100115 .type nlr_pop, @function
@@ -106,14 +121,14 @@ nlr_pop:
106121 mov (%eax ), %eax # load prev nlr_buf
107122 mov %eax , NLR_TOP # store nlr_top (to unlink list)
108123#else
109- call mp_thread_get_state # get mp_state_thread ptr into eax
124+ call MP_THREAD_GET_STATE # get mp_state_thread ptr into eax
110125 mov NLR_TOP_TH_OFF(%eax ), %ecx # get thread.nlr_top (last nlr_buf)
111126 mov (%ecx ), %ecx # load prev nlr_buf
112127 mov %ecx , NLR_TOP_TH_OFF(%eax ) # store prev nlr_buf (to unlink list)
113128#endif
114129
115130 ret # return
116- #if !defined(NLR_OS_WINDOWS)
131+ #if !defined(NLR_OS_WINDOWS) && !defined(NLR_OS_MAC)
117132 .size nlr_pop, .-nlr_pop
118133#endif
119134
@@ -124,6 +139,9 @@ nlr_pop:
124139 .globl _nlr_jump
125140 .def _nlr_jump; .scl 2 ; .type 32 ; .endef
126141_nlr_jump:
142+ #elif defined(NLR_OS_MAC)
143+ .globl _nlr_jump
144+ _nlr_jump:
127145#else
128146 .globl nlr_jump
129147 .type nlr_jump, @function
@@ -133,7 +151,7 @@ nlr_jump:
133151#if !MICROPY_PY_THREAD
134152 mov NLR_TOP, %edx # load nlr_top
135153 test %edx , %edx # check for nlr_top being NULL
136- #if defined(NLR_OS_WINDOWS)
154+ #if defined(NLR_OS_WINDOWS) || defined(NLR_OS_MAC)
137155 je _nlr_jump_fail # fail if nlr_top is NULL
138156#else
139157 je nlr_jump_fail # fail if nlr_top is NULL
@@ -143,10 +161,10 @@ nlr_jump:
143161 mov (%edx ), %eax # load prev nlr_top
144162 mov %eax , NLR_TOP # store nlr_top (to unlink list)
145163#else
146- call mp_thread_get_state # get mp_state_thread ptr into eax
164+ call MP_THREAD_GET_STATE # get mp_state_thread ptr into eax
147165 mov NLR_TOP_TH_OFF(%eax ), %edx # get thread.nlr_top (last nlr_buf)
148166 test %edx , %edx # check for nlr_top being NULL
149- #if defined(NLR_OS_WINDOWS)
167+ #if defined(NLR_OS_WINDOWS) || defined(NLR_OS_MAC)
150168 je _nlr_jump_fail # fail if nlr_top is NULL
151169#else
152170 je nlr_jump_fail # fail if nlr_top is NULL
@@ -167,7 +185,7 @@ nlr_jump:
167185 xor %eax , %eax # clear return register
168186 inc %al # increase to make 1, non-local return
169187 ret # return
170- #if !defined(NLR_OS_WINDOWS)
188+ #if !defined(NLR_OS_WINDOWS) && !defined(NLR_OS_MAC)
171189 .size nlr_jump, .-nlr_jump
172190#endif
173191
0 commit comments