Skip to content

Commit

Permalink
[translation] More Hay translation
Browse files Browse the repository at this point in the history
Still need to translate the functions.
  • Loading branch information
Andy C committed Aug 1, 2023
1 parent edb545e commit 66a1d50
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 215 deletions.
8 changes: 3 additions & 5 deletions core/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,9 @@ def AddBlock(builtins, mem, mutable_opts, dir_stack, cmd_ev, shell_ex,
builtins[builtin_i.shopt] = builtin_pure.Shopt(mutable_opts, cmd_ev)
builtins[builtin_i.try_] = builtin_meta.Try(mutable_opts, mem, cmd_ev,
shell_ex, errfmt)
if mylib.PYTHON:
builtins[builtin_i.hay] = builtin_pure.Hay(hay_state, mutable_opts, mem,
cmd_ev)
builtins[builtin_i.haynode] = builtin_pure.HayNode(
hay_state, mem, cmd_ev)
builtins[builtin_i.hay] = builtin_pure.Hay(hay_state, mutable_opts, mem,
cmd_ev)
builtins[builtin_i.haynode] = builtin_pure.HayNode(hay_state, mem, cmd_ev)


def AddMethods(methods):
Expand Down
39 changes: 18 additions & 21 deletions core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,23 @@ def PopEval(self):
node = self._MakeOutputNode()
self.result_stack = [node]

if mylib.PYTHON: # TODO: hay results should be a value_t tree

def AppendResult(self, d):
# type: (Dict[str, value_t]) -> None
"""Called by haynode builtin."""
UP_children = self.result_stack[-1]['children']
assert UP_children.tag() == value_e.List, UP_children
children = cast(value.List, UP_children)
children.items.append(value.Dict(d))

def Result(self):
# type: () -> Dict[str, value_t]
"""Called by hay eval and eval_hay()"""
return self.output

def HayRegister(self):
# type: () -> Dict[str, value_t]
"""Called by _hay() function."""
return self.result_stack[0]
def AppendResult(self, d):
# type: (Dict[str, value_t]) -> None
"""Called by haynode builtin."""
UP_children = self.result_stack[-1]['children']
assert UP_children.tag() == value_e.List, UP_children
children = cast(value.List, UP_children)
children.items.append(value.Dict(d))

def Result(self):
# type: () -> Dict[str, value_t]
"""Called by hay eval and eval_hay()"""
return self.output

def HayRegister(self):
# type: () -> Dict[str, value_t]
"""Called by _hay() function."""
return self.result_stack[0]

def Resolve(self, first_word):
# type: (str) -> bool
Expand Down Expand Up @@ -489,8 +487,7 @@ def Pop(self):
self.def_stack.pop()
self.cur_defs = self.def_stack[-1]

if mylib.PYTHON:
self.result_stack.pop()
self.result_stack.pop()


class OptHook(object):
Expand Down
37 changes: 15 additions & 22 deletions library/func_hay.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,22 @@ def __init__(self, hay_state, mutable_opts, mem, cmd_ev):
self.mem = mem
self.cmd_ev = cmd_ev

if mylib.PYTHON:
# Hard to translate the Dict[str, Any]
def Call(self, val):
# type: (value_t) -> Dict[str, value_t]

def Call(self, block):
# type: (value_t) -> Dict[str, Any]
call_loc = loc.Missing
if val.tag() != value_e.Block:
raise error.Expr('Expected a block, got %s' % val, call_loc)

call_loc = loc.Missing
if block.tag() != value_e.Block:
raise error.Expr('Expected a block, got %s' % block, call_loc)
block = cast(value.Block, val)
with state.ctx_HayEval(self.hay_state, self.mutable_opts,
self.mem):
unused = self.cmd_ev.EvalBlock(block.body)

UP_block = block
block = cast(value.Block, UP_block)
return self.hay_state.Result()

with state.ctx_HayEval(self.hay_state, self.mutable_opts,
self.mem):
unused = self.cmd_ev.EvalBlock(block.body)

return self.hay_state.Result()

# Note: we should discourage the unvalidated top namesapce for files? It
# needs more validation.
# Note: we should discourage the unvalidated top namesapce for files? It
# needs more validation.


class BlockAsStr(object):
Expand All @@ -118,8 +113,6 @@ def __init__(self, hay_state):
# type: (state.Hay) -> None
self.hay_state = hay_state

if mylib.PYTHON:

def Call(self):
# type: () -> Dict[str, Any]
return self.hay_state.HayRegister()
def Call(self):
# type: () -> Dict[str, value_t]
return self.hay_state.HayRegister()

0 comments on commit 66a1d50

Please sign in to comment.