K-Maude. K-Maude. A Rewriting Based Tool for Semantics of Programming Languages. University of Illinois at Urbana-Champaign WRLA / 66

Similar documents
Towards a Module System for K

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Design

CS422 - Programming Language Design

CS422 - Programming Language Design

3.1 IMP: A Simple Imperative Language

K-Maude: A Rewriting Based Tool for Semantics of Programming Languages

3.7 Denotational Semantics

Programming Language Semantics A Rewriting Approach

Matching Logic. Grigore Rosu University of Illinois at Urbana-Champaign

K and Matching Logic

A Rewriting Logic Approach to Operational Semantics

3.3 Small-Step Structural Operational Semantics (Small-Step SOS)

The Chemical Abstract Machine

The K Semantic Framework

AN EXAMPLE-BASED INTRODUCTION TO K

Induction and Semantics in Dafny

Analyzing Java Programs Using JavaFAN

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

The Journal of Logic and Algebraic Programming

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

3.4 Denotational Semantics

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

On Formal Analysis of OO Languages using. OO Languages and Rewriting Logic: Designing for Performance

Program analysis parameterized by the semantics in Maude

University Alexandru Ioan Cuza of Iaşi Faculty of Computer Science. CinK an exercise on how to think in K. Dorel Lucanu, Traian Florin Şerbănuță

3.2 Big-Step Structural Operational Semantics (Big-Step SOS)

A CRASH COURSE IN SEMANTICS

Syntax-Directed Translation. Lecture 14

Matching Logic A New Program Verification Approach

CS477 - Formal Software Development Methods. Verification of Sequential Programs. Grigore Roşu

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

In Our Last Exciting Episode

The Maude 2.0 System. M. Clavel F. Durán S. Eker P. Lincoln. N. Martí-Oliet J. Meseguer C. Talcott

A Rewrite Framework for Language Definitions and for Generation of Efficient Interpreters

Computing Fundamentals 2 Introduction to CafeOBJ

Context-free grammars (CFG s)

The Rewriting Logic Semantics Project

K Overview and SIMPLE Case Study

Functional Programming. Pure Functional Programming

Formal Semantics of Programming Languages

Intermediate Code Generation

An Equational Specification for the Scheme Language 1

The Maude LTL LBMC Tool Tutorial

Formal Semantics of Programming Languages

Syntax and Grammars 1 / 21

CPS 506 Comparative Programming Languages. Syntax Specification

Compiler Construction

CSc 520 Principles of Programming Languages

A Rewriting Logic Approach to Operational Semantics

K Overview and SIMPLE Case Study

CS422 - Programming Language Design

Syntax Analysis/Parsing. Context-free grammars (CFG s) Context-free grammars vs. Regular Expressions. BNF description of PL/0 syntax

Operational Semantics. One-Slide Summary. Lecture Outline

Lecture 15 CIS 341: COMPILERS

CS422 - Programming Language Design

Application: Programming Language Semantics

Defining Datalog in Rewriting Logic

Mechanical Approach to Linking Operational Semantics and Algebraic Semantics for Verilog using Maude

A K Definition of Scheme

Formal Semantics of Programming Languages

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

RLSRunner: Linking Rascal with K for Program Analysis

Ornaments in ML. Thomas Williams, Didier Rémy. April 18, Inria - Gallium

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen

Semantics and Verification of Software

A Rewriting Semantics for Maude Strategies

Using big-step and small-step semantics in Maude to perform declarative debugging

Compiler Construction

PROGRAM ANALYSIS & SYNTHESIS

CMSC 330: Organization of Programming Languages

K: A Semantic Framework for Programming Languages and Formal Analysis Tools

Outline. What is semantics? Denotational semantics. Semantics of naming. What is semantics? 2 / 21

Pluggable Policies for C

Intermediate Code, Object Representation, Type-Based Optimization

Compiler Construction

Compiler Construction

An Executable Semantic Definition of the Beta Language using Rewriting Logic

Compiler Construction

A Rewriting Logic Approach to Static Checking of Units of Measurement in C

