OILS / core / runtime.asdl View on Github | oilshell.org

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