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