Towards a Module System for K

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

CS422 - Programming Language Design

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Design

CS422 - Programming Language Design

The Chemical Abstract Machine

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

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

K and Matching Logic

3.7 Denotational Semantics

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.

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

3.1 IMP: A Simple Imperative Language

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

A Rewriting Logic Approach to Operational Semantics

The K Semantic Framework

Programming Language Semantics A Rewriting Approach

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

Functional Programming. Pure Functional Programming

The Journal of Logic and Algebraic Programming

Denotational Semantics. Domain Theory

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

Program analysis parameterized by the semantics in Maude

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

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

Analyzing Java Programs Using JavaFAN

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

Computing Fundamentals 2 Introduction to CafeOBJ

Type checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39

RLSRunner: Linking Rascal with K for Program Analysis

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

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

Matching Logic A New Program Verification Approach

Formal semantics of loosely typed languages. Joep Verkoelen Vincent Driessen

The Rewriting Logic Semantics Project

CMSC 330: Organization of Programming Languages

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Induction and Semantics in Dafny

CSCC24 Functional Programming Scheme Part 2

6.821 Programming Languages Handout Fall MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

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

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

RSL Reference Manual

CS422 - Programming Language Design

Intermediate Code Generation

A K Definition of Scheme

Data types for mcrl2

Semantic Analysis. Lecture 9. February 7, 2018

Multi-paradigm Declarative Languages

K Overview and SIMPLE Case Study

More on Operational Semantics

3.4 Denotational Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

AN EXAMPLE-BASED INTRODUCTION TO K

A Rewriting Semantics for Maude Strategies

G Programming Languages - Fall 2012

Chapter 7 Control I Expressions and Statements

CS 242. Fundamentals. Reading: See last slide

Lexical Considerations

CS422 - Programming Language Design

K Overview and SIMPLE Case Study

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

1 Lexical Considerations

Semantics. A. Demers Jan This material is primarily from Ch. 2 of the text. We present an imperative

Homework 3 COSE212, Fall 2018

Onion Language Reference Manual. By: Andrew Aday, (aza2112) Amol Kapoor (ajk2227), Jonathan Zhang (jz2814)

Decaf Language Reference

Strategic Programming in Java

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter

Principles of Programming Languages

Lexical Considerations

Monads. Mark Hills 6 August Department of Computer Science University of Illinois at Urbana-Champaign

Built-in Module BOOL. Lecture Note 01a

A CRASH COURSE IN SEMANTICS

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

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

The syntax of the OUN language

Towards Integrated Specification and Analysis of Machine-Readable Policies Using Maude 1

Programming Languages Third Edition

Compiler Construction

Introduction to Haskell

SML A F unctional Functional Language Language Lecture 19

CS153: Compilers Lecture 16: Local Optimization II

עקרונות שפות תכנות 2018 תרגול 8 Type Inference System

Announcements. Working on requirements this week Work on design, implementation. Types. Lecture 17 CS 169. Outline. Java Types

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions

Pluggable Policies for C

CSE 3302 Programming Languages Lecture 8: Functional Programming

Discussion 12 The MCE (solutions)

Lecture 2: SML Basics

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

Operational Semantics 1 / 13

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

The Substitution Model

The Maude LTL LBMC Tool Tutorial

A Brief Introduction to Scheme (II)

Lecture 3: Recursion; Structural Induction

Transcription:

Towards a Module System for Mark Hills and Grigore Roşu {mhills, grosu}@cs.uiuc.edu Department of Computer Science University of Illinois at Urbana-Champaign WADT 08, 14 June 2008 Hills and Roşu WADT 08: Towards a Module System for 1 / 29

1 2 3 4 5 6 ills and Roşu WADT 08: Towards a Module System for 2 / 29

Formal semantics of programming languages not used widely outside of research community We strongly believe that one important way to increase use of formal semantics is to make semantic definitions more broadly usable and useful This work focuses on two aspects of this goal: Enable improved reuse of definitions through definitional modularity Provide tool support for working with language definitions Hills and Roşu WADT 08: Towards a Module System for 3 / 29

: High Level View Overview Language Semantics in For More Information provides a rewrite-based method to formally define computation Focus here: formal definitions of programming languages Definitions should be flexible and modular: use, and reuse, for language documentation, program execution, analysis, proof Hills and Roşu WADT 08: Towards a Module System for 4 / 29

Basics: Computations Overview Language Semantics in For More Information based around concepts from Rewriting Logic Semantics, with some intuitions from Chemical Abstract Machines and Reduction Semantics Abstract computational structures contain context needed to produce a future computation (like continuations) Context can consist of lists or multisets, generally representing sequential or concurrent computation potential Context includes special component, k, made up of list of computational tasks separated by, like t 1 t 2... t n From here on, computational structures called computations Hills and Roşu WADT 08: Towards a Module System for 5 / 29

