Skip to content

Commit

Permalink
run black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
sskeirik committed Dec 9, 2024
1 parent dacaf9c commit 095a0f8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pykwasm/src/pykwasm/run_wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -193,6 +199,7 @@ def push(*items):
else:
pat.write(output)


class PatternWriter:
def __init__(self, pat: Pattern, pretty=False):
self.pat = pat
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 095a0f8

Please sign in to comment.