-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_imperative5.tex
158 lines (133 loc) · 4.33 KB
/
test_imperative5.tex
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
%! TEX program = lualatex
\documentclass{article}
\usepackage{prettytok}
\prettyinitterm
\errorcontextlines=3
\usepackage{imperative}
\usepackage{genvar}
\AutoGenerateVariants
\begin{document}
\ExplSyntaxOn
\directlua{imperative_debug=true}
\begin{imperativerun}
\zblock{
\ucalllocal{
\pretty:n {hash=##}
\int_step_inline:nn {3} \scope #i {
\pretty:n {i=#i, hash=##}
}
}
}
%\end{ imperativerun}
%\end{document}
%
%\begin{imperativerun}
\int_step_inline:nn {3} \scope #i {
\pretty:n {i=#i, hash=##}
\int_step_inline:nn {3} \scope #j {
\pretty:n {i=#i, j=#j, hash=##}
}
}
\int_step_inline:nn {3} \scope #i {
%\int_step_inline:nn {3} \scope #i {} % must error, variable shadowing
}
\zblock{
\assign #a {hello}
\assign #a {hello}
\ucalllocal{
%#a
\zblock{\pretty{#a}} % but zblock cannot receive from outside [produce]?
}
}
\def\f\scopevar #a{
\zblock{\return{#a}} % zblock can receive from outside \scope
}
\pretty:n {should show single: #a}
\cs_new_protected:Npn \__functiona \scopevar #a {
\cs_new_protected:Npn \__functiona \scopevar #b {
#a #b % this expr compiles to '#1 ##1'
\zblock { \pretty {#a #b} } % this zblock compiles to \something {#1} {##1}
% idea:
% * first compile \zblock alone, giving it the information that #a and #b are outer var (to detect possible reassignment/shadowing error)
% * then it results in \something {#a} {#b}
% * then {#a} {#b} is compiled to {#1} {##1}
\zblock {
\assign #c {123}
\ucalllocal{
\zblock{\pretty{#a #b #c}}
% let's see if the same idea works...
% * first compile zblock alone results in \something {#a} {#b} {#c}
% then the outer zblock compiles the ucall, not knowing what #a and #b corresponds to, only that it's outer
% thus results in an ucall to \something {#a} {#b} {#1} for example
% final result should be something like \zblockcaller {#a} {#b}
}
}
\zblock{
\assign #c {123}
\ucalllocal{
\cs_new_protected:Npn \__functionb \scopevar #d {
#c #d
}
% scope inside ucall. Let's see how it should compile.
% first, the innermost scopevar compiles '#c #d' to '#c ##1'.
% then we have \ucall { ... #c ##1 }, which will be translated to the correct value.
% note that #d must NOT be included in the need list.
%
% ah, problem here.
% Compiling the inner block requires knowing what's the need value of that statement.
% But knowing what's the need value of any statement requires compiling the inner block
% (to know which variables are needed by that statement)...
%
% well, knowing the produce value should not need...
% but the intention here is to only prevent misleading re-assignment instead of all of them...
%
% let's see... how complicated.
% worst case just tell the user to explicitly delete variables.
%
% plan:
% * first keep the expr values uncompiled...
% * then determine what's the produce values, propagate things etc.
% * then compile the inner expr, given the information which values are outervar.
% * finally, from that, determine the need values and propagate it.
}
}
}
}
%TODO implement zfunction later
\zblock {
\assign #a {123##}
\ucalllocal{ \pretty:n {should show single: ##a, a = #a} }
\pretty {should show single: ##a, a = #a}
}% \pretty:no {DEBUG} { \cC{stzz101}{#1} }
\cs_new_protected:Npn \__function \scopevar #a #b #c # {
\pretty:n {should show single: ##a}
\pretty:n {vars: #a #b #c }
\zblock {
\pretty{vars: #a ##} % check closure passing/capturing of #a from scope to zblock
%\assign #c {456} % must error, assign variable from outer function
\ucalllocal{
\cs_gset_protected:Npn \__inner \scopevar #d {
\pretty:n {d=#d, single hash=##a}
}
\__inner {dd#a}
\zblock{
\pretty {c=#c, single hash=##a} % capture #c from outside. check capturing from zblock to inner zblock
}
\cs_gset_protected:Npn \__innerb ##1{
\pretty:n {d=##1, single hash=####a}
}
\__innerb {dd#a}
}
}
\zblock {
%\assign #c {456} % must error, assign variable from outer function
}
\cs_gset_protected:Npn \__inner \scopevar #d {
\pretty:n {d=#d, single hash=##a}
}
\__inner {dd#a}
}
\__function {valuea\par} {valueb} valuec {}
\end{imperativerun}
\ExplSyntaxOff
\end{document}