CafeOBJ. CafeOBJ. Starting CafeOBJ. Wolfgang Schreiner 1. A Quick Overview. 2.

Compiler Construction

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

Mosig M1 - PLSCD Written exam

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Program Representations

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

A Simple Syntax-Directed Translator

UML Modeling and Formal Verification of control/data driven Embedded Systems

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Syntax Intro and Overview. Syntax

The ITP Tool s Manual

Compiler Construction

Introduction to Functional Programming in Haskell 1 / 56

Specification and Analysis of Real-Time Systems Using Real-Time Maude

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

CS422 - Programming Language Design

Programming Language Semantics A Rewriting Approach

Programs as data Parsing cont d; first-order functional language, type checking

Today. Assignments. Lecture Notes CPSC 326 (Spring 2019) Quiz 5. Exam 1 overview. Type checking basics. HW4 due. HW5 out, due in 2 Tuesdays

Transcription:

K-Maude A Rewriting Based Tool for Semantics of Programming Languages Traian Florin Șerbănuță and Grigore Roșu University of Illinois at Urbana-Champaign WRLA 2010 1 / 66

Overview &'(")*#"*%!"#$% (+ K Technique) K-Maude: A prototype implementation of the K framework in Maude. The K framework consists of: A rewriting technique for defining programming lanugages A specialized language to simplify (and enhance) the K technique K-Maude extends Maude language to support the K language 2 / 66

Rewriting Logic Semantics Project Aim: Use RWL to define (and analyze) programming languages Rewriting logic faithfully captures PL semantic frameworks SOS [Verdejo,Martí-Olliet,Meseguer], [Meseguer,Braga] Chemical Abstract Machine [Meseguer] MSOS [Meseguer,Braga], the Maude MSOS tool [Braga,Chalub] Reduction semantics with evaluation contexts [Șerbănuță,Roșu,Meseguer] However, they are captured together with their limitations Motivational question: Can RWL inspire a better language definitional framework? 3 / 66

The K framework The K Technique Flexible, extensible, configurations as multi-sets of nested cells Cells can contain (Multi-)Sets, Lists, Maps, or computations Computation as a list of -separated tasks Next task always at top of the list Easy to define control-intensive features like halt,call/cc Rewriting modulo ACU to improve modularity Specify only what is needed from a cell for a semantic rule Abstract the remainder of the cell with variables Was used to give definitions in Maude for Java 1.4, Scheme, Beta 4 / 66

The K framework Example: The K Technique in Rewriting Logic Memory access in a multi-threaded language Configuration T threads thread* k K env ult Variable Lookup Map{VarId,Location} store Map{Location,KResult} nextloc Nat output List{KResult} X K k X L ρ env T thread Ts threads L V σ store V K k X L ρ env T thread Ts threads L V σ store 5 / 66

The K framework Example: The K Technique in Rewriting Logic Memory access in a multi-threaded language Variable Lookup X K k X L ρ env T thread Ts threads L V σ store V K k X L ρ env T thread Ts threads L V σ store Assignment Executing the assignment X := V K k X L ρ env T thread Ts threads L V σ store x := V K k X L ρ env T thread Ts threads L V σ store 5 / 66

The K framework Example: The K Technique in Rewriting Logic Memory access in a multi-threaded language Variable Lookup X K k X L ρ env T thread Ts threads L V σ store V K k X L ρ env T thread Ts threads L V σ store Assignment Executing the assignment X := V K k X L ρ env T thread Ts threads L V σ store x := V K k X L ρ env T thread Ts threads L V σ store Evaluating the right hand side (strictness) X := Ke K k Ke X :=[] K k if not(ke :: KResult) X := Ke K k Ke X :=[] K k if Ke :: KResult 5 / 66

The K framework The K Language Aim: Optimize the language definition process Automation: generate common fixed form rules from annotations Conciseness: redundancy might lead to copy errors Modularity: language features definitions resilient through structural changes in the configuration Simplicity: intuitive and avoiding unnecessary encodings 6 / 66

