Bdl The B lock D escription L anguage Pierre Weis - Cl ement - - PowerPoint PPT Presentation

bdl
SMART_READER_LITE
LIVE PREVIEW

Bdl The B lock D escription L anguage Pierre Weis - Cl ement - - PowerPoint PPT Presentation

Bdl The B lock D escription L anguage Pierre Weis - Cl ement Franchini Carg` ese 2014 October 19 Motivation Block diagram simulation tools (such as Scicos, Simulink) are routinely used for modeling and simulate dynamical systems.


slide-1
SLIDE 1

Bdl

The Block Description Language

Pierre Weis - Cl´ ement Franchini Carg` ese – 2014 October 19

slide-2
SLIDE 2

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

1

Motivation

Block diagram simulation tools (such as Scicos, Simulink) are routinely used for modeling and simulate dynamical systems. However, seen as modeling languages, they lack a precise defi- nition. Programs correctness is thus difficult to state (if not impossible). Yet, block diagram programs are developped with the aim of generating software embedded into critical systems.

slide-3
SLIDE 3

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

2

Proposal

Design a domain specific language (DSL) to describe the seman- tics of blocks and their connections. High-level language specialized to block description. For sake of safety and efficiency we need:

  • Strong and static type-checking.
  • Compilation (in particular static binding discipline).
  • Semantically sound definition of the language constructs.
slide-4
SLIDE 4

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

3

Bdl

Our DSL is the Block Description Language (Bdl). Characteristics

  • Builtin matrix values and matrix types.
  • Matrix size statically verified.
  • All variables and matrices are initialized.
  • Language constructions are side effect free (pure).
  • Very limited memory side effects (assignments are restricted

to variables declared as mutable).

slide-5
SLIDE 5

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

4

Static semantic description

Type reconstruction, ` a la ML (Damas-Milner algorithm). Compiler automatically finds types and verifies type adequacy. No type annotations in programs (except for interfaces). Polymorphic typing, using type schemes with quantified type pa- rameters.

slide-6
SLIDE 6

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

5

Polymorphic values and functions

[ n, m ] t is the type of a matrix of t values with n rows and m columns. [ 0, 0 ] :: [1, 2] int // An integer vector of size 2 [ 1.1, 2.2; 3.0, 4.0 ] :: [2, 2] float // A 2x2 float matrix Matrix addition has a highly polymorphic type scheme: add_matrix :: for all m n t, function ([m, n] t, [m, n] t) -> [m, n] t

slide-7
SLIDE 7

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

6

Bdl generic functions

Generic functions describe the meaning of high-level operators used in blocks (such as arithmetic operators). The dynamic semantics of generic functions is described in terms

  • f the compiler’s target language basic primitives.

A generic definition is not adequately typable, but all applications

  • f a generic function must statically evaluate to a well-typed

expression. Static semantics of generic functions is thus given by a combi- nation of partial evaluation and type reconstruction.

slide-8
SLIDE 8

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

7

Generic addition

generic ( + ) (x, y) = assert (type of x == type of y); switch size of x case [1, 1], add_scalar (x, y);

  • therwise,

(m, n) = size of x; mutable res = y; for i = 1 : m do for j = 1 : n do res := [res with i, j = add_scalar (x [i, j], y [i, j])]; end; end; res; end; end;

slide-9
SLIDE 9

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19 8

Generic scalar addition

generic add_scalar (x, y) = assert (type of x == type of y); t = type of x; switch t case int8, add_int8 (x, y); case int, add_int (x, y); case float, add_float (x, y);

  • therwise,

partial_evaluation_error ( "no instance of add_scalar for type " ^^ string_of_type (t)); end; end;

slide-10
SLIDE 10

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

9

Primitive addition

Primitive addition for short integers is an external definition (not defined in Bdl). external add_int8 :: function (int8, int8) -> int8 = external "bdl_add_int8"; bdlc will translate any call to “add int8” to a call to the target language primitive addition for eight bits long signed integers. Same definitions for other scalar types (int16, int32, float, ...).

slide-11
SLIDE 11

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

10

Application of generic addition

1 + 2; generic ( + ) (1, 2) => type of 1 and type of 2 is int => assertion is verified => size of x is [1, 1] => call add_scalar (1, 2) => ... add_int (1, 2) => 3

slide-12
SLIDE 12

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

11

Generic application type-checking

1.0 + 2; generic ( + ) (1.0, 2) => type of 1.0 is float type of 2 is int => assertion is not verified Static type checking error.

slide-13
SLIDE 13

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

12

Dynamic semantic description

Small step semantics (source code to source code rewriting rules). Dynamic semantics is described by a partial evaluator. Semantics is defined as iteration of partial evaluation up to nor- mal form.

slide-14
SLIDE 14

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

13

Difficulties

  • Mixing static typing and partial evaluation is challenging.
  • Provide a Bdl semantics for blocks that have a fuzzy defini-

tion in the first place.

slide-15
SLIDE 15

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

14

Current state of the compiler

The front end is written:

  • Concrete syntax is defined
  • YACC parser written

The middle end is actively developped:

  • Scope analysis completed
  • Type reconstruction is in progress
  • Sketchy partial evaluation

The back end is future work:

  • The compiler will produce C source code.
  • Tied to the codegen toolbox for NSP.
  • Still a joint work with ENPC & ALTAIR.
slide-16
SLIDE 16

Pierre.Weis@inria.fr Clement.Franchini@inria.fr 2014-10-19

15

Conclusion

bdlc need to import existing models providing a plausible seman- tics to programs in other modelers (Simulink, Scicos or ScicosPro models). bdlc should be a fast and reliable compiler for block diagram programs written in Bdl.