2d5b475ec10e0544c35a632bce66a58e8d30d09d
[ghc-hetmet.git] / ghc / docs / NOTES.adding-PrimOp
1 This is a short note describing how I (ADR <areid@dcs.glasgow.ac.uk>)
2 added a new primitive operation (makeStablePtr#) to the compiler. It
3 serves as documentation of what I did and as a guide to anyone else
4 wanting to try it.
5
6 1) Change compiler/prelude/PrimOps.lhs:
7
8    - add @MakeStablePtrOp@ to the datatype @PrimitiveOp@.
9
10    - add the following case to @primOpInfo@
11
12         primOpInfo MakeStablePtrOp
13           = AlgResult "makeStablePtr#" []
14         [(ioWorldTy `UniFun` intPrimAndIoWorldTy), ioWorldTy]
15         intPrimAndIoWorldTyCon  []
16     -- makeStablePtr# :: IO_Int# -> IO_Int#
17     -- == makeStablePtr# :: (IoWorld -> (Int#, IoWorld)) -> (IoWorld -> (Int#, IoWorld))
18
19 2) Change compiler/prelude/AbsPrel.lhs:
20
21    - add @MakeStablePtrOp@ to an appropriate place in @list_of_val_assoc_lists@
22
23      (This makes the operation visible to the programmer).
24
25      Since this is a glasgow extension, I added it to one of
26      @extra_known_vals_2@, @unboxed_ops@, @boxed_ops@. @unboxed_ops@
27      is made up of several lists of operators including
28      @prim_ops_used_unboxed_only@. By inspection I decided that this
29      (@prim_ops_used_unboxed_only@) was the one to go for.
30
31 At this point I started recompiling the compiler - this took a long
32 time since the change to @PrimitiveOp@ changed the @.hi@ file
33 resulting in a complete (or near as makes no odds) recmpilation of the
34 compiler. (Is there a way of using fastmake that avoids this?
35
36 3) Change imports/StgMacros.lh to generate code for @MakeStablePtr#@
37
38    - this is just adding a macro that calls the appropriate operation.
39
40    (I suspect I could omit this step if I wanted since all this does
41    (ahem, will do) is call a function in the runtime system.)
42
43 4) Change runtime/storage/SMap.lc to implement the new operation.
44
45    I won't bother describing this just now.
46
47
48 This is a little untidy. I should perhaps add a new flag to the system
49 which turns my extension off and checks that it is only used in
50 conjunction with the Appel generational collector. But we're going to
51 do the same to every collector eventually aren't we?