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

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