diff --git a/data_lang/j8.py b/data_lang/j8.py index 6fadad139c..6387e476e5 100644 --- a/data_lang/j8.py +++ b/data_lang/j8.py @@ -26,9 +26,11 @@ import math from _devbuild.gen.id_kind_asdl import Id, Id_t, Id_str -from _devbuild.gen.value_asdl import (value, value_e, value_t, value_str, Obj) from _devbuild.gen.nil8_asdl import (nvalue, nvalue_t) +from _devbuild.gen.runtime_asdl import error_code_e +from _devbuild.gen.value_asdl import (value, value_e, value_t, value_str, Obj) +from core import bash_impl from core import error from data_lang import pyj8 # dependency issue: consts.py pulls in frontend/option_def.py @@ -360,14 +362,15 @@ def _PrintSparseArray(self, val, level): self._PrintBashPrefix('"SparseArray",', level) - if len(val.d) == 0: # Special case like Python/JS + if bash_impl.SparseArray_Count( + val) == 0: # Special case like Python/JS self.buf.write('{}') else: self.buf.write('{') self._MaybeNewline() i = 0 - for k, v in iteritems(val.d): + for k in bash_impl.SparseArray_GetKeys(val): if i != 0: self.buf.write(',') self._MaybeNewline() @@ -378,6 +381,8 @@ def _PrintSparseArray(self, val, level): self.buf.write(':') self._MaybeSpace() + v, error_code = bash_impl.SparseArray_GetElement(val, k) + assert error_code == error_code_e.OK, error_code pyj8.WriteString(v, self.options, self.buf) i += 1 @@ -394,14 +399,14 @@ def _PrintBashArray(self, val, level): self._PrintBashPrefix('"BashArray",', level) - if len(val.strs) == 0: # Special case like Python/JS + if bash_impl.BashArray_Count(val) == 0: # Special case like Python/JS self.buf.write('{}') else: self.buf.write('{') self._MaybeNewline() first = True - for i, s in enumerate(val.strs): + for i, s in enumerate(bash_impl.BashArray_GetValues(val)): if s is None: continue @@ -431,14 +436,14 @@ def _PrintBashAssoc(self, val, level): self._PrintBashPrefix('"BashAssoc",', level) - if len(val.d) == 0: # Special case like Python/JS + if bash_impl.BashAssoc_Count(val) == 0: # Special case like Python/JS self.buf.write('{}') else: self.buf.write('{') self._MaybeNewline() i = 0 - for k2, v2 in iteritems(val.d): + for k2, v2 in iteritems(bash_impl.BashAssoc_GetDict(val)): if i != 0: self.buf.write(',') self._MaybeNewline() diff --git a/display/pp_value.py b/display/pp_value.py index e236fa0f06..97ac02ea7a 100644 --- a/display/pp_value.py +++ b/display/pp_value.py @@ -7,7 +7,9 @@ import math from _devbuild.gen.pretty_asdl import (doc, Measure, MeasuredDoc) +from _devbuild.gen.runtime_asdl import error_code_e from _devbuild.gen.value_asdl import Obj, value, value_e, value_t, value_str +from core import bash_impl from data_lang import j8 from data_lang import j8_lite from display import ansi @@ -175,10 +177,10 @@ def _YshDict(self, vdict): def _BashArray(self, varray): # type: (value.BashArray) -> MeasuredDoc type_name = self._Styled(self.type_style, AsciiText('BashArray')) - if len(varray.strs) == 0: + if bash_impl.BashArray_Count(varray) == 0: return _Concat([AsciiText('('), type_name, AsciiText(')')]) mdocs = [] # type: List[MeasuredDoc] - for s in varray.strs: + for s in bash_impl.BashArray_GetValues(varray): if s is None: mdocs.append(AsciiText('null')) else: @@ -189,10 +191,10 @@ def _BashArray(self, varray): def _BashAssoc(self, vassoc): # type: (value.BashAssoc) -> MeasuredDoc type_name = self._Styled(self.type_style, AsciiText('BashAssoc')) - if len(vassoc.d) == 0: + if bash_impl.BashAssoc_Count(vassoc) == 0: return _Concat([AsciiText('('), type_name, AsciiText(')')]) mdocs = [] # type: List[MeasuredDoc] - for k2, v2 in iteritems(vassoc.d): + for k2, v2 in iteritems(bash_impl.BashAssoc_GetDict(vassoc)): mdocs.append( _Concat([ AsciiText('['), @@ -206,10 +208,12 @@ def _BashAssoc(self, vassoc): def _SparseArray(self, val): # type: (value.SparseArray) -> MeasuredDoc type_name = self._Styled(self.type_style, AsciiText('SparseArray')) - if len(val.d) == 0: + if bash_impl.SparseArray_Count(val) == 0: return _Concat([AsciiText('('), type_name, AsciiText(')')]) mdocs = [] # type: List[MeasuredDoc] - for k2, v2 in iteritems(val.d): + for k2 in bash_impl.SparseArray_GetKeys(val): + v2, error_code = bash_impl.SparseArray_GetElement(val, k2) + assert error_code == error_code_e.OK, error_code mdocs.append( _Concat([ AsciiText('['),