bardemo works

java11
simonkellet 2 years ago
parent e1268aae42
commit c9ca3c5bba
  1. 3
      Triangle.Compiler/src/main/java/triangle/abstractSyntaxTrees/commands/RepeatCommand.java
  2. 4
      Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java
  3. 27
      Triangle.Compiler/src/main/java/triangle/codeGenerator/entities/BarPrimitiveRoutine.java
  4. BIN
      build/libs/Triangle-Tools.jar
  5. 9
      programs/bardemo.tri

@ -16,6 +16,7 @@ public class RepeatCommand extends Command {
return v.visitRepeatCommand(this, arg); return v.visitRepeatCommand(this, arg);
} }
public final Expression E; //public final Expression E;
public Expression E;
public final Command C; public final Command C;
} }

@ -101,6 +101,7 @@ import triangle.abstractSyntaxTrees.vnames.SimpleVname;
import triangle.abstractSyntaxTrees.vnames.SubscriptVname; import triangle.abstractSyntaxTrees.vnames.SubscriptVname;
import triangle.abstractSyntaxTrees.vnames.Vname; import triangle.abstractSyntaxTrees.vnames.Vname;
import triangle.codeGenerator.entities.AddressableEntity; import triangle.codeGenerator.entities.AddressableEntity;
import triangle.codeGenerator.entities.BarPrimitiveRoutine;
import triangle.codeGenerator.entities.EqualityRoutine; import triangle.codeGenerator.entities.EqualityRoutine;
import triangle.codeGenerator.entities.FetchableEntity; import triangle.codeGenerator.entities.FetchableEntity;
import triangle.codeGenerator.entities.Field; import triangle.codeGenerator.entities.Field;
@ -740,6 +741,9 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
elaborateStdPrimRoutine(StdEnvironment.puteolDecl, Primitive.PUTEOL); elaborateStdPrimRoutine(StdEnvironment.puteolDecl, Primitive.PUTEOL);
elaborateStdEqRoutine(StdEnvironment.equalDecl, Primitive.EQ); elaborateStdEqRoutine(StdEnvironment.equalDecl, Primitive.EQ);
elaborateStdEqRoutine(StdEnvironment.unequalDecl, Primitive.NE); elaborateStdEqRoutine(StdEnvironment.unequalDecl, Primitive.NE);
StdEnvironment.barDecl.entity = new BarPrimitiveRoutine();
} }
boolean tableDetailsReqd; boolean tableDetailsReqd;

@ -0,0 +1,27 @@
package triangle.codeGenerator.entities;
import triangle.abstractMachine.Machine;
import triangle.abstractMachine.OpCode;
import triangle.abstractMachine.Primitive;
import triangle.abstractMachine.Register;
import triangle.codeGenerator.Emitter;
import triangle.codeGenerator.Frame;
public class BarPrimitiveRoutine extends RuntimeEntity implements RoutineEntity {
public BarPrimitiveRoutine() {
super(Machine.closureSize);
}
public void encodeCall(Emitter emitter, Frame frame) {
//push the literal value of 100 onto the stack
emitter.emit(OpCode.LOADL, 0, 100);
emitter.emit(OpCode.CALL, Register.PB, Primitive.MULT);
}
public void encodeFetch(Emitter emitter, Frame frame) {
emitter.emit(OpCode.LOADA, 0, Register.SB, 0);
emitter.emit(OpCode.LOADA, Register.PB, Primitive.MULT);
}
}

Binary file not shown.

@ -9,7 +9,12 @@ in
b := 2; b := 2;
putint(a); putint(a);
puteol();
putint(b); putint(b);
puteol();
putint(|a); putint(|a);
putint(|b) puteol();
end putint(|b);
puteol()
end