poppopjmp / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

circular include causes shedskin crash #118

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
Extract the attached source code.
2.
Run "shedskin main" in the directory where you extracted the source.

Here's what the raw Python version outputs:

    a  b  c  d  e  f  g  h

8   r  n  b  q  k  b  n  r 
7   p  p  p  p  p  p  p  p 
6   .  .  .  .  .  .  .  . 
5   .  .  .  .  .  .  .  . 
4   .  .  .  .  .  .  .  . 
3   .  .  .  .  .  .  .  . 
2   P  P  P  P  P  P  P  P 
1   R  N  B  Q  K  B  N  R 

    a  b  c  d  e  f  g  h

Pawn at e2 can move to: e3 e4

When Shedskin tries to compile, it emits the following:

*** SHED SKIN Python-to-C++ Compiler 0.6 ***
Copyright 2005-2010 Mark Dufour; License GNU GPL version 3 (See LICENSE)

Traceback (most recent call last):
  File "/usr/bin/shedskin", line 3, in <module>
    shedskin.main()
  File "/usr/lib/python2.6/dist-packages/shedskin/__init__.py", line 82, in main
    infer.analyze(name)
  File "/usr/lib/python2.6/dist-packages/shedskin/infer.py", line 872, in analyze
    getgx().main_module = graph.parse_module(getgx().main_mod, ast)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 1539, in parse_module
    mv.dispatch(mod.ast)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 267, in visitModule
    self.visit(child, None)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 243, in visitStmt
    self.visit(b, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 399, in visitImport
    self.importmodules(name, node, False)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 408, in importmodules
    mod = self.importmodule(subname, subname, node, fake)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 415, in importmodule
    mod = self.analyzeModule(name, pseudonym, node, fake)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 478, in analyzeModule
    mod = parse_module(name, None, getmv().module, node)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 1539, in parse_module
    mv.dispatch(mod.ast)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 267, in visitModule
    self.visit(child, None)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 243, in visitStmt
    self.visit(b, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 399, in visitImport
    self.importmodules(name, node, False)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 408, in importmodules
    mod = self.importmodule(subname, subname, node, fake)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 415, in importmodule
    mod = self.analyzeModule(name, pseudonym, node, fake)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 478, in analyzeModule
    mod = parse_module(name, None, getmv().module, node)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 1539, in parse_module
    mv.dispatch(mod.ast)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 267, in visitModule
    self.visit(child, None)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 243, in visitStmt
    self.visit(b, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 543, in visitFunction
    self.visit(node.code, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 243, in visitStmt
    self.visit(b, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 599, in visitIf
    self.visit(faker, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 1241, in visitCallFunc
    self.visit(arg, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 689, in visitCompare
    self.visit(right, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 1353, in visitGetattr
    self.visit(fakefunc, func)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 51, in dispatch
    ASTVisitor.dispatch(self, node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/dist-packages/shedskin/graph.py", line 1245, in visitCallFunc
    constructor = lookupclass(node.node, self)
  File "/usr/lib/python2.6/dist-packages/shedskin/shared.py", line 478, in lookupclass
    if module and node.attrname in module.classes:
AttributeError: module instance has no attribute 'classes'

Shedskin version is 0.6
OS version is Ubuntu 10.04 LTS(Lucid Lynx)

Just in case you're wondering, this is the beginning of a chess engine, 
inspired from the chess.py example in the Shedskin examples distribution.

Original issue reported on code.google.com by kotux...@gmail.com on 25 Nov 2010 at 4:06

Attachments:

GoogleCodeExporter commented 8 years ago
thanks for reporting! :-)

the problem is the circular include, which shedskin doesn't handle correctly 
yet (board imports piece, piece imports board..). cpython has no problem here 
because of late binding. 

moving WHITE, BLACK and EMPTY to piece.py and removing the import of board from 
piece.py makes compilation go further. after removing some dynamic types as 
indicated by shedskin the program compiles and runs.

I'm not sure I will be able to fix this before 0.7, but because circular 
includes aren't very pretty anyway, it doesn't have too much priority.. it does 
have to be fixed at some point, of course.

good luck with your program, and let me know if you run into anything else! :)

Original comment by mark.duf...@gmail.com on 25 Nov 2010 at 11:32

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 25 Nov 2010 at 11:33

GoogleCodeExporter commented 8 years ago
Hmm, I modified the code according to your directions, and Shedskin compiles 
the code without warnings.

But now, when I type "make", G++ shows the following error:

In file included from board.hpp:5,
                 from main.hpp:6,
                 from main.cpp:1:
piece.hpp:26: error: ‘__board__’ has not been declared
piece.hpp:26: error: ‘brd’ was not declared in this scope
piece.hpp:26: error: expected primary-expression before ‘sq’
piece.hpp:26: error: initializer expression list treated as compound expression
piece.hpp:27: error: ‘__board__’ has not been declared
piece.hpp:27: error: ‘brd’ was not declared in this scope
piece.hpp:27: error: expected primary-expression before ‘sq’
piece.hpp:27: error: initializer expression list treated as compound expression
main.cpp: In function ‘void __main__::__init()’:
main.cpp:23: error: ‘__piece__::calc_moves’ cannot be used as a function
In file included from board.hpp:5,
                 from board.cpp:1:
piece.hpp:26: error: ‘__board__’ has not been declared
piece.hpp:26: error: ‘brd’ was not declared in this scope
piece.hpp:26: error: expected primary-expression before ‘sq’
piece.hpp:26: error: initializer expression list treated as compound expression
piece.hpp:27: error: ‘__board__’ has not been declared
piece.hpp:27: error: ‘brd’ was not declared in this scope
piece.hpp:27: error: expected primary-expression before ‘sq’
piece.hpp:27: error: initializer expression list treated as compound expression

However, if I modify main.py to:

# main.py

import board, piece

brd = board.Board()
brd.print_board()

This means there are problems passing brd to piece.calc_moves.
brd never gets modified, or returned, so I'm clueless.

Do you know whats going on?

I've included the new source, to help.

Original comment by kotux...@gmail.com on 25 Nov 2010 at 8:27

Attachments:

GoogleCodeExporter commented 8 years ago
ah, this is another problem that I fixed after 0.6. please pull from GIT: 
gitorious.org/shedskin.

Original comment by mark.duf...@gmail.com on 25 Nov 2010 at 9:08

GoogleCodeExporter commented 8 years ago
Got it. Thanks!

Original comment by kotux...@gmail.com on 25 Nov 2010 at 9:28

GoogleCodeExporter commented 8 years ago
alright, after fixing a minor bug, the original program works from GIT now. it 
may not work anymore after you change it though, because I still have to fix 
one more problem for this to work in general.. so I will leave this issue open 
until that one is solved, hopefully before 0.7 in about two weeks. thanks again 
for reporting!

Original comment by mark.duf...@gmail.com on 27 Nov 2010 at 2:17

GoogleCodeExporter commented 8 years ago
fixed! :D

please let me know if you run into anything else!

Original comment by mark.duf...@gmail.com on 27 Nov 2010 at 11:40