futz with name things.
This commit is contained in:
parent
821ca442aa
commit
3dba5f7aff
@ -138,6 +138,24 @@ class HyASTCompiler(object):
|
|||||||
kw_defaults=[]),
|
kw_defaults=[]),
|
||||||
body=self.compile(body))
|
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")
|
@builds("get")
|
||||||
def compile_index_expression(self, expr):
|
def compile_index_expression(self, expr):
|
||||||
expr.pop(0) # index
|
expr.pop(0) # index
|
||||||
@ -321,6 +339,19 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
@builds(HySymbol)
|
@builds(HySymbol)
|
||||||
def compile_symbol(self, symbol):
|
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(),
|
return ast.Name(id=str(symbol), ctx=ast.Load(),
|
||||||
lineno=symbol.start_line,
|
lineno=symbol.start_line,
|
||||||
col_offset=symbol.start_column)
|
col_offset=symbol.start_column)
|
||||||
|
@ -57,6 +57,7 @@ def _resolve_atom(obj):
|
|||||||
"false": "False",
|
"false": "False",
|
||||||
"null": "None",
|
"null": "None",
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj in table:
|
if obj in table:
|
||||||
return HySymbol(table[obj])
|
return HySymbol(table[obj])
|
||||||
|
|
||||||
|
@ -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 []
|
(defn test-lists []
|
||||||
"NATIVE: test lists work right"
|
"NATIVE: test lists work right"
|
||||||
@ -74,3 +81,10 @@
|
|||||||
"NATIVE: test lambda operator"
|
"NATIVE: test lambda operator"
|
||||||
(def square (lambda [x] (* x x)))
|
(def square (lambda [x] (* x x)))
|
||||||
(assert (= 4 (square 2))))
|
(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)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user