Redesign of Paml Syntax/Semantics

Operator dataOf and "object instance" expression are removed, collections syntax/semantic is improved.

Operator dataOf is removed because object variables can now be accessed by both, data access "." and object access "->", operators. No need to take object data by special switcher like dataOf operator.

Collections now are declared by special syntax col ... of. This highlights that collections are neither objects nor values, but they are a language abstraction for item sequences. Items of a collection can be either objects or values depending on the items type.

Creation of new object instances is now completely an aspect and is implemented via transformations. As result, the type of object variable is a join point, which can be transformed into any initialization expression, and "constructor" is one of possible initialization expressions.

The syntax of message parameters is now unified with local variable declaration with obj/val keywords. The keywords can be omitted if the variable type can be inferred.

value Point
{
X, Y : integer;
}
object Canvas
{
data Height, Width : integer;
If the type of a parameter is unspecified, obj/val keyword is required to specify the parameter is object or value
message Resize ( val height : integer, val width : integer )
{
this.Height = height;
this.Width = width;
}
message DrawPixel ( pixel : Point )
{
TODO:
}
message Clear
{
TODO:
}
}
object Circle
{
data Radius : integer;
data Center : Point;
message MoveTo ( val x : integer, val y : integer )
{
Object data (which are always values) can be changed in any way
this . Center . X = x;
this . Center . Y = y;
}
message MoveTo ( center : Point )
{
this.Center = center;
}
If the type of a parameter is an object, the parameter is a join point, so a transformation can specify how the parameter is initialized
message Draw ( canvas : Canvas )
{
val pixel : Point;
Local collection definition
col pixels of Point;
Calculate pixel coordinates
Local values can be changed in any way
pixel.X = ...;
pixel.Y = ...;
canvas->DrawPixel (pixel);
}
}
subject Painter
{
Collection name is always a join point, to specify how the collection is translated to output code
col Circles of Circle;
message Render
{
val height = 1080, width = 2048;
  • The type of object variable is a join point and can be transformed to any initializing expression (like constructor call)
  • Transformation can capture visible variables (locals "height" and "width" in the example) and use them in the initializing expression.
obj canvas : Canvas;
canvas -> Clear ( ) ;
Object state can be accessed by data access operator "." only for reading
val h = canvas.Height;
canvas->Resize ( height, width : 4096 );
this.Circles (circle)
forEach {
circle->Draw (canvas) };
}
The type of "circle" parameter is inferred as "Circle", it's an object so the parameter is also an join point
message AddCircle (circle)
{
add (this.Circles, circle); "add" is an operator in N-arity syntax
or
this.Circles add circle; "add" is an operator in binary syntax
}
}

Write a comment

Comments: 0

Pallada project, Copyright © 2015 - 2021.

For any mentions and citations of the site materials, a link to the Pallada project site is obligatory.