added bar stuff

This commit is contained in:
simonkellet 2023-10-02 17:48:23 +01:00
parent b1da248676
commit dc5f17620e
13 changed files with 52 additions and 5 deletions

View File

@ -101,6 +101,7 @@ import triangle.abstractSyntaxTrees.vnames.SimpleVname;
import triangle.abstractSyntaxTrees.vnames.SubscriptVname;
import triangle.abstractSyntaxTrees.vnames.Vname;
import triangle.codeGenerator.entities.AddressableEntity;
import triangle.codeGenerator.entities.BarPrimitiveRoutine;
import triangle.codeGenerator.entities.EqualityRoutine;
import triangle.codeGenerator.entities.FetchableEntity;
import triangle.codeGenerator.entities.Field;
@ -184,6 +185,11 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
@Override
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;
}
@ -740,6 +746,7 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
elaborateStdPrimRoutine(StdEnvironment.puteolDecl, Primitive.PUTEOL);
elaborateStdEqRoutine(StdEnvironment.equalDecl, Primitive.EQ);
elaborateStdEqRoutine(StdEnvironment.unequalDecl, Primitive.NE);
StdEnvironment.barDecl.entity = new BarPrimitiveRoutine(); //bardemo.tri now works
}
boolean tableDetailsReqd;

View File

@ -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);
}
}

View File

@ -188,6 +188,11 @@ public final class Checker implements ActualParameterVisitor<FormalParameter, Vo
@Override
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;
}

View File

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

View File

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

Binary file not shown.

BIN
programs/adddeep-folded.tam Normal file

Binary file not shown.

Binary file not shown.

BIN
programs/bardemo.tam Normal file

Binary file not shown.

View File

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

BIN
programs/plusplusidea.tam Normal file

Binary file not shown.

View File

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

Binary file not shown.