1 |
# YSH specific features of eval
|
2 |
|
3 |
## our_shell: ysh
|
4 |
## oils_failures_allowed: 1
|
5 |
|
6 |
|
7 |
|
8 |
var b = ^(echo obj)
|
9 |
eval (b)
|
10 |
|
11 |
eval (^(echo command literal))
|
12 |
|
13 |
eval { echo block }
|
14 |
|
15 |
## STDOUT:
|
16 |
obj
|
17 |
command literal
|
18 |
block
|
19 |
## END
|
20 |
|
21 |
|
22 |
|
23 |
proc run (;;; block) {
|
24 |
eval (block)
|
25 |
}
|
26 |
|
27 |
run {
|
28 |
echo 'In a block!'
|
29 |
}
|
30 |
## STDOUT:
|
31 |
In a block!
|
32 |
## END
|
33 |
|
34 |
|
35 |
proc lazy-block ( ; out; ; block) {
|
36 |
call out->setValue(block)
|
37 |
}
|
38 |
|
39 |
var myglobal = 0
|
40 |
|
41 |
lazy-block (&my_block) {
|
42 |
json write (myglobal)
|
43 |
}
|
44 |
|
45 |
eval (my_block)
|
46 |
setvar myglobal = 1
|
47 |
eval (my_block)
|
48 |
## STDOUT:
|
49 |
0
|
50 |
1
|
51 |
## END
|
52 |
|
53 |
|
54 |
|
55 |
proc p2(code_str) {
|
56 |
var mylocal = 42
|
57 |
eval $code_str
|
58 |
}
|
59 |
|
60 |
p2 'echo mylocal=$mylocal'
|
61 |
|
62 |
proc p (;;; block) {
|
63 |
var mylocal = 99
|
64 |
eval (block)
|
65 |
}
|
66 |
|
67 |
p {
|
68 |
echo mylocal=$mylocal
|
69 |
}
|
70 |
|
71 |
|
72 |
## STDOUT:
|
73 |
mylocal=42
|
74 |
mylocal=99
|
75 |
## END
|
76 |
|
77 |
|
78 |
|
79 |
proc p (;;; block) {
|
80 |
var this = 42
|
81 |
|
82 |
# like push-registers? Not sure
|
83 |
# We could use state.ctx_Temp ? There's also ctx_FuncCall etc.
|
84 |
#
|
85 |
# I think we want to provide full control over the stack.
|
86 |
push-frame {
|
87 |
eval (block)
|
88 |
}
|
89 |
}
|
90 |
|
91 |
p {
|
92 |
echo $this
|
93 |
}
|
94 |
|
95 |
## status: 1
|
96 |
## STDOUT:
|
97 |
TODO
|
98 |
## END
|