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

hy2py doesn't work for require multiple modules #1903

Closed
fatestigma opened this issue Jun 22, 2020 · 2 comments · Fixed by #1906
Closed

hy2py doesn't work for require multiple modules #1903

fatestigma opened this issue Jun 22, 2020 · 2 comments · Fixed by #1906
Labels

Comments

@fatestigma
Copy link
Contributor

It seems that hy2py only generates the last module in (require ...). It might be something wrong within hy_compile according to the generated AST.

Example source file test.hy:

(require
 [hy.contrib.loop [loop]]
 [hy.contrib.walk [let]])

Run with hy2py -sa test.hy:

HyExpression([
  HySymbol('do'),
  HyExpression([
    HySymbol('require'),
    HyList([
      HySymbol('hy.contrib.loop'),
      HyList([
        HySymbol('loop')])]),
    HyList([
      HySymbol('hy.contrib.walk'),
      HyList([
        HySymbol('let')])])])])


Module(
    body=[Import(names=[alias(name='hy.macros', asname=None)]),
        Expr(
            value=Call(
                func=Attribute(value=Attribute(value=Name(id='hy'), attr='macros'), attr='require'),
                args=[Str(s='hy.contrib.walk'), Name(id='None')],
                keywords=[
                    keyword(arg='assignments', value=List(elts=[List(elts=[Str(s='let'), Str(s='let')])])),
                    keyword(arg='prefix', value=Str(s=''))]))])


import hy.macros
hy.macros.require('hy.contrib.walk', None, assignments=[['let', 'let']],
    prefix='')
@fatestigma
Copy link
Contributor Author

It might because Result.__add__ at compiler.py#L1207 (ret += self.compile(...))and compiler.py#L312 (result.expr = other.expr); I printed Result before and after parsing the second require.

# before adding
Result(imports=[],
       stmts=[],
       expr=Call(func=Attribute(value=Attribute(value=Name(id='hy', ctx=Load()), attr='macros', ctx=Load()), attr='require', ctx=Load()),
                 args=[Str(s='hy.contrib.loop'), Constant(value=None)], 
                 keywords=[keyword(arg='assignments', value=List(elts=[List(elts=[Str(s='loop'), Str(s='loop')], ctx=Load())], ctx=Load())), keyword(arg='prefix', value=Str(s=''))]))

# after adding
Result(imports=[],
       stmts=[],
       expr=Call(func=Attribute(value=Attribute(value=Name(id='hy', ctx=Load()), attr='macros', ctx=Load()), attr='require', ctx=Load()),
                 args=[Str(s='hy.contrib.walk'), Constant(value=None)],
                 keywords=[keyword(arg='assignments', value=List(elts=[List(elts=[Str(s='let'), Str(s='let')], ctx=Load())], ctx=Load())), keyword(arg='prefix', value=Str(s=''))]))

@Kodiologist
Copy link
Member

Thanks for pointing my attention to the right place. It was a missing expr_as_stmt, of course.

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

Successfully merging a pull request may close this issue.

2 participants