issue-#192 Kernel.Call does not work with ANYREC-parameters

Post Reply
Zinn
Posts: 476
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main
Contact:

issue-#192 Kernel.Call does not work with ANYREC-parameters

Post by Zinn »

Kernel.Call does not work with ANYREC-parameters
Reported by Eugene Temirgaleev

The following sample program produce a TRAP 0, because the stack does not pass the actual ANYREC parameter.

Code: Select all

MODULE PrivTest;
	IMPORT Meta, Services, Log, Files;
	
	PROCEDURE LogTypeName* (IN rec: ANYREC);
		VAR	name: ARRAY 256 OF CHAR;
	BEGIN
		Services.GetTypeName(rec, name); Log.String(name); Log.Ln
	END LogTypeName;

	PROCEDURE Call*;
		VAR	i, res: Meta.Item; par: ARRAY 10 OF Meta.Item; ok: BOOLEAN;
	BEGIN
		Meta.LookupPath("PrivTest.LogTypeName", i); ASSERT(i.Valid());
		Meta.GetItem(Files.dir, par[0]);
		i.ParamCall(par, res, ok);
	END Call;

	PROCEDURE LogTypeName2* (IN rec1, rec2: ANYREC);
		VAR	name: ARRAY 256 OF CHAR;
	BEGIN
		Services.GetTypeName(rec1, name); Log.String(name); Log.Ln;
		Services.GetTypeName(rec2, name); Log.String(name); Log.Ln
	END LogTypeName2;

	PROCEDURE Call2*;
		VAR	i, res: Meta.Item; par: ARRAY 10 OF Meta.Item; ok: BOOLEAN;
	BEGIN
		Meta.LookupPath("PrivTest.LogTypeName2", i); ASSERT(i.Valid());
		Meta.GetItem(Files.dir, par[0]); Meta.GetItem(Files.dir, par[1]);
		i.ParamCall(par, res, ok);
	END Call2;

END PrivTest.	(!)PrivTest.Call	(!)PrivTest.Call2
Eugene propose the following solution

Code: Select all

	PROCEDURE Call* (adr: INTEGER; sig: Signature; IN par: ARRAY OF INTEGER; n: INTEGER): LONGINT;
		VAR p, kind, sp, size: INTEGER; typ: Type; r: REAL;
	BEGIN
		p := sig.num;
		WHILE p > 0 DO	(* push parameters from right to left *)
			DEC(p);
			typ := sig.par[p].struct;
			kind := sig.par[p].id MOD 16;
			IF (S.VAL(INTEGER, typ) DIV 256 = 0) OR (typ.id MOD 4 IN {0, 3}) THEN	(* scalar *)
				IF (kind = 10) & ((S.VAL(INTEGER, typ) = 8) OR (S.VAL(INTEGER, typ) = 10)) THEN	(* 64 bit *)
					DEC(n); PUSH(par[n])	(* push hi word *)
(* adding this lines here ---------------------*)
				ELSIF S.VAL(INTEGER, typ) = 11 THEN	(* ANYREC *)
					ASSERT(kind # 10);
					DEC(n); PUSH(par[n])	(* push tag *)
(* end adding --------------------------- *)
				END;
				DEC(n); PUSH(par[n])	(* push value/address *)
			ELSIF typ.id MOD 4 = 1 THEN	(* record *)
You have to link BlackBox with the changed KERNEL before you testing it.
- Helmut
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Josef Templ »

Excellent analysis by Eugene Temirgaleev.

I have added an issue for that in redmine.
See https://redmine.blackboxframework.org/issues/192.

- Josef
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Josef Templ »

For the fix as proposed by Eugene Temirgaleev see changes at https://redmine.blackboxframework.org/p ... 4e641e5c4b.

- Josef
Zinn
Posts: 476
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main
Contact:

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Zinn »

In the diff
Josef Templ wrote:For the fix as proposed by Eugene Temirgaleev see changes at https://redmine.blackboxframework.org/p ... 4e641e5c4b.
- Josef
In this change list the line
- 20181111, center #190, add comment about stack and heap memory configuration
is missing.
- Helmut
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Josef Templ »

This because the previous issue has not yet been merged with master.
After that I can resolve the merge conflict with this issue.

- Josef
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Robert »

Is this now ready for voting; is the current diff complete?
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Josef Templ »

I have to remove the merge conflict first.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#192 Kernel.Call does not work with ANYREC-paramet

Post by Josef Templ »

The merge conflict has been removed.
No changes otherwise.

see diffs at https://redmine.blackboxframework.org/p ... 31db1326a6.

- Josef
Post Reply