gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] exception handling now available in gm2


From: Gaius Mulley
Subject: [Gm2] exception handling now available in gm2
Date: 23 Aug 2008 23:17:17 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hi,

as the title suggests, exception handling is now available in gm2.
I suspect there are bugs if exception handling is used with module
priorities (those combinations have not been tested - so I suspect
the worst :-().  However the compiler builds cleanly under LP64
x86, completes make gm2.paranoid.  Here is an example of exception
handlers in action:

address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ type 
gm2
gm2 is /home/gaius/opt/bin/gm2
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ rm 
*.o a.out 
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ ls
builtinlj.mod     except2.mod  except5.cpp  except7.mod  long2.mod  minmax.mod  
shift.mod  t.cpp
constructor1.mod  except3.cpp  except5.mod  except8.mod  long3.mod  shift2.mod  
simple     testsystem.mod
CVS               except4.mod  except6.cpp  except.c     long.mod   shift3.mod  
t1.cpp     tstLength.mod
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ cat 
except8.mod 
(* Copyright (C) 2008 Free Software Foundation, Inc. *)
(* This file is part of GNU Modula-2.

GNU Modula-2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with gm2; see the file COPYING.  If not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)

MODULE except8 ;

FROM libc IMPORT printf ;
FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
FROM SYSTEM IMPORT ADR, WORD, THROW ;


PROCEDURE fly ;
VAR
   r: INTEGER ;
BEGIN
   r := printf("fly main body\n") ;
   IF 4 DIV ip^ = 4
   THEN
      r := printf("yes it worked\n")
   ELSE
      r := printf("no it failed\n")
   END
END fly ;

(*
 *   a GNU M2 version of the Modula-2 example given in the ISO standard.
 *)

PROCEDURE tryFlying ;
VAR
   r: INTEGER ;
BEGIN
   r := printf("tryFlying main body\n");  
   fly ;
EXCEPT
   r := printf("inside tryFlying exception routine\n") ;
   IF (ip#NIL) AND (ip^=0)
   THEN
      r := printf("set value\n") ;
      ip^ := 1 ;
      RETRY
   END
END tryFlying ;


PROCEDURE keepFlying ;
VAR
   t: INTEGER ;
BEGIN
   r := printf("keepFlying main body\n") ;
   tryFlying ;
EXCEPT
   r := printf("inside keepFlying exception routine\n") ;
   IF ip=NIL
   THEN
      r := printf("allocate memory\n") ;
      NEW(ip) ;
      ip^ := 0 ;
      RETRY
   END
END keepFlying ;


VAR
   r : INTEGER ;
   ip: POINTER TO INTEGER ;
BEGIN
   ip := NIL ;
   keepFlying ;
   r := printf("all done\n")
END except8.
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ gm2 
-g -c -fcheck-all except8.mod 
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ gm2 
-g -fcheck-all except8.mod 
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ 
./a.out 
keepFlying main body
tryFlying main body
fly main body
inside tryFlying exception routine
inside keepFlying exception routine
allocate memory
keepFlying main body
tryFlying main body
fly main body
inside tryFlying exception routine
set value
tryFlying main body
fly main body
yes it worked
all done
address@hidden:~/GM2/graft-4.1.2/gcc-4.1.2/gcc/testsuite/gm2/iso/run/pass$ 


as can be seen the option -fcheck-all enables all runtime checking
which also throws an exception should an error occur.  The Modula-2
code above is very similar to the example given in the ISO standard
and demonstrates nested exceptions being thrown and caught.

I plan to correct and improve the documentation in light of these
changes and to add a section on how C++ exceptions can be used in
conjunction with Modula-2.  Then I think after more bug fixing a
release is probably in order.  When building gm2 it is now necessary
to specify at least "--enable-languages=c,c++,gm2" as gm2 uses the C++
libstdc++

regards,
Gaius



Below are the changelog entries for August.



        * gm2/Make-lang.in:  replaces list of checking flags with
          -fcheck-all.
        * gm2/TODO:  corrected sentance.
        * gm2/lang-options.h:  introduced new option, -fdiv-mod-rem.
        * gm2/gm2-compiler/M2Base.def:  ExceptionNonPosDiv,
          ExceptionNonPosMod, ExceptionZeroDiv, ExceptionZeroRem new
          exception handlers defined.
        * gm2/gm2-compiler/M2Base.mod:  ExceptionNonPosDiv,
          ExceptionNonPosMod, ExceptionZeroDiv, ExceptionZeroRem new
          exception handlers implemented.
        * gm2/gm2-compiler/M2GenGCC.def:  export
          LValueToGenericPtr and ZConstToTypedConst.
        * gm2/gm2-compiler/M2GenGCC.mod:  removed (p2c) forward
          declarations for LValueToGenericPtr and ZConstToTypedConst.
        * gm2/gm2-compiler/M2Options.def:  defined and export
          DivModRemChecking.
        * gm2/gm2-compiler/M2Options.mod:  implement detection of
          -fdiv-mod-rem.
        * gm2/gm2-compiler/M2Quads.mod:  (CheckDivModRem) new procedure.
          (BuildBinaryOp) call CheckDivModRem.
        * gm2/gm2-compiler/M2Range.def:  define InitWholeNonPosDivCheck,
          InitWholeNonPosModCheck, InitWholeZeroDivisionCheck and
          InitWholeZeroRemainderCheck.
        * gm2/gm2-compiler/M2Range.mod:  implement InitWholeNonPosDivCheck,
          InitWholeNonPosModCheck, InitWholeZeroDivisionCheck and
          InitWholeZeroRemainderCheck.
        * gm2/gm2-libs/M2RTS.def:  define new exception handlers:
          WholeNonPosDivException, WholeNonPosModException,
          WholeZeroDivException and WholeZeroRemException.
        * gm2/gm2-libs/M2RTS.mod:  implement new exception handlers:
          WholeNonPosDivException, WholeNonPosModException,
          WholeZeroDivException and WholeZeroRemException.
        * gm2/gm2-libs-iso/M2RTS.def:  defined new exception handlers:
          WholeNonPosDivException, WholeNonPosModException,
          WholeZeroDivException and WholeZeroRemException.
        * gm2/gm2-libs-iso/M2RTS.mod:  implemented new exception
          handlers WholeNonPosDivException, WholeNonPosModException,
          WholeZeroDivException and WholeZeroRemException.
        * gm2/gm2-libs-iso/SYSTEM.def:  export THROW.
        * gm2/ulm-lib-gm2/std/M2RTS.mod:  implement new exception
          handlers WholeNonPosDivException, WholeNonPosModException,
          WholeZeroDivException and WholeZeroRemException.

2008-08-16       Gaius Mulley <address@hidden>

        * gm2/gm2spec.c:  set linking to false if -S flag was seen.
        * gm2/examples/cpp/Makefile:  altered flag from -Wcpp to -fcpp.
        * gm2/examples/pthread/libcwrap.c:  (_M2_libcwrap_finish) new
          function stub.
        * gm2/gm2-compiler/M2BasicBlock.mod:  preserve InitStart, InitEnd,
          FinallyStart, FinallyEnd quadruples during basic block elimination.
        * gm2/gm2-compiler/M2Quads.def:  (IsInitStart) (IsInitEnd)
          (IsFinallyStart) (IsFinallyEnd) new functions defined and exported.
        * gm2/gm2-compiler/M2Quads.mod:  (IsInitStart) (IsInitEnd)
          (IsFinallyStart) (IsFinallyEnd) new functions implemented.
        * gm2/gm2-libs-coroutines/KeyBoardLEDs.c:  (_M2_KeyBoardLEDs_init)
          (_M2_KeyBoardLEDs_finish)  new functions.
        * gm2/gm2.texi:  changed configure example to include the build of
          c++.

2008-08-15       Gaius Mulley <address@hidden>

        * gm2/gm2/Make-lang.in:  include gm2/config-make for TARGET_SUBDIR
          macro.  Link stage2 and stage3 cc1gm2 against libstdc++.a.
        * gm2/config-lang.in:  require target-libstdc++-v3.  Also generate
          gm2/config-make during configure.
        * gm2/gm2spec.c:  (add_lstdcpp) new function which is called if
          linking.
        * gm2/lang-specs.h:  gm2lgen enable generation of C++ main via -cpp.
          Change references to %g.c to %g.cpp.
        * gm2/p2crc:  define ThrowName.
        * gm2/gm2-compiler/gm2lcc.mod:  correctly initialise LibrariesFound
          to FALSE.
        * gm2/gm2-compiler/gm2lgen.mod:  introduced new switch -cpp which
          informs gm2lgen to generate a C++ main with a try catch dispatcher.
        * gm2/gm2-libs/M2RTS.mod:  fixed space.
        * gm2/gm2-libs/RTExceptions.def:  define BaseExceptionsThrow and
          DefaultErrorCatch.
        * gm2/gm2-libs/RTExceptions.mod:  implement BaseExceptionsThrow and
          DefaultErrorCatch.  Also fixed PushHandler and PopHandler.
        * gm2/gm2-libs-boot/SYSTEM.def:  tidied up header comment.
        * gm2/p2c/p2c-src/src/decl.c:  removed spaces.
        * gm2/p2c/p2c-src/src/funcs.c:  (proc_throw) new function.
        * gm2/p2c/p2c-src/src/trans.h:  define name_THROW.
        * gm2/make-config.in:  new file.
        
2008-08-11       Gaius Mulley <address@hidden>

        * gm2/bnf/m2-3.bnf:  call BuildReThrow after statement sequence
          in an exception block.
        * gm2/gm2-compiler/M2GenGCC.mod:  implement rethrow.
        * gm2/gm2-compiler/M2Quads.def:  (BuildReThrow) define and export.
        * gm2/gm2-compiler/M2Quads.mod:  (BuildReThrow) implemented.
        * gm2/gm2-libs/M2RTS.mod:  fixed dates.

2008-08-09       Gaius Mulley <address@hidden>

        * gm2/Make-lang.in:  added gt dependancies for gm2builtins.h
          and gm2except.h.  Added rules and dependancies to build
          gm2except.c and link it to cc1gm2.  Updated GM2DISTFILES.
        * gm2/config-lang.in:  updated gtfiles to include gm2except.c
          and gm2builtins.c.
        * gm2/gccgm2.c:  updated dates.  Updated prototype (removed
          PARAMS).  (gimplify_expr_stmt) new function.
          (genericize_try_block) new function.  (genericize_catch_block)
          new function.  (init_m2_builtins) call gm2except_InitExceptions.
        * gm2/gm2-tree.def:  define TRY_BLOCK, HANDLER, EXPR_STMT nodes.
        * gm2/gm2-tree.h:  (TRY_STMTS), (TRY_HANDLERS), (FN_TRY_BLOCK_P),
          (HANDLER_PARMS), (HANDLER_BODY), (HANDLER_TYPE),
          (STMT_EXPR_STMT), (EXPR_STMT_EXPR) new macros.
        * gm2/gm2.texi:  minor cosmetic changes.  Also heavily altered
          exception handling internal section to reflect using C++
          tree nodes rather than setjmp/longjmp mechanism.
        * gm2/gm2builtins.c:  added GTY(()) clauses to global tree
          variables and imported appropriate GTY related header files.
          This has probably fixed a number of garbage collection bugs.
        * gm2/m2pp.c:  major changes to allow this file to be built and
          linked to cc1plus as well as cc1gm2.  (m2pp_print_char),
          (m2pp_try_block), (m2pp_cleanup_point_expr), (m2pp_handler),
          (m2pp_try_catch_expr), (m2pp_throw), (m2pp_catch_expr),
          (m2pp_try_finally_expr), (m2pp_if_stmt),
          (m2pp_compound_expression), (m2pp_target_expression) new
          functions.
        * gm2/bnf/m2-2.bnf:  (PutExceptionFinally), (PutExceptionBlock),
          (GetCurrentScope) call these building functions when parsing
          source.  (RetryStatement) new separate rule.
          (InitialBlock), (FinalBlock) new rules.
        * gm2/bnf/m2-3.bnf:  (RetryStatement) new separate rule.
        * gm2/bnf/m2-h.bnf:  (RetryStatement) new separate rule.
        * gm2/bnf/m2-2.bnf:  (RetryStatement) new separate rule.
        * gm2/gm2-compiler/M2Base.def:  added space.
        * gm2/gm2-compiler/M2BasicBlock.mod:  (ConvertQuads2BasicBlock)
          updated to understand about CatchBegin and CatchEnd quads.
        * gm2/gm2-compiler/M2GenGCC.mod:  (CodeTry), (CodeCatchBegin),
          (CodeCatchEnd), (CodeRetry), (CodeThrow) new procedures.
        * gm2/gm2-compiler/M2Optimize.def:  fixed dates.
        * gm2/gm2-compiler/M2Optimize.mod:  fixed dates.
        * gm2/gm2-compiler/M2Quads.def:  (IsCatchBegin), (IsCatchEnd)
          new functions defined and exported.
        * gm2/gm2-compiler/M2Quads.mod:  (BuildThrowProcedure) new
          procedure.  (IsUnConditional)  understands ThrowOp and RetryOp.
          (WriteQuad) displays ThrowOp.  (IsQuadA) new function which
          allows (IsCall), (IsReturn), (IsNewLocalVar), (IsKillLocalVar),
          (ProcedureScope) to be refactored.  (IsCatchBegin),
          (IsCatchEnd), new functions.  (BuildExceptInitial) new
          procedure.  (BuildExceptFinally) new procedure.
          (BuildExceptProcedure) new procedure.  (BuildRetry) new
          procedure.
        * gm2/gm2-compiler/M2System.def:  fixed dates.  (Throw) exported.
          (IsPseudoSystemProcedure) exported.
        * gm2/gm2-compiler/M2System.mod:  initialize Throw, implement
          IsPseudoSystemProcedure.
        * gm2/gm2-compiler/SymbolTable.def:  (PutExceptionBlock),
          (HasExceptionBlock), (PutExceptionFinally),
          (HasExceptionFinally) defined and export new procedures.
        * gm2/gm2-compiler/SymbolTable.mod:  (PutExceptionBlock),
          (HasExceptionBlock), (PutExceptionFinally),
          (HasExceptionFinally) new procedures implemented.
        * gm2/gm2-compiler/gccgm2.def:  (BuildTryCatch),
          (BuildThrow) new functions defined.
        * gm2/gm2-libs/M2RTS.mod:  explicitly qualify RTExceptions.Raise.
        * gm2/gm2-libs/SYSTEM.def:  export new internal procedure THROW.
          (THROW) defined.
        * gm2/tools-src/createUlmSys:  fixed dates.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]