Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
1fb03174
Commit
1fb03174
authored
Jan 03, 2014
by
Damien George
Browse files
Change mp_compile so that it returns a function object for the module.
parent
14f945c2
Changes
13
Hide whitespace changes
Inline
Side-by-side
py/builtinimport.c
View file @
1fb03174
...
...
@@ -11,8 +11,8 @@
#include
"lexer.h"
#include
"lexerunix.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"compile.h"
#include
"runtime0.h"
#include
"runtime.h"
#include
"map.h"
...
...
py/compile.c
View file @
1fb03174
...
...
@@ -10,9 +10,11 @@
#include
"lexer.h"
#include
"parse.h"
#include
"scope.h"
#include
"compile.h"
#include
"runtime0.h"
#include
"emit.h"
#include
"obj.h"
#include
"compile.h"
#include
"runtime.h"
// TODO need to mangle __attr names
...
...
@@ -3016,7 +3018,7 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
}
}
bool
mp_compile
(
mp_parse_node_t
pn
,
bool
is_repl
)
{
mp_obj_t
mp_compile
(
mp_parse_node_t
pn
,
bool
is_repl
)
{
compiler_t
*
comp
=
m_new
(
compiler_t
,
1
);
comp
->
qstr___class__
=
qstr_from_str_static
(
"__class__"
);
...
...
@@ -3146,7 +3148,19 @@ bool mp_compile(mp_parse_node_t pn, bool is_repl) {
}
}
bool
had_error
=
comp
->
had_error
;
m_del_obj
(
compiler_t
,
comp
);
return
!
comp
->
had_error
;
if
(
had_error
)
{
// TODO return a proper error message
return
mp_const_none
;
}
else
{
#if MICROPY_EMIT_CPYTHON
// can't create code, so just return true
return
mp_const_true
;
#else
// return function that executes the outer module
return
rt_make_function_from_id
(
1
);
#endif
}
}
py/compile.h
View file @
1fb03174
bool
mp_compile
(
mp_parse_node_t
pn
,
bool
is_repl
);
mp_obj_t
mp_compile
(
mp_parse_node_t
pn
,
bool
is_repl
);
py/emitbc.c
View file @
1fb03174
...
...
@@ -9,7 +9,6 @@
#include
"mpconfig.h"
#include
"lexer.h"
#include
"parse.h"
#include
"compile.h"
#include
"scope.h"
#include
"runtime0.h"
#include
"emit.h"
...
...
py/emitcpy.c
View file @
1fb03174
...
...
@@ -9,7 +9,6 @@
#include
"mpconfig.h"
#include
"lexer.h"
#include
"parse.h"
#include
"compile.h"
#include
"scope.h"
#include
"runtime0.h"
#include
"emit.h"
...
...
py/emitpass1.c
View file @
1fb03174
...
...
@@ -9,7 +9,6 @@
#include
"mpconfig.h"
#include
"lexer.h"
#include
"parse.h"
#include
"compile.h"
#include
"scope.h"
#include
"runtime0.h"
#include
"emit.h"
...
...
stm/audio.c
View file @
1fb03174
...
...
@@ -8,7 +8,6 @@
#include
"misc.h"
#include
"mpconfig.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"runtime.h"
...
...
stm/lcd.c
View file @
1fb03174
...
...
@@ -5,7 +5,6 @@
#include
"misc.h"
#include
"mpconfig.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"runtime.h"
...
...
stm/main.c
View file @
1fb03174
...
...
@@ -20,8 +20,8 @@
#include
"lexer.h"
#include
"lexerstm.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"compile.h"
#include
"runtime0.h"
#include
"runtime.h"
#include
"repl.h"
...
...
@@ -489,25 +489,22 @@ void do_repl(void) {
mp_lexer_free
(
lex
);
if
(
pn
!=
MP_PARSE_NODE_NULL
)
{
bool
comp_ok
=
mp_compile
(
pn
,
true
);
if
(
comp_ok
)
{
mp_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
if
(
module_fun
!=
mp_const_none
)
{
nlr_buf_t
nlr
;
uint32_t
start
=
sys_tick_counter
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
rt_call_function_0
(
module_fun
);
nlr_pop
();
// optional timing
if
(
0
)
{
uint32_t
ticks
=
sys_tick_counter
-
start
;
// TODO implement a function that does this properly
printf
(
"(took %lu ms)
\n
"
,
ticks
);
}
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
);
printf
(
"
\n
"
);
mp_obj_t
module_fun
=
mp_compile
(
pn
,
true
);
if
(
module_fun
!=
mp_const_none
)
{
nlr_buf_t
nlr
;
uint32_t
start
=
sys_tick_counter
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
rt_call_function_0
(
module_fun
);
nlr_pop
();
// optional timing
if
(
0
)
{
uint32_t
ticks
=
sys_tick_counter
-
start
;
// TODO implement a function that does this properly
printf
(
"(took %lu ms)
\n
"
,
ticks
);
}
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
);
printf
(
"
\n
"
);
}
}
}
...
...
@@ -532,12 +529,7 @@ bool do_file(const char *filename) {
return
false
;
}
bool
comp_ok
=
mp_compile
(
pn
,
false
);
if
(
!
comp_ok
)
{
return
false
;
}
mp_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
mp_obj_t
module_fun
=
mp_compile
(
pn
,
false
);
if
(
module_fun
==
mp_const_none
)
{
return
false
;
}
...
...
@@ -1133,17 +1125,15 @@ soft_reset:
printf
(
"pars;al=%u
\n
"
,
m_get_total_bytes_allocated
());
sys_tick_delay_ms
(
1000
);
//parse_node_show(pn, 0);
bool
comp_ok
=
mp_compile
(
pn
,
false
);
mp_obj_t
module_fun
=
mp_compile
(
pn
,
false
);
printf
(
"comp;al=%u
\n
"
,
m_get_total_bytes_allocated
());
sys_tick_delay_ms
(
1000
);
if
(
!
comp_ok
)
{
if
(
module_fun
==
mp_const_none
)
{
printf
(
"compile error
\n
"
);
}
else
{
// execute it!
mp_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
// flash once
led_state
(
PYB_LED_G1
,
1
);
sys_tick_delay_ms
(
100
);
...
...
stm/pybwlan.c
View file @
1fb03174
...
...
@@ -18,7 +18,6 @@
#include
"misc.h"
#include
"lexer.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"map.h"
#include
"runtime.h"
...
...
stm/timer.c
View file @
1fb03174
...
...
@@ -9,7 +9,6 @@
#include
"misc.h"
#include
"mpconfig.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"runtime.h"
...
...
unix-cpy/main.c
View file @
1fb03174
...
...
@@ -8,8 +8,8 @@
#include
"lexer.h"
#include
"lexerunix.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"compile.h"
#include
"runtime0.h"
#include
"runtime.h"
...
...
@@ -37,10 +37,10 @@ void do_file(const char *file) {
//printf("----------------\n");
//parse_node_show(pn, 0);
//printf("----------------\n");
bool
comp_ok
=
mp_compile
(
pn
,
false
);
mp_obj_t
module_fun
=
mp_compile
(
pn
,
false
);
//printf("----------------\n");
if
(
!
comp_ok
)
{
if
(
module_fun
==
mp_const_none
)
{
printf
(
"compile error
\n
"
);
}
}
...
...
unix/main.c
View file @
1fb03174
...
...
@@ -9,8 +9,8 @@
#include
"lexer.h"
#include
"lexerunix.h"
#include
"parse.h"
#include
"compile.h"
#include
"obj.h"
#include
"compile.h"
#include
"runtime0.h"
#include
"runtime.h"
#include
"repl.h"
...
...
@@ -85,19 +85,16 @@ static void do_repl(void) {
if
(
pn
!=
MP_PARSE_NODE_NULL
)
{
//mp_parse_node_show(pn, 0);
bool
comp_ok
=
mp_compile
(
pn
,
true
);
if
(
comp_ok
)
{
mp_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
if
(
module_fun
!=
mp_const_none
)
{
nlr_buf_t
nlr
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
rt_call_function_0
(
module_fun
);
nlr_pop
();
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
);
printf
(
"
\n
"
);
}
mp_obj_t
module_fun
=
mp_compile
(
pn
,
true
);
if
(
module_fun
!=
mp_const_none
)
{
nlr_buf_t
nlr
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
rt_call_function_0
(
module_fun
);
nlr_pop
();
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
);
printf
(
"
\n
"
);
}
}
}
...
...
@@ -142,7 +139,7 @@ void do_file(const char *file) {
//printf("----------------\n");
//parse_node_show(pn, 0);
//printf("----------------\n");
bool
comp_ok
=
mp_compile
(
pn
,
false
);
mp_obj_t
module_fun
=
mp_compile
(
pn
,
false
);
//printf("----------------\n");
#if MICROPY_EMIT_CPYTHON
...
...
@@ -150,19 +147,16 @@ void do_file(const char *file) {
printf
(
"compile error
\n
"
);
}
#else
if
(
1
&&
comp_ok
)
{
if
(
1
&&
module_fun
!=
mp_const_none
)
{
// execute it
mp_obj_t
module_fun
=
rt_make_function_from_id
(
1
);
if
(
module_fun
!=
mp_const_none
)
{
nlr_buf_t
nlr
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
rt_call_function_0
(
module_fun
);
nlr_pop
();
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
);
printf
(
"
\n
"
);
}
nlr_buf_t
nlr
;
if
(
nlr_push
(
&
nlr
)
==
0
)
{
rt_call_function_0
(
module_fun
);
nlr_pop
();
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
);
printf
(
"
\n
"
);
}
}
#endif
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment