futz with name things.

This commit is contained in:
Paul R. Tagliamonte 2013-03-09 19:46:32 -05:00
parent 821ca442aa
commit 3dba5f7aff
3 changed files with 46 additions and 0 deletions

View File

@ -138,6 +138,24 @@ class HyASTCompiler(object):
kw_defaults=[]),
body=self.compile(body))
@builds("import")
def compile_import_expression(self, expr):
expr.pop(0) # index
return ast.Import(
lineno=expr.start_line,
col_offset=expr.start_column,
names=[ast.alias(name=str(x), asname=None) for x in expr])
@builds("import_from")
def compile_import_from_expression(self, expr):
expr.pop(0) # index
return ast.ImportFrom(
lineno=expr.start_line,
col_offset=expr.start_column,
module=str(expr.pop(0)),
names=[ast.alias(name=str(x), asname=None) for x in expr],
level=0)
@builds("get")
def compile_index_expression(self, expr):
expr.pop(0) # index
@ -321,6 +339,19 @@ class HyASTCompiler(object):
@builds(HySymbol)
def compile_symbol(self, symbol):
if "." in symbol:
glob, local = symbol.rsplit(".", 1)
glob = HySymbol(glob)
glob.replace(symbol)
return ast.Attribute(
lineno=symbol.start_line,
col_offset=symbol.start_column,
value=self.compile_symbol(glob),
attr=str(local),
ctx=ast.Load()
)
return ast.Name(id=str(symbol), ctx=ast.Load(),
lineno=symbol.start_line,
col_offset=symbol.start_column)

View File

@ -57,6 +57,7 @@ def _resolve_atom(obj):
"false": "False",
"null": "None",
}
if obj in table:
return HySymbol(table[obj])

View File

@ -1,5 +1,12 @@
;
(import sys)
(import-from os.path exists isdir isfile)
(defn test-sys-argv []
"NATIVE: test sys.argv"
(assert (isinstance sys.argv list)))
(defn test-lists []
"NATIVE: test lists work right"
@ -74,3 +81,10 @@
"NATIVE: test lambda operator"
(def square (lambda [x] (* x x)))
(assert (= 4 (square 2))))
(defn test-imported-bits []
"NATIVE: test the imports work"
(assert (is (exists ".") true))
(assert (is (isdir ".") true))
(assert (is (isfile ".") false)))