Permalink
Browse files

Implement source with argv array.

The 2 tests from the last commit now pass.
  • Loading branch information...
Andy Chu
Andy Chu committed Jun 22, 2018
1 parent 1d6bbeb commit cb9850fe12528ee6887bfd565aecc1d216b5140a
Showing with 24 additions and 3 deletions.
  1. +14 −1 core/cmd_exec.py
  2. +9 −1 core/state.py
  3. +1 −1 test/spec.sh
View
@@ -249,7 +249,20 @@ def _Source(self, argv):
try:
line_reader = reader.FileLineReader(f, self.arena)
_, c_parser = parse_lib.MakeParser(line_reader, self.arena)
return self._EvalHelper(c_parser, path)
# A sourced module CAN have a new arguments array, but it always shares
# the same variable scope as the caller. The caller could be at either a
# global or a local scope.
source_argv = argv[1:]
if source_argv:
self.mem.PushSourceArgv(source_argv)
try:
status = self._EvalHelper(c_parser, path)
finally:
if source_argv:
self.mem.PopSourceArgv()
return status
except _ControlFlow as e:
if e.IsReturn():
View
@@ -466,14 +466,22 @@ def PopCall(self):
self.var_stack.pop()
self.argv_stack.pop()
def PushSourceArgv(self, argv):
"""For 'source foo.sh 1 2 3."""
self.func_name_stack.append('source')
self.argv_stack.append(_ArgFrame(argv))
def PopSourceArgv(self):
self.func_name_stack.pop()
self.argv_stack.pop()
def PushTemp(self):
"""For the temporary scope in 'FOO=bar BAR=baz echo'."""
# We don't want the 'read' builtin to write to this frame!
self.var_stack.append(_StackFrame(readonly=True))
def PopTemp(self):
self.var_stack.pop()
#util.log('**** PopTemp()')
#
# Argv
View
@@ -268,7 +268,7 @@ if_() {
}
builtins() {
sh-spec spec/builtins.test.sh --osh-failures-allowed 3 \
sh-spec spec/builtins.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH "$@"
}

0 comments on commit cb9850f

Please sign in to comment.