added bar stuff

main
simonkellet 1 year ago
parent b1da248676
commit dc5f17620e
  1. 7
      Triangle.Compiler/src/main/java/triangle/codeGenerator/Encoder.java
  2. 27
      Triangle.Compiler/src/main/java/triangle/codeGenerator/entities/BarPrimitiveRoutine.java
  3. 5
      Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/Checker.java
  4. 6
      Triangle.Compiler/src/main/java/triangle/optimiser/ConstantFolder.java
  5. 2
      Triangle.Compiler/src/main/java/triangle/syntacticAnalyzer/Parser.java
  6. BIN
      build/libs/Triangle-Tools.jar
  7. BIN
      programs/adddeep-folded.tam
  8. BIN
      programs/adddeep-notfolded.tam
  9. BIN
      programs/bardemo.tam
  10. 2
      programs/bardemo.tri
  11. BIN
      programs/plusplusidea.tam
  12. 8
      programs/plusplusidea.tri
  13. BIN
      programs/repeatuntil.tam

@ -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;
@ -184,6 +185,11 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
@Override @Override
public Void visitRepeatCommand(RepeatCommand ast, Frame frame) { public Void visitRepeatCommand(RepeatCommand ast, Frame frame) {
var loopAddr = emitter.getNextInstrAddr();
ast.C.visit(this, frame);
ast.E.visit(this, frame);
emitter.emit(OpCode.JUMPIF, Machine.falseRep, Register.CB, loopAddr);
return null; return null;
} }
@ -740,6 +746,7 @@ 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(); //bardemo.tri now works
} }
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) {
//machine code to load 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);
}
}

@ -188,6 +188,11 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
@Override @Override
public Void visitRepeatCommand(RepeatCommand ast, Void arg) { public Void visitRepeatCommand(RepeatCommand ast, Void arg) {
var eType = ast.E.visit(this);
checkAndReportError(eType.equals(StdEnvironment.booleanType), "Boolean expression expected here", ast.E);
ast.C.visit(this);
return null; return null;
} }

@ -497,14 +497,13 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
return null; return null;
} }
/*
@Override @Override
public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) { public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) {
return null; return null;
} }
*/
// TODO uncomment if you've implemented the repeat command /*
* Now not needed!
@Override @Override
public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) { public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) {
ast.C.visit(this); ast.C.visit(this);
@ -514,6 +513,7 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
} }
return null; return null;
} }
*/
@Override @Override
public AbstractSyntaxTree visitMultipleArrayAggregate(MultipleArrayAggregate ast, Void arg) { public AbstractSyntaxTree visitMultipleArrayAggregate(MultipleArrayAggregate ast, Void arg) {

@ -602,7 +602,7 @@ public class Parser {
start(declarationPos); start(declarationPos);
switch (currentToken.kind) { switch (currentToken.kind) {
case Token.CONST: { case Token.CONST: {
acceptIt(); acceptIt();
Identifier iAST = parseIdentifier(); Identifier iAST = parseIdentifier();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -5,7 +5,7 @@ let
in in
begin begin
a := 1; a := 4;
b := 2; b := 2;
putint(a); putint(a);

Binary file not shown.

@ -0,0 +1,8 @@
let
var a: Integer
in
begin
a := 0;
a := a + 1;
putint(a);
end

Binary file not shown.
Loading…
Cancel
Save