Franck Pommereau

fixed net compilation API

......@@ -47,7 +47,9 @@ def build (lang, tree, saveto) :
os.unlink(tmp.name)
else :
mod = lang.build(tree, out.name, os.path.basename(out.name))
mod.ast = tree
if mod is not None :
mod.__ast__ = tree
return mod
class BaseDeclare (object) :
_levels = [None]
......
......@@ -13,10 +13,6 @@ class Declare (BaseDeclare) :
_levels = ["import", "decl"]
_default = "decl"
class GoModule (object) :
def __init__ (self, srcpath) :
self.path = os.path.splitext(srcpath)[0]
def update_gopath () :
# TODO: fix this wrt installation path
path = os.path.join(os.path.dirname(os.path.dirname(inspect.getfile(snakes))),
......@@ -40,4 +36,3 @@ def build (ast, src, name) :
except ValueError :
continue
raise CompilationError(ast, name, out)
return GoModule(src)
......
import types, traceback, sys, importlib
import types, traceback, sys
from snakes.compil import CompilationError, BaseDeclare
from . import codegen as codegen
......@@ -15,11 +15,9 @@ class Declare (BaseDeclare) :
def build (ast, src, name) :
if isinstance(src, str) :
src = open(src)
ctx = {}
try :
spec = importlib.util.spec_from_file_location(module_name, file_path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
mod = types.ModuleType(ast.name)
exec(src.read(), mod.__dict__)
except Exception as err :
c, v, t = sys.exc_info()
msg = traceback.format_exception_only(c, v)
......