|
|
@ -97,8 +97,7 @@ public final class Encoder implements Visitor { |
|
|
|
public Object visitAssignCommand(AssignCommand ast, Object o) { |
|
|
|
public Object visitAssignCommand(AssignCommand ast, Object o) { |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Integer valSize = (Integer) ast.E.visit(this, frame); |
|
|
|
Integer valSize = (Integer) ast.E.visit(this, frame); |
|
|
|
encodeStore(ast.V, new Frame(frame, valSize.intValue()), |
|
|
|
encodeStore(ast.V, new Frame(frame, valSize.intValue()), valSize.intValue()); |
|
|
|
valSize.intValue()); |
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -193,8 +192,7 @@ public Object visitCallExpression(CallExpression ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitCharacterExpression(CharacterExpression ast, |
|
|
|
public Object visitCharacterExpression(CharacterExpression ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Integer valSize = (Integer) ast.type.visit(this, null); |
|
|
|
Integer valSize = (Integer) ast.type.visit(this, null); |
|
|
|
emit(Machine.LOADLop, 0, 0, ast.CL.spelling.charAt(1)); |
|
|
|
emit(Machine.LOADLop, 0, 0, ast.CL.spelling.charAt(1)); |
|
|
@ -270,8 +268,7 @@ public Object visitVnameExpression(VnameExpression ast, Object o) { |
|
|
|
|
|
|
|
|
|
|
|
// Declarations
|
|
|
|
// Declarations
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, |
|
|
|
public Object visitBinaryOperatorDeclaration(BinaryOperatorDeclaration ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
return Integer.valueOf(0); |
|
|
|
return Integer.valueOf(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -282,12 +279,10 @@ public Object visitConstDeclaration(ConstDeclaration ast, Object o) { |
|
|
|
|
|
|
|
|
|
|
|
if (ast.E instanceof CharacterExpression) { |
|
|
|
if (ast.E instanceof CharacterExpression) { |
|
|
|
CharacterLiteral CL = ((CharacterExpression) ast.E).CL; |
|
|
|
CharacterLiteral CL = ((CharacterExpression) ast.E).CL; |
|
|
|
ast.entity = new KnownValue(Machine.characterSize, |
|
|
|
ast.entity = new KnownValue(Machine.characterSize, characterValuation(CL.spelling)); |
|
|
|
characterValuation(CL.spelling)); |
|
|
|
|
|
|
|
} else if (ast.E instanceof IntegerExpression) { |
|
|
|
} else if (ast.E instanceof IntegerExpression) { |
|
|
|
IntegerLiteral IL = ((IntegerExpression) ast.E).IL; |
|
|
|
IntegerLiteral IL = ((IntegerExpression) ast.E).IL; |
|
|
|
ast.entity = new KnownValue(Machine.integerSize, |
|
|
|
ast.entity = new KnownValue(Machine.integerSize, Integer.parseInt(IL.spelling)); |
|
|
|
Integer.parseInt(IL.spelling)); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
int valSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
int valSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
ast.entity = new UnknownValue(valSize, frame.level, frame.size); |
|
|
|
ast.entity = new UnknownValue(valSize, frame.level, frame.size); |
|
|
@ -326,8 +321,7 @@ public Object visitProcDeclaration(ProcDeclaration ast, Object o) { |
|
|
|
int argsSize = 0; |
|
|
|
int argsSize = 0; |
|
|
|
|
|
|
|
|
|
|
|
emit(Machine.JUMPop, 0, Machine.CBr, 0); |
|
|
|
emit(Machine.JUMPop, 0, Machine.CBr, 0); |
|
|
|
ast.entity = new KnownRoutine(Machine.closureSize, frame.level, |
|
|
|
ast.entity = new KnownRoutine(Machine.closureSize, frame.level, nextInstrAddr); |
|
|
|
nextInstrAddr); |
|
|
|
|
|
|
|
writeTableDetails(ast); |
|
|
|
writeTableDetails(ast); |
|
|
|
if (frame.level == Machine.maxRoutineLevel) |
|
|
|
if (frame.level == Machine.maxRoutineLevel) |
|
|
|
reporter.reportRestriction("can't nest routines so deeply"); |
|
|
|
reporter.reportRestriction("can't nest routines so deeply"); |
|
|
@ -361,8 +355,7 @@ public Object visitTypeDeclaration(TypeDeclaration ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, |
|
|
|
public Object visitUnaryOperatorDeclaration(UnaryOperatorDeclaration ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
return Integer.valueOf(0); |
|
|
|
return Integer.valueOf(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -380,8 +373,7 @@ public Object visitVarDeclaration(VarDeclaration ast, Object o) { |
|
|
|
|
|
|
|
|
|
|
|
// Array Aggregates
|
|
|
|
// Array Aggregates
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, |
|
|
|
public Object visitMultipleArrayAggregate(MultipleArrayAggregate ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
int elemSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
int elemSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
Frame frame1 = new Frame(frame, elemSize); |
|
|
|
Frame frame1 = new Frame(frame, elemSize); |
|
|
@ -396,8 +388,7 @@ public Object visitSingleArrayAggregate(SingleArrayAggregate ast, Object o) { |
|
|
|
|
|
|
|
|
|
|
|
// Record Aggregates
|
|
|
|
// Record Aggregates
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, |
|
|
|
public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
int fieldSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
int fieldSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
Frame frame1 = new Frame(frame, fieldSize); |
|
|
|
Frame frame1 = new Frame(frame, fieldSize); |
|
|
@ -406,8 +397,7 @@ public Object visitMultipleRecordAggregate(MultipleRecordAggregate ast, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitSingleRecordAggregate(SingleRecordAggregate ast, |
|
|
|
public Object visitSingleRecordAggregate(SingleRecordAggregate ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
return ast.E.visit(this, o); |
|
|
|
return ast.E.visit(this, o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -425,8 +415,7 @@ public Object visitConstFormalParameter(ConstFormalParameter ast, Object o) { |
|
|
|
public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) { |
|
|
|
public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) { |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
int argsSize = Machine.closureSize; |
|
|
|
int argsSize = Machine.closureSize; |
|
|
|
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level, |
|
|
|
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level, -frame.size - argsSize); |
|
|
|
-frame.size - argsSize); |
|
|
|
|
|
|
|
writeTableDetails(ast); |
|
|
|
writeTableDetails(ast); |
|
|
|
return Integer.valueOf(argsSize); |
|
|
|
return Integer.valueOf(argsSize); |
|
|
|
} |
|
|
|
} |
|
|
@ -435,8 +424,7 @@ public Object visitFuncFormalParameter(FuncFormalParameter ast, Object o) { |
|
|
|
public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) { |
|
|
|
public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) { |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
int argsSize = Machine.closureSize; |
|
|
|
int argsSize = Machine.closureSize; |
|
|
|
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level, |
|
|
|
ast.entity = new UnknownRoutine(Machine.closureSize, frame.level, -frame.size - argsSize); |
|
|
|
-frame.size - argsSize); |
|
|
|
|
|
|
|
writeTableDetails(ast); |
|
|
|
writeTableDetails(ast); |
|
|
|
return Integer.valueOf(argsSize); |
|
|
|
return Integer.valueOf(argsSize); |
|
|
|
} |
|
|
|
} |
|
|
@ -445,21 +433,18 @@ public Object visitProcFormalParameter(ProcFormalParameter ast, Object o) { |
|
|
|
public Object visitVarFormalParameter(VarFormalParameter ast, Object o) { |
|
|
|
public Object visitVarFormalParameter(VarFormalParameter ast, Object o) { |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
ast.T.visit(this, null); |
|
|
|
ast.T.visit(this, null); |
|
|
|
ast.entity = new UnknownAddress(Machine.addressSize, frame.level, |
|
|
|
ast.entity = new UnknownAddress(Machine.addressSize, frame.level, -frame.size - Machine.addressSize); |
|
|
|
-frame.size - Machine.addressSize); |
|
|
|
|
|
|
|
writeTableDetails(ast); |
|
|
|
writeTableDetails(ast); |
|
|
|
return Integer.valueOf(Machine.addressSize); |
|
|
|
return Integer.valueOf(Machine.addressSize); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitEmptyFormalParameterSequence( |
|
|
|
public Object visitEmptyFormalParameterSequence(EmptyFormalParameterSequence ast, Object o) { |
|
|
|
EmptyFormalParameterSequence ast, Object o) { |
|
|
|
|
|
|
|
return Integer.valueOf(0); |
|
|
|
return Integer.valueOf(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitMultipleFormalParameterSequence( |
|
|
|
public Object visitMultipleFormalParameterSequence(MultipleFormalParameterSequence ast, Object o) { |
|
|
|
MultipleFormalParameterSequence ast, Object o) { |
|
|
|
|
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
int argsSize1 = ((Integer) ast.FPS.visit(this, frame)).intValue(); |
|
|
|
int argsSize1 = ((Integer) ast.FPS.visit(this, frame)).intValue(); |
|
|
|
Frame frame1 = new Frame(frame, argsSize1); |
|
|
|
Frame frame1 = new Frame(frame, argsSize1); |
|
|
@ -468,8 +453,7 @@ public Object visitMultipleFormalParameterSequence( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitSingleFormalParameterSequence( |
|
|
|
public Object visitSingleFormalParameterSequence(SingleFormalParameterSequence ast, Object o) { |
|
|
|
SingleFormalParameterSequence ast, Object o) { |
|
|
|
|
|
|
|
return ast.FP.visit(this, o); |
|
|
|
return ast.FP.visit(this, o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -489,8 +473,8 @@ public Object visitFuncActualParameter(FuncActualParameter ast, Object o) { |
|
|
|
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement); |
|
|
|
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement); |
|
|
|
} else if (ast.I.decl.entity instanceof UnknownRoutine) { |
|
|
|
} else if (ast.I.decl.entity instanceof UnknownRoutine) { |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address; |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address; |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement; |
|
|
|
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement; |
|
|
|
// static link, code address
|
|
|
|
// static link, code address
|
|
|
@ -510,8 +494,8 @@ public Object visitProcActualParameter(ProcActualParameter ast, Object o) { |
|
|
|
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement); |
|
|
|
emit(Machine.LOADAop, 0, Machine.CBr, address.displacement); |
|
|
|
} else if (ast.I.decl.entity instanceof UnknownRoutine) { |
|
|
|
} else if (ast.I.decl.entity instanceof UnknownRoutine) { |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address; |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.I.decl.entity).address; |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
} else if (ast.I.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement; |
|
|
|
int displacement = ((PrimitiveRoutine) ast.I.decl.entity).displacement; |
|
|
|
// static link, code address
|
|
|
|
// static link, code address
|
|
|
@ -528,14 +512,12 @@ public Object visitVarActualParameter(VarActualParameter ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitEmptyActualParameterSequence( |
|
|
|
public Object visitEmptyActualParameterSequence(EmptyActualParameterSequence ast, Object o) { |
|
|
|
EmptyActualParameterSequence ast, Object o) { |
|
|
|
|
|
|
|
return Integer.valueOf(0); |
|
|
|
return Integer.valueOf(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitMultipleActualParameterSequence( |
|
|
|
public Object visitMultipleActualParameterSequence(MultipleActualParameterSequence ast, Object o) { |
|
|
|
MultipleActualParameterSequence ast, Object o) { |
|
|
|
|
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
int argsSize1 = ((Integer) ast.AP.visit(this, frame)).intValue(); |
|
|
|
int argsSize1 = ((Integer) ast.AP.visit(this, frame)).intValue(); |
|
|
|
Frame frame1 = new Frame(frame, argsSize1); |
|
|
|
Frame frame1 = new Frame(frame, argsSize1); |
|
|
@ -544,8 +526,7 @@ public Object visitMultipleActualParameterSequence( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitSingleActualParameterSequence( |
|
|
|
public Object visitSingleActualParameterSequence(SingleActualParameterSequence ast, Object o) { |
|
|
|
SingleActualParameterSequence ast, Object o) { |
|
|
|
|
|
|
|
return ast.AP.visit(this, o); |
|
|
|
return ast.AP.visit(this, o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -592,8 +573,7 @@ public Object visitErrorTypeDenoter(ErrorTypeDenoter ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, |
|
|
|
public Object visitSimpleTypeDenoter(SimpleTypeDenoter ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
return Integer.valueOf(0); |
|
|
|
return Integer.valueOf(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -619,8 +599,7 @@ public Object visitRecordTypeDenoter(RecordTypeDenoter ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, |
|
|
|
public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
int offset = ((Integer) o).intValue(); |
|
|
|
int offset = ((Integer) o).intValue(); |
|
|
|
int fieldSize; |
|
|
|
int fieldSize; |
|
|
|
|
|
|
|
|
|
|
@ -637,8 +616,7 @@ public Object visitMultipleFieldTypeDenoter(MultipleFieldTypeDenoter ast, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, |
|
|
|
public Object visitSingleFieldTypeDenoter(SingleFieldTypeDenoter ast, Object o) { |
|
|
|
Object o) { |
|
|
|
|
|
|
|
int offset = ((Integer) o).intValue(); |
|
|
|
int offset = ((Integer) o).intValue(); |
|
|
|
int fieldSize; |
|
|
|
int fieldSize; |
|
|
|
|
|
|
|
|
|
|
@ -663,12 +641,11 @@ public Object visitIdentifier(Identifier ast, Object o) { |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
if (ast.decl.entity instanceof KnownRoutine) { |
|
|
|
if (ast.decl.entity instanceof KnownRoutine) { |
|
|
|
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address; |
|
|
|
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address; |
|
|
|
emit(Machine.CALLop, displayRegister(frame.level, address.level), |
|
|
|
emit(Machine.CALLop, displayRegister(frame.level, address.level), Machine.CBr, address.displacement); |
|
|
|
Machine.CBr, address.displacement); |
|
|
|
|
|
|
|
} else if (ast.decl.entity instanceof UnknownRoutine) { |
|
|
|
} else if (ast.decl.entity instanceof UnknownRoutine) { |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address; |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address; |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
emit(Machine.CALLIop, 0, 0, 0); |
|
|
|
emit(Machine.CALLIop, 0, 0, 0); |
|
|
|
} else if (ast.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
} else if (ast.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement; |
|
|
|
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement; |
|
|
@ -692,12 +669,11 @@ public Object visitOperator(Operator ast, Object o) { |
|
|
|
Frame frame = (Frame) o; |
|
|
|
Frame frame = (Frame) o; |
|
|
|
if (ast.decl.entity instanceof KnownRoutine) { |
|
|
|
if (ast.decl.entity instanceof KnownRoutine) { |
|
|
|
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address; |
|
|
|
ObjectAddress address = ((KnownRoutine) ast.decl.entity).address; |
|
|
|
emit(Machine.CALLop, displayRegister(frame.level, address.level), |
|
|
|
emit(Machine.CALLop, displayRegister(frame.level, address.level), Machine.CBr, address.displacement); |
|
|
|
Machine.CBr, address.displacement); |
|
|
|
|
|
|
|
} else if (ast.decl.entity instanceof UnknownRoutine) { |
|
|
|
} else if (ast.decl.entity instanceof UnknownRoutine) { |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address; |
|
|
|
ObjectAddress address = ((UnknownRoutine) ast.decl.entity).address; |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.closureSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
emit(Machine.CALLIop, 0, 0, 0); |
|
|
|
emit(Machine.CALLIop, 0, 0, 0); |
|
|
|
} else if (ast.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
} else if (ast.decl.entity instanceof PrimitiveRoutine) { |
|
|
|
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement; |
|
|
|
int displacement = ((PrimitiveRoutine) ast.decl.entity).displacement; |
|
|
@ -749,8 +725,7 @@ public Object visitSubscriptVname(SubscriptVname ast, Object o) { |
|
|
|
indexSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
indexSize = ((Integer) ast.E.visit(this, frame)).intValue(); |
|
|
|
if (elemSize != 1) { |
|
|
|
if (elemSize != 1) { |
|
|
|
emit(Machine.LOADLop, 0, 0, elemSize); |
|
|
|
emit(Machine.LOADLop, 0, 0, elemSize); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.multDisplacement); |
|
|
|
Machine.multDisplacement); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (ast.indexed) |
|
|
|
if (ast.indexed) |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
@ -785,8 +760,7 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Decides run-time representation of a standard constant.
|
|
|
|
// Decides run-time representation of a standard constant.
|
|
|
|
private final void elaborateStdConst(Declaration constDeclaration, |
|
|
|
private final void elaborateStdConst(Declaration constDeclaration, int value) { |
|
|
|
int value) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (constDeclaration instanceof ConstDeclaration) { |
|
|
|
if (constDeclaration instanceof ConstDeclaration) { |
|
|
|
ConstDeclaration decl = (ConstDeclaration) constDeclaration; |
|
|
|
ConstDeclaration decl = (ConstDeclaration) constDeclaration; |
|
|
@ -797,20 +771,17 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Decides run-time representation of a standard routine.
|
|
|
|
// Decides run-time representation of a standard routine.
|
|
|
|
private final void elaborateStdPrimRoutine(Declaration routineDeclaration, |
|
|
|
private final void elaborateStdPrimRoutine(Declaration routineDeclaration, int routineOffset) { |
|
|
|
int routineOffset) { |
|
|
|
|
|
|
|
routineDeclaration.entity = new PrimitiveRoutine(Machine.closureSize, routineOffset); |
|
|
|
routineDeclaration.entity = new PrimitiveRoutine(Machine.closureSize, routineOffset); |
|
|
|
writeTableDetails(routineDeclaration); |
|
|
|
writeTableDetails(routineDeclaration); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final void elaborateStdEqRoutine(Declaration routineDeclaration, |
|
|
|
private final void elaborateStdEqRoutine(Declaration routineDeclaration, int routineOffset) { |
|
|
|
int routineOffset) { |
|
|
|
|
|
|
|
routineDeclaration.entity = new EqualityRoutine(Machine.closureSize, routineOffset); |
|
|
|
routineDeclaration.entity = new EqualityRoutine(Machine.closureSize, routineOffset); |
|
|
|
writeTableDetails(routineDeclaration); |
|
|
|
writeTableDetails(routineDeclaration); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final void elaborateStdRoutine(Declaration routineDeclaration, |
|
|
|
private final void elaborateStdRoutine(Declaration routineDeclaration, int routineOffset) { |
|
|
|
int routineOffset) { |
|
|
|
|
|
|
|
routineDeclaration.entity = new KnownRoutine(Machine.closureSize, 0, routineOffset); |
|
|
|
routineDeclaration.entity = new KnownRoutine(Machine.closureSize, 0, routineOffset); |
|
|
|
writeTableDetails(routineDeclaration); |
|
|
|
writeTableDetails(routineDeclaration); |
|
|
|
} |
|
|
|
} |
|
|
@ -947,18 +918,17 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
if (baseObject instanceof KnownAddress) { |
|
|
|
if (baseObject instanceof KnownAddress) { |
|
|
|
ObjectAddress address = ((KnownAddress) baseObject).address; |
|
|
|
ObjectAddress address = ((KnownAddress) baseObject).address; |
|
|
|
if (V.indexed) { |
|
|
|
if (V.indexed) { |
|
|
|
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), |
|
|
|
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), address.displacement + V.offset); |
|
|
|
address.displacement + V.offset); |
|
|
|
|
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.STOREIop, valSize, 0, 0); |
|
|
|
emit(Machine.STOREIop, valSize, 0, 0); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
emit(Machine.STOREop, valSize, displayRegister(frame.level, |
|
|
|
emit(Machine.STOREop, valSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement + V.offset); |
|
|
|
address.displacement + V.offset); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (baseObject instanceof UnknownAddress) { |
|
|
|
} else if (baseObject instanceof UnknownAddress) { |
|
|
|
ObjectAddress address = ((UnknownAddress) baseObject).address; |
|
|
|
ObjectAddress address = ((UnknownAddress) baseObject).address; |
|
|
|
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
if (V.indexed) |
|
|
|
if (V.indexed) |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
if (V.offset != 0) { |
|
|
|
if (V.offset != 0) { |
|
|
@ -988,22 +958,20 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
// presumably offset = 0 and indexed = false
|
|
|
|
// presumably offset = 0 and indexed = false
|
|
|
|
int value = ((KnownValue) baseObject).value; |
|
|
|
int value = ((KnownValue) baseObject).value; |
|
|
|
emit(Machine.LOADLop, 0, 0, value); |
|
|
|
emit(Machine.LOADLop, 0, 0, value); |
|
|
|
} else if ((baseObject instanceof UnknownValue) || |
|
|
|
} else if ((baseObject instanceof UnknownValue) || (baseObject instanceof KnownAddress)) { |
|
|
|
(baseObject instanceof KnownAddress)) { |
|
|
|
|
|
|
|
ObjectAddress address = (baseObject instanceof UnknownValue) ? ((UnknownValue) baseObject).address |
|
|
|
ObjectAddress address = (baseObject instanceof UnknownValue) ? ((UnknownValue) baseObject).address |
|
|
|
: ((KnownAddress) baseObject).address; |
|
|
|
: ((KnownAddress) baseObject).address; |
|
|
|
if (V.indexed) { |
|
|
|
if (V.indexed) { |
|
|
|
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), |
|
|
|
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), address.displacement + V.offset); |
|
|
|
address.displacement + V.offset); |
|
|
|
|
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.LOADIop, valSize, 0, 0); |
|
|
|
emit(Machine.LOADIop, valSize, 0, 0); |
|
|
|
} else |
|
|
|
} else |
|
|
|
emit(Machine.LOADop, valSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, valSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement + V.offset); |
|
|
|
address.displacement + V.offset); |
|
|
|
} else if (baseObject instanceof UnknownAddress) { |
|
|
|
} else if (baseObject instanceof UnknownAddress) { |
|
|
|
ObjectAddress address = ((UnknownAddress) baseObject).address; |
|
|
|
ObjectAddress address = ((UnknownAddress) baseObject).address; |
|
|
|
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
if (V.indexed) |
|
|
|
if (V.indexed) |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
if (V.offset != 0) { |
|
|
|
if (V.offset != 0) { |
|
|
@ -1026,14 +994,13 @@ public Object visitProgram(Program ast, Object o) { |
|
|
|
// If indexed = true, code will have been generated to load an index value.
|
|
|
|
// If indexed = true, code will have been generated to load an index value.
|
|
|
|
if (baseObject instanceof KnownAddress) { |
|
|
|
if (baseObject instanceof KnownAddress) { |
|
|
|
ObjectAddress address = ((KnownAddress) baseObject).address; |
|
|
|
ObjectAddress address = ((KnownAddress) baseObject).address; |
|
|
|
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), |
|
|
|
emit(Machine.LOADAop, 0, displayRegister(frame.level, address.level), address.displacement + V.offset); |
|
|
|
address.displacement + V.offset); |
|
|
|
|
|
|
|
if (V.indexed) |
|
|
|
if (V.indexed) |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
} else if (baseObject instanceof UnknownAddress) { |
|
|
|
} else if (baseObject instanceof UnknownAddress) { |
|
|
|
ObjectAddress address = ((UnknownAddress) baseObject).address; |
|
|
|
ObjectAddress address = ((UnknownAddress) baseObject).address; |
|
|
|
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, |
|
|
|
emit(Machine.LOADop, Machine.addressSize, displayRegister(frame.level, address.level), |
|
|
|
address.level), address.displacement); |
|
|
|
address.displacement); |
|
|
|
if (V.indexed) |
|
|
|
if (V.indexed) |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
emit(Machine.CALLop, Machine.SBr, Machine.PBr, Machine.addDisplacement); |
|
|
|
if (V.offset != 0) { |
|
|
|
if (V.offset != 0) { |
|
|
|