OILS / core / runtime.asdl View on Github | oils.pub

196 lines, 81 significant
1# Data types used at runtime
2
3module runtime
4{
5 # import from frontend/syntax.asdl
6 use frontend syntax {
7 loc Token
8 expr word command
9 CompoundWord DoubleQuoted
10 ArgList re redir_loc proc_sig
11 Func
12 }
13
14 use core value {
15 value Obj
16 }
17
18 # Evaluating SimpleCommand results in either an argv array or an assignment.
19 # in 'local foo', rval is None.
20 AssignArg = (str var_name, value? rval, bool plus_eq, CompoundWord blame_word)
21
22 ProcArgs = (
23 # Unevaluated args
24 ArgList typed_args,
25
26 # Evaluated args, similar to typed_args.py Reader
27 List[value]? pos_args, Dict[str, value]? named_args,
28
29 # block_arg comes from either p (; ; myblock) or p { echo b }
30 value? block_arg
31 )
32
33 # note: could import 'builtin' from synthetic option_asdl
34 cmd_value =
35 Argv(List[str] argv, List[CompoundWord] arg_locs,
36 bool is_last_cmd,
37 Obj? self_obj, ProcArgs? proc_args)
38
39 | Assign(int builtin_id,
40 List[str] argv, List[CompoundWord] arg_locs,
41 List[AssignArg] pairs)
42
43 # A Piece is a part of a word that's been evaluated
44 # Bare word | echo *.py | quoted=False do_split=False
45 # Unquoted subst | $x ${x} | quoted=False do_split=True
46 # Quoted string | 'sq' "$x" | quoted=True do_split=False
47 # The 'quoted' flag is used to determine whether globbing will occur, as well
48 # as empty elision like x=''; $x$x versus "$x"$x
49 Piece = (str s, bool quoted, bool do_split)
50
51 # A parse-time word_part from syntax.asdl is evaluated to a runtime
52 # part_value.
53 part_value =
54 String %Piece
55
56 # "$@" or "${a[@]}" # never globbed or split (though other shells
57 # split them)
58 | Array(List[str] strs, bool quoted)
59 # only produced when EXTGLOB_FS flag is passed
60 | ExtGlob(List[part_value] part_vals)
61
62 coerced = Int | Float | Neither
63
64 # evaluation state for BracedVarSub. See "doc/ref/chap-word-lang.md" for
65 # the description of h-value of a variable substitution.
66 VarSubState = (bool join_array, value h_value, Token array_ref)
67
68 # A Cell is a wrapper for a value.
69 # TODO: add location for declaration for 'assigning const' error
70
71 # Invariant: if exported or nameref is set, the val should be Str or Undef.
72 # This is enforced in mem.SetValue but isn't expressed in the schema.
73 Cell = (bool exported, bool readonly, bool nameref, value val)
74
75 # Where scopes are used
76 # Shopt: to respect shopt -u dynamic_scope.
77 # GetValue: Dynamic or LocalOrGlobal
78 # SetValue: Dynamic or LocalOnly
79 # Dynamic:
80 # GetValue: Shell Style
81 # SetValue: Shell Style
82 # LocalOrGlobal:
83 # GetValue: YSH style
84 # SetValue: N/A
85 # LocalOnly:
86 # GetValue: N/A, we can always READ globals
87 # SetValue: setvar, parameter bindings, for loop iterator vars
88 # GlobalOnly:
89 # GetValue: N/A
90 # SetValue: internal use in COMPREPLY, and YSH 'setglobal' keyword
91
92 # TODO: Avoid mutating __builtins__? This could be illegal:
93 #
94 # setvar io.glob = 'foo'
95 #
96 # Instead of LocalOnly, GlobalOnly, have MutateLocalOnly, MutateGlobalOnly?
97 # So they don't find the 'io' or 'vm' builtin Objs
98
99 scope = Shopt | Dynamic | LocalOrGlobal | LocalOnly | GlobalOnly
100
101 # What is valid in arrays or assoc arrays a[i] or A[i] in shell.
102 # Used for ${a[i]=x}.
103 a_index = Str(str s) | Int(int i)
104
105 # For the place in ${a[0]=a}
106 # Transformed into sh_lvalue_t
107 VTestPlace = (str? name, a_index? index)
108
109 redirect_arg =
110 Path(str filename)
111 | CopyFd(int target_fd)
112 | MoveFd(int target_fd) # 3>&1-
113 | CloseFd
114 | HereDoc(str body) # call this String and combine with Path?
115
116 # Evaluated version of syntax.Redir
117 RedirValue = (id op_id, loc op_loc, redir_loc loc, redirect_arg arg)
118
119 # An exit status with location info. For process sub.
120 StatusArray = (
121 List[int]? codes, # init to null, rarely allocated
122 List[loc]? locs # init to null, rarely allocated
123 )
124
125 CommandStatus = (
126 # set for atoms
127 bool check_errexit,
128
129 # By default, don't show the code on errexit. Sometimes we want to.
130 bool show_code
131
132 # Should we use 'int simple_status' for atoms like atoms like ls (( [[ ?
133
134 # for pipeline
135 bool pipe_negated,
136 List[int]? pipe_status, # init to null, rarely allocated
137 List[loc]? pipe_locs, # init to null, rarely allocated
138 )
139
140 # core/process.py
141 # A Job is a Process or Pipeline.
142 # - Processes usually go from Running to Stopped, unless unless Ctrl-Z stops
143 # them.
144 # - Pipelines go Running to Done. They are never stopped; only the processes
145 # inside them are stopped.
146 job_state = Running | Exited | Stopped
147
148 # event is W1_EXITED or W1_STOPPED
149 wait_status =
150 Proc(job_state state, int code)
151 | Pipeline(job_state state, List[int] codes)
152 # because the 'wait' builtin is interruptible
153 | Cancelled(int sig_num)
154
155 flow = Nothing | Break | Raise
156
157 # For word splitting (in frontend/consts.py and osh/split.py)
158 span = Black | Delim | Backslash
159
160 emit = Part | Delim | Empty | Escape | Nothing
161 generate [integers]
162 state = Invalid | Start | DE_White1 | DE_Gray | DE_White2 | Black | Backslash | Done
163 generate [integers]
164
165 # Edges are characters. DE_ is the delimiter prefix. DE_White is for
166 # whitespace; DE_Gray is for other IFS chars; Black is for significant
167 # characters. Sentinel is the end of the string.
168 char_kind = DE_White | DE_Gray | Black | Backslash | Sentinel
169 generate [integers]
170
171 # core/bash_impl.py
172 error_code = OK | IndexOutOfRange
173
174 # Flag arguments can be any of these types.
175 flag_type = Bool | Int | Float | Str
176
177 # For dev.Tracer
178 trace =
179 External(List[str] argv) # sync, needs argv (command.Simple or 'command')
180 | CommandSub # sync
181 | ForkWait # sync
182 | Fork # async, needs argv, & fork
183 | PipelinePart # async
184 | ProcessSub # async (other processes can be started)
185 | HereDoc # async (multiple here docs per process)
186
187 # tools/ysh_ify.py
188 word_style = Expr | Unquoted | DQ | SQ
189
190 # Hay "first word" namespace
191 HayNode = (Dict[str, HayNode] children)
192
193 comp_action = Other | FileSystem | BashFunc
194}
195
196# vim: sw=2