123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- {****************************************************************}
- { CODE GENERATOR TEST PROGRAM }
- {****************************************************************}
- { NODE TESTED : secondcalln() }
- {****************************************************************}
- { PRE-REQUISITES: secondload() }
- { secondassign() }
- { secondcalln() }
- { secondadd() }
- { secondtypeconv() }
- {****************************************************************}
- { DEFINES: }
- {****************************************************************}
- { REMARKS: This tests a subset of the secondcalln() , it }
- { verifies procedural variables for safecall }
- { calling conventions. }
- {****************************************************************}
- program tcalpvr5;
- {$MODE OBJFPC}
- {$STATIC ON}
- {$R+}
- const
- RESULT_U8BIT = $55;
- RESULT_U16BIT = $500F;
- RESULT_S32BIT = $500F0000;
- RESULT_S64BIT = -12000;
- type
- troutine = procedure (x: longint; y: byte);safecall;
- troutineresult = function (x: longint; y: byte): int64;safecall;
- tsimpleobject = object
- constructor init;
- procedure test_normal(x: byte);safecall;
- procedure test_static(x: byte);static;safecall;
- procedure test_virtual(x: byte);virtual;safecall;
- end;
- tsimpleclass = class
- constructor create;
- procedure test_normal(x: byte);safecall;
- class procedure test_static(x: byte);safecall;
- procedure test_virtual(x: byte);virtual;safecall;
- procedure test_normal_self(self : tsimpleclass; x: byte); message 0;safecall;
- class procedure test_static_self(self : tsimpleclass; x: byte); message 1;safecall;
- procedure test_virtual_self(self : tsimpleclass; x: byte);virtual;message 2;safecall;
- end;
- tobjectmethod = procedure (x: byte) of object ;safecall;
- tclassmethod = procedure (x: byte) of object;safecall;
- { used for testing pocontainsself explicit parameter }
- tclassmethodself = procedure (self : tsimpleclass; x: byte) of object;safecall;
- var
- proc : troutine;
- func : troutineresult;
- obj_method : tobjectmethod;
- cla_method : tclassmethod;
- cla_method_self : tclassmethodself;
- global_s32bit : longint;
- global_s64bit : int64;
- global_u8bit : byte;
- value_s32bit : longint;
- value_u8bit : byte;
- obj : tsimpleobject;
- cla : tsimpleclass;
- procedure fail;
- begin
- WriteLn('Failed!');
- halt(1);
- end;
- procedure clear_globals;
- begin
- global_s32bit := 0;
- global_u8bit := 0;
- global_s64bit := 0;
- end;
- procedure clear_values;
- begin
- value_s32bit := 0;
- value_u8bit := 0;
- end;
- procedure testroutine(x: longint; y: byte);safecall;
- begin
- global_s32bit := x;
- global_u8bit := y;
- end;
- function testroutineresult(x: longint; y: byte): int64;safecall;
- begin
- global_s32bit := x;
- global_u8bit := y;
- testroutineresult := RESULT_S64BIT;
- end;
- function getroutine: troutine;
- begin
- getroutine:=proc;
- end;
- function getroutineresult : troutineresult;
- begin
- getroutineresult := func;
- end;
- { IMPOSSIBLE TO DO CURRENTLY !
- function get_object_method_static : tnormalmethod;
- begin
- get_object_method_static := @obj.test_static;
- end;
- }
- { objects access }
- function get_object_method_normal : tobjectmethod;
- begin
- get_object_method_normal := @obj.test_normal;
- end;
- function get_object_type_method_virtual : tobjectmethod;
- begin
- get_object_type_method_virtual := @obj.test_virtual;
- end;
- function get_object_method_virtual : tobjectmethod;
- begin
- get_object_method_virtual := @obj.test_virtual;
- end;
- { class access }
- function get_class_method_normal_self : tclassmethodself;
- begin
- get_class_method_normal_self := @cla.test_normal_self;
- end;
- {
- HOW CAN WE GET THIS ADDRESS???
- function get_class_method_static_self : tclassmethodself;
- begin
- get_class_method_static_self := @cla.test_static_self;
- end;
- }
- function get_class_method_virtual_self : tclassmethodself;
- begin
- get_class_method_virtual_self := @cla.test_virtual_self;
- end;
- function get_class_method_normal : tclassmethod;
- begin
- get_class_method_normal := @cla.test_normal;
- end;
- {
- function get_class_method_static : tclassmethod;
- begin
- get_class_method_static := @cla.test_static;
- end;}
- function get_class_method_virtual : tclassmethod;
- begin
- get_class_method_virtual := @cla.test_virtual;
- end;
- {****************************************************************************************************}
- constructor tsimpleobject.init;
- begin
- end;
- procedure tsimpleobject.test_normal(x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- procedure tsimpleobject.test_static(x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- procedure tsimpleobject.test_virtual(x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- {****************************************************************************************************}
- constructor tsimpleclass.create;
- begin
- inherited create;
- end;
- procedure tsimpleclass. test_normal(x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- class procedure tsimpleclass.test_static(x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- procedure tsimpleclass.test_virtual(x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- procedure tsimpleclass.test_normal_self(self : tsimpleclass; x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- class procedure tsimpleclass.test_static_self(self : tsimpleclass; x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- procedure tsimpleclass.test_virtual_self(self : tsimpleclass; x: byte);safecall;
- begin
- global_u8bit := x;
- end;
- var
- failed : boolean;
- Begin
- { setup variables }
- proc := @testroutine;
- func := @testroutineresult;
- obj.init;
- cla:=tsimpleclass.create;
- {****************************************************************************************************}
- Write('Testing procedure variable call (LOC_REGISTER)..');
- clear_globals;
- clear_values;
- failed := false;
- { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
- troutine(getroutine)(RESULT_S32BIT,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- clear_globals;
- clear_values;
- { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
- value_s32bit := RESULT_S32BIT;
- value_u8bit := RESULT_U8BIT;
- troutine(getroutine)(value_s32bit , value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- Write('Testing procedure variable call (LOC_REFERENCE)..');
- clear_globals;
- clear_values;
- failed := false;
- { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
- proc(RESULT_S32BIT,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- clear_globals;
- clear_values;
- { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
- value_s32bit := RESULT_S32BIT;
- value_u8bit := RESULT_U8BIT;
- proc(value_s32bit , value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- {****************************************************************************************************}
- Write('Testing function variable call (LOC_REGISTER)..');
- clear_globals;
- clear_values;
- failed := false;
- { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
- global_s64bit := troutineresult(getroutineresult)(RESULT_S32BIT,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- if global_s64bit <> RESULT_S64BIT then
- failed := true;
- clear_globals;
- clear_values;
- { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
- value_s32bit := RESULT_S32BIT;
- value_u8bit := RESULT_U8BIT;
- global_s64bit := troutineresult(getroutineresult)(value_s32bit , value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- if global_s64bit <> RESULT_S64BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- Write('Testing function variable call (LOC_REFERENCE)..');
- clear_globals;
- clear_values;
- failed := false;
- { parameters in LOC_CONSTANT, routine address in LOC_REGISTER }
- global_s64bit := func(RESULT_S32BIT,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- if global_s64bit <> RESULT_S64BIT then
- failed := true;
- clear_globals;
- clear_values;
- { parameters in LOC_REFERENCE,routine address in LOC_REGISTER }
- value_s32bit := RESULT_S32BIT;
- value_u8bit := RESULT_U8BIT;
- global_s64bit := func(value_s32bit , value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- if global_s32bit <> RESULT_S32BIT then
- failed := true;
- if global_s64bit <> RESULT_S64BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- {****************************************************************************************************}
- Write('Testing object method variable call (LOC_REGISTER) ..');
- clear_globals;
- clear_values;
- failed := false;
- tobjectmethod(get_object_method_normal)(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- tobjectmethod(get_object_type_method_virtual)(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- tobjectmethod(get_object_method_virtual)(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- value_u8bit := RESULT_U8BIT;
- tobjectmethod(get_object_method_normal)(value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- value_u8bit := RESULT_U8BIT;
- tobjectmethod(get_object_type_method_virtual)(value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- value_u8bit := RESULT_U8BIT;
- tobjectmethod(get_object_method_virtual)(value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- Write('Testing object method variable call (LOC_REFERENCE) ..');
- clear_globals;
- clear_values;
- failed := false;
- obj_method:[email protected]_normal;
- obj_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- obj_method:[email protected]_virtual;
- obj_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- obj_method:[email protected]_virtual;
- obj_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- value_u8bit := RESULT_U8BIT;
- obj_method:[email protected]_normal;
- obj_method(value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- value_u8bit := RESULT_U8BIT;
- obj_method:[email protected]_virtual;
- obj_method(value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- value_u8bit := RESULT_U8BIT;
- obj_method:[email protected]_normal;
- obj_method(value_u8bit);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- {****************************************************************************************************}
- Write('Testing class method variable call (LOC_REGISTER) ..');
- clear_globals;
- clear_values;
- failed := false;
- tclassmethod(get_class_method_normal)(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- tclassmethod(get_class_method_virtual)(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- tclassmethodself(get_class_method_normal_self)(cla,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- tclassmethodself(get_class_method_virtual_self)(cla,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- If failed then
- fail
- else
- WriteLn('Passed!');
- Write('Testing class method variable call (LOC_REFERENCE)...');
- clear_globals;
- clear_values;
- failed := false;
- cla_method := @cla.test_normal;
- cla_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- cla_method := @cla.test_virtual;
- cla_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- cla_method := @cla.test_virtual;
- cla_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- { cla_method := @cla.test_static;
- cla_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;}
- clear_globals;
- clear_values;
- cla_method_self := @cla.test_normal_self;
- cla_method_self(cla, RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- cla_method_self := @cla.test_virtual_self;
- cla_method_self(cla,RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- cla_method_self := @cla.test_virtual_self;
- cla_method_self(cla, RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;
- clear_globals;
- clear_values;
- { cla_method := @cla.test_static;
- cla_method(RESULT_U8BIT);
- if global_u8bit <> RESULT_U8BIT then
- failed := true;}
- If failed then
- fail
- else
- WriteLn('Passed!');
- end.
- {
- $Log$
- Revision 1.4 2003-01-16 22:14:49 peter
- * fixed wrong methodpointer loads
- Revision 1.3 2002/12/29 15:30:55 peter
- * updated for 1.1 compiler that does not allow calling conventions
- for constructor/destructor
- Revision 1.2 2002/09/07 15:40:54 peter
- * old logs removed and tabs fixed
- Revision 1.1 2002/05/05 13:58:50 carl
- + finished procedural variable testsuit
- + finished method testsuit
- }
|