Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit fee00bb

Browse files
committed
Merge master into branch
2 parents 778cd00 + fd06d71 commit fee00bb

File tree

20 files changed

+63
-47
lines changed

20 files changed

+63
-47
lines changed

deps/k_release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.0.50
1+
6.0.52

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.412
1+
0.1.413

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.412"
7+
version = "0.1.413"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from typing import Final
77

88

9-
K_VERSION: Final = '6.0.50'
9+
K_VERSION: Final = '6.0.52'

src/pyk/cterm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from itertools import chain
66
from typing import TYPE_CHECKING
77

8-
from .kast.inner import KApply, KAtt, KInner, KRewrite, KToken, KVariable, Subst, bottom_up
8+
from .kast.inner import KApply, KInner, KRewrite, KToken, KVariable, Subst, bottom_up
9+
from .kast.kast import KAtt
910
from .kast.manip import (
1011
abstract_term_safely,
1112
apply_existential_substitutions,

src/pyk/kast/inner.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
from typing import TYPE_CHECKING, final, overload
1010

1111
from ..utils import EMPTY_FROZEN_DICT, FrozenDict
12-
from .kast import EMPTY_ATT, KAst, KAtt, WithKAtt
12+
from .kast import KAst
1313

1414
if TYPE_CHECKING:
1515
from collections.abc import Callable, Iterator
1616
from typing import Any, Final, TypeVar
1717

1818
T = TypeVar('T', bound='KAst')
19-
W = TypeVar('W', bound='WithKAtt')
2019
KI = TypeVar('KI', bound='KInner')
2120
A = TypeVar('A', bound='Any')
2221
B = TypeVar('B', bound='Any')
@@ -249,21 +248,16 @@ def __lt__(self, other: Any) -> bool:
249248
@classmethod
250249
def from_dict(cls: type[KVariable], d: Mapping[str, Any]) -> KVariable:
251250
cls._check_node(d)
252-
att = KAtt.from_dict(d['att']) if d.get('att') else EMPTY_ATT
253-
254-
sort: KSort | None
255-
if KAtt.SORT in att:
256-
sort = KSort.from_dict(att[KAtt.SORT])
257-
else:
258-
sort = None
259-
251+
sort = None
252+
if 'sort' in d:
253+
sort = KSort.from_dict(d['sort'])
260254
return KVariable(name=d['name'], sort=sort)
261255

262256
def to_dict(self) -> dict[str, Any]:
263-
_att = KAtt({})
257+
_d: dict[str, Any] = {'node': 'KVariable', 'name': self.name}
264258
if self.sort is not None:
265-
_att = _att.update({KAtt.SORT: self.sort.to_dict()})
266-
return {'node': 'KVariable', 'name': self.name, 'att': _att.to_dict()}
259+
_d['sort'] = self.sort.to_dict()
260+
return _d
267261

268262
def let(self, *, name: str | None = None, sort: str | KSort | None = None) -> KVariable:
269263
name = name if name is not None else self.name
@@ -456,7 +450,7 @@ def from_dict(cls: type[KAs], d: Mapping[str, Any]) -> KAs:
456450
def to_dict(self) -> dict[str, Any]:
457451
return {'node': 'KAs', 'pattern': self.pattern.to_dict(), 'alias': self.alias.to_dict()}
458452

459-
def let(self, *, pattern: KInner | None = None, alias: KInner | None = None, att: KAtt | None = None) -> KAs:
453+
def let(self, *, pattern: KInner | None = None, alias: KInner | None = None) -> KAs:
460454
pattern = pattern if pattern is not None else self.pattern
461455
alias = alias if alias is not None else self.alias
462456
return KAs(pattern=pattern, alias=alias)
@@ -470,14 +464,13 @@ def match(self, term: KInner) -> Subst | None:
470464

471465
@final
472466
@dataclass(frozen=True)
473-
class KRewrite(KInner, WithKAtt):
467+
class KRewrite(KInner):
474468
lhs: KInner
475469
rhs: KInner
476470

477-
def __init__(self, lhs: KInner, rhs: KInner, att: KAtt = EMPTY_ATT):
471+
def __init__(self, lhs: KInner, rhs: KInner):
478472
object.__setattr__(self, 'lhs', lhs)
479473
object.__setattr__(self, 'rhs', rhs)
480-
object.__setattr__(self, 'att', att)
481474

482475
def __iter__(self) -> Iterator[KInner]:
483476
return iter([self.lhs, self.rhs])
@@ -494,31 +487,24 @@ def from_dict(cls: type[KRewrite], d: Mapping[str, Any]) -> KRewrite:
494487
return KRewrite(
495488
lhs=KInner.from_dict(d['lhs']),
496489
rhs=KInner.from_dict(d['rhs']),
497-
att=KAtt.from_dict(d['att']) if d.get('att') else EMPTY_ATT,
498490
)
499491

500492
def to_dict(self) -> dict[str, Any]:
501493
return {
502494
'node': 'KRewrite',
503495
'lhs': self.lhs.to_dict(),
504496
'rhs': self.rhs.to_dict(),
505-
'att': self.att.to_dict(),
506497
}
507498

508499
def let(
509500
self,
510501
*,
511502
lhs: KInner | None = None,
512503
rhs: KInner | None = None,
513-
att: KAtt | None = None,
514504
) -> KRewrite:
515505
lhs = lhs if lhs is not None else self.lhs
516506
rhs = rhs if rhs is not None else self.rhs
517-
att = att if att is not None else self.att
518-
return KRewrite(lhs=lhs, rhs=rhs, att=att)
519-
520-
def let_att(self, att: KAtt) -> KRewrite:
521-
return self.let(att=att)
507+
return KRewrite(lhs=lhs, rhs=rhs)
522508

523509
def map_inner(self: KRewrite, f: Callable[[KInner], KInner]) -> KRewrite:
524510
return self.let(lhs=f(self.lhs), rhs=f(self.rhs))

src/pyk/kast/kast.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222

2323
class KAst(ABC):
24+
@staticmethod
25+
def version() -> int:
26+
return 3
27+
2428
@classmethod
2529
def from_dict(cls: type[T], d: Mapping[str, Any]) -> T:
2630
from . import inner, outer
@@ -175,7 +179,7 @@ def kast_term(dct: Mapping[str, Any], cls: type[T] = KAst) -> T: # type: ignore
175179
if dct['format'] != 'KAST':
176180
raise ValueError(f"Invalid format: {dct['format']}")
177181

178-
if dct['version'] != 2:
182+
if dct['version'] != KAst.version():
179183
raise ValueError(f"Invalid version: {dct['version']}")
180184

181185
return cls.from_dict(dct['term'])

src/pyk/ktool/kprint.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import TYPE_CHECKING
1212

1313
from ..cli.utils import check_dir_path, check_file_path
14-
from ..kast import kast_term
14+
from ..kast import KAst, kast_term
1515
from ..kast.inner import KInner
1616
from ..kast.outer import read_kast_definition
1717
from ..kast.pretty import PrettyPrinter
@@ -29,7 +29,6 @@
2929
from tempfile import _TemporaryFileWrapper
3030
from typing import Final
3131

32-
from ..kast import KAst
3332
from ..kast.inner import KSort, KToken
3433
from ..kast.outer import KDefinition, KFlatModule
3534
from ..kast.pretty import SymbolTable
@@ -270,7 +269,7 @@ def kast_to_kore(self, kast: KInner, sort: KSort | None = None) -> Pattern:
270269
_LOGGER.warning(ve)
271270

272271
_LOGGER.warning(f'Falling back to using `kast` for KAst -> Kore: {kast}')
273-
kast_json = {'format': 'KAST', 'version': 2, 'term': kast.to_dict()}
272+
kast_json = {'format': 'KAST', 'version': KAst.version(), 'term': kast.to_dict()}
274273
proc_res = self._expression_kast(
275274
json.dumps(kast_json),
276275
input=KAstInput.JSON,

src/pyk/ktool/krun.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def run_kore_process(
7272
output: KRunOutput | None = KRunOutput.PRETTY,
7373
pipe_stderr: bool = True,
7474
bug_report: BugReport | None = None,
75+
debugger: bool = False,
7576
) -> CompletedProcess:
7677
with self._temp_file() as ntf:
7778
pgm.write(ntf)
@@ -94,6 +95,7 @@ def run_kore_process(
9495
bug_report=self._bug_report,
9596
check=False,
9697
pipe_stderr=pipe_stderr,
98+
debugger=debugger,
9799
)
98100

99101
def run_kore(
@@ -111,6 +113,7 @@ def run_kore(
111113
check: bool = False,
112114
pipe_stderr: bool = True,
113115
bug_report: BugReport | None = None,
116+
debugger: bool = False,
114117
) -> None:
115118
result = self.run_kore_process(
116119
pgm,
@@ -124,6 +127,7 @@ def run_kore(
124127
output=output,
125128
pipe_stderr=pipe_stderr,
126129
bug_report=bug_report,
130+
debugger=debugger,
127131
)
128132

129133
if output != KRunOutput.NONE:
@@ -152,6 +156,7 @@ def run_kore_term(
152156
pipe_stderr: bool = True,
153157
check: bool = False,
154158
bug_report: BugReport | None = None,
159+
debugger: bool = False,
155160
) -> Pattern:
156161
proc_res = self.run_kore_process(
157162
pattern,
@@ -163,6 +168,7 @@ def run_kore_term(
163168
output=KRunOutput.NONE,
164169
pipe_stderr=pipe_stderr,
165170
bug_report=bug_report,
171+
debugger=debugger,
166172
)
167173

168174
if check:
@@ -194,6 +200,7 @@ def _krun(
194200
pipe_stderr: bool = True,
195201
logger: Logger | None = None,
196202
bug_report: BugReport | None = None,
203+
debugger: bool = False,
197204
) -> CompletedProcess:
198205
if input_file:
199206
check_file_path(input_file)
@@ -221,6 +228,7 @@ def _krun(
221228
no_expand_macros=no_expand_macros,
222229
search_final=search_final,
223230
no_pattern=no_pattern,
231+
debugger=debugger,
224232
)
225233

226234
if bug_report is not None:
@@ -232,7 +240,7 @@ def _krun(
232240
bug_report.add_command(args)
233241

234242
try:
235-
return run_process(args, check=check, pipe_stderr=pipe_stderr, logger=logger or _LOGGER)
243+
return run_process(args, check=check, pipe_stderr=pipe_stderr, logger=logger or _LOGGER, exec_process=debugger)
236244
except CalledProcessError as err:
237245
raise RuntimeError(
238246
f'Command krun exited with code {err.returncode} for: {input_file}', err.stdout, err.stderr
@@ -254,6 +262,7 @@ def _build_arg_list(
254262
no_expand_macros: bool,
255263
search_final: bool,
256264
no_pattern: bool,
265+
debugger: bool,
257266
) -> list[str]:
258267
args = [command]
259268
if input_file:
@@ -280,4 +289,6 @@ def _build_arg_list(
280289
args += ['--search-final']
281290
if no_pattern:
282291
args += ['--no-pattern']
292+
if debugger:
293+
args += ['--debugger']
283294
return args

src/pyk/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ def run_process(
382382
cwd: str | Path | None = None,
383383
env: Mapping[str, str] | None = None,
384384
logger: Logger | None = None,
385+
exec_process: bool = False,
385386
) -> CompletedProcess:
386387
if cwd is not None:
387388
cwd = Path(cwd)
@@ -400,6 +401,15 @@ def run_process(
400401
stderr = subprocess.PIPE if pipe_stderr else None
401402

402403
logger.info(f'Running: {command}')
404+
405+
if exec_process:
406+
sys.stdout.flush()
407+
sys.stderr.flush()
408+
if type(args) is str:
409+
args = shlex.split(args)
410+
argslist = list(args)
411+
os.execvp(argslist[0], argslist)
412+
403413
start_time = time.time()
404414

405415
res = subprocess.run(args, input=input, cwd=cwd, env=env, stdout=stdout, stderr=stderr, text=True)

0 commit comments

Comments
 (0)