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
b14de21f
Commit
b14de21f
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Optimise typedargslist_name to not create a node if just an id.
parent
a2f2f7db
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/compile.c
+60
-51
60 additions, 51 deletions
py/compile.c
py/parse.c
+2
-1
2 additions, 1 deletion
py/parse.c
with
62 additions
and
52 deletions
py/compile.c
+
60
−
51
View file @
b14de21f
...
@@ -643,9 +643,8 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_
...
@@ -643,9 +643,8 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_
}
}
void
compile_funcdef_param
(
compiler_t
*
comp
,
py_parse_node_t
pn
)
{
void
compile_funcdef_param
(
compiler_t
*
comp
,
py_parse_node_t
pn
)
{
assert
(
PY_PARSE_NODE_IS_STRUCT
(
pn
));
if
(
PY_PARSE_NODE_IS_STRUCT
_KIND
(
pn
,
PN_typedargslist_name
))
{
py_parse_node_struct_t
*
pns
=
(
py_parse_node_struct_t
*
)
pn
;
py_parse_node_struct_t
*
pns
=
(
py_parse_node_struct_t
*
)
pn
;
if
(
PY_PARSE_NODE_STRUCT_KIND
(
pns
)
==
PN_typedargslist_name
)
{
if
(
!
PY_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
2
]))
{
if
(
!
PY_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
2
]))
{
// this parameter has a default value
// this parameter has a default value
// in CPython, None (and True, False?) as default parameters are loaded with LOAD_NAME; don't understandy why
// in CPython, None (and True, False?) as default parameters are loaded with LOAD_NAME; don't understandy why
...
@@ -662,7 +661,8 @@ void compile_funcdef_param(compiler_t *comp, py_parse_node_t pn) {
...
@@ -662,7 +661,8 @@ void compile_funcdef_param(compiler_t *comp, py_parse_node_t pn) {
}
}
}
}
}
}
}
else
if
(
PY_PARSE_NODE_STRUCT_KIND
(
pns
)
==
PN_typedargslist_star
)
{
}
else
if
(
PY_PARSE_NODE_IS_STRUCT_KIND
(
pn
,
PN_typedargslist_star
))
{
py_parse_node_struct_t
*
pns
=
(
py_parse_node_struct_t
*
)
pn
;
if
(
PY_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
0
]))
{
if
(
PY_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
0
]))
{
// bare star
// bare star
comp
->
have_bare_star
=
true
;
comp
->
have_bare_star
=
true
;
...
@@ -2206,10 +2206,18 @@ void compile_node(compiler_t *comp, py_parse_node_t pn) {
...
@@ -2206,10 +2206,18 @@ void compile_node(compiler_t *comp, py_parse_node_t pn) {
void
compile_scope_func_lambda_param
(
compiler_t
*
comp
,
py_parse_node_t
pn
,
pn_kind_t
pn_name
,
pn_kind_t
pn_star
,
pn_kind_t
pn_dbl_star
,
bool
allow_annotations
)
{
void
compile_scope_func_lambda_param
(
compiler_t
*
comp
,
py_parse_node_t
pn
,
pn_kind_t
pn_name
,
pn_kind_t
pn_star
,
pn_kind_t
pn_dbl_star
,
bool
allow_annotations
)
{
// TODO verify that *k and **k are last etc
// TODO verify that *k and **k are last etc
assert
(
PY_PARSE_NODE_IS_STRUCT
(
pn
));
py_parse_node_struct_t
*
pns
=
(
py_parse_node_struct_t
*
)
pn
;
qstr
param_name
=
0
;
qstr
param_name
=
0
;
py_parse_node_t
pn_annotation
=
PY_PARSE_NODE_NULL
;
py_parse_node_t
pn_annotation
=
PY_PARSE_NODE_NULL
;
if
(
PY_PARSE_NODE_IS_ID
(
pn
))
{
param_name
=
PY_PARSE_NODE_LEAF_ARG
(
pn
);
if
(
comp
->
have_bare_star
)
{
// comes after a bare star, so doesn't count as a parameter
}
else
{
comp
->
scope_cur
->
num_params
+=
1
;
}
}
else
{
assert
(
PY_PARSE_NODE_IS_STRUCT
(
pn
));
py_parse_node_struct_t
*
pns
=
(
py_parse_node_struct_t
*
)
pn
;
if
(
PY_PARSE_NODE_STRUCT_KIND
(
pns
)
==
pn_name
)
{
if
(
PY_PARSE_NODE_STRUCT_KIND
(
pns
)
==
pn_name
)
{
param_name
=
PY_PARSE_NODE_LEAF_ARG
(
pns
->
nodes
[
0
]);
param_name
=
PY_PARSE_NODE_LEAF_ARG
(
pns
->
nodes
[
0
]);
//int node_index = 1; unused
//int node_index = 1; unused
...
@@ -2266,6 +2274,7 @@ void compile_scope_func_lambda_param(compiler_t *comp, py_parse_node_t pn, pn_ki
...
@@ -2266,6 +2274,7 @@ void compile_scope_func_lambda_param(compiler_t *comp, py_parse_node_t pn, pn_ki
// TODO anything to implement?
// TODO anything to implement?
assert
(
0
);
assert
(
0
);
}
}
}
if
(
param_name
!=
0
)
{
if
(
param_name
!=
0
)
{
if
(
!
PY_PARSE_NODE_IS_NULL
(
pn_annotation
))
{
if
(
!
PY_PARSE_NODE_IS_NULL
(
pn_annotation
))
{
...
...
This diff is collapsed.
Click to expand it.
py/parse.c
+
2
−
1
View file @
b14de21f
...
@@ -414,7 +414,8 @@ py_parse_node_t py_parse(py_lexer_t *lex, int wanted_rule) {
...
@@ -414,7 +414,8 @@ py_parse_node_t py_parse(py_lexer_t *lex, int wanted_rule) {
// never emit these rules if they have only 1 argument
// never emit these rules if they have only 1 argument
// NOTE: can't put atom_paren here because we need it to distinguisg, for example, [a,b] from [(a,b)]
// NOTE: can't put atom_paren here because we need it to distinguisg, for example, [a,b] from [(a,b)]
if
(
rule
->
rule_id
==
RULE_else_stmt
||
rule
->
rule_id
==
RULE_testlist_comp_3b
||
rule
->
rule_id
==
RULE_import_as_names_paren
||
rule
->
rule_id
==
RULE_typedargslist_colon
||
rule
->
rule_id
==
RULE_typedargslist_equal
||
rule
->
rule_id
==
RULE_dictorsetmaker_colon
||
rule
->
rule_id
==
RULE_classdef_2
||
rule
->
rule_id
==
RULE_with_item_as
||
rule
->
rule_id
==
RULE_assert_stmt_extra
||
rule
->
rule_id
==
RULE_as_name
||
rule
->
rule_id
==
RULE_raise_stmt_from
||
rule
->
rule_id
==
RULE_vfpdef
)
{
// TODO possibly put varargslist_name, varargslist_equal here as well
if
(
rule
->
rule_id
==
RULE_else_stmt
||
rule
->
rule_id
==
RULE_testlist_comp_3b
||
rule
->
rule_id
==
RULE_import_as_names_paren
||
rule
->
rule_id
==
RULE_typedargslist_name
||
rule
->
rule_id
==
RULE_typedargslist_colon
||
rule
->
rule_id
==
RULE_typedargslist_equal
||
rule
->
rule_id
==
RULE_dictorsetmaker_colon
||
rule
->
rule_id
==
RULE_classdef_2
||
rule
->
rule_id
==
RULE_with_item_as
||
rule
->
rule_id
==
RULE_assert_stmt_extra
||
rule
->
rule_id
==
RULE_as_name
||
rule
->
rule_id
==
RULE_raise_stmt_from
||
rule
->
rule_id
==
RULE_vfpdef
)
{
emit_rule
=
false
;
emit_rule
=
false
;
}
}
...
...
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