Skip to content

Commit 15db8fa

Browse files
committed
New implementation of addOp in uvm.pas
1 parent 2ed5a43 commit 15db8fa

File tree

12 files changed

+336
-184
lines changed

12 files changed

+336
-184
lines changed

RhodusIDE/Win32/Debug/rhodusIDE.ini

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,35 @@ Width=2199
66
[memoOutput]
77
Top=4
88
Left=1
9-
Width=1462
9+
Width=1464
1010
Height=262
1111
[synEditor]
1212
Top=1
1313
Left=1
14-
Width=1464
15-
Height=939
14+
Width=1466
15+
Height=937
1616
[pnlRight]
1717
Top=86
18-
Left=1777
18+
Left=1779
1919
Width=412
20-
Height=1271
20+
Height=1269
2121
[pnlInfo]
22-
Top=582
22+
Top=580
2323
Left=1
2424
Width=410
2525
Height=688
2626
[pnlDrawing]
2727
Top=1
2828
Left=1
2929
Width=408
30-
Height=576
30+
Height=574
3131
[pnlLeftPanel]
3232
Top=86
3333
Left=0
3434
Width=300
35-
Height=1271
35+
Height=1269
3636
[FontPreferences]
3737
fontSize=15
3838
fontName=Consolas
3939
[IDE]
40-
theme=Carbon
40+
theme=Calypso SE

Rhodus_Version_3/RhodusVersionThreeProject.dpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ uses
9595
uMath in 'uMath.pas',
9696
uBuiltInGraphics in 'uBuiltInGraphics.pas',
9797
uRhodusLibTypes in '..\librhodus\uRhodusLibTypes.pas',
98-
uIntStack in '..\VirtualMachine\uIntStack.pas';
98+
uIntStack in '..\VirtualMachine\uIntStack.pas',
99+
uJumpTables in '..\VirtualMachine\uJumpTables.pas';
99100

100101
begin
101102
ReportMemoryLeaksOnShutdown := True;

Rhodus_Version_3/RhodusVersionThreeProject.dproj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
<DCCReference Include="uBuiltInGraphics.pas"/>
227227
<DCCReference Include="..\librhodus\uRhodusLibTypes.pas"/>
228228
<DCCReference Include="..\VirtualMachine\uIntStack.pas"/>
229+
<DCCReference Include="..\VirtualMachine\uJumpTables.pas"/>
229230
<BuildConfiguration Include="Base">
230231
<Key>Base</Key>
231232
</BuildConfiguration>
@@ -264,23 +265,23 @@
264265
<Overwrite>true</Overwrite>
265266
</Platform>
266267
</DeployFile>
267-
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule">
268-
<Platform Name="iOSSimulator">
268+
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule">
269+
<Platform Name="OSX32">
269270
<Overwrite>true</Overwrite>
270271
</Platform>
271272
</DeployFile>
272-
<DeployFile LocalName="Win32\Debug\RhodusVersionThreeProject.exe" Configuration="Debug" Class="ProjectOutput">
273+
<DeployFile LocalName="Win32\Release\RhodusVersionThreeProject.exe" Configuration="Release" Class="ProjectOutput">
273274
<Platform Name="Win32">
274275
<RemoteName>RhodusVersionThreeProject.exe</RemoteName>
275276
<Overwrite>true</Overwrite>
276277
</Platform>
277278
</DeployFile>
278-
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule">
279-
<Platform Name="OSX32">
279+
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule">
280+
<Platform Name="iOSSimulator">
280281
<Overwrite>true</Overwrite>
281282
</Platform>
282283
</DeployFile>
283-
<DeployFile LocalName="Win32\Release\RhodusVersionThreeProject.exe" Configuration="Release" Class="ProjectOutput">
284+
<DeployFile LocalName="Win32\Debug\RhodusVersionThreeProject.exe" Configuration="Debug" Class="ProjectOutput">
284285
<Platform Name="Win32">
285286
<RemoteName>RhodusVersionThreeProject.exe</RemoteName>
286287
<Overwrite>true</Overwrite>

Rhodus_Version_3/TestScripts/loops.rh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import testUtils
44
setColor ("yellow")
55
println ("---------------------- Loop Tests ------------------------")
66
setColor ("white")
7+
78
testUtils.beginTests ("Repeat/Until Tests")
89

910
// ----------------------------------------------
@@ -109,15 +110,13 @@ for i = 8 downto 3 do
109110
end;
110111
testUtils.runtestTrue (i == 2); // iteration loop will be one less than lower limit
111112

