Permalink
Browse files

Implement $0

  • Loading branch information...
Andy Chu
Andy Chu committed Mar 17, 2017
1 parent f1a7e38 commit 8af0906d6b2772832c0904ef4a8cb1b491f238cd
Showing with 9 additions and 6 deletions.
  1. +3 −4 bin/oil.py
  2. +5 −1 core/cmd_exec.py
  3. +1 −1 core/word_eval.py
View
@@ -181,11 +181,10 @@ def OshMain(argv):
if 'lexer' in opts.trace:
util.WrapMethods(lexer.Lexer, state)
# TODO: Should be bin/osh sys.argv[0] if no args
if len(argv) >= 2:
dollar0 = argv[0]
if len(argv) == 0:
dollar0 = sys.argv[0] # e.g. bin/osh
else:
dollar0 = ''
dollar0 = argv[0] # the script name
# TODO: Create a --parse action or 'osh parse' or 'oil osh-parse'
# osh-fix
View
@@ -100,7 +100,7 @@ class Mem(object):
def __init__(self, argv0, argv):
self.top = {} # string -> (flags, Value)
self.var_stack = [self.top]
self.argv0 = argv
self.argv0 = argv0
self.argv_stack = [argv]
self.last_status = 0 # Mutable public variable
@@ -113,6 +113,10 @@ def Pop(self):
self.var_stack.pop()
self.argv_stack.pop()
def GetArgv0(self):
"""For $0."""
return self.argv0
def GetArgv(self):
"""For $* and $@."""
return self.argv_stack[-1] # top of stack
View
@@ -537,7 +537,7 @@ def _EvalVarNum(self, var_num):
assert var_num >= 0
if var_num == 0:
raise NotImplementedError
return True, Value.FromString(self.mem.GetArgv0())
else:
index = var_num - 1
if index < len(argv):

0 comments on commit 8af0906

Please sign in to comment.