Skip to content

Selección de Instrucciones

Especificación de la etapa de selección de instrucciones (perteneciente a la fase de generación de código) utilizando como metalenguaje una especificación de código:

Code Functions

FunctionsCode Templates
run⟦programrun⟦program → varDefinition* statement*⟧ =
     metadata⟦program⟧
     execute⟦statementi
     HALT
execute⟦statementexecute⟦print → expression⟧ =
     #LINE {end.line}
     value⟦expression⟧
     OUT<expression.type>

execute⟦assignment → left:expression right:expression⟧ =
     #LINE {end.line}
     address⟦left⟧
     value⟦right⟧
     STORE<left.type>

value⟦expressionvalue⟦arithmetic → left:expression operator:string right:expression⟧ =
     value⟦left⟧
     value⟦right⟧
     if operator == "+"
         ADD<arithmetic.type>
     if operator == "-"
         SUB<arithmetic.type>
     if operator == "*"
         MUL<arithmetic.type>
     if operator == "/"
         DIV<arithmetic.type>

value⟦variable → name:string⟧ =
     address⟦variable⟧
     LOAD<variable.type>

value⟦intLiteral → intValue:int⟧ =
     PUSH {intValue}

value⟦floatLiteral → floatValue:float⟧ =
     PUSHF {floatValue}

address⟦expression⟧address⟦arithmetic → left:expression operator:string right:expression⟧ =
    

address⟦variable → name:string⟧ =
     PUSHA {variable.varDefinition.address}

address⟦intLiteral → intValue:int⟧ =
    

address⟦floatLiteral → floatValue:float⟧ =
    

metadata⟦programmetadata⟦program → varDefinition* statement*⟧ =
     #SOURCE {source_file}
     metadata⟦varDefinitioni
metadata⟦varDefinitionmetadata⟦varDefinition → type name:string⟧ =
     #GLOBAL {name}: {maplType(type)}

Auxiliary Functions

NameDescription
maplType(type)Returns the MAPL equivalent to the MLang type argument:
    intType -> int
    floatType -> float