This repository was archived by the owner on Nov 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGtail.m
73 lines (68 loc) · 1.58 KB
/
Gtail.m
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module
#include "../expr/einfo_t.t"
#include "../expr/id_t.t"
#include "../ExprE/Expr_t.t"
#include "../ExprE/Eprint.t"
#include "../misc/setofid.t"
#include "Genv.t"
#include "Gutil.t"
#include "Gseq.t"
#include "Gfreeset.t"
#include "Gmode_t.t"
#include "Gcodedef_t.t"
#include "Gcode.t"
/*import G: Gmode->Expr->Genv->Int->Glabel->Int ->
(Glabel->((List Gcode)#Glabel));*/
export Gtail, Gtail2;
rec
vareq (mkid n1 _ _ _) (Eidapl (mkid n2 _ _ _) []) = n1 = n2
|| vareq (mkid n1 _ _ _) (Einfo _ (Eidapl (mkid n2 _ _ _) [])) = n1 = n2
|| vareq _ _ = false
and Gtail3 (i.il) (e.el) (s.sl) pos r n =
if vareq i e then
Gtail3 il el sl (pos+1) r n
else
Gseq [ G (C(n)) e r n Notalabel 0;
if Imem i s then
Gseq [ Gtail3 il el sl (pos+1) r (n+1);
Gi [ MOVE (n-pos+1) ]
]
else
Gseq [ Gi [ MOVE (n-pos+1) ];
Gtail3 il el sl (pos+1) r n
]
]
|| Gtail3 _ [] sl _ _ _ = Gi []
|| Gtail3 il el sl _ _ _ = fail "Gtail3"
and Gtail2 el r n =
let rel = reverse el in
let nel = head n rel in
let iil = listenv r n in
let (_.sl) =
itlist
(\(i,e).\(s.sl).
if vareq i e then
s.s.sl
else
Iu (Gfreeset e) s.s.sl)
(combine(iil, nel))
[[]]
and m = length el
in
if n > m then
Gseq [ Gtail3 iil rel sl 1 r n;
Gi [ POP (n-m) ]
]
else
Gseq [ Gcpushrev (head (m-n) el) r n;
Gtail3 iil nel sl 1 r m
]
and Gtail (Eidapl f [].el) r n =
case lookenv r f in
0: Gseq [ Gtail2 el r n;
Gi [ PUSHGLOBAL f ]
]
||_: Gtail2 (Eidapl f [].el) r n
end
|| Gtail es _ _ = fail ("Gtail "@show_list pr es)
end