Basics: Computations, Continued Overview Language Semantics in For More Information Intuition from CHAMs: language constructs can heat (break apart into pieces for evaluation) and cool (form back together) Represented using, like a 1 + a 2 a 1 + a 2 Operators containing called freezers Heating/cooling pair can be seen as an equation Intuition from RS: can be seen as similar to evaluation contexts, marking the location where evaluation can occur Hills and Roşu WADT 08: Towards a Module System for 6 / 29

Basics: Cells Outline Overview Language Semantics in For More Information Computations take place in context of a configuration Configurations hierarchical (like in RLS), made up of cells Each cell holds specific piece of information: computation, environment, store, etc Two regularly used cells: (top), representing entire configuration k, representing current computation Cells can be repeated (e.g., multiple computations in a concurrent language) Hills and Roşu WADT 08: Towards a Module System for 7 / 29

Example: Configuration Overview Language Semantics in For More Information Hills and Roşu WADT 08: Towards a Module System for 8 / 29

Basics: Equations and Rules Overview Language Semantics in For More Information Computations defined used equations and rules Heating/Cooling Rules (Structural Equations): manipulate term structure, non-computational, reversible, can think of as just equations Rules: computational, not reversible, may be concurrent Hills and Roşu WADT 08: Towards a Module System for 9 / 29

Example: Equations Overview Language Semantics in For More Information a 1 + a 2 a 1 + a 2 a 1 + a 2 a 2 a 1 + if b then s 1 else s 2 = b if then s 1 else s 2 Reminder: is not an evaluation context, but a freezer. Also, operations with freezers are boring to write, so we can mark operations strict(natlist), with a freezer generated for each position in the list. To do so for all operands, just use strict. _+_ : AExp AExp -> AExp [strict] Hills and Roşu WADT 08: Towards a Module System for 10 / 29

