@@ -41,6 +41,14 @@ def _CheckPosArgs(pos_args_raw, blame_loc):
41
41
42
42
43
43
class EvalExpr (vm ._Callable ):
44
+ """io->evalExpr(ex) evaluates an expression
45
+
46
+ Notes compared with io->eval(cmd):
47
+ - there is no evalToDict variant - doesn't make sense
48
+ - Does it need in_captured_frame=true?
49
+ - That is for "inline procs" like cd, but doesn't seem to be necessary
50
+ for expressions. Unless we had mutations in expressions.
51
+ """
44
52
45
53
def __init__ (self , expr_ev ):
46
54
# type: (expr_eval.ExprEvaluator) -> None
@@ -71,21 +79,23 @@ def Call(self, rd):
71
79
return result
72
80
73
81
74
- def _PrintFrame (prefix , frame ):
75
- # type: (str, Dict[str, Cell]) -> None
76
- print ('%s %s' % (prefix , ' ' .join (frame .keys ())))
82
+ if 0 :
83
+
84
+ def _PrintFrame (prefix , frame ):
85
+ # type: (str, Dict[str, Cell]) -> None
86
+ print ('%s %s' % (prefix , ' ' .join (frame .keys ())))
77
87
78
- rear = frame .get ('__E__' )
79
- if rear :
80
- rear_val = rear .val
81
- if rear_val .tag () == value_e .Frame :
82
- r = cast (value .Frame , rear_val )
83
- _PrintFrame ('--> ' + prefix , r .frame )
88
+ rear = frame .get ('__E__' )
89
+ if rear :
90
+ rear_val = rear .val
91
+ if rear_val .tag () == value_e .Frame :
92
+ r = cast (value .Frame , rear_val )
93
+ _PrintFrame ('--> ' + prefix , r .frame )
84
94
85
95
86
96
class EvalInFrame (vm ._Callable ):
87
97
"""
88
- For making "inline procs"
98
+ DEPRECATED, replaced by eval(b, in_captured_frame=true)
89
99
"""
90
100
91
101
def __init__ (self , mem , cmd_ev ):
@@ -140,46 +150,38 @@ def Call(self, rd):
140
150
unused = rd .PosValue ()
141
151
bound = rd .PosCommand ()
142
152
143
- frag = typed_args .GetCommandFrag (bound )
144
-
145
153
dollar0 = rd .NamedStr ("dollar0" , None )
146
154
pos_args_raw = rd .NamedList ("pos_args" , None )
147
155
vars_ = rd .NamedDict ("vars" , None )
148
156
in_captured_frame = rd .NamedBool ("in_captured_frame" , None )
149
157
rd .Done ()
150
158
159
+ frag = typed_args .GetCommandFrag (bound )
160
+
151
161
pos_args = _CheckPosArgs (pos_args_raw , rd .LeftParenToken ())
152
162
153
- # TODO: Add debug_frame here, with ctx_Eval or ctx_EvalDebugFrame
154
163
with state .ctx_TokenDebugFrame (self .mem , rd .LeftParenToken ()):
155
164
if self .which == EVAL_NULL :
156
- # _PrintFrame('[captured]', captured_frame)
157
- with state .ctx_EnclosedFrame (self .mem ,
158
- bound .captured_frame ,
159
- bound .module_frame ,
160
- None ,
161
- inside = in_captured_frame ):
162
- # _PrintFrame('[new]', self.cmd_ev.mem.var_stack[-1])
163
- with state .ctx_Eval (self .mem , dollar0 , pos_args , vars_ ):
164
- unused_status = self .cmd_ev .EvalCommandFrag (frag )
165
- return value .Null
166
-
165
+ bindings = None # type: Optional[Dict[str, value_t]]
167
166
elif self .which == EVAL_DICT :
168
- # TODO: dollar0, pos_args, vars_ not supported
169
- #
170
- # Does ctx_EnclosedFrame has different scoping rules? For "vars"?
171
-
172
- bindings = NewDict () # type: Dict[str, value_t]
173
- with state .ctx_EnclosedFrame (self .mem ,
174
- bound .captured_frame ,
175
- bound .module_frame ,
176
- bindings ,
177
- inside = in_captured_frame ):
167
+ bindings = NewDict ()
168
+ else :
169
+ raise AssertionError ()
170
+
171
+ # _PrintFrame('[captured]', captured_frame)
172
+ with state .ctx_EnclosedFrame (self .mem ,
173
+ bound .captured_frame ,
174
+ bound .module_frame ,
175
+ bindings ,
176
+ inside = in_captured_frame ):
177
+ # _PrintFrame('[new]', self.cmd_ev.mem.var_stack[-1])
178
+ with state .ctx_Eval (self .mem , dollar0 , pos_args , vars_ ):
178
179
unused_status = self .cmd_ev .EvalCommandFrag (frag )
179
- return value .Dict (bindings )
180
180
181
+ if self .which == EVAL_NULL :
182
+ return value .Null
181
183
else :
182
- raise AssertionError ( )
184
+ return value . Dict ( bindings )
183
185
184
186
185
187
class CaptureStdout (vm ._Callable ):
0 commit comments