Agenda
-
Modim overview
A short overview of what is implemented inside Modim
-
Modim's Modelica Frontend
Parsing, Abstract Syntax & Type-Evaluation
-
How To
How to do things with modim today.
-
Questions
Room for your questions.
A few facts and figures
Modim (Modelica Incremental Modules) is a toolchain for the separate compilation of Modelica models
- Modim currently contains of:
- ~ 6000 lines of scala (frontend and coder)
- ~ 3500 lines of Java (runtime)
- ~ 1000 lines of html-templates (user interface)
- Modim is free software under the LGPL
- Built using sbt (compatible to maven)
- Source code managed via git
- Project will be hosted under a redmine instance
Modim
Modim (Modelica Incremental Modules) is a toolchain for the separate compilation of Modelica models
- separate Type-Evaluation
- separate Analysis
- separate Translation
Current Modules
Usable
Work in progress
To be done
Modim
Frontend
Abstract Syntax
Parser
Type Evaluator
Type Checker
Coder
Models
Functions
Equations
Relations
Runtime
User Interface
Type Inspection
Simulation
Verification
Frontend Abstract Syntax
Modim contains an abstract syntax tree written as case-classes
/**
* The stored definition unit
*/
sealed case class Unit(within : Option[Name] = None, defs : List[TypeDef] = Nil)
sealed abstract class ClassSpec extends TExp
sealed case class TypeDefOptions(replaceable : Boolean = false,
fin : Boolean = false,
partial : Boolean = false,
encapsulated : Boolean = false)
sealed case class TypeDef(name : String, sort : Sort = Class, rhs : TExp, cns : Option[Constraint] = None, options : TypeDefOptions = TypeDefOptions(), comment : Comment = Comment()) extends Locatable
sealed case class Constraint(by : TExp, c:Comment=Comment()) extends Locatable
type Algorithm = List[Statement]
sealed case class Behavior(algorithms : List[Algorithm] = List(),
equations : List[Equation] = List(),
initial_algorithms : List[Algorithm] = List(),
initial_equations : List[Equation] = List(),
external : Option[ExternalDef] = None)
sealed case class ExternalDef(lang : String, lhs : Option[Exp], rhs : Exp, a : Option[Mod] = None) extends Locatable
sealed case class Composition(typedefs : List[TypeDef] = List(),
redeclared_types : List[TypeDef] = List(),
imports : List[Import] = List(),
extensions : List[Extend] = List(),
defs : List[Def] = List(),
redeclared_defs : List[Def] = List(),
cargo : Behavior = Behavior()
) extends ClassSpec
Frontend Abstract Syntax
There are 32 syntactic groups
sealed abstract class Location {
sealed case class Unit(within : Option[Name] = None, defs : List[TypeDef] = Nil)
sealed abstract class ClassSpec extends TExp
sealed case class TypeDefOptions(replaceable : Boolean = false,
sealed case class TypeDef(name : String, sort : Sort = Class, rhs : TExp, cns : Option[Constraint] = None, options : TypeDefOptions = TypeDefOptions(), comment : Comment = Comment()) extends Locatable
sealed case class Constraint(by : TExp, c:Comment=Comment()) extends Locatable
sealed case class Behavior(algorithms : List[Algorithm] = List(),
sealed case class ExternalDef(lang : String, lhs : Option[Exp], rhs : Exp, a : Option[Mod] = None) extends Locatable
sealed case class Composition(typedefs : List[TypeDef] = List(),
sealed case class Enumeration(literals : List[EnumLiteral]) extends ClassSpec with Locatable
sealed case class EnumLiteral(name : String, c:Comment=Comment())
sealed case class DerSpec(name : Name,
sealed case class Extension(rhs : Composition, mod : Option[Mod] = None) extends ClassSpec
sealed case class Comment(str : Option[String] = None, annotation : Option[Mod] = None)
sealed abstract class Sort
sealed abstract class Connectivity
sealed abstract class Variability {
sealed abstract class Causality
sealed abstract class Import extends Locatable
sealed abstract class Visibility
sealed abstract class InnerOuter
sealed case class DefOptions(fin : Boolean = false,
sealed case class Def(name : String, t : TExp, cns : Option[Constraint] = None,
sealed abstract class Statement(comment : Comment = Comment())
sealed abstract class Equation(comment : Comment = Comment())
sealed abstract class Exp extends Locatable
sealed case class Idx(x : String, r : Option[Exp] = None)
sealed abstract class TExp extends Locatable
sealed case class Redeclare(e : Boolean, t : TypeDef) extends Locatable
sealed case class RedeclareRedef(e : Boolean, d : Def) extends Locatable
sealed case class Redef(e : Boolean=false, f : Boolean=false, name : List[String] = Nil, mod : Option[Mod]=None, rhs : Option[Exp]=None, comment : Option[String]=None) extends Locatable
sealed case class Mod(types : List[Redeclare]=Nil, components : List[RedeclareRedef]=Nil, redefs : List[Redef]=Nil)
←
→
/
#
FrontEnd: Type Evaluation
Modelica contains rather complicated type-expressions:
- Multiple Inheritance
- Bounded Quantification
- Higher-order types
In particular, there is no specific order of type evaluation specified in Modelica.
FrontEnd: Lazy Types
Modim evaluates types lazily
case class NamedType(name : List[String],
expr : TExp,
context : Either[NamedType, Map[String, Type]],
sort : Sort = Class,
actualParams : Map[String, Type] = Map()) extends Type
A NamedType can be evaluated into one of 10 basic types.
case class TErr(cause : TypeError, loc : Location, info : Any*) extends Type {
from : Option[NamedType] = None) extends Type {
case class TFunction(inputs : List[FunctionParam], outputs : List[FunctionParam]) extends Type {
case class TArray(t : Type, dims : Int) extends Type {
case class TEnum(name : List[String], variants : List[String]) extends Type {
case class TNamedExternalObject(definition : NamedType, javaClass : Option[String] = None) extends Type {
case object TExternalObject extends Type
case object TInteger extends Type
case object TReal extends Type
case object TString extends Type
case object TBoolean extends Type
Parse a Modelica source file (scala)
val path = scalax.file.Path.fromString("/home/choeger/uebb/MSL/trunk/Modelica/Electrical/package.mo")
val parser = new de.tuberlin.uebb.modelica.modim.impl.ModelicaParboiledParser() {}
val run = parser.parseFile(path)
run.result
Some(Unit(Some(List(Modelica)),
List(TypeDef(Electrical,Package,Composition(List(),List(),List(),
List(Extend(TProj(TProj(TIde(Modelica),Icons),Package),Public,None)),List(),List(),
Behavior(List(),List(),List(),List(),None)),None,
TypeDefOptions(false,false,false,false),
Comment(...)
Parse a Modelica source file (scala)
ModelicaParboiledParser parser = new ModelicaParboiledParser();
scalax.file.Path path = scalax.file.Path.fromString("/home/choeger/uebb/MSL/trunk/Modelica/Electrical/package.mo");
ParsingResult run = parser.parseFile(path);
System.out.println(run.result());
Some(Unit(Some(List(Modelica)),
List(TypeDef(Electrical,Package,Composition(List(),List(),List(),
List(Extend(TProj(TProj(TIde(Modelica),Icons),Package),Public,None)),List(),List(),
Behavior(List(),List(),List(),List(),None)),None,
TypeDefOptions(false,false,false,false),
Comment(...)
Thank you for your attention!
Questions?