added bar stuff
This commit is contained in:
parent
b1da248676
commit
dc5f17620e
@ -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) {
|
||||||
|
Binary file not shown.
BIN
programs/adddeep-folded.tam
Normal file
BIN
programs/adddeep-folded.tam
Normal file
Binary file not shown.
BIN
programs/adddeep-notfolded.tam
Normal file
BIN
programs/adddeep-notfolded.tam
Normal file
Binary file not shown.
BIN
programs/bardemo.tam
Normal file
BIN
programs/bardemo.tam
Normal file
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);
|
||||||
|
BIN
programs/plusplusidea.tam
Normal file
BIN
programs/plusplusidea.tam
Normal file
Binary file not shown.
8
programs/plusplusidea.tri
Normal file
8
programs/plusplusidea.tri
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
let
|
||||||
|
var a: Integer
|
||||||
|
in
|
||||||
|
begin
|
||||||
|
a := 0;
|
||||||
|
a := a + 1;
|
||||||
|
putint(a);
|
||||||
|
end
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user