Re: An IDL for SCXML interpreters

Sorry, forgot to send to the list.

Le 3 juil. 2015 à 16:01, Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de <mailto:radomski@tk.informatik.tu-darmstadt.de>> a écrit :
> 
> [explicitly bcc'ing David, Jacob and Zjnue for I know that they maintain SCXML implementations] - this post is pertaining to action point 1 from my previous mail:
> 
> 1. An Interface Description Language (IDL) for SCXML interpreters.

You can keep your various FromXXX methods as optional, but please allow an overloaded constructor for languages that aren't JAVA :p
So, define the constructor's behavior for DOM, XML string, and URI arguments, leaving room for other types (e.g. File in JSSC).


> 1.1 For simple life-cycle and interpretation of state-charts.
> 1.2 A set of hooks for (on-line) visualisation.
> 1.3 A set of hooks for (on-line) modelling / debugging.
> 
> For now, I'd like to focus on point 1.1, but we ought to keep the others in mind and maybe eventually extend our ambitions. At least 1.2 is very useful as it would allow or a common visualisation. I hereby propose a first sketch for an Interface Description Language (IDL) for SCXML (see below). It will only allow to instantiate interpreters, run them and deliver events. A typical session would look like this:
> 
> import namespace scxml;
> try {
> Interpreter session = Implementation.fromURI("http://www <http://www/>.example.com/foo.scxml <http://example.com/foo.scxml>");
> for(;;) {
> int state = session.step();
> if (state == FINISHED)
> break;
> if (state == AFTER_MACROSTEP && session.configuration.in('foo'))
> session.receive('bar.baz');
> }
> } catch (Exception e) {
> print e;
> }

That may be "typical" but it's impossible in EcmaScript, which has very few blocking calls.


> == 1. Threads
> I want to avoid any assumptions about the availability of threads in the embedding platform. As such, there is e.g. no non-blocking interpret(). It would be the responsibility of the target platform to emulate something like this by embedding the block above in a thread.

ECMAScript itself does not use threads. However, the APIs and libraries it can use tend to use threads internally (e.g. network, filesystem, data encoding/decoding…) and the language deals with it by using callbacks, often wrapped in event handlers or Promises.

As a result, a typical ECMAScript session would look more like:

require(SCXML)

session = new SCXML("foo.scxml")
session.ready.then(session.start.bind(session))
session.on("step", () => { if(session.configuration.has('foo')) session.receive('bar.baz') })

I suggest specifying both a blocking IDL and a Promise one, implementations being free to implement either (but not both at once because methdos would have the same name), and an Event IDL (which can work with both).

E.g in async mode a method like step() returns a Promise that resolves when the macrostep is done. In blocking mode it returns when the macrostep is done. We can't have both. Don't even think of stepAsync(). An implementation that supports both might allow some configuration to switch modes, but really, I don't see it being useful. And in either case you could have session.on("done").


> == 2. Exceptions
> Similarly I want to avoid any assumption about the availability of exceptions, therefore step() might return FAULT and set the lastError attribute:
> 
> int state;
> for(;;) {
> state - session.step();
> switch(state) {
> case FAULT:
> print session.lastError;
> break;
> case FINISHED:
> return;
> }
> }

Again, the assumption that blocking is always available is false. As before, write a blocking IDL, a Promise IDL (Promises can reject with an error), and an event IDL with on("error") conditions.


> == 3. Data
> 0. If nothing in a Data object is set, its value is undefined

OK.

> 1. If an atom is given, the respective field is to be interpreted as the evaluation of that atom, e.g. "3" is a string, 3 is an integer.

evaluation how? JSON? how about an optional type attribute on <content> / <data> that I've suggested before?

> 2. If a node is given and 1. is not the case, the field is to be represented as a DOM Node

How about multiple node children?

> 3. If a key in a compound is set and 1. and 2. are not the case, the respective field is a map

Can you give an example for that one?

> 4. If an index is set and none of the above applies, the respective field is an array. Setting a an item at an index N will cause the array to behave as if it has N fields for the largest N. With all unset fields undefined.

What's the difference between indices and keys? In ES, indices are just positive integer keys.
I'd say that an array is when you have multiple children with no keys/indices at all.

> == 6. Naming
> AFTER_MACROSTEP might just as well be called STABLE. I choose the former for its more explicit reference to the runtime semantics of SCXML, which might play a role if we were to specify a bunch of hooks for 1.2 and 1.3 (see debugger paper[1], table 1)

I feel that "stable" should be used only when the queue is empty. Otherwise it's not going to remain stable even one moment.


Sorry, I'll have to continue later.


   David

Received on Wednesday, 15 July 2015 07:00:56 UTC