Ejemplo n.º 1
0
def progmem_array(id_, rhs) -> "MockObj":
    rhs = safe_exp(rhs)
    obj = MockObj(id_, ".")
    assignment = ProgmemAssignmentExpression(id_.type, id_, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id_, obj)
    return obj
Ejemplo n.º 2
0
def add(expression: Union[Expression, Statement]):
    """Add an expression to the codegen section.

    After this is called, the given given expression will
    show up in the setup() function after this has been called.
    """
    CORE.add(expression)
Ejemplo n.º 3
0
def static_const_array(id_, rhs) -> "MockObj":
    rhs = safe_exp(rhs)
    obj = MockObj(id_, ".")
    assignment = StaticConstAssignmentExpression(id_.type, id_, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id_, obj)
    return obj
def Pvariable(
        id,  # type: ID
        rhs,  # type: SafeExpType
        type=None  # type: MockObj
):
    # type: (...) -> MockObj
    """Declare a new pointer variable in the code generation.

    :param id: The ID used to declare the variable.
    :param rhs: The expression to place on the right hand side of the assignment.
    :param type: Manually define a type for the variable, only use this when it's not possible
      to do so during config validation phase (for example because of template arguments).

    :returns The new variable as a MockObj.
    """
    rhs = safe_exp(rhs)
    obj = MockObj(id, '->')
    if type is not None:
        id.type = type
    decl = VariableDeclarationExpression(id.type, '*', id)
    CORE.add_global(decl)
    assignment = AssignmentExpression(None, None, id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    return obj
def progmem_array(id, rhs):
    rhs = safe_exp(rhs)
    obj = MockObj(id, '.')
    assignment = ProgmemAssignmentExpression(id.type, id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    return obj
Ejemplo n.º 6
0
def variable(id,  # type: ID
             rhs,  # type: Expression
             type=None  # type: MockObj
             ):
    # type: (...) -> MockObj
    rhs = safe_exp(rhs)
    obj = MockObj(id, u'.')
    id.type = type or id.type
    assignment = AssignmentExpression(id.type, '', id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    obj.requires.append(assignment)
    return obj
Ejemplo n.º 7
0
def Pvariable(id,  # type: ID
              rhs,  # type: Expression
              has_side_effects=True,  # type: bool
              type=None  # type: MockObj
              ):
    # type: (...) -> MockObj
    rhs = safe_exp(rhs)
    if not has_side_effects and hasattr(rhs, '_has_side_effects'):
        # pylint: disable=attribute-defined-outside-init, protected-access
        rhs._has_side_effects = False
    obj = MockObj(id, u'->', has_side_effects=has_side_effects)
    id.type = type or id.type
    assignment = AssignmentExpression(id.type, '*', id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    obj.requires.append(assignment)
    return obj
Ejemplo n.º 8
0
def variable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj":
    """Declare a new variable, not pointer type, in the code generation.

    :param id_: The ID used to declare the variable.
    :param rhs: The expression to place on the right hand side of the assignment.
    :param type_: Manually define a type for the variable, only use this when it's not possible
      to do so during config validation phase (for example because of template arguments).

    :returns The new variable as a MockObj.
    """
    assert isinstance(id_, ID)
    rhs = safe_exp(rhs)
    obj = MockObj(id_, ".")
    if type_ is not None:
        id_.type = type_
    assignment = AssignmentExpression(id_.type, "", id_, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id_, obj)
    return obj
Ejemplo n.º 9
0
def add(
        expression,  # type: Union[Expression, Statement]
        require=True  # type: bool
):
    # type: (...) -> None
    CORE.add(expression, require=require)