-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfn.h
More file actions
54 lines (48 loc) · 1.31 KB
/
Copy pathfn.h
File metadata and controls
54 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef FN_H
#define FN_H
#include "k.h"
#include "scope.h"
#include "p.h"
extern K fnestack[1024];
extern int fnestacki;
#define FN_VALENCE(v) (ik(v)&0xff)
#define FN_FMIDX(v) ((ik(v)>>8)&0xff)
#define FN_VF(val,fm) t(1,((val)&0xff)|(((fm)&0xff)<<8))
void fninit(void);
K fnnew(char *f);
void fnfree(K f);
K fnd(K f);
K fncp(K f);
K fne_(K f, K x, char *av);
K fne(K f, K x, char *av);
K fne_fast(K f, K x);
K fapply(K f, K x, char *av_outer);
/* closure: if x is a 0xc3 lambda whose scope is s0, replace its scope
with a captured copy. Defined here as static inline so callers
(fne_, fne_fast) can inline it on the hot lambda-return path
without an indirect call -- making this non-static visibly
regressed p005 by breaking LTO. Returns the (possibly copy-
modified) lambda; returns 3 (KERR_TYPE) for any non-0xc3 input --
callers gate on 0xc3 to avoid that path. */
static inline K closure(K x, K s0, K closurescope) {
K r=KERR_TYPE; K *_px,_s,*_fs,*_pr;
if(0xc3==s(x)) {
_px=px(x);
_s=_px[2];
if(_s==null) return x;
_fs=px(_s);
if(_fs[0]!=s0) return x;
r=fncp(x);
if(E(r)) { _k(x); return r; }
_k(x);
_pr=px(r);
_s=_pr[2];
_fs=px(_s);
_k(_fs[0]);
_fs[0]=k_(closurescope);
}
return r;
}
K merge_args(K p, K x);
K wrap_proj(K f, K args);
#endif /* FN_H */