Example: Rules Outline Overview Language Semantics in For More Information i 1 + i 2 i, where i is the sum of i 1 and i 2 if true then s 1 else s 2 s 1 if false then s 1 else s 2 s 2 x := v k (x, l) env (l, store v Hills and Roşu WADT 08: Towards a Module System for 11 / 29

For More Information Overview Language Semantics in For More Information For more information on : A Rewriting Logic Approach to Type Inference (earlier talk) website: http://fsl.cs.uiuc.edu/k Includes tech reports and other papers related to Hills and Roşu WADT 08: Towards a Module System for 12 / 29

Overview Example Problem The Need for Rewriting logic semantics equations/rules (just rules from here, unless distinction matters) match across configuration items Configuration items provide context to where rule can apply Hills and Roşu WADT 08: Towards a Module System for 13 / 29

Overview Example Problem The Need for Rewriting logic semantics equations/rules (just rules from here, unless distinction matters) match across configuration items Configuration items provide context to where rule can apply Problem: change in configuration structure can change context, break existing rules Hills and Roşu WADT 08: Towards a Module System for 13 / 29

Example Outline Overview Example Problem x := v k (x, l) env (l, store v Hills and Roşu WADT 08: Towards a Module System for 14 / 29

Overview Example Problem Example, After Configuration Change x := v k (x, l) env t (l, store v Hills and Roşu WADT 08: Towards a Module System for 15 / 29

Overview Example Problem Context transformers solve problem by transforming context of rule to match configuration Handles almost all common cases using simple restrictions Top level configuration items should have distinct names Matching items are those closest together in graph Ambiguous matches will be flagged by tool User can explicitly specify context to handle unusual cases Hills and Roşu WADT 08: Towards a Module System for 16 / 29

Variable Patterns Outline Variable Patterns Sort Inference Provide way to define sorts of variables based on regular expressions for variable names Similar concepts found in other formalisms (e.g., ASF+SDF) Patterns visible throughout specification, not just in declaration module Example: var Var[0-9] for variables Var0, Var1,..., Var9 Hills and Roşu WADT 08: Towards a Module System for 17 / 29

Sort Inference Outline Variable Patterns Sort Inference In some specifications, variable declarations can make up half of spec Patterns help reduce this; sort inference can reduce even more Sorts of variables inferred based on definitions of ops Variables can always be explicitly declared or tagged with sorts if needed x := v k (x, l) env (l, store v Hills and Roşu WADT 08: Towards a Module System for 18 / 29

Module Formats Outline Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules Modules use similar syntax to Maude modules Module formats provided on top of standard module syntax to improve conciseness, allow defaults, enable special tool support Currently defined module formats: abstract syntax, language feature/semantics, configuration item, utility (similar to generic), language provides built-ins (sets, maps, lists, etc); additional can be defined using standard algebraic techniques Note: Meta-information can be associated with all items in modules; not shown below to reduce clutter Hills and Roşu WADT 08: Towards a Module System for 19 / 29

Generic Modules Outline Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Path/Name 2 imports /Some/Mod, /Other/Mod with { attribs }. 3 exports SImp, SImp, _op_ : SImp SImp -> SImp. 4 requires Val, SReq, _ : SReq -> SReq. 5 6 sort Loc. 7 sortalias Store = FiniteMap(Loc,Val). 8 subsort SSub < SSup. 9 10 var V : Val. var Store[0-9 ]* : Store. 11 12 op _someop_ : SomeSort SomeSort -> SomeSort. 13 eq [OptEqName] T = T [ where optional side-conditions ]. 14 rl [OptRlName] T2 => T3 [ where optional side-conditions ]. 15 end module Hills and Roşu WADT 08: Towards a Module System for 20 / 29

Example: Abstract Syntax Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Exp/AExp is 2 imports Exp with { sort Exp renamed AExp }. 3 var AE[0-9 a-za-z]* : AExp. 4 end module Undecorated module names are syntax modules Imports allow sort renaming Variable pattern declarations usable in other modules that (directly or indirectly) import this module Non-pattern variable declarations considered local Hills and Roşu WADT 08: Towards a Module System for 21 / 29

Example: Abstract Syntax Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Exp/AExp/Plus is 2 imports Exp/AExp. 3 _+_ : AExp AExp -> AExp. 4 end module Syntax defined using mixfix notation Any attributes (strict, etc) defined directly on syntax considered defaults Hills and Roşu WADT 08: Towards a Module System for 22 / 29

Example: Semantics Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Exp/AExp/Plus[Dynamic] is 2 imports Exp/AExp/Plus 3 with { op _+_ now strict, extends + [Int * Int -> Int] }. 4 end module Type of dynamics given after path in [brackets] Any attributes on syntax can be overridden on import Strictness auto-generates structural equalities for heating/cooling Extends uses predefined operations to give semantics to common constructs Hills and Roşu WADT 08: Towards a Module System for 23 / 29

Example: Semantics Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Dynamic/Exp/BExp/And[Dynamic] is 2 imports Exp/BExp/And with { op _and_ now strict(1) }. 3 rl true and B => B. 4 rl false and B => false. 5 end module Strictness can be enforced on individual arguments; here only first strict for short-circuit evaluation Combination of rules and strictness assign meaning to language construct Hills and Roşu WADT 08: Towards a Module System for 24 / 29

Example: Semantics Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Exp/BExp/And[Static] is 2 imports Exp/BExp/And with { op _and_ now strict }. 3 rl bool and bool => bool. 4 rl T1 and T2 => fail [ where T1 =/= bool or T2 =/= bool ]. 5 end module Strictness can be different for static or dynamic semantics Side condition added to distinguish fail case Hills and Roşu WADT 08: Towards a Module System for 25 / 29

Example: Language Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules 1 module Imp[Language] is 2 imports type=config Top,, Env, Store. 3 config = top(store(store) env(env) k() nextloc(nat)). 4 5 imports type=dynamic 6 Val/Int, Val/Bool, Exp/AExp/Name, Exp/AExp/Plus, 7 Exp/BExp/LEq, Exp/BExp/Not, Exp/BExp/And, Stmt/Seq, 8 Stmt/Assign, Stmt/IfThenElse, Stmt/While, Stmt/Halt, Pgm. 9 end module Language modules set up configuration, bring in semantics On import, type=tag syntactic sugar for Module[tag] config used to define state configuration Hills and Roşu WADT 08: Towards a Module System for 26 / 29

Config Example Outline Module Syntax Generic Modules Abstract Syntax Modules Semantics Modules Language Modules config = top(store(store) t*(env(env) k()) nextloc(nat)). Hills and Roşu WADT 08: Towards a Module System for 27 / 29

Related Work, Briefly Related Work Future Work Modular Semantics: MSOS, Action Semantics, Monads, Modular ASMs (Montages) Rewriting Logic Semantics: work on modularity (Braga and Meseguer) Tool Support: Action Semantics, Montages, many others Hills and Roşu WADT 08: Towards a Module System for 28 / 29

Future Work Outline Related Work Future Work Continue development of tools (Eclipse plugin, translation to Maude/) Continue moving over language modules Online module database with links into tool: build languages through module sharing and reuse Hills and Roşu WADT 08: Towards a Module System for 29 / 29