コード例 #1
0
ファイル: rootops.py プロジェクト: DawidvC/Logix
def makeLanguages(logixModuleName, homedir, moduledict):
    import pycompile

    pycompile.installRootopCompilers()
    
    modname = logixModuleName + ".base"

    quotelang = makeQuotelang(parent=None, module=modname)
    syntaxlang = makeSyntaxlang(parent=quotelang, module=modname)
    langlang = makeLangLang(syntaxlang, parent=quotelang, module=modname)
    syntaxlang.__impl__.addOp(langlang.__impl__.getOp("(^"))

    global defaultBaseLang
    defaultBaseLang = langlang

    baselang = Language("base", langlang, modname)
    baselang.operatorBase = PyOp

    filename = homedir + "/base.lx"
    env = dict(__name__=modname,
               base=baselang)
    baselang.__impl__.parse(file(filename, 'U'), mode='exec', execenv=env)
    pycompile.installPyCompilers(baselang.__impl__)

    # HACK: Fix up base lmodule
    mod = new.module(filename)
    mod.__file__ = filename
    vars(mod).update(env)
    moduledict[modname] = mod
    mod.langlang = langlang
    mod.syntaxlang = syntaxlang
    mod.quotelang = quotelang

    return quotelang, syntaxlang, langlang, baselang
コード例 #2
0
def makeLanguages(logixModuleName, homedir, moduledict):
    import pycompile

    pycompile.installRootopCompilers()

    modname = logixModuleName + ".base"

    quotelang = makeQuotelang(parent=None, module=modname)
    syntaxlang = makeSyntaxlang(parent=quotelang, module=modname)
    langlang = makeLangLang(syntaxlang, parent=quotelang, module=modname)
    syntaxlang.__impl__.addOp(langlang.__impl__.getOp("(^"))

    global defaultBaseLang
    defaultBaseLang = langlang

    baselang = Language("base", langlang, modname)
    baselang.operatorBase = PyOp

    filename = homedir + "/base.lx"
    env = dict(__name__=modname, base=baselang)
    baselang.__impl__.parse(file(filename, 'U'), mode='exec', execenv=env)
    pycompile.installPyCompilers(baselang.__impl__)

    # HACK: Fix up base lmodule
    mod = new.module(filename)
    mod.__file__ = filename
    vars(mod).update(env)
    moduledict[modname] = mod
    mod.langlang = langlang
    mod.syntaxlang = syntaxlang
    mod.quotelang = quotelang

    return quotelang, syntaxlang, langlang, baselang
コード例 #3
0
ファイル: rootops.py プロジェクト: DawidvC/Logix
def makeLanguages(logixModuleName, homedir, moduledict):
    import pycompile

    pycompile.installRootopCompilers()
    
    modname = logixModuleName + ".base"

    quotelang = makeQuotelang(parent=None, module=modname)
    syntaxlang = makeSyntaxlang(parent=quotelang, module=modname)
    langlang = makeLangLang(syntaxlang, parent=quotelang, module=modname)
    syntaxlang.__impl__.addOp(langlang.__impl__.getOp("(^"))

    global defaultBaseLang
    defaultBaseLang = langlang

    # {{{ baselang = create baselang (possibly from cache)
    baselang = Language("base", langlang, modname)

    filename = homedir + "/base.lx"
    env = dict(__name__=modname,
               base=baselang,
               langlang=langlang)

    def persistent_load(pid):
        res = {'nothing': nothing,
               'eol': Tokenizer.endOfLine,
               'eob': Tokenizer.endOfBlock,
               'eof': Tokenizer.endOfFile }.get(pid)
        if res: return res
        else: raise cPickle.UnpicklingError, 'Invalid persistent id'

    def persistent_id(x):
        return {id(nothing): "nothing",
                id(Tokenizer.endOfLine) : "eol",
                id(Tokenizer.endOfBlock): "eob",
                id(Tokenizer.endOfFile):  "eof"}.get(id(x))
  
    opFile = "%s/logix_opcache" % homedir
  
    if not path.exists(opFile):
        baselang.__impl__.parse(file(filename, 'U'),
                                mode='exec', execenv=env)
        oplst = [x.syntax for x in baselang.__impl__.operators.values()]

        p = cPickle.Pickler(file(opFile,"w+"))
        p.persistent_id = persistent_id
        p.dump(oplst)

    else:
        p = cPickle.Unpickler(file(opFile))
        p.persistent_load = persistent_load
        for syntax in p.load():
            baselang.__impl__.newOpFromSyntax(syntax)
    # }}}

    pycompile.installPyCompilers(baselang.__impl__)

    # HACK: Fix up base lmodule
    mod = new.module(filename)
    mod.__file__ = filename
    vars(mod).update(env)
    moduledict[modname] = mod
    mod.langlang = langlang
    mod.syntaxlang = syntaxlang
    mod.quotelang = quotelang

    return quotelang, syntaxlang, langlang, baselang
コード例 #4
0
ファイル: rootops.py プロジェクト: manbaum/Logix
def makeLanguages(logixModuleName, homedir, moduledict):
    import pycompile

    pycompile.installRootopCompilers()

    modname = logixModuleName + ".base"

    quotelang = makeQuotelang(parent=None, module=modname)
    syntaxlang = makeSyntaxlang(parent=quotelang, module=modname)
    langlang = makeLangLang(syntaxlang, parent=quotelang, module=modname)
    syntaxlang.__impl__.addOp(langlang.__impl__.getOp("(^"))

    global defaultBaseLang
    defaultBaseLang = langlang

    # {{{ baselang = create baselang (possibly from cache)
    baselang = Language("base", langlang, modname)

    filename = homedir + "/base.lx"
    env = dict(__name__=modname, base=baselang, langlang=langlang)

    def persistent_load(pid):
        res = {
            'nothing': nothing,
            'eol': Tokenizer.endOfLine,
            'eob': Tokenizer.endOfBlock,
            'eof': Tokenizer.endOfFile
        }.get(pid)
        if res: return res
        else: raise cPickle.UnpicklingError, 'Invalid persistent id'

    def persistent_id(x):
        return {
            id(nothing): "nothing",
            id(Tokenizer.endOfLine): "eol",
            id(Tokenizer.endOfBlock): "eob",
            id(Tokenizer.endOfFile): "eof"
        }.get(id(x))

    opFile = "%s/logix_opcache" % homedir

    if not path.exists(opFile):
        baselang.__impl__.parse(file(filename, 'U'), mode='exec', execenv=env)
        oplst = [x.syntax for x in baselang.__impl__.operators.values()]

        p = cPickle.Pickler(file(opFile, "w+"))
        p.persistent_id = persistent_id
        p.dump(oplst)

    else:
        p = cPickle.Unpickler(file(opFile))
        p.persistent_load = persistent_load
        for syntax in p.load():
            baselang.__impl__.newOpFromSyntax(syntax)
    # }}}

    pycompile.installPyCompilers(baselang.__impl__)

    # HACK: Fix up base lmodule
    mod = new.module(filename)
    mod.__file__ = filename
    vars(mod).update(env)
    moduledict[modname] = mod
    mod.langlang = langlang
    mod.syntaxlang = syntaxlang
    mod.quotelang = quotelang

    return quotelang, syntaxlang, langlang, baselang