コード例 #1
0
    def load_namespace(self, module_name: str) -> dict:
        from core.avm import Interpreter, Frame

        module_name = module_name.replace('.', '/')

        if module_name in self.__loaded.keys():
            return self.__loaded[module_name]

        p = self.__search_module(module_name)

        if p is None:
            return None

        if self.__get_type(p) == 'py':
            return self.__add_to_loaded(module_name,
                                        self.__load_py_namespace(p))

        elif self.__get_type(p) == 'ail':
            ast = Parser(p).parse(Lex(p).lex())
            cobj = Compiler(filename=p).compile(ast).code_object

            frame = Frame(cobj, cobj.varnames, cobj.consts)

            Interpreter().exec(cobj, frame)

            v = frame.variable

            return self.__add_to_loaded(module_name, v)

        return None
コード例 #2
0
ファイル: ail_launcher.py プロジェクト: laomobk/AIL
def launch_main(argv: list):
    init_paths()

    if len(argv) == 0:
        from core import ashell
        ashell.Shell().run_shell()
        return

    if len(argv) > 1:
        print('Usage : ./ail_launcher.py file')
        sys.exit(1)

    fpath = argv[0]

    try:
        from core.alex import Lex
        from core.aparser import Parser
        from core.acompiler import Compiler
        from core.avm import Interpreter

        ast = Parser(fpath).parse(Lex(fpath).lex())
        Interpreter().exec(
            Compiler(ast, filename=fpath).compile(ast).code_object)

    except FileExistsError as e:
        print('AIL : can\'t open file \'%s\' : %s' % (fpath, str(e)))
        sys.exit(1)
コード例 #3
0
def test_parse():
    import pprint

    l = Lex('tests/test.ail')
    ts = l.lex()

    p = Parser('tests/test.ail')
    t = p.test(ts)
    pt = test_utils.make_ast_tree(t)
    pprint.pprint(pt)
コード例 #4
0
ファイル: acompiler.py プロジェクト: laomobk/AIL
def test_compiler():
    from core.aparser import Parser
    from core.alex import Lex

    l = Lex('../tests/test.ail')
    ts = l.lex()

    p = Parser('../tests/test.ail')
    t = p.parse(ts)

    c = Compiler(t)
    bf = c.compile(t)

    test_utils.show_bytecode(bf)
コード例 #5
0
    def __get_more_line_state(self, line: str) -> int:
        '''
        :return : -1 end more | 0 normal | 1 start more
        '''
        self.__write(line)

        ts = Lex(self.__temp_name).lex()

        for tok in ts.token_list[::-1]:
            if tok.ttype == tokent.LAP_IDENTIFIER:
                if tok.value in _MORE_KEYWORD:
                    return 1
                if tok.value in _END_KEYWORD:
                    return -1

        return 0
コード例 #6
0
ファイル: avm.py プロジェクト: laomobk/AIL
def test_vm():
    import pickle
    from core.alex import Lex
    from core.aparser import Parser
    from core.acompiler import Compiler

    l = Lex('tests/test.ail')
    ts = l.lex()

    t = Parser('tests/test.ail').parse(ts)

    cbf = Compiler(filename='<TEST>').compile(t)

    co = cbf.code_object

    inter = Interpreter()
    inter.exec(co)
コード例 #7
0
    def __init__(self):
        self.__buffer = []

        self.ps1 = '>> '
        self.ps2 = '.. '

        self.__more_level = 0

        self.__temp_name = '.temp.tmp'
        self.__fbuffer = open(self.__temp_name, 'w')

        self.__program = 'begin\n%s\nend\n'

        self.__main_frame = Frame()
        self.__main_frame.variable = _SHELL_NAMESPACE

        self.__lexer = Lex(self.__temp_name)
        self.__parser = Parser(self.__temp_name)
        self.__compiler = Compiler(filename='<shell>')
        self.__inter = Interpreter()