From K technique to the K language Automation: reduce strictness rules to annotations Problem: Strictness rules are very common and very mechanical Most expressions are strict in their defining context X:=Ke K k Ke X :=[] K k if not(ke :: KResult) X:=Ke K k Ke X :=[] K k if Ke :: KResult Solution: Automatically generate strictness rules from annotations Stmt ::= VarId := AExp [strict(2)] 7 / 66

From K technique to the K language Conciseness: in-place rewriting Problem: Redundancy rhs has to re-copy things matched by the lhs X := V K k X L ρ env T thread Ts threads L V σ store x := V K k X L ρ env T thread Ts threads L V σ store Solution: Make rules more local X := V K k X L ρ env T thread Ts threads L V V σ store 8 / 66

From K technique to the K language Modularity: Context Transformers Problem: Changes of configuration structure inflict unneeded changes in semantic rules X := V K k X L ρ env T thread Ts threads L V V σ store Solution: Liberate rules from structural constraints Use a global configuration structure... K k Map env thread threads Map store Nat nextloc List output T... to infer missing context for all rules in the definition X := V K k X L ρ env L V V σ store 9 / 66

From K technique to the K language Simplicity: Get rid of contextual (named) variables Problem: Variables unused by the rule are unnecessary X := V K k X L ρ env L V V σ store Solution: Abstract cell variables using the structure of the cell. Abstract other unused variables to anonymous variables X := V k X L env L _ V store 10 / 66

From K technique to the K language All in one step Assignment using plain K-technique in RWL Strictness X := Ke K k Ke X :=[] K k if not(ke :: KResult) X := Ke K k Ke X :=[] K k if Ke :: KResult Executing the assignment X := V K k X L ρ env T thread Ts threads L V σ store x := V K k X L ρ env T thread Ts threads L V σ store Assignment using the K language Strictness: Stmt ::= VarId := AExp [strict(2)] Executing the assignment X := V k X L env L _ V store Using global configuration term K k Map env thread threads Map 11 / 66

K definition of IMP++ IMP++ Annotated Syntax AExp ::= Int VarId AExp + AExp [strict] AExp / AExp [strict] BExp ::= Bool AExp <= AExp [seqstrict] not BExp [strict] BExp and BExp [strict(1)] Stmt ::= skip Stmt ; Stmt VarId := AExp [strict(2)] if BExp then Stmt else Stmt [strict(1)] while BExp do Stmt print AExp [strict] var VarId ; Stmt 12 / 66

K definition of IMP++ Intuition for strictness Stmt ::= VarId := AExp [strict(2)] AExp ::= AExp + AExp [strict] Corresponding to descent rules in SOS A, σ A, σ X := A, σ X := A, σ Corresponding to evaluation contexts in reduction semantics C AExp ::= C AExp + AExp AExp + C AExp 13 / 66

K definition of IMP++ IMP Semantics (I) i 1 + i 2 i 1 + Int i 2 i 1 / i 2 i 1 / Int i 2 where i 1 0 i 1 <= i 2 i 1 Int i 2 not t Bool t true and b b false and b false skip s 1 ; s 2 s 1 s 2 if true then s 1 else s 2 s 1 if false then s 1 else s 2 s 2 14 / 66

K definition of IMP++ IMP++ Configuration K k Map env thread threads Map store Nat nextloc List output T T threads thread* k K env Map{VarId,Location} store Map{Location,KResult} nextloc Nat output List{KResult} ult 15 / 66

K definition of IMP++ IMP Semantics (II) x k x l env l v store i x := v k x l env l _ store v while b do s if b then (s ; while b do s) else k var x ; s s env(ρ) print v k v k ρ env ρ[l/x] l 0 env(ρ) k _ env ρ out store l nextloc l + 1 16 / 66

The K-Maude tool K-Maude in a nutshell Provides infrastructure for the K technique in Maude Defines modules for computations, lists, sets, maps, and configurations Defines a way to specify K language definitions in Maude Non executable, but abiding to the Maude language syntax Compiles K language definitions using the K technique in Maude Obtained definitions are executable and amenable to search/model checking 17 / 66

