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