Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser static objects are not initialized before the next compilation #175

Closed
valq7711 opened this issue Jul 17, 2018 · 0 comments
Closed

Comments

@valq7711
Copy link
Collaborator

valq7711 commented Jul 17, 2018

parser.pyj module has several static objects that are mutated during the process.
(I mean BASELIB and CLASS_MAP at least). Thus, when two or more files are compiled at once, these objects contain data from the previous compilation, because there is no initialization / cleanup before the next compilation. I caught this bug when compiling in a browser.

It seems, there is no trivial-elegant solution, because parser has recursive calls + baselib is parsed at separated step before file compiling (these objects should be kept after baselib has been parsed)

Possible fix:

  1. Create function parser.init_mod() that will initialize static objects
  2. Fix rapydscript.compile(): If browser_env: Call parser.init_mod()
  3. Fix compile.pyj: call parser.init_mod() and rapydscript.parse_baselib(...) before each file compiling (i.e. move rapydscript.parse_baselib(...) from module.exports = def():... into compile_single_file(...))

thoughts?

The bug demo

#make two files:
 
#foo.pyj:
def foo():
    a = range(10)

#bar.pyj:
def bar():
    print('hello')

try to compile files at once:
rapydscript -p foo.pyj bar.pyj you will see that bar exhaust includes range() as overhead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant