dropbox/pyston — pull request #148 by tjhance (2014-09-05 08:39:14+00:00)
Title: (more) correct semantics for import

I added IMPORT_NAME and while I was at it, IMPORT_STAR, as language primitives. The implementation felt a bit clunky but I'm getting use to the code generator still. (One awkwardness is that IMPORT_STAR is an expression like the other LangPrimitives, but it needs to be wrapped in a Stmt.)

To illustrate here's a comparison of CPython bytecode to our IR:

```
import a.b

2 0 LOAD_CONST 1 (-1)
3 LOAD_CONST 0 (None)
6 IMPORT_NAME 0 (a.b)
9 STORE_FAST 0 (a)

#0x38213f0 = :IMPORT_NAME(-1, :NONE(), a.b)
a = #0x38213f0
```

```
import a.b as foo

3 12 LOAD_CONST 1 (-1)
15 LOAD_CONST 0 (None)
18 IMPORT_NAME 0 (a.b)
21 LOAD_ATTR 1 (b)
24 STORE_FAST 1 (foo)

#0x3821500 = :IMPORT_NAME(-1, :NONE(), a.b)
#0x3821500 = #0x3821500.b
foo = #0x3821500
```

```
from a.b import *

4 27 LOAD_CONST 1 (-1)
30 LOAD_CONST 2 (('*',))
33 IMPORT_NAME 0 (a.b)
36 IMPORT_STAR

#0x3821530 = :IMPORT_NAME(0, ("*",), a.b)
:IMPORT_STAR(#0x3821530)
```

```
from a.b import c

5 37 LOAD_CONST 1 (-1)
40 LOAD_CONST 3 (('c',))
43 IMPORT_NAME 0 (a.b)
46 IMPORT_FROM 2 (c)
49 STORE_FAST 2 (c)
52 POP_TOP
53 LOAD_CONST 0 (None)
56 RETURN_VALUE

#0x3821660 = :IMPORT_NAME(0, ("c",), a.b)
#0x3821710 = :IMPORT_FROM(#0x3821660, c)
c = #0x3821710
return
```