-
Notifications
You must be signed in to change notification settings - Fork 0
DASM Syntax
DASM stands for DOSTE ASeMbly, where DOSTE is the old name for Cadence. This script notation is intended to be a low-level way of constructing and manipulating the Cadence environment. Here is a brief introduction to the syntax of DASM, more can be found in the original PhD thesis for which Cadence was developed.
this.x = 2;
this.y = (this.x * 2);There must always be some base context, in this case it is this which refers to the root of the interpreter being used to parse the DASM script. Other contexts may be used:
true.not = false;Longer statements can be used where there is a more complex structure:
this.x.y.z = true;And if this longer path is used often it can be useful to define a shortcut, similar to the use of #define or static const in C++. A shortcut only exists at the time the script is parsed and if it is redefined further down the script it will not change anything which used it previously.
@myvar = (this.x.y);
@myvar.z = true;The above is the same as the previous example.
this.x = (5 + 4 * 3);The above evaluates to 27 where normally, in most languages, it would be 17. All operators have the same precedence, from left to right. Therefore, it is essential to either use brackets or order your statements accordingly.
this.x = (5 + (4 * 3));The following is also incorrect (and will probably give a warning):
this.x = 5 + 4 * 3;Here the value of this.x will be 5 since the assignment only looks at the next specified item and not the entire collection of following items. Always put brackets around complex (ie. more than single element) statements on the right-hand-side of an assignment unless you really know what you are doing.
this.x = (new);
this.x.y = (new);
this.x.y.z = 100;The new keyword will automatically generate a new unique identifier that can then be populated as shown above. Note that new must always be at the beginning of an expression and so must be inside brackets here. A simpler syntax for construction may be:
this.x = (new
y = (new
z = 100
)
);The above saves repetition of this.x which can become a big problem when large numbers of items are being put into it. Note, however, that semicolons are not used as this is a single statement.
this.x = (new
a = 1
b = 2
c = 3
);Array indexing is just like anything else in DASM, numbers can be used as identifiers:
this.x.0 = 1;
this.x.1 = 2;However, a more familiar syntax is available where indexes may be put into angular brackets:
this.x[0] = 1;
this.x[1] = 2;There is no built-in notion of the length of an array, this is something the user must specify themselves:
this.x.length = 2;There is also no need for array indexes to be sequential:
this.x[0] = 1;
this.x[5542] = 333;this.u is { this.v };Here the observable u is defined to be the same as v. If v changes then u will automatically be updated to reflect the change. Any expression that does not involve a side-effect (assignment of definition) may be used.
this.u is { this.v * 2 };