Merge branch 'future_division' of github.com:khinsen/hy into pr-106
This commit is contained in:
commit
a71f166610
3
bin/hy
3
bin/hy
@ -21,6 +21,7 @@ from hy.lex.states import Idle, LexException
|
||||
from hy.lex.machine import Machine
|
||||
from hy.compiler import hy_compile
|
||||
from hy.core import process
|
||||
from hy.importer import compile_
|
||||
|
||||
import hy.completer
|
||||
|
||||
@ -58,7 +59,7 @@ class HyREPL(code.InteractiveConsole):
|
||||
_machine = Machine(Idle, 1, 0)
|
||||
try:
|
||||
_ast = hy_compile(tokens, root=ast.Interactive)
|
||||
code = compile(_ast, filename, symbol)
|
||||
code = compile_(_ast, filename, symbol)
|
||||
except Exception:
|
||||
self.showtraceback()
|
||||
return False
|
||||
|
@ -17,6 +17,7 @@ print ""
|
||||
print ast.dump(_ast)
|
||||
print ""
|
||||
print ""
|
||||
print "from __future__ import division"
|
||||
print astor.codegen.to_source(_ast)
|
||||
|
||||
import_file_to_module("<STDIN>", sys.argv[1])
|
||||
|
@ -31,7 +31,7 @@ import imp
|
||||
import sys
|
||||
import ast
|
||||
import os
|
||||
|
||||
import __future__
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
from io import StringIO
|
||||
@ -39,6 +39,10 @@ else:
|
||||
from StringIO import StringIO # NOQA
|
||||
|
||||
|
||||
def compile_(ast, filename, mode):
|
||||
return compile(ast, filename, mode, __future__.CO_FUTURE_DIVISION)
|
||||
|
||||
|
||||
def import_buffer_to_hst(fd):
|
||||
tree = tokenize(fd.read() + "\n")
|
||||
tree = process(tree)
|
||||
@ -65,7 +69,7 @@ def import_file_to_module(name, fpath):
|
||||
_ast = import_file_to_ast(fpath)
|
||||
mod = imp.new_module(name)
|
||||
mod.__file__ = fpath
|
||||
eval(compile(_ast, fpath, "exec"), mod.__dict__)
|
||||
eval(compile_(_ast, fpath, "exec"), mod.__dict__)
|
||||
return mod
|
||||
|
||||
|
||||
@ -77,7 +81,7 @@ def hy_eval(hytree, namespace):
|
||||
foo.end_column = 0
|
||||
hytree.replace(foo)
|
||||
_ast = hy_compile(hytree, root=ast.Expression)
|
||||
return eval(compile(_ast, "<eval>", "eval"), namespace)
|
||||
return eval(compile_(_ast, "<eval>", "eval"), namespace)
|
||||
|
||||
|
||||
def write_hy_as_pyc(fname):
|
||||
@ -88,7 +92,7 @@ def write_hy_as_pyc(fname):
|
||||
timestamp = long(os.stat(fname).st_mtime)
|
||||
|
||||
_ast = import_file_to_ast(fname)
|
||||
code = compile(_ast, fname, "exec")
|
||||
code = compile_(_ast, fname, "exec")
|
||||
cfile = "%s.pyc" % fname[:-len(".hy")]
|
||||
|
||||
with open(cfile, 'wb') as fc:
|
||||
|
@ -27,7 +27,10 @@
|
||||
|
||||
(setv test_div (fn []
|
||||
"NATIVE: Test division"
|
||||
(assert (= 25 (/ 100 2 2)))))
|
||||
(assert (= 25 (/ 100 2 2)))
|
||||
; Commented out until float constants get implemented
|
||||
; (assert (= 0.5 (/ 1 2)))
|
||||
(assert (= 1 (* 2 (/ 1 2))))))
|
||||
|
||||
(setv test_int_div (fn []
|
||||
"NATIVE: Test integer division"
|
||||
|
Loading…
Reference in New Issue
Block a user