samiam95124 / Pascal-P6

6th version of Niklaus Wirth's original Pascal language compiler system
Other
28 stars 9 forks source link

Enable overload modules from uses or joins #62

Closed samiam95124 closed 1 year ago

samiam95124 commented 1 year ago

As detailed in vs. 0.1, calls to overloads from uses or joins modules. Presently, such calls end up like:

`` module test1;

procedure x;

begin end;

overload procedure x(c: char);

begin end;

begin

end.

program test;

uses test1;

begin

x; x('c')

end.

! x; :6 :7 ! x('c') sfr l test.27 l test.27=0 cup l test1.x :7 :8 sfr l test.28 ! ldcc 'c' chkc 0 255 ! end. l test.28=0 cup l test1.x ``

This can be resolved in two different ways:

  1. The number of the label can be added to the end.
  2. The concatenated digests from the parameters can be added to the end.

1 is simple, but the order of the overloads must match between header files and source files[1]. If that is not true, the resulting error will be strange.

2 is more secure, and it's the method IP pascal (and C++!) uses. Its more secure.

At the moment, I am leaning towards #2.

samiam95124 commented 1 year ago

There are a couple of side effects of the "type spagetti" approach:

  1. Specifying exactly which overload you want in the debugger could be a pain, or in fact a large pain if the called routine has a complex parameter list. This is a problem shared with C++. Ways to mitigate this include giving the ability to list overloads, and select one by number.
  2. Opening up symbol parsing on the debug command line creates parsing issues. '@', '(' and ')' have other uses on the command line. This may not be a big problem, since they are only expected as tails to the symbol, and not leader symbols. IE, simply spacing them off fixes it.

Anyways, the digest method is 1/2 implemented.

Ok, so why do I suddenly care a lot about overloads in separate modules? Because IP Pascal used them extensively, and I am reusing libraries from IP Pascal (which was, after all, a large part of the point of being Pascaline compatible.). Thus I got tired of having to change the IP Pascal libraries to fit the lack of function in P6.

samiam95124 commented 1 year ago

Function complete. Testing is another ticket.

samiam95124 commented 1 year ago

Encountered an issue with this. Turns out ALL routines have to have a digest appended, because at the time the first routine of an overload group is parsed, we don't know if it is going to be part of an overload group. This worked, but creamed the debugger test, because it didn't know about overloads.

The fix was to have debug ignore the type endings, but that still leaves the debugger unable to handle overloads. I have opened another ticket for that.