1 | # Data types used at runtime
|
2 |
|
3 | module 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 | LiteralBlock Func
|
12 | }
|
13 |
|
14 | use core value {
|
15 | value
|
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 | # note: could import 'builtin' from synthetic option_asdl
|
23 | cmd_value =
|
24 | Argv(List[str] argv, List[CompoundWord] arg_locs,
|
25 | bool is_last_cmd,
|
26 | ArgList? typed_args,
|
27 | # Evaluated args, similar to typed_args.py Reader
|
28 | List[value]? pos_args, Dict[str, value]? named_args,
|
29 | # block_arg comes from either p (; ; myblock) or p { echo b }
|
30 | value? block_arg)
|
31 |
|
32 | | Assign(int builtin_id,
|
33 | List[str] argv, List[CompoundWord] arg_locs,
|
34 | List[AssignArg] pairs)
|
35 |
|
36 | # - Single or double quoted parts get neither split or globbed.
|
37 | # - Bare words like echo or *.py are globbed, but NOT split with IFS.
|
38 | # - Unquoted Substitutions are split and globbed.
|
39 | Piece = (str s, bool quoted, bool do_split)
|
40 |
|
41 | # A parse-time word_part from syntax.asdl is evaluated to a runtime
|
42 | # part_value.
|
43 | part_value =
|
44 | String %Piece
|
45 |
|
46 | # "$@" or "${a[@]}" # never globbed or split (though other shells
|
47 | # split them)
|
48 | | Array(List[str] strs)
|
49 | # only produced when EXTGLOB_FS flag is passed
|
50 | | ExtGlob(List[part_value] part_vals)
|
51 |
|
52 | coerced = Int | Float | Neither
|
53 |
|
54 | # evaluation state for BracedVarSub
|
55 | VarSubState = (bool join_array, bool is_type_query, bool has_test_op)
|
56 |
|
57 | # A Cell is a wrapper for a value.
|
58 | # TODO: add location for declaration for 'assigning const' error
|
59 |
|
60 | # Invariant: if exported or nameref is set, the val should be Str or Undef.
|
61 | # This is enforced in mem.SetValue but isn't expressed in the schema.
|
62 | Cell = (bool exported, bool readonly, bool nameref, value val)
|
63 |
|
64 | # Where scopes are used
|
65 | # Shopt: to respect shopt -u dynamic_scope.
|
66 | # Dynamic -> LocalOrGlobal for reading
|
67 | # Dynamic -> LocalOnly for writing.
|
68 | # Dynamic:
|
69 | # GetValue: Shell Style
|
70 | # SetValue: Shell Style
|
71 | # LocalOrGlobal:
|
72 | # GetValue: Oil style
|
73 | # SetValue: N/A
|
74 | # LocalOnly:
|
75 | # GetValue: N/A, we can always READ globals
|
76 | # SetValue: setvar, parameter bindings, for loop iterator vars
|
77 | # GlobalOnly:
|
78 | # GetValue: N/A
|
79 | # SetValue: internal use in COMPREPLY, and Oil's 'setglobal' keyword
|
80 |
|
81 | scope = Shopt | Dynamic | LocalOrGlobal | LocalOnly | GlobalOnly
|
82 |
|
83 | # What is valid in arrays or assoc arrays a[i] or A[i] in shell.
|
84 | # Used for ${a[i]=x}.
|
85 | a_index = Str(str s) | Int(int i)
|
86 |
|
87 | # For the place in ${a[0]=a}
|
88 | # Transformed into sh_lvalue_t
|
89 | VTestPlace = (str? name, a_index? index)
|
90 |
|
91 | redirect_arg =
|
92 | Path(str filename)
|
93 | | CopyFd(int target_fd)
|
94 | | MoveFd(int target_fd) # 3>&1-
|
95 | | CloseFd
|
96 | | HereDoc(str body) # call this String and combine with Path?
|
97 |
|
98 | # Evaluated version of syntax.Redir
|
99 | RedirValue = (id op_id, loc op_loc, redir_loc loc, redirect_arg arg)
|
100 |
|
101 | # An exit status with location info. For process sub.
|
102 | StatusArray = (
|
103 | List[int]? codes, # init to null, rarely allocated
|
104 | List[loc]? locs # init to null, rarely allocated
|
105 | )
|
106 |
|
107 | CommandStatus = (
|
108 | # set for atoms
|
109 | bool check_errexit,
|
110 |
|
111 | # By default, don't show the code on errexit. Sometimes we want to.
|
112 | bool show_code
|
113 |
|
114 | # Should we use 'int simple_status' for atoms like atoms like ls (( [[ ?
|
115 |
|
116 | # for pipeline
|
117 | bool pipe_negated,
|
118 | List[int]? pipe_status, # init to null, rarely allocated
|
119 | List[loc]? pipe_locs, # init to null, rarely allocated
|
120 | )
|
121 |
|
122 | wait_status =
|
123 | Proc(int code)
|
124 | | Pipeline(List[int] codes)
|
125 | # because the 'wait' builtin is interruptible
|
126 | | Cancelled(int sig_num)
|
127 |
|
128 | flow = Nothing | Break | Raise
|
129 |
|
130 | # For word splitting (in frontend/consts.py and osh/split.py)
|
131 | span = Black | Delim | Backslash
|
132 |
|
133 | emit = Part | Delim | Empty | Escape | Nothing
|
134 | generate [integers]
|
135 | state = Invalid | Start | DE_White1 | DE_Gray | DE_White2 | Black | Backslash | Done
|
136 | generate [integers]
|
137 |
|
138 | # Edges are characters. DE_ is the delimiter prefix. DE_White is for
|
139 | # whitespace; DE_Gray is for other IFS chars; Black is for significant
|
140 | # characters. Sentinel is the end of the string.
|
141 | char_kind = DE_White | DE_Gray | Black | Backslash | Sentinel
|
142 | generate [integers]
|
143 |
|
144 | # core/process.py
|
145 | # A Job is a Process or Pipeline.
|
146 | # - Processes usually go from Running to Stopped, unless unless Ctrl-Z stops
|
147 | # them.
|
148 | # - Pipelines go Running to Done. They are never stopped; only the processes
|
149 | # inside them are stopped.
|
150 | job_state = Running | Done | Stopped
|
151 |
|
152 | # Flag arguments can be any of these types.
|
153 | flag_type = Bool | Int | Float | Str
|
154 |
|
155 | # For dev.Tracer
|
156 | trace =
|
157 | External(List[str] argv) # sync, needs argv (command.Simple or 'command')
|
158 | | CommandSub # sync
|
159 | | ForkWait # sync
|
160 | | Fork # async, needs argv, & fork
|
161 | | PipelinePart # async
|
162 | | ProcessSub # async (other processes can be started)
|
163 | | HereDoc # async (multiple here docs per process)
|
164 |
|
165 | # tools/ysh_ify.py
|
166 | word_style = Expr | Unquoted | DQ | SQ
|
167 |
|
168 | # Hay "first word" namespace
|
169 | HayNode = (Dict[str, HayNode] children)
|
170 |
|
171 | comp_action = Other | FileSystem | BashFunc
|
172 | }
|
173 |
|
174 | # vim: sw=2
|