Skip to content

Commit

Permalink
More performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Nov 6, 2021
1 parent 4cb0bff commit 48fed81
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -135,5 +135,4 @@ pyston/
coconut-prelude/
index.rst
vprof.json
profile.txt
coconut/icoconut/coconut/
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -174,7 +174,7 @@ docs: clean

.PHONY: clean
clean:
rm -rf ./docs ./dist ./build ./tests/dest ./pyprover ./pyston ./coconut-prelude index.rst vprof.json profile.txt
rm -rf ./docs ./dist ./build ./tests/dest ./pyprover ./pyston ./coconut-prelude index.rst vprof.json profile.log
-find . -name '*.pyc' -delete
-C:/GnuWin32/bin/find.exe . -name '*.pyc' -delete
-find . -name '__pycache__' -delete
Expand Down Expand Up @@ -212,7 +212,7 @@ check-reqs:
.PHONY: profile-parser
profile-parser: export COCONUT_PURE_PYTHON=TRUE
profile-parser:
coconut tests/src/cocotest/agnostic tests/dest/cocotest --force --profile --verbose --recursion-limit 4096 2>&1 | tee ./profile.txt
coconut tests/src/cocotest/agnostic tests/dest/cocotest --force --profile --verbose --recursion-limit 4096 2>&1 | tee ./profile.log

.PHONY: profile-lines
profile-lines: export COCONUT_PURE_PYTHON=TRUE
Expand Down
38 changes: 20 additions & 18 deletions coconut/compiler/grammar.py
Expand Up @@ -1116,15 +1116,16 @@ class Grammar(object):
infix_op = condense(backtick.suppress() + test_no_infix + backtick.suppress())

infix_expr = Forward()
infix_item = attach(
Group(Optional(chain_expr))
+ OneOrMore(
infix_op + Group(Optional(lambdef | chain_expr)),
),
infix_handle,
)
infix_expr <<= (
chain_expr + ~backtick
| attach(
Group(Optional(chain_expr))
+ OneOrMore(
infix_op + Group(Optional(lambdef | chain_expr)),
),
infix_handle,
)
| infix_item
)

none_coalesce_expr = attach(tokenlist(infix_expr, dubquestion, allow_trailing=False), none_coalesce_handle)
Expand All @@ -1137,12 +1138,13 @@ class Grammar(object):
| comp_dubstar_pipe
| comp_back_dubstar_pipe
)
comp_pipe_item = attach(
OneOrMore(none_coalesce_expr + comp_pipe_op) + (lambdef | none_coalesce_expr),
comp_pipe_handle,
)
comp_pipe_expr = (
none_coalesce_expr + ~comp_pipe_op
| attach(
OneOrMore(none_coalesce_expr + comp_pipe_op) + (lambdef | none_coalesce_expr),
comp_pipe_handle,
)
comp_pipe_item
| none_coalesce_expr
)

pipe_op = (
Expand Down Expand Up @@ -1435,22 +1437,22 @@ class Grammar(object):
)

matchlist_isinstance = base_match + OneOrMore(keyword("is") + atom_item) # match_trailer expects unsuppressed isinstance
isinstance_match = base_match + ~keyword("is") | labeled_group(matchlist_isinstance, "trailer")
isinstance_match = labeled_group(matchlist_isinstance, "trailer") | base_match

matchlist_bar_or = isinstance_match + OneOrMore(bar.suppress() + isinstance_match)
bar_or_match = isinstance_match + ~bar | labeled_group(matchlist_bar_or, "or")
bar_or_match = labeled_group(matchlist_bar_or, "or") | isinstance_match

matchlist_infix = bar_or_match + OneOrMore(infix_op + atom_item)
infix_match = bar_or_match + ~backtick | labeled_group(matchlist_infix, "infix")
infix_match = labeled_group(matchlist_infix, "infix") | bar_or_match

matchlist_as = infix_match + OneOrMore(keyword("as") + name) # match_trailer expects unsuppressed as
as_match = infix_match + ~keyword("as") | labeled_group(matchlist_as, "trailer")
as_match = labeled_group(matchlist_as, "trailer") | infix_match

matchlist_and = as_match + OneOrMore(keyword("and").suppress() + as_match)
and_match = as_match + ~keyword("and") | labeled_group(matchlist_and, "and")
and_match = labeled_group(matchlist_and, "and") | as_match

matchlist_kwd_or = and_match + OneOrMore(keyword("or").suppress() + and_match)
kwd_or_match = and_match + ~keyword("or") | labeled_group(matchlist_kwd_or, "or")
kwd_or_match = labeled_group(matchlist_kwd_or, "or") | and_match

match <<= trace(kwd_or_match)

Expand Down
6 changes: 2 additions & 4 deletions coconut/compiler/util.py
Expand Up @@ -661,10 +661,8 @@ def disallow_keywords(kwds, with_suffix=None):


def any_keyword_in(kwds):
item = keyword(kwds[0], explicit_prefix=False)
for k in kwds[1:]:
item |= keyword(k, explicit_prefix=False)
return item
"""Match any of the given keywords."""
return regex_item(r"|".join(k + r"\b" for k in kwds))


def keyword(name, explicit_prefix=None):
Expand Down

0 comments on commit 48fed81

Please sign in to comment.