Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3...

18
1 OpenModelica Eclipse Plugin and MetaModelica Exercises Adrian Pop [email protected] PELAB/IDA/LIU 2007-03-29 OpenModelica & MetaModelica Course 2 Outline Eclipse and Exercise Setup Exercises 01_experiment 02a_exp1, 02b_exp2 03_assignment 04a_assigntwotype 04b_modassigntwotype 05_advanced 06_OMCAndCorba 07-10 – as samples of Prog. Lang. modeling

Transcript of Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3...

Page 1: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

1

OpenModelica Eclipse Plugin and

MetaModelica ExercisesAdrian Pop

[email protected]/IDA/LIU

2007-03-29OpenModelica & MetaModelica Course

2

OutlineEclipse and Exercise SetupExercises

01_experiment02a_exp1, 02b_exp203_assignment04a_assigntwotype04b_modassigntwotype05_advanced06_OMCAndCorba07-10 – as samples of Prog. Lang. modeling

Page 2: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

2

3

Eclipse Setup – Switching Workspace

4

Select and Open all projects

Page 3: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

3

5

Refresh all projects

6

Close all projects

Page 4: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

4

7

Open the first project

8

Eclipse Setup – Creating the projects

Build Automaticallyshould be DISABLEDfor all projects

Page 5: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

5

9

Build the first project

10

Eclipse – Building a project

leave empty – builds the projectclean – cleans the projectrun – runs the program

the problems are inthe Problems view after the build

the build and run resultsare displayed in the console

Page 6: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

6

11

Setting the debug configuration

12

Specify the executable from the project

Click Browse and select the executable you just built.

Give parameters to the program

Page 7: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

7

13

Specify the name of the executable

Click Browse and select the executable you just built.

14

Set breakpoints in .mo file

Double click on the ruler to set breakpoints

Page 8: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

8

15

Run the debug configuration to start debugging

Click and select the debug configuration.The debugging will start.

16

Eclipse will ask to switch to debugging perspective

Page 9: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

9

17

Debugging perspective

Use the buttons to step.Only step into works right now.

Browse variables here.Also there is a tab with breakpoints.

18

Switching perspectives

Switch between Debug and Modelica Perspective

Page 10: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

10

19

Eclipse Setup – Creating the projects

repeat the procedure for all exercises01_experiment02a_exp1, 02b_exp203_assignment04a_assigntwotype04b_modassigntwotype05_advanced06_OMCAndCorba

leave open only the project you are working on! close all the others

20

Eclipse – Building a project

Page 11: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

11

21

Eclipse – Opening views

To open additional views:Window->ShowView->Other

22

Exercises

Each exercise is in a different Eclipse projectAll exercises have :

README.txt - information about the exerciseSOLUTION.txt – the solution of the exercise (if the exercise has some implementation assignment)program.txt – input program to the exercise, edit if needed (for the exercises which have an input)

Consult the MetaModelica Programming Guideand the slides if you need additional information during the exercises. Of course, feel free to ask us any type of questions, is faster and better!

Page 12: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

12

23

Exercises - 01_experiment

See README.txt in the Eclipse project

In this exercise you experiment withTypesConstantsFunctions

AssignmentWrite functions in Functions.mo to display the constants defined in Types.mo.Search for // your code here in Main.mo and Functions.mo

Compare your solution with the SOLUTION.txtyou find in the Eclipse project

24

Exercises – 02a_exp1

See README.txt in the Eclipse project

In this exercise you will add new constructs to the exp1 language and deal with their evaluation.Assignment - add new constructs to the language

a power operator (^)a factorial operator (!)search for // your code here within Exp1.mo

Notethe parser/lexer are ready, you only have to uncomment some rules in parser.y

Compare your solution with the SOLUTION.txtyou find in the Eclipse project

Page 13: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

13

25

Exercises – 02b_exp2

See README.txt in the Eclipse project

In this exercise you will explore a different way to model the exp1 language using different Exp trees.Explore the Exp2.mo file and compare it with Exp1.mo file.

26

Exercises – 03_assignment

See README.txt in the Eclipse projectAssignment - add functions to print:

the assignments present in the current program before the actual evaluationthe environment after it was augmented with the assignmentssearch for // your code here within Assignment.mo

Compare your solution with the SOLUTION.txt you find in the Eclipse project

Page 14: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

14

27

Exercises – 04a_assigntwotype

See README.txt in the Eclipse project

Assignment - add functions to print:add a new String type which can hold only integers as strings to the current Exp node add cases to evaluate expressions/assignments of the form "2" + 1 + "1" + 1.0 in the eval functionsearch for // your code here within AssignTwoType.mo

Notethe parser/lexer are ready, you only have to uncomment some rules in parser.y

Compare your solution with the SOLUTION.txt you find in the Eclipse project

28

Exercises – 04b_modassigntwotype

See README.txt in the Eclipse projectIn this exercise you will explore a different way to structure your code within different packages.The code from 04a_assigntwotype is now split over 4 packages.Compare the 04a/b projects.

Page 15: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

15

29

Exercises – 05_advanced (I)

See README.txt in the Eclipse projectIn this exercise you experiment with

polymorphic typesconstantshigher order functions

Assignment 1Write a polymorphic function that orders a list of any type.The function has as input a list and a compare function between the objects of that list. Write the comparison functions for Integers, Strings and Reals.Test your function on the Types.intList

30

Exercises – 05_advanced (II)

See README.txt in the Eclipse project

Assignment 2Write a polymorphic map function that applies a function over a list and returns a new list with the result.Write three functions that transform from:

integer to real integer to stringreal to string

Use your map function and the two transformation functions to transform the Types.intList to a list of reals and a list of string, then apply the ordering function from Assignment 1 on the newly created lists

Page 16: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

16

31

Exercises – 05_advanced (III)

See README.txt in the Eclipse projectAssignment 3

Write a polymorphic map function that applies a print function over a list (of Strings) and prints the it.Use the transformer functions from real->string and integer->string from Assignment 2 to transform the real list or the integer list to a string list for printing.

Compare your solution with the SOLUTION.txt you find in the Eclipse project

32

OMC Overview

We are Switching to OMC Overview now!

Page 17: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

17

33

Eclipse – Switching to Java Perspective

34

Exercises – 06_OMCAndCorba

See README.txt in the Eclipse projectIn this exercise you will send commands to the OMC Compiler (omc.exe) via CORBAOMCProxy.java has functionality for

starting the omc process if is not already startedthe starting is a bit different for Windows/Linux

sending commands to OMClogging facilities

If you need clients in C++ or Python checkhttp://www.ida.liu.se/labs/pelab/modelica/OpenModelica.htmldeveloper pages

Page 18: Eclipse MDT and MetaModelica Exercises-070329 · 07-10 – as samples of Prog. Lang. modeling. 2 3 Eclipse Setup – Switching Workspace 4 Select and Open all projects. 3 5 Refresh

18

35

Eclipse Setup – Creating the projects

36

End

Thank you!

Administrative Question:What would you like to implement tomorrow

in the OpenModelica Compiler?