The K-Maude tool K-Maude interface: IMP language in K-Maude IMP language in K-Maude what to look for Syntax Strictness annotations as metadata All syntax is flattened into the computation sort K Semantics Structure of configuration declared as a term In current version using mb configuation _ : KSentence. 1 K (structural) and (computational) rules In current version using mb rule _ : KSentence. 1 structural rules distinguished by metadata K in-place rewriting L is written in K-Maude as [L => R] R Anonymous variable? and open-ended cells... 1 Gray part omitted in the sequel 18 / 66

The K-Maude tool K-Maude interface: IMP language in K-Maude Syntax sorts AExp BExp Stmt Pgm. subsort VarId Int AExp. op _+_ : AExp AExp AExp [prec 33 gather (E e) metadata "strict"]. op _/_ : AExp AExp AExp [prec 31 gather (E e) metadata "strict"]. subsort Bool BExp. op _ =_ : AExp AExp BExp [prec 37 metadata "seqstrict"]. op not_ : BExp BExp [prec 53 metadata "strict"]. op _and_ : BExp BExp BExp [prec 55 metadata "strict(1)"]. op skip : Stmt. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict (2)"]. op _;_ : Stmt Stmt Stmt [prec 60 gather (e E)]. op if_then_else_ : BExp Stmt Stmt Stmt [prec 59 metadata "strict(1)"]. op while_do_ : BExp Stmt Stmt [prec 59]. ops print_ : AExp Stmt [prec 59 metadata "strict" format (b o d)]. op var_;_ : VarId Stmt Stmt [prec 70]. 19 / 66

The K-Maude tool K-Maude interface: IMP language in K-Maude Syntax Becomes Computation All syntactic sorts are made part of the computation sort subsort AExp BExp Stmt Pgm K. Values need to be distinguised as result computations subsorts Int Bool KResult. 20 / 66

The K-Maude tool K-Maude interface: IMP language in K-Maude Semantics (I) rule [I1 + I2 I1 +Int I2]. rule [I1 / I2 I1 / Int I2] if I2 =/=Bool 0. rule [ I1 = I2 I1 =Int I2]. rule [not(t) notbool T]. rule [true and B B]. rule [false and? false]. rule [skip.k]. rule [S1 ; S2 S1 S2]. rule [if true then S1 else? S1]. rule [if false then? else S2 S2]. 21 / 66

The K-Maude tool K-Maude interface: IMP language in K-Maude Configuration Configuration is a (multi-level) (multi-)set of cells A cell _ _ /_ has a CellLabel as identifier (same on both ends) A cell can contain either a computation K, a Map, a Set, or a List. In configuration terms denotes potential multiplicity var Sigma : Map. var K : K. ops output threads thread env store nextloc : CellLabel. configuration T threads thread * k K / k env Env / env / thread * / threads store Store / store nextloc N / nextloc output Output / output / T. 22 / 66

The K-Maude tool K-Maude interface: IMP language in K-Maude Semantics (II) rule k [X I ]... / k env...x L... / env store...l I... / store. rule k [X := I.k]... / k env...x L... / env store...l [? I ]... / store. rule k [while B do S if B then S ; while B do S else skip]... / k. rule k [print(i).k]... / k output...[.l l ( I )] / output. rule k [var X ; S S env(env)]... / k env [Env Env[N / X]] / env store...[.m N 0]... / store nextloc [N N +Int 1] / nextloc. rule k [env(env).k]... / k env [? Env] / env. 23 / 66

The K-Maude tool K-Maude compiler Compilation process K-Maude takes a Maude module containing a K definition...... and (meta-)transforms it into an executable Maude module implementing the desired definition Compilation split in small steps It applies in reverse order all K-language transformations. Each step takes a Maude module and produces a Maude module 24 / 66

