示例#1
0
 def parse_trait_clause(self):
     expr = self.parse_expr()
     self.expect('dot')
     source_info = expr.source_info
     receiver = ast.Ref(source_info, o.get_symbol('Trait'))
     message = ast.Message(source_info, o.get_symbol('build:'), [expr])
     expr = ast.Send(source_info, receiver, message)
     return expr
示例#2
0
 def visit_ref(self, ref, cls_env, lex_env, top):
     name = ref.name
     if name == o.get_symbol('self'):
         loc = ast.SelfLoc()
     elif name == o.get_symbol('super'):
         loc = ast.SuperLoc()
     else:
         loc = self.lookup_var(name, lex_env, cls_env)
     return ref._replace(name=loc)
示例#3
0
 def make_dnu_args(self, selector, args):
     msg_cls = self.core_lookup(o.get_symbol('Message'))
     msg = msg_cls.new_instance()
     selector_slot_num = \
         msg_cls.instance_variable_slot(o.get_symbol('selector'))
     arguments_slot_num = \
         msg_cls.instance_variable_slot(o.get_symbol('arguments'))
     msg.get_slot(selector_slot_num).assign(selector)
     msg.get_slot(arguments_slot_num).assign(args)
     return [msg]
示例#4
0
 def load_syntax(self):
     from onyx.syntax.parser import Parser
     import onyx.objects as o
     import onyx.syntax.ast as ast
     mod_syntax = Parser.parse_file(self.fspath.strpath)
     imports = mod_syntax.imports
     syntax = mod_syntax.body
     tester_name = o.get_symbol('tests.tester')
     tester_imp = ast.ModuleImport(None, tester_name)
     imports.append(tester_imp)
     syntax = ast.Assign(None, o.get_symbol('testCase'), syntax)
     return ast.Module(None, imports, syntax)
示例#5
0
    def do_message_send(self, message, receiver, args):
        self.announce_msg_send(receiver, message.selector, args)
        receiver_class = self.get_onyx_class(receiver)
        is_class = getattr(receiver, 'is_class', False)
        result = message.method_cache.get((receiver_class.name, is_class))
        if not result:
            result = receiver_class.lookup_method(self, message.selector,
                                                  is_class)
            message.method_cache[(receiver_class.name, is_class)] = result

        if not result.is_success:
            dnu_selector = o.get_symbol('doesNotUnderstand:')
            result = receiver_class.lookup_method(self, dnu_selector, is_class)
            if not result.is_success:
                raise Exception('dnu')

            args = self.make_dnu_args(message.selector,
                                      [self.deref_value(a) for a in args])

        receiver = self.deref_value(receiver)
        args = [self.deref_value(a) for a in args]
        self.env = self.make_method_env(result.method, args, receiver,
                                        result.cls)
        self.announce_method_invoke(result.cls, receiver, result.method)
        self.doing(result.method.statements)
示例#6
0
    def parse_expr_array(self):
        source_info = self.current_token().source_info
        self.expect('lcurl')
        _, statements = self.parse_statements()
        source_info += self.current_token().source_info
        self.expect('rcurl')

        size = len(statements)
        rcvr = ast.Send(
            source_info, ast.Ref(source_info, o.get_symbol('Array')),
            ast.Message(source_info, o.get_symbol('new:'),
                        [ast.Const(source_info, size)]))
        if size == 0:
            return rcvr
        messages = [
            ast.Message(source_info, o.get_symbol('at:put:'),
                        [ast.Const(source_info, i), e])
            for i, e in enumerate(statements)
        ]
        messages.append(ast.Message(source_info, o.get_symbol('yourself'), []))
        return ast.Send(source_info, rcvr, ast.Cascade(source_info, messages))
示例#7
0
    def parse_kmsg(self):
        source_info = self.current_token().source_info
        selector = []
        args = []

        while self.current_is_oneof('kw'):
            selector.append(self.current_token().value)
            self.step()

            arg = self.parse_primary()
            arg = self.parse_unary(arg)
            args.append(self.parse_binary(arg))
        selector = o.get_symbol(''.join(selector))
        source_info += args[-1].source_info
        return self.make_message(source_info, selector, args)
示例#8
0
    def parse_module_name(self):
        start = self.current_token().source_info
        self.expect('lpmod')
        name = []
        while True:
            if not self.current_is_oneof('id'):
                self.parse_error('expected id')

            name.append(self.current_token().value)
            self.step()

            if self.current_token().matches(Token('rcurl', '}')):
                si = start + self.current_token().source_info
                self.step()
                return o.get_symbol('.'.join(name))

            self.expect('dot')
示例#9
0
 def visit_class(self, cls, cls_env, lex_env, top):
     super_name = cls.superclass_name
     if super_name == o.get_symbol('nil'):
         super_slots = []
         super_cls_loc = None
     else:
         super_cls_loc = self.lookup_var_in_top(super_name)
         super_slots = self.class_slots[super_cls_loc]
     instance_vars = super_slots + cls.instance_vars
     self.clear_unresolved(cls.name)
     self.exports.add(cls.name)
     loc = ast.GlobalLoc(self.module_name, cls.name)
     self.top_names[cls.name] = loc
     self.class_slots[loc] = instance_vars
     self.export_classes.add(loc)
     cls = cls._replace(loc=loc, superclass_name=super_cls_loc)
     return cls.visit_children_static(self.visit, instance_vars, lex_env,
                                      False)
示例#10
0
 def add_core_import(self, syntax):
     return self.add_import(syntax, o.get_symbol('core'))
示例#11
0
def make_symbol(match):
    return o.get_symbol(match.group(1))