| 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 | Func
|
| 12 | }
|
| 13 |
|
| 14 | use core value {
|
| 15 | value Obj
|
| 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 | Obj? self_obj, 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, bool quoted)
|
| 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. See "doc/ref/chap-word-lang.md" for
|
| 62 | # the description of h-value of a variable substitution.
|
| 63 | VarSubState = (bool join_array, value h_value, Token array_ref)
|
| 64 |
|
| 65 | # A Cell is a wrapper for a value.
|
| 66 | # TODO: add location for declaration for 'assigning const' error
|
| 67 |
|
| 68 | # Invariant: if exported or nameref is set, the val should be Str or Undef.
|
| 69 | # This is enforced in mem.SetValue but isn't expressed in the schema.
|
| 70 | Cell = (bool exported, bool readonly, bool nameref, value val)
|
| 71 |
|
| 72 | # Where scopes are used
|
| 73 | # Shopt: to respect shopt -u dynamic_scope.
|
| 74 | # GetValue: Dynamic or LocalOrGlobal
|
| 75 | # SetValue: Dynamic or LocalOnly
|
| 76 | # Dynamic:
|
| 77 | # GetValue: Shell Style
|
| 78 | # SetValue: Shell Style
|
| 79 | # LocalOrGlobal:
|
| 80 | # GetValue: YSH style
|
| 81 | # SetValue: N/A
|
| 82 | # LocalOnly:
|
| 83 | # GetValue: N/A, we can always READ globals
|
| 84 | # SetValue: setvar, parameter bindings, for loop iterator vars
|
| 85 | # GlobalOnly:
|
| 86 | # GetValue: N/A
|
| 87 | # SetValue: internal use in COMPREPLY, and YSH 'setglobal' keyword
|
| 88 |
|
| 89 | # TODO: Avoid mutating __builtins__? This could be illegal:
|
| 90 | #
|
| 91 | # setvar io.glob = 'foo'
|
| 92 | #
|
| 93 | # Instead of LocalOnly, GlobalOnly, have MutateLocalOnly, MutateGlobalOnly?
|
| 94 | # So they don't find the 'io' or 'vm' builtin Objs
|
| 95 |
|
| 96 | scope = Shopt | Dynamic | LocalOrGlobal | LocalOnly | GlobalOnly
|
| 97 |
|
| 98 | # What is valid in arrays or assoc arrays a[i] or A[i] in shell.
|
| 99 | # Used for ${a[i]=x}.
|
| 100 | a_index = Str(str s) | Int(int i)
|
| 101 |
|
| 102 | # For the place in ${a[0]=a}
|
| 103 | # Transformed into sh_lvalue_t
|
| 104 | VTestPlace = (str? name, a_index? index)
|
| 105 |
|
| 106 | redirect_arg =
|
| 107 | Path(str filename)
|
| 108 | | CopyFd(int target_fd)
|
| 109 | | MoveFd(int target_fd) # 3>&1-
|
| 110 | | CloseFd
|
| 111 | | HereDoc(str body) # call this String and combine with Path?
|
| 112 |
|
| 113 | # Evaluated version of syntax.Redir
|
| 114 | RedirValue = (id op_id, loc op_loc, redir_loc loc, redirect_arg arg)
|
| 115 |
|
| 116 | # An exit status with location info. For process sub.
|
| 117 | StatusArray = (
|
| 118 | List[int]? codes, # init to null, rarely allocated
|
| 119 | List[loc]? locs # init to null, rarely allocated
|
| 120 | )
|
| 121 |
|
| 122 | CommandStatus = (
|
| 123 | # set for atoms
|
| 124 | bool check_errexit,
|
| 125 |
|
| 126 | # By default, don't show the code on errexit. Sometimes we want to.
|
| 127 | bool show_code
|
| 128 |
|
| 129 | # Should we use 'int simple_status' for atoms like atoms like ls (( [[ ?
|
| 130 |
|
| 131 | # for pipeline
|
| 132 | bool pipe_negated,
|
| 133 | List[int]? pipe_status, # init to null, rarely allocated
|
| 134 | List[loc]? pipe_locs, # init to null, rarely allocated
|
| 135 | )
|
| 136 |
|
| 137 | # core/process.py
|
| 138 | # A Job is a Process or Pipeline.
|
| 139 | # - Processes usually go from Running to Stopped, unless unless Ctrl-Z stops
|
| 140 | # them.
|
| 141 | # - Pipelines go Running to Done. They are never stopped; only the processes
|
| 142 | # inside them are stopped.
|
| 143 | job_state = Running | Exited | Stopped
|
| 144 |
|
| 145 | # event is W1_EXITED or W1_STOPPED
|
| 146 | wait_status =
|
| 147 | Proc(job_state state, int code)
|
| 148 | | Pipeline(job_state state, List[int] codes)
|
| 149 | # because the 'wait' builtin is interruptible
|
| 150 | | Cancelled(int sig_num)
|
| 151 |
|
| 152 | flow = Nothing | Break | Raise
|
| 153 |
|
| 154 | # For word splitting (in frontend/consts.py and osh/split.py)
|
| 155 | span = Black | Delim | Backslash
|
| 156 |
|
| 157 | emit = Part | Delim | Empty | Escape | Nothing
|
| 158 | generate [integers]
|
| 159 | state = Invalid | Start | DE_White1 | DE_Gray | DE_White2 | Black | Backslash | Done
|
| 160 | generate [integers]
|
| 161 |
|
| 162 | # Edges are characters. DE_ is the delimiter prefix. DE_White is for
|
| 163 | # whitespace; DE_Gray is for other IFS chars; Black is for significant
|
| 164 | # characters. Sentinel is the end of the string.
|
| 165 | char_kind = DE_White | DE_Gray | Black | Backslash | Sentinel
|
| 166 | generate [integers]
|
| 167 |
|
| 168 | # core/bash_impl.py
|
| 169 | error_code = OK | IndexOutOfRange
|
| 170 |
|
| 171 | # Flag arguments can be any of these types.
|
| 172 | flag_type = Bool | Int | Float | Str
|
| 173 |
|
| 174 | # For dev.Tracer
|
| 175 | trace =
|
| 176 | External(List[str] argv) # sync, needs argv (command.Simple or 'command')
|
| 177 | | CommandSub # sync
|
| 178 | | ForkWait # sync
|
| 179 | | Fork # async, needs argv, & fork
|
| 180 | | PipelinePart # async
|
| 181 | | ProcessSub # async (other processes can be started)
|
| 182 | | HereDoc # async (multiple here docs per process)
|
| 183 |
|
| 184 | # tools/ysh_ify.py
|
| 185 | word_style = Expr | Unquoted | DQ | SQ
|
| 186 |
|
| 187 | # Hay "first word" namespace
|
| 188 | HayNode = (Dict[str, HayNode] children)
|
| 189 |
|
| 190 | comp_action = Other | FileSystem | BashFunc
|
| 191 | }
|
| 192 |
|
| 193 | # vim: sw=2
|