Trap on [code] procedure call

Post Reply
SovietPony
Posts: 10
Joined: Sun Dec 02, 2018 4:47 pm
Contact:

Trap on [code] procedure call

Post by SovietPony »

Code: Select all

MODULE Test;

	IMPORT SYSTEM;

	TYPE
		T = RECORD END;

	VAR
		r: T;

	PROCEDURE [code] Fail (r: T);

BEGIN
	Fail(r)
END Test.
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Trap on [code] procedure call

Post by cfbsoftware »

For anybody who is interesting in investigating this further, the key points I have found that contribute to the failure are:

1. It is a code procedure
2. The parameter is a record
3. The parameter r is a value, not a VAR parameter

e.g. If the parameter is an INTEGER, or a record passed as a VAR then the compiler does not Trap 0.

The other curious aspects of the example supplied e.g. it is an empty record, there are no code values etc. do not appear to be relevant to the failing condition.
luowy
Posts: 87
Joined: Thu Dec 17, 2015 1:32 pm

Re: Trap on [code] procedure call

Post by luowy »

the first parameter of code procedure is special, reject non varpar comp type in frontend is a choice solution for this issue.
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: Trap on [code] procedure call

Post by Josef Templ »

the first parameter is passed as register eax but in case of a RECORD value parameter this is not possible.
So it should be rejected.
I would suggest to reject it in the backend, though, because code procedures are highly platform specific.
see DevCPC.Call:
Result(x.obj.link, tag) (* use result load for first parameter *)
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Trap on [code] procedure call

Post by cfbsoftware »

Josef Templ wrote:the first parameter is passed as register eax but in case of a RECORD value parameter this is not possible.
Additionally, it is not possible in the case of an ARRAY value parameter.
luowy
Posts: 87
Joined: Thu Dec 17, 2015 1:32 pm

Re: Trap on [code] procedure call

Post by luowy »

Josef Templ wrote: I would suggest to reject it in the backend, though, because code procedures are highly platform specific.
see DevCPC.Call:
Result(x.obj.link, tag) (* use result load for first parameter *)
if reject it in the backend, the errpos will be point to the end of the procedure head, instead of the first parameter. that is my concern.

and i also suggest dont use any open array value type parameters in code procedure.
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: Trap on [code] procedure call

Post by Josef Templ »

There would also be the alternative of treating structured value parameters as VAR pars, i.e. to pass the address in eax.
Post Reply