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.lex.machine import Machine
|
||||||
from hy.compiler import hy_compile
|
from hy.compiler import hy_compile
|
||||||
from hy.core import process
|
from hy.core import process
|
||||||
|
from hy.importer import compile_
|
||||||
|
|
||||||
import hy.completer
|
import hy.completer
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ class HyREPL(code.InteractiveConsole):
|
|||||||
_machine = Machine(Idle, 1, 0)
|
_machine = Machine(Idle, 1, 0)
|
||||||
try:
|
try:
|
||||||
_ast = hy_compile(tokens, root=ast.Interactive)
|
_ast = hy_compile(tokens, root=ast.Interactive)
|
||||||
code = compile(_ast, filename, symbol)
|
code = compile_(_ast, filename, symbol)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.showtraceback()
|
self.showtraceback()
|
||||||
return False
|
return False
|
||||||
|
@ -17,6 +17,7 @@ print ""
|
|||||||
print ast.dump(_ast)
|
print ast.dump(_ast)
|
||||||
print ""
|
print ""
|
||||||
print ""
|
print ""
|
||||||
|
print "from __future__ import division"
|
||||||
print astor.codegen.to_source(_ast)
|
print astor.codegen.to_source(_ast)
|
||||||
|
|
||||||
import_file_to_module("<STDIN>", sys.argv[1])
|
import_file_to_module("<STDIN>", sys.argv[1])
|
||||||
|
@ -31,7 +31,7 @@ import imp
|
|||||||
import sys
|
import sys
|
||||||
import ast
|
import ast
|
||||||
import os
|
import os
|
||||||
|
import __future__
|
||||||
|
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
@ -39,6 +39,10 @@ else:
|
|||||||
from StringIO import StringIO # NOQA
|
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):
|
def import_buffer_to_hst(fd):
|
||||||
tree = tokenize(fd.read() + "\n")
|
tree = tokenize(fd.read() + "\n")
|
||||||
tree = process(tree)
|
tree = process(tree)
|
||||||
@ -65,7 +69,7 @@ def import_file_to_module(name, fpath):
|
|||||||
_ast = import_file_to_ast(fpath)
|
_ast = import_file_to_ast(fpath)
|
||||||
mod = imp.new_module(name)
|
mod = imp.new_module(name)
|
||||||
mod.__file__ = fpath
|
mod.__file__ = fpath
|
||||||
eval(compile(_ast, fpath, "exec"), mod.__dict__)
|
eval(compile_(_ast, fpath, "exec"), mod.__dict__)
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
@ -77,7 +81,7 @@ def hy_eval(hytree, namespace):
|
|||||||
foo.end_column = 0
|
foo.end_column = 0
|
||||||
hytree.replace(foo)
|
hytree.replace(foo)
|
||||||
_ast = hy_compile(hytree, root=ast.Expression)
|
_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):
|
def write_hy_as_pyc(fname):
|
||||||
@ -88,7 +92,7 @@ def write_hy_as_pyc(fname):
|
|||||||
timestamp = long(os.stat(fname).st_mtime)
|
timestamp = long(os.stat(fname).st_mtime)
|
||||||
|
|
||||||
_ast = import_file_to_ast(fname)
|
_ast = import_file_to_ast(fname)
|
||||||
code = compile(_ast, fname, "exec")
|
code = compile_(_ast, fname, "exec")
|
||||||
cfile = "%s.pyc" % fname[:-len(".hy")]
|
cfile = "%s.pyc" % fname[:-len(".hy")]
|
||||||
|
|
||||||
with open(cfile, 'wb') as fc:
|
with open(cfile, 'wb') as fc:
|
||||||
|
@ -27,7 +27,10 @@
|
|||||||
|
|
||||||
(setv test_div (fn []
|
(setv test_div (fn []
|
||||||
"NATIVE: Test division"
|
"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 []
|
(setv test_int_div (fn []
|
||||||
"NATIVE: Test integer division"
|
"NATIVE: Test integer division"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user