implement outward calling of nested procedures, fix standalone mode

This commit is contained in:
slederer 2025-04-01 00:14:20 +02:00
parent 6d08db2933
commit a1795d9b1f

View file

@ -111,7 +111,7 @@ begin
emitIns2('BRANCH','@+2'); (* NOP, to make alignment explicit *)
emitIns('.CPOOL'); (* header/prologue + 2 constants is 32 bytes *)
if useStdlib then
if useStdlib and not useStandalone then
begin
writeln(outfile, '%include "stdlib.lsym"');
writeln(outfile, '%incbin "stdlib.lib"');
@ -312,7 +312,12 @@ begin
emitArrayConsts;
if useStandalone then
emitInclude('corelib.s')
begin
emitInclude('corelib.s');
emitInclude('runtime.s');
emitInclude('float32.s');
emitInclude('stdlib.s');
end
else
emitInclude('coreloader.lsym');
@ -1059,6 +1064,7 @@ end;
*)
procedure emitProcedureCall(aProc: ProcRef);
var procLabel: IdentString;
i:integer;
begin
(* pass pointer to stackframe of caller for nested procedures *)
if aProc^.isNested then
@ -1069,9 +1075,17 @@ begin
if aProc^.level > curProcedure^.level then
emitIns2('LOADREG','FP')
else
(* TODO: calling nested aProc with a lower nesting level.
need to chase a chain of old BP pointers. *)
errorExit2('internal error: outward call of nested aProc not implemented', '');
begin
(* Calling nested aProc with a lower nesting level.
Need to chase a chain of old BP pointers. *)
emitIns2('LOADREG', 'BP');
(* BP points to the stackframe of the outer procedure,
@BP contains the stackframe of the procedure one step further
outwards, and so on.
*)
for i := aProc^.level + 1 to curProcedure^.level do
emitIns('LOADI');
end;
end;
emitFpAdjust(-curProcedure^.tempsSize);