112-
113113
for i = 1 to 10 do
114114
if i == 5 then
115115
break;
116116
end;
117117
end;
118118
testUtils.runtestTrue (i == 5);
119119

120-
121120
for i = 1 to 10 do
122121
for j = 1 to 5 do
123122
if j == 3 then
@@ -130,6 +129,7 @@ for i = 1 to 10 do
130129
end;
131130
testUtils.runtestTrue (i == 5);
132131

132+
133133
// ----------------------------------------------
134134

135135
principal = 500;

Rhodus_Version_3/uBuiltInMath.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ procedure TBuiltInMath.getSin (vm : TObject);
102102
st := TVM (vm).pop;
103103
case st.stackType of
104104
stInteger : TVM (vm).push(sin (st.iValue));
105-
stDouble : TVM (vm).push (sin (st.dValue));
106-
stArray : begin
107-
TVM (vm).push(st.aValue.applyUniFunction(sin));
108-
end
105+
stDouble : TVM (vm).push (sin (st.dValue));
106+
stArray : begin
107+
TVM (vm).push(st.aValue.applyUniFunction(sin));
108+
end
109109
else
110110
raiseMathError ('sin');
111111
end;

Rhodus_Version_3/uCompile.pas

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ procedure TCompiler.compileIfStatement(node: TASTIf);
152152
jumpLocation_1, jumpLocation_2: integer;
153153
begin
154154
compileCode(node.condition);
155-
jumpLocation_1 := code.addByteCode(oJmpIfFalse);
155+
jumpLocation_1 := code.addByteCode(oJmpIfFalse, node.lineNumber);
156156
compileCode(node.thenStatementList);
157157

158158
if node.elseStatementList <> nil then
159159
begin
160-
jumpLocation_2 := code.addByteCode(oJmp);
160+
jumpLocation_2 := code.addByteCode(oJmp, node.lineNumber);
161161
code.setGotoLabel(jumpLocation_1, code.getCurrentInstructionPointer - jumpLocation_1);
162162
compileCode(node.elseStatementList);
163163
code.setGotoLabel(jumpLocation_2, code.getCurrentInstructionPointer - jumpLocation_2);
@@ -238,10 +238,10 @@ procedure TCompiler.compileForStatement(node: TASTFor);
238238

239239
// count up or down
240240
if node.iterationBlock.direction.nodeType = ntTo then
241-
code.addByteCode(oIsGt)
241+
code.addByteCode(oIsGt, node.lineNumber)
242242
else
243-
code.addByteCode(oIsLt);
244-
jumpLocation_1 := code.addByteCode(oJmpIfTrue);
243+
code.addByteCode(oIsLt, node.lineNumber);
244+
jumpLocation_1 := code.addByteCode(oJmpIfTrue, node.lineNumber);
245245

246246
// Compile the body
247247
compileCode(node.body);
@@ -263,7 +263,7 @@ procedure TCompiler.compileForStatement(node: TASTFor);
263263
code.addByteCode(oDec, symbol.symbolName, node.iterationBlock.stepValue);
264264
end;
265265

266-
jumpLocation_2 := code.addByteCode(oJmp);
266+
jumpLocation_2 := code.addByteCode(oJmp, node.iterationBlock.lineNumber);
267267
code.setGotoLabel(jumpLocation_2, again - code.getCurrentInstructionPointer + 1);
268268
code.setGotoLabel(jumpLocation_1, code.getCurrentInstructionPointer - jumpLocation_1);
269269

@@ -296,13 +296,13 @@ procedure TCompiler.compileWhileStatement(node: TASTNode);
296296
compileCode((node as TASTWhile).condition);
297297

298298
// record the jump location because we're going to patch the relative jump value later
299-
jumpLocation_exit := code.addByteCode(oJmpIfFalse);
299+
jumpLocation_exit := code.addByteCode(oJmpIfFalse, node.lineNumber);
300300

301301
// compile the body of while loop
302302
compileCode((node as TASTWhile).statementList);
303303

304304
// Record the location of the 'jump back' to jmp instruction
305-
jumpLocation_back := code.addByteCode(oJmp);
305+
jumpLocation_back := code.addByteCode(oJmp, node.lineNumber);
306306

