Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
c9f91976
Commit
c9f91976
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Crude try-except working.
parent
ce89a21e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/vm.c
+25
-7
25 additions, 7 deletions
py/vm.c
unix/mpyconfig.h
+1
-1
1 addition, 1 deletion
unix/mpyconfig.h
with
26 additions
and
8 deletions
py/vm.c
+
25
−
7
View file @
c9f91976
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
// args are in reverse order in array
// args are in reverse order in array
py_obj_t
py_execute_byte_code
(
const
byte
*
code
,
uint
len
,
const
py_obj_t
*
args
,
uint
n_args
)
{
py_obj_t
py_execute_byte_code
(
const
byte
*
code
,
uint
len
,
const
py_obj_t
*
args
,
uint
n_args
)
{
// careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think)
const
byte
*
ip
=
code
;
const
byte
*
ip
=
code
;
py_obj_t
stack
[
10
];
py_obj_t
stack
[
10
];
py_obj_t
*
sp
=
&
stack
[
10
];
// stack grows down, sp points to top of stack
py_obj_t
*
sp
=
&
stack
[
10
];
// stack grows down, sp points to top of stack
...
@@ -27,6 +29,10 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
...
@@ -27,6 +29,10 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
py_obj_t
fast0
=
NULL
,
fast1
=
NULL
,
fast2
=
NULL
,
fastn
[
4
]
=
{
NULL
,
NULL
,
NULL
,
NULL
};
py_obj_t
fast0
=
NULL
,
fast1
=
NULL
,
fast2
=
NULL
,
fastn
[
4
]
=
{
NULL
,
NULL
,
NULL
,
NULL
};
nlr_buf_t
nlr
;
nlr_buf_t
nlr
;
// on the exception stack we store (ip, sp) for each block
machine_uint_t
exc_stack
[
8
];
machine_uint_t
*
volatile
exc_sp
=
&
exc_stack
[
-
1
];
// stack grows up, exc_sp points to top of stack
// init args
// init args
for
(
int
i
=
0
;
i
<
n_args
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n_args
;
i
++
)
{
if
(
i
==
0
)
{
if
(
i
==
0
)
{
...
@@ -203,8 +209,9 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
...
@@ -203,8 +209,9 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
*/
*/
case
PYBC_SETUP_EXCEPT
:
case
PYBC_SETUP_EXCEPT
:
// push_block(PYBC_SETUP_EXCEPT, code + unum, sp)
DECODE_UINT
;
assert
(
0
);
*++
exc_sp
=
(
machine_uint_t
)
code
+
unum
;
*++
exc_sp
=
(
machine_uint_t
)
sp
;
break
;
break
;
case
PYBC_END_FINALLY
:
case
PYBC_END_FINALLY
:
...
@@ -237,8 +244,14 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
...
@@ -237,8 +244,14 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
break
;
break
;
case
PYBC_POP_EXCEPT
:
case
PYBC_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
// pops block, checks it's an exception block, and restores the stack, saving the 3 exception values to local threadstate
assert
(
0
);
assert
(
exc_sp
>=
&
exc_stack
[
0
]);
//sp = (py_obj_t*)(*exc_sp--);
//exc_sp--; // discard ip
exc_sp
-=
2
;
//sp += 3; // pop 3 exception values
assert
(
sp
<=
&
stack
[
10
]);
break
;
break
;
case
PYBC_BINARY_OP
:
case
PYBC_BINARY_OP
:
...
@@ -303,6 +316,8 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
...
@@ -303,6 +316,8 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
case
PYBC_RETURN_VALUE
:
case
PYBC_RETURN_VALUE
:
nlr_pop
();
nlr_pop
();
assert
(
sp
==
&
stack
[
9
]);
assert
(
exc_sp
==
&
exc_stack
[
-
1
]);
return
*
sp
;
return
*
sp
;
default:
default:
...
@@ -316,11 +331,14 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
...
@@ -316,11 +331,14 @@ py_obj_t py_execute_byte_code(const byte *code, uint len, const py_obj_t *args,
}
else
{
}
else
{
// exception occurred
// exception occurred
if
(
0
)
{
if
(
exc_sp
>=
&
exc_stack
[
0
]
)
{
// catch exception and pass to byte code
// catch exception and pass to byte code
//i
p =
pop
s
p
=
(
py_obj_t
*
)(
exc_sp
[
0
]);
//s
p =
pop
i
p
=
(
const
byte
*
)(
exc_sp
[
-
1
]);
// push(traceback, exc-val, exc-type)
// push(traceback, exc-val, exc-type)
PUSH
(
py_const_none
);
PUSH
(
nlr
.
ret_val
);
PUSH
(
py_const_none
);
}
else
{
}
else
{
// re-raise exception
// re-raise exception
nlr_jump
(
nlr
.
ret_val
);
nlr_jump
(
nlr
.
ret_val
);
...
...
This diff is collapsed.
Click to expand it.
unix/mpyconfig.h
+
1
−
1
View file @
c9f91976
// options to control how Micro Python is built
// options to control how Micro Python is built
#define MICROPY_ENABLE_FLOAT (1)
#define MICROPY_ENABLE_FLOAT (1)
#define MICROPY_EMIT_CPYTHON (
1
)
#define MICROPY_EMIT_CPYTHON (
0
)
#define MICROPY_EMIT_X64 (0)
#define MICROPY_EMIT_X64 (0)
#define MICROPY_EMIT_THUMB (0)
#define MICROPY_EMIT_THUMB (0)
#define MICROPY_EMIT_INLINE_THUMB (0)
#define MICROPY_EMIT_INLINE_THUMB (0)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment