From 095a0f8882c726ddb0e3e1a9cd4ad8ad22e44831 Mon Sep 17 00:00:00 2001 From: Stephen Skeirik Date: Mon, 9 Dec 2024 17:43:20 -0500 Subject: [PATCH] run black formatter --- pykwasm/src/pykwasm/run_wasm.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pykwasm/src/pykwasm/run_wasm.py b/pykwasm/src/pykwasm/run_wasm.py index 4268976b3..0d769a01d 100644 --- a/pykwasm/src/pykwasm/run_wasm.py +++ b/pykwasm/src/pykwasm/run_wasm.py @@ -84,7 +84,8 @@ def build_subst_key(key_name): if key in config_subst: raise ValueError(f'redundant key found in substitution map: {prekey}') - if sort == 'String': val = '"' + f'{val}' + '"' + if sort == 'String': + val = '"' + f'{val}' + '"' config_subst[key] = KToken(val, sort) # parse module as binary (with fallback to textual parser) @@ -109,7 +110,9 @@ def build_subst_key(key_name): # check substitution keys ulm_keys = {'GAS_CELL', 'ENTRY_CELL', 'CREATE_CELL'} if ulm_keys.issubset(init_subst.keys()) and not ulm_keys.issubset(config_subst.keys()): - raise ValueError(f'ULM Wasm detected but required substition keys for these cells are missing: {ulm_keys - config_subst.keys()}') + raise ValueError( + f'ULM Wasm detected but required substition keys for these cells are missing: {ulm_keys - config_subst.keys()}' + ) # update config substitution final_subst = init_subst | config_subst @@ -125,7 +128,7 @@ def build_subst_key(key_name): # log input kore if debug: - with open(wasm_file.name + '.input.kore','w') as f: + with open(wasm_file.name + '.input.kore', 'w') as f: patched_config_kore.write(f) # run the config @@ -137,18 +140,20 @@ def build_subst_key(key_name): print(proc_data.stderr, file=sys.stderr) proc_data.check_returncode() + class DepthChange(Enum): UP = 1 DOWN = -1 PRINT = 0 + def pattern_write(pat: Pattern, output: IO[str], pretty=True) -> None: """Serialize pattern to kore; used for monkey patch on Pattern object because default write function will blow the stack""" if pretty: _up, _down, _print = DepthChange.UP, DepthChange.DOWN, DepthChange.PRINT else: - _up, _down, _print = ['']*3 + _up, _down, _print = [''] * 3 not_first_term = False print_spacer = False depth = 0 @@ -174,7 +179,8 @@ def push(*items): pat = stack.pop() if isinstance(pat, str): if print_spacer: - if not_first_term: output.write('\n' + depth*' ') + if not_first_term: + output.write('\n' + depth * ' ') not_first_term = True print_spacer = False output.write(pat) @@ -183,7 +189,7 @@ def push(*items): elif isinstance(pat, Assoc): push(_print, pat.kore_symbol(), '{}(', _up, pat.app, _down, ')') elif isinstance(pat, MLPattern): - push(_print, pat.symbol(), '{', pat.sorts, '}(', pat.ctor_patterns, ')') + push(_print, pat.symbol(), '{', pat.sorts, '}(', pat.ctor_patterns, ')') elif isinstance(pat, SortApp): push(pat.name, '{', pat.sorts, '}') elif isinstance(pat, DepthChange): @@ -193,6 +199,7 @@ def push(*items): else: pat.write(output) + class PatternWriter: def __init__(self, pat: Pattern, pretty=False): self.pat = pat @@ -204,6 +211,7 @@ def write(self, output: IO[str]): else: self.pat.write(output) + def debug(pat) -> str: if isinstance(pat, str): return pat @@ -222,6 +230,7 @@ def debug(pat) -> str: else: return repr(pat) + def wasm2kast(wasm_bytes: IO[bytes], filename=None) -> KInner: """Returns a dictionary representing the Kast JSON.""" ast = parse_module(wasm_bytes)