From 14e716f05f3f1c1fde545b3135cf1610c4fed2bb Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Mon, 17 Dec 2012 01:22:37 -0500 Subject: [PATCH] late night hacks --- hy/compiler/modfaker.py | 6 +++++- hy/lang/builtins.py | 5 ++++- hylander.hy | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hy/compiler/modfaker.py b/hy/compiler/modfaker.py index 6b40c98..a1d4dac 100644 --- a/hy/compiler/modfaker.py +++ b/hy/compiler/modfaker.py @@ -59,10 +59,14 @@ def forge_module(name, fpath, forest): _add_native_methods(mod) def shim(): + ns = globals() + for tree in _hy_forest: + tree.set_namespace(ns) + for tree in _hy_forest: - tree.set_namespace(globals()) tree() + mod.__dict__['_hy_self'] = mod eval(shim.__code__, mod.__dict__) return mod diff --git a/hy/lang/builtins.py b/hy/lang/builtins.py index 282ea9e..b9100e8 100644 --- a/hy/lang/builtins.py +++ b/hy/lang/builtins.py @@ -1,4 +1,5 @@ # +import sys def _define(obj): @@ -30,8 +31,10 @@ def _import(obj): mods = args[0] for module in mods: + basename = module.split(".", 1)[0] mod = __import__(module) - obj.namespace[module] = mod + sys.modules[module] = mod + ns[basename] = mod builtins = { diff --git a/hylander.hy b/hylander.hy index 5c53dae..fd18431 100644 --- a/hylander.hy +++ b/hylander.hy @@ -1,9 +1,9 @@ ; vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 filetype=lisp -(import ["sys"]) +(import ["sys" + "os.path"]) (def square (fn [x] (* x x))) -(print (square 2)) -(print sys.argv) +(print os.path)