[M3devel] why MOD 10000 in line number for exception handlers?

Jay K jay.krell at cornell.edu
Sat Sep 22 20:11:44 CEST 2012


m3front/stmts/TryFinStmt.m3

        forigin  : INTEGER;        ...  last_name : INTEGER := 0;  next_uid  : INTEGER := 0;...

PROCEDURE HandlerName (uid: INTEGER): TEXT =  CONST Insert = ARRAY BOOLEAN OF TEXT { "_M3_LINE_", "_I3_LINE_" };  BEGIN    RETURN M3ID.ToText (Module.Name (NIL))           & Insert [Module.IsInterface ()]           & Fmt.Int (uid);  END HandlerName;
PROCEDURE Check (p: P;  VAR cs: Stmt.CheckState) =  VAR zz: Scope.T;  oc: Stmt.Outcomes;  name: INTEGER;  BEGIN...        p.viaProc := TRUE;        name := p.forigin MOD 10000;        p.handler.name := HandlerName (name);        IF (name = last_name) THEN          INC (next_uid);          p.handler.name := p.handler.name & "_" & Fmt.Int (next_uid);        ELSE          last_name := name;          next_uid := 0;        END;

So the names of exception handlers are usuallythe module name, followed by _M3_LINE_ or _I3_LINE_ followedby a line number. BUT the line number is taken MOD 10000and, something like, if the line number occasionally clashes,we append another number...

Why?

Now, I can see that multiple lines can have the same name:  TRY TRY EXCEPT EXCEPTon one line.

and the code should have a comment like that. But why the MOD 10000?

Is that in case INTEGER is 16 bits??To keep the lengths of the names bounded??

I suggest the code look more like:

        p.viaProc := TRUE;        name := p.forigin;        p.handler.name := HandlerName (name);        (* Handle the case of multiple exception handlers on the same line.         * "TRY TRY EXCEPT EXCEPT" by appending _1, _2 to the second, third,         * etc. handlers.         *)        IF (name = last_name) THEN          INC (next_uid);          p.handler.name := p.handler.name & "_" & Fmt.Int (next_uid);        ELSE          last_name := name;          next_uid := 0;        END;

At first I didn't think of multiple exception handlers on the same line.But now that I thought of that, my real agenda is wrong -- to eliminatethe second number entirely.

For now I'm stuck recognizing these patterns in my backend, becauseother oddities on the frontend (that I'm still convinced are a bug).

I'd also be willing to append _0 or _1 for the first exception handler on a line,for more consistency, at the cost of more noise for the overwhelmingly common case.You know..if there were always two numbers, it would have saved me time...since I coded at first to recognize just one number, then later hit a problem when two occured.

 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20120922/ce5b2162/attachment-0001.html>


More information about the M3devel mailing list