package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.patio.PatioFunctionDeclaration; import org.shedlang.compiler.patio.PatioLocal; import org.shedlang.compiler.patio.instructions.PatioCall; import org.shedlang.compiler.patio.operands.PatioIntConst; import org.shedlang.compiler.patio.operands.PatioLocalRef; import org.shedlang.compiler.patio.operands.PatioOperand; import org.shedlang.compiler.patio.types.PatioType; import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import java.math.BigInteger; import java.util.List; public class ShidToPatioInts { public static final PatioFunctionDeclaration INT_CREATE_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_create", List.of( PatioLocal.param("value", PatioTypes.INT) ), List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); public static final PatioFunctionDeclaration INT_ADD_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_add", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); public static final PatioFunctionDeclaration INT_SUB_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_sub", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); public static final PatioFunctionDeclaration INT_MULTIPLY_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_multiply", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(ShidToPatioTypes.VALUE_TYPE), Sources.RUNTIME ); public static final PatioFunctionDeclaration INT_EQUALS_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_equals", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(PatioTypes.BOOL), Sources.RUNTIME ); public static final PatioFunctionDeclaration INT_NOT_EQUAL_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_not_equal", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(PatioTypes.BOOL), Sources.RUNTIME ); private static final PatioFunctionDeclaration INT_LESS_THAN_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_less_than", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(PatioTypes.BOOL), Sources.RUNTIME ); private static final PatioFunctionDeclaration INT_LESS_THAN_OR_EQUAL_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_less_than_or_equal", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(PatioTypes.BOOL), Sources.RUNTIME ); private static final PatioFunctionDeclaration INT_GREATER_THAN_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_greater_than", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(PatioTypes.BOOL), Sources.RUNTIME ); private static final PatioFunctionDeclaration INT_GREATER_THAN_OR_EQUAL_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__int_greater_than_or_equal", List.of( PatioLocal.param("left", ShidToPatioTypes.VALUE_TYPE), PatioLocal.param("right", ShidToPatioTypes.VALUE_TYPE) ), List.of(PatioTypes.BOOL), Sources.RUNTIME ); public static final PatioType INT_TYPE = ShidToPatioTypes.VALUE_TYPE; private ShidToPatioInts() { } public static ShidToPatioContext storeConst( PatioLocalRef destination, BigInteger value, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_CREATE_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_CREATE_DECLARATION.name(), List.of(PatioIntConst.of(value.intValueExact())), source )); } public static ShidToPatioContext add( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_ADD_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_ADD_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext sub( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_SUB_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_SUB_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext multiply( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_MULTIPLY_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_MULTIPLY_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext equals( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_EQUALS_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_EQUALS_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext notEqual( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_NOT_EQUAL_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_NOT_EQUAL_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext lessThan( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_LESS_THAN_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_LESS_THAN_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext lessThanOrEqual( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_LESS_THAN_OR_EQUAL_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_LESS_THAN_OR_EQUAL_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext greaterThan( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_GREATER_THAN_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_GREATER_THAN_DECLARATION.name(), List.of(left, right), source )); } public static ShidToPatioContext greaterThanOrEqual( PatioLocalRef destination, PatioOperand left, PatioOperand right, Source source, ShidToPatioContext context ) { return context .ensureCompilationUnitElement(INT_GREATER_THAN_OR_EQUAL_DECLARATION) .addInstruction(new PatioCall( List.of(destination), INT_GREATER_THAN_OR_EQUAL_DECLARATION.name(), List.of(left, right), source )); } }