307307
// Lastly, patch the relative jump instructions
308308
code.setGotoLabel(jumpLocation_back,
@@ -344,7 +344,7 @@ procedure TCompiler.compileRepeatStatement(node: TASTRepeat);
344344
// compile the condition statement in until
345345
compileCode(node.condition);
346346

347-
jumpLocation := code.addByteCode(oJmpIfFalse);
347+
jumpLocation := code.addByteCode(oJmpIfFalse, node.lineNumber);
348348
code.setGotoLabel(jumpLocation,
349349
again - code.getCurrentInstructionPointer + 1);
350350

@@ -537,8 +537,8 @@ procedure TCompiler.compileUserFunction(node: TASTNode);
537537
compilingFunction := True;
538538
compileCode(functionNode.body);
539539
compilingFunction := False;
540-
code.addByteCode(oPushNone);
541-
code.addByteCode(oRet); // This is to make sure we return
540+
code.addByteCode(oPushNone, functionNode.lineNumber);
541+
code.addByteCode(oRet, node.lineNumber); // This is to make sure we return
542542
code.compactCode();
543543
finally
544544
code := oldCode;
@@ -599,28 +599,28 @@ procedure TCompiler.compileBinOperator(node: TASTBinOp; opCode: Byte);
599599
begin
600600
compileCode(node.left);
601601
compileCode(node.right);
602-
code.addByteCode(opCode);
602+
code.addByteCode(opCode, node.lineNumber);
603603
end;
604604

605605
procedure TCompiler.compilePowerOperator(node: TASTPowerOp);
606606
begin
607607
compileCode(node.left);
608608
compileCode(node.right);
609-
code.addByteCode(oPower);
609+
code.addByteCode(oPower, node.lineNumber);
610610
end;
611611

612612

613613
procedure TCompiler.compileNotOperator (node : TASTNotOp);
614614
begin
615615
compileCode (node.expression);
616-
code.addByteCode (oNot);
616+
code.addByteCode (oNot, node.lineNumber);
617617
end;
618618

619619

620620
procedure TCompiler.compileUniOperator(node: TASTUniOp; opCode: Byte);
621621
begin
622622
compileCode(node.left);
623-
code.addByteCode(opCode);
623+
code.addByteCode(opCode, node.lineNumber);
624624
end;
625625

626626
procedure TCompiler.compilePrintStatement(node: TASTNode);
@@ -633,23 +633,23 @@ procedure TCompiler.compilePrintStatement(node: TASTNode);
633633
compileCode((node as TASTPrint).argumentList.list[i]);
634634

635635
code.addByteCode(oPushi, (node as TASTPrint).argumentList.list.Count, node.lineNumber);
636-
code.addByteCode(oPrint);
636+
code.addByteCode(oPrint, node.lineNumber);
637637
end
638638
else
639639
begin
640640
for i := 0 to (node as TASTPrintLn).argumentList.list.Count - 1 do
641641
compileCode((node as TASTPrintLn).argumentList.list[i]);
642642

643643
code.addByteCode(oPushi, (node as TASTPrintLn).argumentList.list.Count, node.lineNumber);
644-
code.addByteCode(oPrintln);
644+
code.addByteCode(oPrintln, node.lineNumber);
645645
end;
646646
end;
647647

648648

649649
procedure TCompiler.compileSetColor (node : TASTNode);
650650
begin
651651
compileCode((node as TASTSetColor).expression);
652-
code.addByteCode(oSetColor);
652+
code.addByteCode(oSetColor, node.lineNumber);
653653
end;
654654

655655

@@ -658,20 +658,20 @@ procedure TCompiler.compileAssert(node: TASTNode);
658658
if node is TASTAssertTrue then
659659
begin
660660
compileCode((node as TASTAssertTrue).expression);
661-
code.addByteCode(oAssertTrue);
661+
code.addByteCode(oAssertTrue, node.lineNumber);
662662
end
663663
else
664664
begin
665665
compileCode((node as TASTAssertFalse).expression);
666-
code.addByteCode(oAssertFalse);
666+
code.addByteCode(oAssertFalse, node.lineNumber);
667667
end;
668668
end;
669669

670670

671671
procedure TCompiler.compileHelp (node: TASTNode);
672672
begin
673673
compileCode((node as TASTHelp).expression);
674-
code.addByteCode(oHelp);
674+
code.addByteCode(oHelp, node.lineNumber);
675675
end;
676676

677677

@@ -698,18 +698,18 @@ procedure TCompiler.compileSwitchStatement(node: TASTSwitch);
698698
compileCode(node.switchExpression);
699699
for i := 0 to listOfCaseStatements.list.Count - 1 do
700700
begin
701-
code.addByteCode(oDup);
701+
code.addByteCode(oDup, node.switchExpression.lineNumber);
702702
code.addByteCode(oPushi, caseValues[i], node.lineNumber);
703-
code.addByteCode(oIsEq);
704-
jumpToLocation[i] := code.addByteCode(oJmpIfTrue);
703+
code.addByteCode(oIsEq, node.switchExpression.lineNumber);
704+
jumpToLocation[i] := code.addByteCode(oJmpIfTrue, node.switchExpression.lineNumber);
705705
end;
706-
elseJump := code.addByteCode(oJmp);
706+
elseJump := code.addByteCode(oJmp, node.lineNumber);
707707

708708
for i := 0 to listOfCaseStatements.list.Count - 1 do
709709
begin
710710
entryLocation[i] := code.getCurrentInstructionPointer;
711711
compileCode((listOfCaseStatements.list[i] as TASTCaseStatement).statementList);
712-
jumpToEndLocation[i] := code.addByteCode(oJmp);
712+
jumpToEndLocation[i] := code.addByteCode(oJmp, node.lineNumber);
713713
end;
714714

715715
elseDestination := code.getCurrentInstructionPointer;
@@ -719,7 +719,7 @@ procedure TCompiler.compileSwitchStatement(node: TASTSwitch);
719719
//code.addByteCode(oNop);
720720
code.setGotoLabel(elseJump, elseDestination - elseJump);
721721

722-
lastInstruction := code.addByteCode(oPopDup); // pop the dup
722+
lastInstruction := code.addByteCode(oPopDup, node.lineNumber); // pop the dup
723723
for i := 0 to listOfCaseStatements.list.Count - 1 do
724724
begin
725725
code.setGotoLabel(jumpToLocation[i], entryLocation[i] - jumpToLocation[i]);
@@ -825,7 +825,7 @@ procedure TCompiler.compileImportStmt(node: TASTImport);
825825
if not compiler.startCompilation(module, root, compilerError) then
826826
raise ECompilerException.Create (compilerError.errorMsg, compilerError.lineNumber, compilerError.columnNumber);
827827

828-
module.moduleProgram.addByteCode(oHalt);
828+
module.moduleProgram.addByteCode(oHalt, 0);
829829
finally
830830
root.Free;
831831
compiler.Free;
@@ -989,13 +989,13 @@ procedure TCompiler.compileSlice (node : TASTNode);
989989
sliceNode := TASTSlice (node);
990990
compileCode (sliceNode.lower);
991991
compileCode (sliceNode.upper);
992-
code.addByteCode(oBuildSlice);
992+
code.addByteCode(oBuildSlice, node.lineNumber);
993993
end;
994994

995995

996996
procedure TCompiler.compileSliceAll (node : TASTNode);
997997
begin
998-
code.addByteCode(oSliceAll);
998+
code.addByteCode(oSliceAll, node.lineNumber);
999999
end;
10001000

10011001

@@ -1052,14 +1052,14 @@ procedure TCompiler.compileCode(node: TASTNode);
10521052
begin
10531053
compileCode((node as TASTExpressionStatement).expression);
10541054
//if not interactive then
1055-
code.addByteCode(oPop);
1055+
code.addByteCode(oPop, node.lineNumber);
10561056
end;
10571057
ntFunction:
10581058
compileUserFunction(node);
10591059
ntReturn:
10601060
begin
10611061
compileCode((node as TASTReturn).expression);
1062-
code.addByteCode(oRet);
1062+
code.addByteCode(oRet, node.lineNumber);
10631063
end;
10641064
ntGlobalStmt:
10651065
compileGlobalVariable(node);
@@ -1119,7 +1119,7 @@ procedure TCompiler.compileCode(node: TASTNode);
11191119
compileBinOperator(node as TASTBinOp, oIsLte);
11201120

11211121
ntBoolean:
1122-
code.addByteCode(oPushb, (node as TASTBoolean).bValue);
1122+
code.addByteCode(oPushb, (node as TASTBoolean).bValue, node.lineNumber);
11231123
ntInteger:
11241124
code.addByteCode(oPushi, (node as TASTInteger).iValue, node.lineNumber);
11251125
ntFloat:
@@ -1134,7 +1134,7 @@ procedure TCompiler.compileCode(node: TASTNode);
11341134
end;
11351135
ntBreak:
11361136
// place holder for the jmp instruction
1137-
stackOfBreakStacks.Peek.Push(code.addByteCode(oJmp));
1137+
stackOfBreakStacks.Peek.Push(code.addByteCode(oJmp, node.lineNumber));
11381138
ntNull : begin end;
11391139
else
11401140
raise ECompilerException.Create('Internal error: Unrecognized node type in AST (compileCode): ' + TRttiEnumerationType.GetName(node.nodeType), 0, 0);

0 commit comments

Comments
 (0)