123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- {****************************************************************}
- { CODE GENERATOR TEST PROGRAM }
- { By Carl Eric Codere }
- {****************************************************************}
- { NODE TESTED : secondfuncret() }
- {****************************************************************}
- { DEFINES: }
- { FPC = Target is FreePascal compiler }
- {****************************************************************}
- { REMARKS : Tested with Delphi 3 as reference implementation }
- {****************************************************************}
- program tfuncret;
- {$ifdef ver70}
- {$define tp}
- {$endif}
- const
- { adjusts the size of the bigrecord }
- MAX_INDEX = 7;
- RESULT_S64BIT = -12;
- RESULT_S32BIT = -124356;
- RESULT_U32BIT = 654321;
- RESULT_U8BIT = $55;
- type
- {
- the size of this record should *at least* be the size
- of a natural register for the target processor
- }
- tbigrecord = record
- x : cardinal;
- y : cardinal;
- z : array[0..MAX_INDEX] of byte;
- end;
- procedure fail;
- begin
- WriteLn('Failure.');
- halt(1);
- end;
- {****************************************************************}
- { SIMPLE CASE }
- {****************************************************************}
- function getresult_simple_s64bit: int64;
- var
- s64bit : int64;
- i: integer;
- begin
- getresult_simple_s64bit := 0;
- s64bit:=RESULT_S64BIT;
- getresult_simple_s64bit := s64bit;
- end;
- function getresult_simple_s32bit: longint;
- var
- s32bit : longint;
- i: longint;
- begin
- getresult_simple_s32bit := 0;
- i:=1;
- i:=i*RESULT_S32BIT div i;
- s32bit:=i;
- getresult_simple_s32bit := s32bit;
- end;
- function getresult_simple_bigrecord : tbigrecord;
- var
- localbigrecord : tbigrecord;
- i: integer;
- begin
- localbigrecord.x := RESULT_U32BIT;
- localbigrecord.y := RESULT_U32BIT;
- for i:=0 to MAX_INDEX do
- localbigrecord.z[i] := RESULT_U8BIT;
- getresult_simple_bigrecord := localbigrecord;
- end;
- {****************************************************************}
- { WITH NESTING }
- {****************************************************************}
- function getresult_nested_s64bit: int64;
- procedure nested_one;
- var
- s64bit : int64;
- i: longint;
- begin
- getresult_nested_s64bit := 0;
- s64bit:=RESULT_S64BIT;
- getresult_nested_s64bit := s64bit;
- end;
- begin
- nested_one;
- end;
- function getresult_nested_s32bit: longint;
- procedure nested_one;
- var
- s32bit : longint;
- i: longint;
- begin
- getresult_nested_s32bit := 0;
- i:=1;
- i:=i*RESULT_S32BIT div i;
- s32bit:=i;
- getresult_nested_s32bit := s32bit;
- end;
- begin
- nested_one;
- end;
- function getresult_nested_bigrecord : tbigrecord;
- procedure nested_one;
- var
- localbigrecord : tbigrecord;
- i: longint;
- begin
- localbigrecord.x := RESULT_U32BIT;
- localbigrecord.y := RESULT_U32BIT;
- for i:=0 to MAX_INDEX do
- localbigrecord.z[i] := RESULT_U8BIT;
- getresult_nested_bigrecord := localbigrecord;
- end;
- begin
- nested_one;
- end;
- {****************************************************************}
- { WITH COMPLEX NESTING }
- {****************************************************************}
- function getresult_nested_complex_s64bit: int64;
- procedure nested_one;
- var
- s64bit : int64;
- i: integer;
- function nested_two: int64;
- begin
- nested_two:=0;
- getresult_nested_complex_s64bit := 0;
- s64bit:=RESULT_S64BIT;
- getresult_nested_complex_s64bit := s64bit;
- end;
- begin
- nested_two;
- end;
- begin
- nested_one;
- end;
- function getresult_nested_complex_s32bit: longint;
- procedure nested_one;
- var
- s32bit : longint;
- i: longint;
- function nested_two: longint;
- begin
- nested_two := 0;
- getresult_nested_complex_s32bit := 0;
- i:=1;
- i:=i*RESULT_S32BIT div i;
- s32bit:=i;
- getresult_nested_complex_s32bit := s32bit;
- end;
- begin
- nested_two;
- end;
- begin
- nested_one;
- end;
- function getresult_nested_complex_bigrecord : tbigrecord;
- procedure nested_one;
- var
- localbigrecord : tbigrecord;
- function nested_two : tbigrecord;
- var
- i : integer;
- begin
- nested_two := localbigrecord;
- localbigrecord.x := RESULT_U32BIT;
- localbigrecord.y := RESULT_U32BIT;
- for i:=0 to MAX_INDEX do
- localbigrecord.z[i] := RESULT_U8BIT;
- getresult_nested_complex_bigrecord := localbigrecord;
- end;
- begin
- nested_two;
- end;
- begin
- nested_one;
- end;
- var
- failed : boolean;
- bigrecord : tbigrecord;
- i: integer;
- Begin
- Write('secondfuncret simple case tests...');
- failed := false;
- if getresult_simple_s64bit <> RESULT_S64BIT then
- failed := true;
- if getresult_simple_s32bit <> RESULT_S32BIT then
- failed := true;
- bigrecord := getresult_simple_bigrecord;
- if bigrecord.x <> RESULT_U32BIT then
- failed := true;
- if bigrecord.y <> RESULT_U32BIT then
- failed := true;
- for i:=0 to MAX_INDEX do
- begin
- if bigrecord.z[i] <> RESULT_U8BIT then
- begin
- failed := true;
- break;
- end;
- end;
- if failed then
- fail
- else
- WriteLn('Success!');
- Write('secondfuncret simple nesting case tests...');
- failed := false;
- if getresult_nested_s64bit <> RESULT_S64BIT then
- failed := true;
- if getresult_nested_s32bit <> RESULT_S32BIT then
- failed := true;
- bigrecord := getresult_nested_bigrecord;
- if bigrecord.x <> RESULT_U32BIT then
- failed := true;
- if bigrecord.y <> RESULT_U32BIT then
- failed := true;
- for i:=0 to MAX_INDEX do
- begin
- if bigrecord.z[i] <> RESULT_U8BIT then
- begin
- failed := true;
- break;
- end;
- end;
- if failed then
- fail
- else
- WriteLn('Success!');
- Write('secondfuncret complex nesting case tests...');
- failed := false;
- if getresult_nested_complex_s64bit <> RESULT_S64BIT then
- failed := true;
- if getresult_nested_complex_s32bit <> RESULT_S32BIT then
- failed := true;
- bigrecord := getresult_nested_complex_bigrecord;
- if bigrecord.x <> RESULT_U32BIT then
- failed := true;
- if bigrecord.y <> RESULT_U32BIT then
- failed := true;
- for i:=0 to MAX_INDEX do
- begin
- if bigrecord.z[i] <> RESULT_U8BIT then
- begin
- failed := true;
- break;
- end;
- end;
- if failed then
- fail
- else
- WriteLn('Success!');
- end.
|