Merge branch 'master' into move-autohotkey-grammar

This commit is contained in:
Paul Chaignon
2015-02-01 20:12:22 +01:00
8 changed files with 5587 additions and 217 deletions

6
.gitmodules vendored
View File

@@ -555,3 +555,9 @@
[submodule "vendor/grammars/AutoHotkey"]
path = vendor/grammars/AutoHotkey
url = https://github.com/ahkscript/AutoHotkey
[submodule "vendor/grammars/ats.sublime"]
path = vendor/grammars/ats.sublime
url = https://github.com/steinwaywhw/ats-mode-sublimetext
[submodule "vendor/grammars/Modelica"]
path = vendor/grammars/Modelica
url = https://github.com/BorisChumichev/modelicaSublimeTextPackage

View File

@@ -46,6 +46,8 @@ vendor/grammars/Julia.tmbundle:
- source.julia
vendor/grammars/LiveScript.tmbundle:
- source.livescript
vendor/grammars/Modelica/:
- source.modelica
vendor/grammars/NSIS:
- source.nsis
vendor/grammars/NimLime:
@@ -128,6 +130,8 @@ vendor/grammars/assembly.tmbundle:
vendor/grammars/atom-salt:
- source.python.salt
- source.yaml.salt
vendor/grammars/ats.sublime:
- source.ats
vendor/grammars/autoitv3-tmbundle:
- source.autoit.3
vendor/grammars/awk-sublime:

View File

@@ -82,10 +82,9 @@ ATS:
- ats2
extensions:
- .dats
- .atxt
- .hats
- .sats
tm_scope: source.ocaml
tm_scope: source.ats
ace_mode: ocaml
ActionScript:
@@ -1241,6 +1240,7 @@ Handlebars:
type: markup
aliases:
- hbs
- htmlbars
extensions:
- .handlebars
- .hbs
@@ -1840,6 +1840,13 @@ Mirah:
tm_scope: source.ruby
ace_mode: ruby
Modelica:
type: programming
extensions:
- .mo
tm_scope: source.modelica
ace_mode: text
Monkey:
type: programming
extensions:

View File

