loopwhilecom. now works
This commit is contained in:
parent
a3f6b13947
commit
c505b9cb2c
6
.classpath
Normal file
6
.classpath
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -60,3 +60,4 @@ local.properties
|
||||
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||
#.project
|
||||
/.gradle/
|
||||
/build/
|
||||
|
8
.project
8
.project
@ -1,10 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>a5-triangle-tools</name>
|
||||
<name>Triangle-Tools</name>
|
||||
<comment>Project a5-triangle-tools created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
@ -12,6 +17,7 @@
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
@ -181,11 +181,29 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
|
||||
var loopAddr = emitter.getNextInstrAddr();
|
||||
ast.C.visit(this, frame);
|
||||
emitter.patch(jumpAddr);
|
||||
|
||||
ast.E.visit(this, frame);
|
||||
emitter.emit(OpCode.JUMPIF, Machine.trueRep, Register.CB, loopAddr);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitLoopWhile(LoopWhile ast, Frame frame) {
|
||||
var loopAddr = emitter.getNextInstrAddr();
|
||||
ast.C1.visit(this, frame); //(LOOP = C1)
|
||||
|
||||
ast.E.visit(this, frame); //check if the while is false first (WHILE = E)
|
||||
var jumpIfAddr = emitter.emit(OpCode.JUMPIF, Machine.falseRep, Register.CB, 0);
|
||||
//store this address
|
||||
|
||||
ast.C2.visit(this, frame); // visit the do section now (DO = C2)
|
||||
emitter.emit(OpCode.JUMP, Machine.trueRep, Register.CB, loopAddr); //jump back to C1
|
||||
|
||||
emitter.patch(jumpIfAddr); //patch the jmpIfAddr to go back to the while section
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Expressions
|
||||
@Override
|
||||
public Integer visitArrayExpression(ArrayExpression ast, Frame frame) {
|
||||
@ -794,10 +812,4 @@ public final class Encoder implements ActualParameterVisitor<Frame, Integer>,
|
||||
var baseObject = (AddressableEntity) V.visit(this, frame);
|
||||
baseObject.encodeFetchAddress(emitter, frame, V);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitLoopWhile(LoopWhile loopWhile, Frame arg) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -497,6 +497,17 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSyntaxTree visitLoopWhile(LoopWhile ast, Void arg) {
|
||||
ast.C1.visit(this);
|
||||
AbstractSyntaxTree replacement = ast.E.visit(this);
|
||||
if (replacement != null) {
|
||||
ast.E = (Expression) replacement;
|
||||
}
|
||||
ast.C2.visit(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO uncomment if you've implemented the repeat command
|
||||
// @Override
|
||||
// public AbstractSyntaxTree visitRepeatCommand(RepeatCommand ast, Void arg) {
|
||||
@ -596,11 +607,4 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
|
||||
// any unhandled situation (i.e., not foldable) is ignored
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSyntaxTree visitLoopWhile(LoopWhile loopWhile, Void arg) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -386,7 +386,6 @@ public class Parser {
|
||||
case Token.IN:
|
||||
case Token.EOT:
|
||||
case Token.RCURLY:
|
||||
|
||||
finish(commandPos);
|
||||
commandAST = new EmptyCommand(commandPos);
|
||||
break;
|
||||
|
@ -169,7 +169,7 @@ public class LayoutVisitor implements ActualParameterVisitor<Void, DrawingTree>,
|
||||
var d1 = ast.C1.visit(this);
|
||||
var d2 = ast.E.visit(this);
|
||||
var d3 = ast.C2.visit(this);
|
||||
return layoutTernary("LoopWhile.", d1, d2, d3);
|
||||
return layoutTernary("LoopWhileCom.", d1, d2, d3);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,6 +53,11 @@ public class TestScanner {
|
||||
compileExpectSuccess("/while-curly.tri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoopWhileDoCommand() {
|
||||
compileExpectSuccess("/loopwhile.tri");
|
||||
}
|
||||
|
||||
private void compileExpectSuccess(String filename) {
|
||||
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
|
||||
// which adds the programs directory to the list of places Java can easily find files
|
||||
|
Binary file not shown.
BIN
loopwhile.tam
BIN
loopwhile.tam
Binary file not shown.
@ -6,9 +6,6 @@ let
|
||||
in
|
||||
begin
|
||||
a := 0;
|
||||
b := 10;
|
||||
putint(b);
|
||||
|
||||
loop
|
||||
begin
|
||||
put('a');
|
||||
@ -16,5 +13,4 @@ begin
|
||||
end
|
||||
while a < 5 do
|
||||
put('b');
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user