The K-Maude tool K-Maude compiler The assignment rule (this time in K-Maude) Original K-Maude rule: rule k [X := I.k]... / k env...x L... / env store...l [? I ]... / store. Generated (executable, abstract) Maude rule rl threads?13:set thread?14:set k "_:=_ "((" VarId" X:VarId )(. kl ),(" Int " I : Int )(. kl ))?15:K / k env?16:map ("VarId" X:VarId)(. kl ) (" Int " L: Int )(. kl ) / env / thread / threads store?17:map ("Int" L: Int )(. kl )?18:K / store threads?13:set thread?14:set k?15:k / k env?16:map ("VarId" X:VarId)(. kl ) (" Int " L: Int )(. kl ) / env / thread / threads store?17:map ("Int" L: Int )(. kl ) (" Int " I : Int )(. kl ) / store [metadata "computational rule"]. 25 / 66

The K-Maude tool Conclusions &'(")*#"*% K framework:!"#$% (+ K Technique) Takes the strengths of other PL semantic frameworks...... and adds to them the strength of rewriting. K-Maude: Faithful implementation of the K Language in Maude Compiles K definitions into executable/analyzable Maude definitions Future Work: (Re-)integrate with Full Maude Backward translations to give answers and errors at the top level 26 / 66

Required modules including PL INT. Builtin Integers including PL VARID. Builtin Variable identifiers including K. Basic structure of the computation including CONFIG. Predefined cells and configuration infrastructure including K RULES. K rules and in place rewriting including K CONFIG. to allow specifying configuration as a term including K ANONYMOUS VARIABLES. introduces anonymous variable including K OPEN CELLS. to use open cells lik _..._ _ including K MAP EXTRAS. to do bulk assigments in the map 27 / 66

