-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiter.mdtlbl
97 lines (90 loc) · 2.01 KB
/
iter.mdtlbl
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#**
* 一个简单的内存和迭代器结构示例
*#
const Memory = (
take $.Mem = _0;
take $.Beg = _1;
take $.Len = _2;
match $.Beg {
[0] {
const $.Index = (setres _0;);
}
__ {
const $.Index = (
take Idx = _0;
take Beg = ...Beg;
setres ($ = Beg + Idx;);
);
}
}
const $.IndexTo = (
take Target = _0;
take Idx = _1;
take Beg = ...Beg;
Target = Beg + Idx;
);
const $.Read = (
take Idx = _0;
read $ ...Mem ...Index[Idx];
);
const $.Write = (
take Idx = _0;
take Data = _1;
write Data ...Mem ...Index[Idx];
);
const $.Iter = (
take $.Mem = ..;
take Beg = ...Beg;
match ...Beg {
[0] {
take $.End = ...Len;
}
Beg {
take Len = ...Len;
take $.End = ($ = Len + Beg;);
}
}
take I = $.i;
take ...IndexTo[I 0];
const $.Get = (
read $ ...Mem.Mem ...i;
);
const $.Run = (
const F = _0;
take Binder = ..;
take I = ...i;
take Get = Builtin.BindHandle2[`Binder` `Get`];
take Builtin.Const[`Get` Get];
take F[I Get];
);
const $.Next = (
const F = _0;
take I = ...i;
if I < ...End {
take ...Run[F];
I++;
}
);
const $.ForEach = (
const F = _0;
take I = ...i;
while I < ...End {
take ...Run[F];
I++;
}
);
);
);
take Mem = Memory[cell1 16 16];
take Iter = Mem.Iter[];
take Iter.Next[(
print "first: "_1"\n";
)];
take Iter.ForEach[(
const f.F = (
print "i: "_0", val: "_1"\n";
);
take f.F[_0 _1];
)];
print "Idx10: "Iter.Mem.Read[10];
printflush message1;