Skip to content

Commit

Permalink
Merge branch 'master' into _update-deps/runtimeverification/k
Browse files Browse the repository at this point in the history
  • Loading branch information
tothtamas28 authored Dec 4, 2024
2 parents cffd32c + 233b1e6 commit a44f6c9
Show file tree
Hide file tree
Showing 17 changed files with 422 additions and 286 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:
uses: ./.github/actions/with-docker
with:
container-name: ${CONTAINER}
- name: 'Build and run integration tests'
- name: 'Build K definitions'
run: docker exec -u user ${CONTAINER} make kdist
- name: 'Run integration tests'
run: docker exec -u user ${CONTAINER} make cov-integration
- name: 'Tear down Docker container'
if: always()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ kdist: kdist-build
KDIST_ARGS :=

kdist-build: poetry-install have-k
$(POETRY_RUN) kdist --verbose build -j3 $(KDIST_ARGS)
$(POETRY_RUN) kdist --verbose build -j4 $(KDIST_ARGS)

kdist-clean: poetry-install
$(POETRY_RUN) kdist clean
Expand Down
2 changes: 1 addition & 1 deletion package/smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euxo pipefail

kimp --help

kimp run --verbose examples/sumto10.imp --env 'x=0,y=1' --env z=2
kimp run --verbose examples/sumto10.imp --env 'x=0,y=1' --env b1=false --env b2=true

kimp prove --verbose examples/specs/imp-sum-spec.k IMP-SUM-SPEC sum-spec

Expand Down
11 changes: 10 additions & 1 deletion src/kimp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ def create_argument_parser() -> ArgumentParser:

# Run
def env(s: str) -> list[tuple[str, int]]:
return [(var.strip(), int(val)) for var, val in (assign.split('=') for assign in s.split(','))]
def parse(s: str) -> int:
match s:
case 'true':
return True
case 'false':
return False
case _:
return int(s)

return [(var.strip(), parse(val)) for var, val in (assign.split('=') for assign in s.split(','))]

run_subparser = command_parser.add_parser('run', help='Run an IMP program', parents=[shared_args])
run_subparser.add_argument('input_file', metavar='INPUT_FILE', type=file_path, help='Path to .imp file')
Expand Down
35 changes: 35 additions & 0 deletions src/kimp/kdist/imp-semantics/calc.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
requires "expr.k"


module CALC-SYNTAX
imports EXPR-SYNTAX
imports ID-SYNTAX

syntax Expr ::= Id

syntax Stmt ::= Id "=" Expr ";" [group(stmt), strict(2), format(%1 %2 %3%4)]
syntax Stmt ::= right:
Stmt Stmt [group(seq-stmt), format(%1%n%2)]

syntax priority stmt > seq-stmt
endmodule


module CALC
imports CALC-SYNTAX
imports EXPR-RULES

configuration
<k color="green"> $PGM:Stmt </k>
<env color="yellow"> $ENV:Map </env>

rule [step]: <k> S1:Stmt S2:Stmt => S1 ~> S2 ... </k>

rule [var]:
<k> X:Id => V ... </k>
<env> X |-> V ... </env>

rule [assign]:
<k> X = V:Value ; => .K ... </k>
<env> E => E [ X <- V ] </env>
endmodule
112 changes: 0 additions & 112 deletions src/kimp/kdist/imp-semantics/calls.k

This file was deleted.

72 changes: 72 additions & 0 deletions src/kimp/kdist/imp-semantics/expr.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module EXPR-SYNTAX
imports UNSIGNED-INT-SYNTAX
imports BOOL-SYNTAX

syntax Value ::= Int
| Bool

syntax KResult ::= Value

syntax Expr ::= Value
| "(" Expr ")" [bracket, format(%1%2%3)]

syntax Expr ::= "-" Expr [strict, format(%1%2)]
| "!" Expr [strict, format(%1%2)]
> left:
Expr "*" Expr [seqstrict]
| Expr "/" Expr [seqstrict]
> left:
Expr "+" Expr [seqstrict]
| Expr "-" Expr [seqstrict]
> left:
Expr ">=" Expr [seqstrict]
| Expr ">" Expr [seqstrict]
| Expr "<=" Expr [seqstrict]
| Expr "<" Expr [seqstrict]
> left:
Expr "==" Expr [seqstrict]
| Expr "!=" Expr [seqstrict]
> left:
Expr "&&" Expr [strict(1)]
> left:
Expr "||" Expr [strict(1)]
endmodule


module EXPR-RULES
imports EXPR-SYNTAX
imports INT
imports BOOL

rule - X => 0 -Int X
rule ! B => notBool B

rule X + Y => X +Int Y
rule X - Y => X -Int Y
rule X * Y => X *Int Y
rule X / Y => X /Int Y

rule I1 >= I2 => I1 >=Int I2
rule I1 > I2 => I1 >Int I2
rule I1 <= I2 => I1 <=Int I2
rule I1 < I2 => I1 <Int I2

rule B1 == B2 => B1 ==Bool B2
rule I1 == I2 => I1 ==Int I2

rule B1 != B2 => B1 =/=Bool B2
rule I1 != I2 => I1 =/=Int I2

rule true && B => B
rule false && _ => false

rule true || _ => true
rule false || B => B
endmodule


module EXPR
imports EXPR-RULES

configuration <k> $PGM:Expr </k>
endmodule
66 changes: 0 additions & 66 deletions src/kimp/kdist/imp-semantics/expressions.k

This file was deleted.

5 changes: 3 additions & 2 deletions src/kimp/kdist/imp-semantics/imp-verification.k
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
requires "statements.k"
requires "imp.k"


module IMP-VERIFICATION-SYNTAX
imports ID-SYNTAX
Expand All @@ -9,7 +10,7 @@ endmodule

module IMP-VERIFICATION
imports IMP-VERIFICATION-SYNTAX
imports STATEMENTS
imports IMP

// inequality sign normalization
rule A >Int B => B <Int A [simplification]
Expand Down
38 changes: 38 additions & 0 deletions src/kimp/kdist/imp-semantics/imp.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
requires "calc.k"


module IMP-SYNTAX
imports CALC-SYNTAX

syntax Stmt ::= "if" "(" Expr ")" Stmt "else" Stmt [group(stmt), strict(1), avoid, format(%1 %2%3%4% %5 %6 %7)] // dangling else
| "if" "(" Expr ")" Stmt [group(stmt), format(%1 %2%3%4 %5)]
| "while" "(" Expr ")" Stmt [group(stmt), format(%1 %2%3%4 %5)] // not strict!
| "{" Stmt "}" [group(stmt), format(%1%i%n%2%d%n%3)]
| "{" "}" [group(stmt), format(%1%2)]
endmodule


module IMP
imports IMP-SYNTAX
imports CALC

rule [if-true]: <k> if ( true ) S1 else _ => S1 ... </k>
rule [if-false]: <k> if ( false ) _ else S2 => S2 ... </k>

rule [if-else]: <k> if ( C ) S => if ( C ) S else {} ... </k>

rule [while]:
<k>
while ( C ) S
=>
if ( C ) {
S
while ( C ) S
}
...
</k>

rule [block]: <k> { S } => S ~> { } ... </k>

rule [done]: <k> { } => .K ... </k>
endmodule
Loading

0 comments on commit a44f6c9

Please sign in to comment.