Compiling K-Maude definitions into Maude What K-Maude does? K-Maude takes a Maude module containing a K definition...... and transforms it into an executable Maude module implementing the desired definition Compilation split in small steps Each step takes a Maude module and produces a Maude Module Case study: Assignment in a multi-threaded language 28 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Original K-Maude definition sorts AExp Stmt. subsort VarId Int AExp. subsorts AExp Stmt K. subsort Int KResult. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict (2)"]. mb rule k [X:VarId := I : Int.k]... / k env... X:VarId L:Int... / env store... L:Int [? I : Int ]... / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 29 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Resolving opened cells sorts AExp Stmt. subsort VarId Int AExp. subsorts AExp Stmt K. subsort Int KResult. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict (2)"]. mb rule k [X:VarId := I : Int.k]... / k env... X:VarId L:Int... / env store... L:Int [? I : Int ]... / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 30 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Opened cells resolved sorts AExp Stmt. subsort VarId Int AExp. subsorts AExp Stmt K. subsort Int KResult. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict (2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [? I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 31 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Turning anonymous constants into anonymous variables sorts AExp Stmt. subsort VarId Int AExp. subsorts AExp Stmt K. subsort Int KResult. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict (2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [? I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 32 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language No more anonymous constants sorts AExp Stmt. subsort VarId Int AExp. subsorts AExp Stmt K. subsort Int KResult. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict(2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [?: Int I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 33 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Merging syntax sorts into K sorts AExp Stmt. subsort VarId Int AExp. subsorts AExp Stmt < K. subsort Int KResult. op _:=_ : VarId AExp Stmt [prec 40 metadata "strict(2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [?: Int I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 34 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Syntax sorts are gone subsort VarId Int K. subsort Int KResult. op _:=_ : VarId K K [prec 40 metadata "strict(2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [?: Int I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 35 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Adding Proper computations subsort VarId Int K. subsort Int KResult. op _:=_ : VarId K K [prec 40 metadata "strict(2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [?: Int I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 36 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language All non-result computations are proper subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [?: Int I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 37 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Inferring missing configuration subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. mb rule k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env store?:map L:Int [?: Int I : Int ] / store : KSentence. mb configuration T threads thread * k K:K / k env Env:Map / env / thread * / threads store Store:Map / store nextloc N:Nat / nextloc output Output:List / output / T result Output:List / result : KSentence. 38 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Configuration no longer needed subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. mb rule threads?:set thread?:set k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L: Int / env / thread / threads store?:map L:Int [?: Int I : Int ] / store : KSentence. 39 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Resolve anonymous variables subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. mb rule threads?:set thread?:set k [X:VarId := I : Int.k]?:K / k env?:map X:VarId L:Int / env / thread / threads store?:map L:Int [?:Int I:Int] / store : KSentence. 40 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Anonymous variables become real variables subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. mb rule threads?13:set thread?14:set k [X:VarId := I : Int.k]?15:K / k env?16:map X:VarId L:Int / env / thread / threads store?17:map L:Int [?18:Int I:Int] / store : KSentence. 41 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Generating Maude rules from K rules subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. mb rule threads?13:set thread?14:set k [X:VarId := I : Int.k]?15:K / k env?16:map X:VarId L:Int / env / thread / threads store?17:map L:Int [?18: Int I : Int ] / store : KSentence. 42 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language K rules are gone subsort VarId KProper. subsort Int KResult. op _:=_ : VarId K KProper [prec 40 metadata "strict(2)"]. rl threads?13:set thread?14:set k X:VarId := I : Int?15:K / k env?16:map X:VarId L:Int / env / thread / threads store?17:map L:Int?18:Int / store threads?13:set thread?14:set k.k?15:k / k env?16:map X:VarId L:Int / env / thread / threads store?17:map L:Int I : Int / store. 43 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language... K abstract syntax op VarId : VarId KProperLabel. op Int : Int KResultLabel. op "_:=_" : KProperLabel [prec 40 metadata "arity 2 strict (2)"]. rl threads?13:set thread?14:set k "_:=_"(VarId(X:VarId )(. kl ), Int ( I : Int )(. kl ))?15:K / k env?16:map VarId(X:VarId)(.kl) Int (L: Int )(. kl ) / env / thread / threads store?17:map Int(L:Int )(. kl ) Int(?18:Int )(. kl ) / store threads?13:set thread?14:set k.k?15:k / k env?16:map VarId(X:VarId)(.kl) Int (L: Int )(. kl ) / env / thread / threads store?17:map Int(L:Int )(. kl ) Int ( I : Int )(. kl ) / store. 44 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language... Resolving strictness annotations op VarId : VarId KProperLabel. op Int : Int KResultLabel. op "_:=_" : KProperLabel [prec 40 metadata "arity 2 strict(2)"]. rl threads?13:set thread?14:set k "_:=_"(VarId(X:VarId )(. kl ), Int ( I : Int )(. kl ))?15:K / k env?16:map VarId(X:VarId)(.kl) Int (L: Int )(. kl ) / env / thread / threads store?17:map Int(L:Int )(. kl ) Int(?18:Int )(. kl ) / store threads?13:set thread?14:set k.k?15:k / k env?16:map VarId(X:VarId)(.kl) Int (L: Int )(. kl ) / env / thread / threads store?17:map Int(L:Int )(. kl ) Int ( I : Int )(. kl ) / store. 45 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Strictness annotations became strict contexts op VarId : VarId KProperLabel. op Int : Int KResultLabel. op "_:=_" : KProperLabel [prec 40]. mb context "_:=_"(K1:K,[]) : KSentence. rl threads?13:set thread?14:set k "_:=_"(VarId(X:VarId), Int ( I : Int ))?15:K / k env?16:map VarId(X:VarId) Int (L: Int ) / env / thread / threads store?17:map Int(L:Int) Int(?18:Int ) / store threads?13:set thread?14:set k.k?15:k / k env?16:map VarId(X:VarId) Int (L: Int ) / env / thread / threads store?17:map Int(L:Int) Int ( I : Int ) / store. 46 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Resolving strict contexts op VarId : VarId KProperLabel. op Int : Int KResultLabel. op "_:=_" : KProperLabel [prec 40]. mb context "_:=_"(K1:K,[]) : KSentence. rl threads?13:set thread?14:set k "_:=_"(VarId(X:VarId), Int ( I : Int ))?15:K / k env?16:map VarId(X:VarId) Int (L: Int ) / env / thread / threads store?17:map Int(L:Int) Int(?18:Int ) / store threads?13:set thread?14:set k.k?15:k / k env?16:map VarId(X:VarId) Int (L: Int ) / env / thread / threads store?17:map Int(L:Int) Int ( I : Int ) / store. 47 / 66

Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Strict contexts transalte to strictness equations op VarId : VarId KProperLabel. op Int : Int KResultLabel. op "_:=_" : KProperLabel [prec 40]. eq k "_:=_"(K1:K, Kcxt:KProper) Rest:K / k = k Kcxt:KProper "_ :=[]"( K1:K) Rest:K / k. eq k Kcxt:KResult "_ :=[]"( K1:K) Rest:K / k = k "_:=_"(K1:K, Kcxt:KResult) Rest:K / k. rl threads?13:set thread?14:set k "_:=_"(VarId(X:VarId), Int ( I : Int ))?15:K / k env?16:map VarId(X:VarId) Int (L: Int ) / env / thread / threads store?17:map Int(L:Int) Int(?18:Int ) / store threads?13:set thread?14:set k.k?15:k / k env?16:map VarId(X:VarId) Int (L: Int ) / env / thread / threads store?17:map Int(L:Int) Int ( I : Int ) / store. 48 / 66

Getting K-Maude Google code project page http://k-framework.googlecode.com svn access: http://k-framework.googlecode.com/svn/k-maude/trunk reporting issues: http://code.google.com/p/k-framework/issues Actively developing, please update regularly 49 / 66

Compiling K-Maude definitions into Maude Currently supporting one-module definitions only First make sure Maude loads your definition kcompile.sh tool usage: tools/kcompile.sh <source_file>[.maude] [<module_name>] If <module_name> is not specified, is asumed to be allcaps(<source_file>). <source_file> should ensure that a module <module_name> is loaded. Module <module_name> should contain the entire definition of the language. Output is printed in <source_file>-compiled.maude. If an error occurs in the compilation process (including warnings such as Module redefined), the script will stop, displaying the input, the (maybe partial) generated output, and the error/warning messages reported by Maude. 50 / 66

Outline The K framework Example: The K Technique in Rewriting Logic From K technique to the K language K definition of IMP++ The K-Maude tool K-Maude interface: IMP language in K-Maude K-Maude compiler Compiling K-Maude definitions into Maude Case study: Assignment in a multi-threaded language Language definitions: from RWL to K K Technique K Conventions K-Maude Back to Maude 51 / 66

Language definitions: from RWL to K K Technique 2002-2003 eq evalexps(exps(x := E) env([x,l] Env) cont(c) S) = evalexps(exps(e) cont(l int (1) C) env([x,l] Env) S). eq evalcont(cont(vl Ll C) store(st) S) = evalcont(cont(c) store(st[ Ll Vl ]) S). With carried-along environment (seemed to have been faster) rl k([(set X = E) @ ([X,L] Env)] -> K) = k([e @ ([X,L] Env)] -> L => int(1) -> K). rl k(v -> L => K), m(m) => k(k), m(m[l <- V]). ow [wq dop 52 / 66

Language definitions: from RWL to K K Technique 2002-2003 Continuation is maintained separate from the expressions eq evalexps(exps(x := E) env([x,l] Env) cont(c) S) = evalexps(exps(e) cont(l -> int(1) -> C) env([x,l] Env) S) eq evalcont(cont(vl -> Ll -> C) store(st) S) = evalcont(cont(c) store(st[ll <- Vl]) S). wij diow udwq 53 / 66

Language definitions: from RWL to K K Technique Computation as continuation 54 / 66

Language definitions: from RWL to K K Technique Strictness as heating and cooling 55 / 66

Language definitions: from RWL to K K Technique Configuration as hierarchical multi-set 56 / 66

Language definitions: from RWL to K K Technique Abstract syntax instead of concrete syntax 57 / 66

Language definitions: from RWL to K K Conventions Strictness annotations 58 / 66

Language definitions: from RWL to K K Conventions Local rewriting 59 / 66

Language definitions: from RWL to K K Conventions Context Inference 60 / 66

Language definitions: from RWL to K K Conventions Anonymous variables and cell comprehension 61 / 66

K-Maude Syntax with annotations 62 / 66

K-Maude Generalized Strictness 63 / 66

K-Maude Configuration 64 / 66

K-Maude K rules 65 / 66

Conclusions 66 / 66