[project @ 2003-08-20 12:55:14 by simonmar]
[ghc-hetmet.git] / ghc / rts / Apply.h
1 // -----------------------------------------------------------------------------
2 // Apply.h
3 //
4 // (c) The University of Glasgow 2002
5 //
6 // Helper bits for the generic apply code (AutoApply.hc)
7 // -----------------------------------------------------------------------------
8
9 #ifndef APPLY_H
10 #define APPLY_H
11
12 // Build a new PAP: function is in R1,p
13 // ret addr and m arguments taking up n words are on the stack.
14 #define BUILD_PAP(m,n,f)                        \
15  {                                              \
16     StgPAP *pap;                                \
17     nat size, i;                                \
18     TICK_SLOW_CALL_BUILT_PAP();                 \
19     size = PAP_sizeW(n);                        \
20     HP_CHK_NP(size, Sp[0] = f;);                \
21     TICK_ALLOC_PAP(n, 0);                       \
22     pap = (StgPAP *) (Hp + 1 - size);           \
23     SET_HDR(pap, &stg_PAP_info, CCCS);          \
24     pap->arity = arity - m;                     \
25     pap->fun = R1.cl;                           \
26     pap->n_args = n;                            \
27     for (i = 0; i < n; i++) {                   \
28       pap->payload[i] = (StgClosure *)Sp[1+i];  \
29     }                                           \
30     R1.p = (P_)pap;                             \
31     Sp += 1 + n;                                \
32     JMP_(ENTRY_CODE(Sp[0]));                    \
33  }
34
35 // Copy the old PAP, build a new one with the extra arg(s)
36 // ret addr and m arguments taking up n words are on the stack.
37 #define NEW_PAP(m,n,f)                                  \
38  {                                                      \
39      StgPAP *pap, *new_pap;                             \
40      nat size, i;                                       \
41      TICK_SLOW_CALL_NEW_PAP();                          \
42      pap = (StgPAP *)R1.p;                              \
43      size = PAP_sizeW(pap->n_args + n);                 \
44      HP_CHK_NP(size, Sp[0] = f;);                       \
45      TICK_ALLOC_PAP(n, 0);                              \
46      new_pap = (StgPAP *) (Hp + 1 - size);              \
47      SET_HDR(new_pap, &stg_PAP_info, CCCS);             \
48      new_pap->arity = arity - m;                        \
49      new_pap->n_args = pap->n_args + n;                 \
50      new_pap->fun = pap->fun;                           \
51      for (i = 0; i < pap->n_args; i++) {                \
52          new_pap->payload[i] = pap->payload[i];         \
53      }                                                  \
54      for (i = 0; i < n; i++) {                          \
55         new_pap->payload[pap->n_args+i] = (StgClosure *)Sp[1+i];        \
56      }                                                  \
57      R1.p = (P_)new_pap;                                \
58      Sp += n+1;                                         \
59      JMP_(ENTRY_CODE(Sp[0]));                           \
60  }
61
62 // canned slow entry points, indexed by arg type (ARG_P, ARG_PP, etc.)
63 extern StgFun * stg_ap_stack_entries[];
64
65 // canned register save code for heap check failure in a function
66 extern StgFun * stg_stack_save_entries[];
67
68 // canned bitmap for each arg type
69 extern StgWord stg_arg_bitmaps[];
70
71 #endif // APPLY_H
72