REQUIRED MODIFICATIONS TO GOFER V2.30B Keith Wansbrough March 7, 1997. There are a number of changes that must be made to allow the implementation of I/O monad transformers. These changes are given here to Gofer v2.30b. ** **** First, changes to Gofer itself: ** diff --unified=3 OrigGofer/src/gofer.c MyGofer/src/gofer.c --- OrigGofer/src/gofer.c Fri Mar 31 22:14:56 1995 +++ MyGofer/src/gofer.c Fri Oct 25 14:54:45 1996 @@ -77,7 +77,11 @@ /* charge. I ask however that you show your appreciation for the many */ /* hours of work involved by retaining my name in the banner. Thanks! */ - printf("Gofer Version 2.30b Copyright (c) Mark P Jones 1991-1995\n\n"); + printf("Gofer Version 2.30b+ Copyright (c) Mark P Jones 1991-1995\n\n"); + + /* '+' added KSW 1996-10-25 to denote addition of primSTSemisafeRun */ + /* etc. */ + fflush(stdout); interpreter(argc,argv); printf("[Leaving Gofer]\n"); diff --unified=3 OrigGofer/src/prims.c MyGofer/src/prims.c --- OrigGofer/src/prims.c Fri Jun 24 04:00:00 1994 +++ MyGofer/src/prims.c Fri Oct 25 14:58:59 1996 @@ -8,6 +8,11 @@ * the primitives table and consChar() parts are retained. * ------------------------------------------------------------------------*/ +/* + * primSTSemisafeRun, primSTGetWorld and primSTSetWorld + * added by Keith Wansbrough (KSW) 1996-10-22..1996-10-25. + */ + #if PRIMITIVES_CODE #include #if (TURBOC | BCC) @@ -150,6 +155,9 @@ #if IO_MONAD PROTO_PRIM(primSTRun); +PROTO_PRIM(primSTSemisafeRun); /* KSW */ +PROTO_PRIM(primSTGetWorld); /* KSW */ +PROTO_PRIM(primSTSetWorld); /* KSW */ PROTO_PRIM(primFst); PROTO_PRIM(primSnd); PROTO_PRIM(primSTReturn); @@ -305,6 +313,9 @@ #if IO_MONAD {"primSTRun", 1, GofcPrim(primSTRun)}, + {"primSTSemisafeRun", 2, GofcPrim(primSTSemisafeRun)}, /* KSW */ + {"primSTGetWorld", 1, GofcPrim(primSTGetWorld)}, /* KSW */ + {"primSTSetWorld", 2, GofcPrim(primSTSetWorld)}, /* KSW */ {"primFst", 1, NoGofcPrim(primFst)}, {"primSnd", 1, NoGofcPrim(primSnd)}, {"primSTReturn", 1, GofcPrim(primSTReturn)}, @@ -1829,6 +1840,23 @@ ap(primArg(1),UNIT)); } +primFun(primSTSemisafeRun) { /* KSW */ /* ST monad run, explicit world */ + Cell m = primArg(2); /* :: ST s a -> s -> (a,s) */ + Cell s = primArg(1); + updapRoot(m,s); +} + +primFun(primSTGetWorld) { /* KSW */ /* ST monad get world */ + Cell s = primArg(1); /* :: ST s s */ + updapRoot(ap(mkTuple(2),s),s); /* = \s -> (s,s) */ +} + +primFun(primSTSetWorld) { /* KSW */ /* ST monad set world */ + Cell news = primArg(2); /* :: s -> ST s () */ + Cell olds = primArg(1); /* = \s -> \_ -> ((),s) */ + updapRoot(ap(mkTuple(2),UNIT),news); +} + primFun(primFst) { /* fst primitive */ eval(primArg(1)); /* :: (a,s) -> a */ updateRoot(top()); ** **** Next, changes to the prelude. These changes assume ccio.prelude is **** the concatenation of cc.prelude and iomonad.gs in the standard **** distribution. ** --- OrigGofer/ccio.prelude Mon Feb 17 19:06:24 1997 +++ AS-MMS/cc-mod.prelude Mon Feb 17 19:08:48 1997 @@ -10,6 +10,9 @@ -- -- Enhanced prelude for use of overloading with constructor classes. -- Based on the Haskell standard prelude version 1.2. +-- +-- Modified to support semisafeRunST +-- by Keith Wansbrough KSW 1996-10-22..1996-10-23. help = "press :? for a list of commands" @@ -950,6 +954,9 @@ primitive putchar "primIOPutchar" :: Char -> IO () primitive thenIO "primIOBind" :: IO a -> (a -> IO b) -> IO b primitive interleaveST "primSTInter" :: ST s a -> ST s a +primitive semisafeRunST "primSTSemisafeRun" :: ST s a -> s -> (a,s) +primitive getworldST "primSTGetWorld" :: ST s s +primitive setworldST "primSTSetWorld" :: s -> ST s () instance Eq (MutVar s a) where (==) = mutvarEq ** **** It was also found necessary to increase the index space in Gofer, **** following the README file in the code used by Liang, Hudak and **** Jones. The following is a quote from that file. ** To run the modular interpreter, you need Gofer version 2.30 compiled as LARGE_GOFER with the following patch to the prelude.h file: 311c311 < #define NUM_INDEXES Pick(700, 2000, 2000) --- > #define NUM_INDEXES Pick(700, 2000, 10000) ** **** REFERENCES: ** @MastersThesis{ Wansbrough97:Modular, author="Keith Wansbrough", title="A Modular Monadic Action Semantics", school="Department of Computer Science, University of Auckland", year="1997", month=feb, documentURL="http://www.cs.auckland.ac.nz/~kwan001/thesis/index.html", } @InProceedings{ Liang*95:Monad, author="Sheng Liang and Paul Hudak and Mark Jones", title="Monad Transformers and Modular Interpreters", booktitle="Conference Record of {POPL} '95: 22nd {ACM} {SIGPLAN}-{SIGACT} Symposium on {P}rinciples of {P}rogramming {L}anguages, San Francisco, California, January {22--25}, 1995", year="1995", pages="{333--343}", publisher="{ACM} Press", address="New York", } --Keith Wansbrough.