@@ -152,12 +152,12 @@ procedure TCompiler.compileIfStatement(node: TASTIf);
152152 jumpLocation_1, jumpLocation_2: integer;
153153begin
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);
599599begin
600600 compileCode(node.left);
601601 compileCode(node.right);
602- code.addByteCode(opCode);
602+ code.addByteCode(opCode, node.lineNumber );
603603end ;
604604
605605procedure TCompiler.compilePowerOperator (node: TASTPowerOp);
606606begin
607607 compileCode(node.left);
608608 compileCode(node.right);
609- code.addByteCode(oPower);
609+ code.addByteCode(oPower, node.lineNumber );
610610end ;
611611
612612
613613procedure TCompiler.compileNotOperator (node : TASTNotOp);
614614begin
615615 compileCode (node.expression);
616- code.addByteCode (oNot);
616+ code.addByteCode (oNot, node.lineNumber );
617617end ;
618618
619619
620620procedure TCompiler.compileUniOperator (node: TASTUniOp; opCode: Byte);
621621begin
622622 compileCode(node.left);
623- code.addByteCode(opCode);
623+ code.addByteCode(opCode, node.lineNumber );
624624end ;
625625
626626procedure 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 ;
646646end ;
647647
648648
649649procedure TCompiler.compileSetColor (node : TASTNode);
650650begin
651651 compileCode((node as TASTSetColor).expression);
652- code.addByteCode(oSetColor);
652+ code.addByteCode(oSetColor, node.lineNumber );
653653end ;
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 ;
668668end ;
669669
670670
671671procedure TCompiler.compileHelp (node: TASTNode);
672672begin
673673 compileCode((node as TASTHelp).expression);
674- code.addByteCode(oHelp);
674+ code.addByteCode(oHelp, node.lineNumber );
675675end ;
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 );
993993end ;
994994
995995
996996procedure TCompiler.compileSliceAll (node : TASTNode);
997997begin
998- code.addByteCode(oSliceAll);
998+ code.addByteCode(oSliceAll, node.lineNumber );
999999end ;
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