Beispiel #1
0
    def compile_block(self, context: 'Context') -> List[B]:
        function_name = context.vars['name'].value
        arguments = context.vars['arguments']  # type: List[Argument]
        lifetime = context.vars['lifetime'].value

        code = [[]]

        block_inside = context.expr.block_lines

        # OH SHIT
        # Не работает code, если её вставлять в другую вложенность

        for expr in block_inside:  # type: Expression
            if str(expr.func_token) == 'code':
                code.append([])
            else:
                code[-1].append(expr)

        func = Function(
            function_name,
            arguments,
            FunctionType.BLOCK,
            lifetime,
            source=block_inside,
            code=code,
        )

        context.ns.symbol_lifetime_push(lifetime, func)

        return [
            B(
                B.NONE, "Add macro function `{}` to current namespace".format(
                    function_name)),
        ]
Beispiel #2
0
 def compile(self, context: 'Context') -> List[B]:
     register_name = context.vars['name'].value
     busy = set()
     vars = context.ch_ns.get_vars()
     for var in vars:
         if isinstance(var.value_type, AddressBrType):
             busy.add(var.value)
     empty = _get_first_empty(sorted(list(busy)))
     context.ns.symbol_push(
         Variable(register_name, AddressBrType(None, value=empty)))
     return [
         B(
             "#", "Added new variable `{}` "
             "with address `{}` to local namespace".format(
                 register_name, empty))
     ]
Beispiel #3
0
    def compile_block(self, context: 'Context') -> List[B]:
        function_name = context.vars['name'].value
        arguments = context.vars['arguments']  # type: List[Argument]
        lifetime = context.vars['lifetime'].value
        # Because variables['arguments'] List[Argument], not Variable

        block_inside = context.expr.block_lines
        func = Function(
            function_name,
            arguments,
            FunctionType.NO_BLOCK,
            lifetime,
            source=block_inside,
            code=block_inside,
        )

        context.ns.symbol_lifetime_push(lifetime, func)

        return [
            B(B.NONE,
              "Add function `{}` to current namespace".format(function_name)),
        ]
Beispiel #4
0
 def compile(self, context: 'Context') -> List[B]:
     return [
         B("."),
     ]
Beispiel #5
0
 def compile(self, context: 'Context') -> List[B]:
     addr_to = context.vars['to'].value
     addr_from = context.vars['from'].value
     return [
         B(">", addr_to - addr_from),
     ]
Beispiel #6
0
 def compile(self, context: 'Context') -> List[B]:
     value = context.vars['value'].value
     return [
         B("<", value),
     ]
Beispiel #7
0
 def compile(self, context: 'Context'):
     return [B("]")]
Beispiel #8
0
 def compile(self, context: 'Context') -> List[B]:
     return [B("#", "Nope func")]