@@ -1,215 +0,0 @@
%{
#include "./../ATEXT/atextfun.hats"
%}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>EFFECTIVATS-DiningPhil2</title>
#patscode_style()
</head>
<body>
<h1>
Effective ATS: Dining Philosophers
</h1>
In this article, I present an implementation of a slight variant of the
famous problem of 5-Dining-Philosophers by Dijkstra that makes simple but
convincing use of linear types.
<h2>
The Original Problem
</h2>
There are five philosophers sitting around a table and there are also 5
forks placed on the table such that each fork is located between the left
hand of a philosopher and the right hand of another philosopher. Each
philosopher does the following routine repeatedly: thinking and dining. In
order to dine, a philosopher needs to first acquire two forks: one located
on his left-hand side and the other on his right-hand side. After
finishing dining, a philosopher puts the two acquired forks onto the table:
one on his left-hand side and the other on his right-hand side.
<h2>
A Variant of the Original Problem
</h2>
The following twist is added to the original version:
<p>
After a fork is used, it becomes a "dirty" fork and needs to be put in a
tray for dirty forks. There is a cleaner who cleans dirty forks and then
puts them back on the table.
<h2>
Channels for Communication
</h2>
A channel is just a shared queue of fixed capacity. The following two
functions are for inserting an element into and taking an element out of a
given channel:
<pre
class="patsyntax">
#pats2xhtml_sats("\
fun{a:vt0p} channel_insert (channel (a), a): void
fun{a:vt0p} channel_takeout (chan: channel (a)): (a)
")</pre>
If [channel_insert] is called on a channel that is full, then the caller is
blocked until an element is taken out of the channel. If [channel_takeout]
is called on a channel that is empty, then the caller is blocked until an
element is inserted into the channel.
<h2>
A Channel for Each Fork
</h2>
Forks are resources given a linear type. Each fork is initially stored in a
channel, which can be obtained by calling the following function:
<pre
class="patsyntax">
#pats2xhtml_sats("\
fun fork_changet (n: nphil): channel(fork)
")</pre>
where the type [nphil] is defined to be [natLt(5)] (for natural numbers
less than 5). The channels for storing forks are chosen to be of capacity
2. The reason that channels of capacity 2 are chosen to store at most one
element (in each of them) is to guarantee that these channels can never be
full (so that there is no attempt made to send signals to awake callers
supposedly being blocked due to channels being full).
<h2>
A Channel for the Fork Tray
</h2>
A tray for storing "dirty" forks is also a channel, which can be obtained
by calling the following function:
<pre
class="patsyntax">
#pats2xhtml_sats("\
fun forktray_changet ((*void*)): channel(fork)
")</pre>
The capacity chosen for the channel is 6 (instead of 5) so that it can
never become full (as there are only 5 forks in total).
<h2>
Philosopher Loop
</h2>
Each philosopher is implemented as a loop:
<pre
class="patsyntax">
#pats2xhtml_dats('\
implement
phil_loop (n) = let
//
val () = phil_think (n)
//
val nl = phil_left (n) // = n
val nr = phil_right (n) // = (n+1) % 5
//
val ch_lfork = fork_changet (nl)
val ch_rfork = fork_changet (nr)
//
val lf = channel_takeout (ch_lfork)
val () = println! ("phil_loop(", n, ") picks left fork")
//
val () = randsleep (2) // sleep up to 2 seconds
//
val rf = channel_takeout (ch_rfork)
val () = println! ("phil_loop(", n, ") picks right fork")
//
val () = phil_dine (n, lf, rf)
//
val ch_forktray = forktray_changet ()
val () = channel_insert (ch_forktray, lf) // left fork to dirty tray
val () = channel_insert (ch_forktray, rf) // right fork to dirty tray
//
in
phil_loop (n)
end // end of [phil_loop]
')</pre>
It should be straighforward to follow the code for [phil_loop].
<h2>
Fork Cleaner Loop
</h2>
A cleaner is implemented as a loop:
<pre
class="patsyntax">
#pats2xhtml_dats('\
implement
cleaner_loop () = let
//
val ch = forktray_changet ()
val f0 = channel_takeout (ch) // [f0] is dirty
//
val () = cleaner_wash (f0) // washes dirty [f0]
val () = cleaner_return (f0) // puts back cleaned [f0]
//
in
cleaner_loop ()
end // end of [cleaner_loop]
')</pre>
The function [cleaner_return] first finds out the number of a given fork
and then uses the number to locate the channel for storing the fork. Its
actual implementation is given as follows:
<pre
class="patsyntax">
#pats2xhtml_dats('\
implement
cleaner_return (f) =
{
val n = fork_get_num (f)
val ch = fork_changet (n)
val () = channel_insert (ch, f)
}
')</pre>
It should now be straighforward to follow the code for [cleaner_loop].
<h2>
Testing
</h2>
The entire code of this implementation is stored in the following files:
<pre>
DiningPhil2.sats
DiningPhil2.dats
DiningPhil2_fork.dats
DiningPhil2_thread.dats
</pre>
There is also a Makefile available for compiling the ATS source code into
an excutable for testing. One should be able to encounter a deadlock after
running the simulation for a while.
<hr size="2">
This article is written by <a href="http://www.cs.bu.edu/~hwxi/">Hongwei Xi</a>.
</body>
</html>
%{
implement main () = fprint_filsub (stdout_ref, "main_atxt.txt")
%}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,285 @@
within Modelica.Electrical.Analog;
package Sensors "Potential, voltage, current, and power sensors"
extends Modelica.Icons.SensorsPackage;
model PotentialSensor "Sensor to measure the potential"
extends Modelica.Icons.RotationalSensor;
Interfaces.PositivePin p "pin to be measured" annotation (Placement(
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
Modelica.Blocks.Interfaces.RealOutput phi
"Absolute voltage potential as output signal"
annotation (Placement(transformation(extent={{100,-10},{120,10}},
rotation=0)));
equation
p.i = 0;
phi = p.v;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={
Text(
extent={{-29,-11},{30,-70}},
lineColor={0,0,0},
textString="V"),
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
Line(points={{100,0},{70,0}}, color={0,0,255}),
Text(
extent={{-150,80},{150,120}},
textString="%name",
lineColor={0,0,255})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={Line(points={{-70,0},{-96,0}}, color={0,0,0}),
Line(points={{100,0},{70,0}}, color={0,0,255})}),
Documentation(revisions="<html>
<ul>
<li><i> 1998 </i>
by Christoph Clauss<br> initially implemented<br>
</li>
</ul>
</html>", info="<html>
<p>The potential sensor converts the voltage of a node (with respect to the ground node) into a real valued signal. It does not influence the current sum at the node which voltage is measured, therefore, the electrical behavior is not influenced by the sensor.</p>
</html>"));
end PotentialSensor;
model VoltageSensor "Sensor to measure the voltage between two pins"
extends Modelica.Icons.RotationalSensor;
Interfaces.PositivePin p "positive pin" annotation (Placement(
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
Interfaces.NegativePin n "negative pin" annotation (Placement(
transformation(extent={{90,-10},{110,10}}, rotation=0)));
Modelica.Blocks.Interfaces.RealOutput v
"Voltage between pin p and n (= p.v - n.v) as output signal"
annotation (Placement(transformation(
origin={0,-100},
extent={{10,-10},{-10,10}},
rotation=90)));
equation
p.i = 0;
n.i = 0;
v = p.v - n.v;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={
Text(
extent={{-29,-11},{30,-70}},
lineColor={0,0,0},
textString="V"),
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
Line(points={{70,0},{90,0}}, color={0,0,0}),
Line(points={{0,-90},{0,-70}}, color={0,0,255}),
Text(
extent={{-150,80},{150,120}},
textString="%name",
lineColor={0,0,255})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={
Line(points={{-70,0},{-96,0}}, color={0,0,0}),
Line(points={{70,0},{96,0}}, color={0,0,0}),
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
Documentation(revisions="<html>
<ul>
<li><i> 1998 </i>
by Christoph Clauss<br> initially implemented<br>
</li>
</ul>
</html>", info="<html>
<p>The voltage sensor converts the voltage between the two connectors into a real valued signal. It does not influence the current sum at the nodes in between the voltage is measured, therefore, the electrical behavior is not influenced by the sensor.</p>
</html>"));
end VoltageSensor;
model CurrentSensor "Sensor to measure the current in a branch"
extends Modelica.Icons.RotationalSensor;
Interfaces.PositivePin p "positive pin" annotation (Placement(
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
Interfaces.NegativePin n "negative pin" annotation (Placement(
transformation(extent={{90,-10},{110,10}}, rotation=0)));
Modelica.Blocks.Interfaces.RealOutput i
"current in the branch from p to n as output signal"
annotation (Placement(transformation(
origin={0,-100},
extent={{10,-10},{-10,10}},
rotation=90)));
equation
p.v = n.v;
p.i = i;
n.i = -i;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={
Text(
extent={{-29,-11},{30,-70}},
lineColor={0,0,0},
textString="A"),
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
Text(
extent={{-150,80},{150,120}},
textString="%name",
lineColor={0,0,255}),
Line(points={{70,0},{90,0}}, color={0,0,0}),
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={
Text(
extent={{-153,79},{147,119}},
textString="%name",
lineColor={0,0,255}),
Line(points={{-70,0},{-96,0}}, color={0,0,0}),
Line(points={{70,0},{96,0}}, color={0,0,0}),
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
Documentation(revisions="<html>
<ul>
<li><i> 1998 </i>
by Christoph Clauss<br> initially implemented<br>
</li>
</ul>
</html>", info="<html>
<p>The current sensor converts the current flowing between the two connectors into a real valued signal. The two connectors are in the sensor connected like a short cut. The sensor has to be placed within an electrical connection in series. It does not influence the current sum at the connected nodes. Therefore, the electrical behavior is not influenced by the sensor.</p>
</html>"));
end CurrentSensor;
model PowerSensor "Sensor to measure the power"
Modelica.Electrical.Analog.Interfaces.PositivePin pc
"Positive pin, current path"
annotation (Placement(transformation(extent={{-90,-10},{-110,10}}, rotation=
0)));
Modelica.Electrical.Analog.Interfaces.NegativePin nc
"Negative pin, current path"
annotation (Placement(transformation(extent={{110,-10},{90,10}}, rotation=0)));
Modelica.Electrical.Analog.Interfaces.PositivePin pv
"Positive pin, voltage path"
annotation (Placement(transformation(extent={{-10,110},{10,90}}, rotation=0)));
Modelica.Electrical.Analog.Interfaces.NegativePin nv
"Negative pin, voltage path"
annotation (Placement(transformation(extent={{10,-110},{-10,-90}}, rotation=
0)));
Modelica.Blocks.Interfaces.RealOutput power
annotation (Placement(transformation(
origin={-80,-110},
extent={{-10,10},{10,-10}},
rotation=270)));
Modelica.Electrical.Analog.Sensors.VoltageSensor voltageSensor
annotation (Placement(transformation(
origin={0,-30},
extent={{10,-10},{-10,10}},
rotation=90)));
Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor
annotation (Placement(transformation(extent={{-50,-10},{-30,10}}, rotation=
0)));
Modelica.Blocks.Math.Product product
annotation (Placement(transformation(
origin={-30,-50},
extent={{-10,-10},{10,10}},
rotation=270)));
equation
connect(pv, voltageSensor.p) annotation (Line(points={{0,100},{0,-20},{
6.12323e-016,-20}}, color={0,0,255}));
connect(voltageSensor.n, nv) annotation (Line(points={{-6.12323e-016,-40},{
-6.12323e-016,-63},{0,-63},{0,-100}}, color={0,0,255}));
connect(pc, currentSensor.p)
annotation (Line(points={{-100,0},{-50,0}}, color={0,0,255}));
connect(currentSensor.n, nc)
annotation (Line(points={{-30,0},{100,0}}, color={0,0,255}));
connect(currentSensor.i, product.u2) annotation (Line(points={{-40,-10},{-40,
-30},{-36,-30},{-36,-38}}, color={0,0,127}));
connect(voltageSensor.v, product.u1) annotation (Line(points={{10,-30},{-24,
-30},{-24,-38}}, color={0,0,127}));
connect(product.y, power) annotation (Line(points={{-30,-61},{-30,-80},{-80,
-80},{-80,-110}}, color={0,0,127}));
annotation (Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Ellipse(
extent={{-70,70},{70,-70}},
lineColor={0,0,0},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Line(points={{0,100},{0,70}}, color={0,0,255}),
Line(points={{0,-70},{0,-100}}, color={0,0,255}),
Line(points={{-80,-100},{-80,0}}, color={0,0,255}),
Line(points={{-100,0},{100,0}}, color={0,0,255}),
Text(
extent={{150,120},{-150,160}},
textString="%name",
lineColor={0,0,255}),
Line(points={{0,70},{0,40}}, color={0,0,0}),
Line(points={{22.9,32.8},{40.2,57.3}}, color={0,0,0}),
Line(points={{-22.9,32.8},{-40.2,57.3}}, color={0,0,0}),
Line(points={{37.6,13.7},{65.8,23.9}}, color={0,0,0}),
Line(points={{-37.6,13.7},{-65.8,23.9}}, color={0,0,0}),
Line(points={{0,0},{9.02,28.6}}, color={0,0,0}),
Polygon(
points={{-0.48,31.6},{18,26},{18,57.2},{-0.48,31.6}},
lineColor={0,0,0},
fillColor={0,0,0},
fillPattern=FillPattern.Solid),
Ellipse(
extent={{-5,5},{5,-5}},
lineColor={0,0,0},
fillColor={0,0,0},
fillPattern=FillPattern.Solid),
Text(
extent={{-29,-11},{30,-70}},
lineColor={0,0,0},
textString="P")}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics),
Documentation(info="<html>
<p>This power sensor measures instantaneous electrical power of a singlephase system and has a separated voltage and current path. The pins of the voltage path are pv and nv, the pins of the current path are pc and nc. The internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.</p>
</html>", revisions="<html>
<ul>
<li><i>January 12, 2006</i> by Anton Haumer implemented</li>
</ul>
</html>"));
end PowerSensor;
annotation (
Documentation(info="<html>
<p>This package contains potential, voltage, and current sensors. The sensors can be used to convert voltages or currents into real signal values o be connected to components of the Blocks package. The sensors are designed in such a way that they do not influence the electrical behavior.</p>
</html>",
revisions="<html>
<dl>
<dt>
<b>Main Authors:</b>
<dd>
Christoph Clau&szlig;
&lt;<a href=\"mailto:Christoph.Clauss@eas.iis.fraunhofer.de\">Christoph.Clauss@eas.iis.fraunhofer.de</a>&gt;<br>
Andr&eacute; Schneider
&lt;<a href=\"mailto:Andre.Schneider@eas.iis.fraunhofer.de\">Andre.Schneider@eas.iis.fraunhofer.de</a>&gt;<br>
Fraunhofer Institute for Integrated Circuits<br>
Design Automation Department<br>
Zeunerstra&szlig;e 38<br>
D-01069 Dresden<br>
<p>
<dt>
<b>Copyright:</b>
<dd>
Copyright &copy; 1998-2010, Modelica Association and Fraunhofer-Gesellschaft.<br>
<i>The Modelica package is <b>free</b> software; it can be redistributed and/or modified
under the terms of the <b>Modelica license</b>, see the license conditions
and the accompanying <b>disclaimer</b> in the documentation of package
Modelica in file \"Modelica/package.mo\".</i><br>
<p>
</dl>
</html>"));
end Sensors;

1
vendor/grammars/Modelica vendored Submodule

1
vendor/grammars/ats.sublime vendored Submodule