Use of extension functions in streaming mode in Saxon/Net - saxon

I would like to know whether it is possible to call user extension functions in streaming mode using XSLT 3.0 on Saxon EE for .Net.
And if it is, under what constraints (e.g. "never pass nodes as parameters but atomic values are OK", etc.)
I have looked at the main documentation but could not find anything.

I don't think it's been tested, so I suggest you try it and see. The streamability analysis uses the general streamability rules, so if you pass atomic values (or unstreamed nodes) then it should be OK. You might be able to get away with passing nodes as well, provided you don't try doing any downwards navigation from them. If you pass a sequence of nodes rather than a single node then they may get buffered.

Related

How to walk whole Parse Tree and print it's content with slight changes in ANTLR4?

So as stated in the title, my task is to traverse the Parse Tree generated for code written in Java (grammar is a standard Java grammar), print most of it unchanged and modify only some words, for example type declarations.
My current approach was to create ParseTreeListener and implement the logic in the enterEveryRule method, but unfortunately it doesn't appear to work even for basic printing. The output is very messy and there are a lot of repetitions, as if every node was visited multiple times.
My another try was to implement appropriate methods in BaseListener that would do the changes to the type declarations I need, but from there I see no possibility to print the rest of the code unchanged.
Looking forward to your help!
You could use ANTLR's string templates to produce code from the ASTs.
In general, you start with set of "standard" string templates that can regenerate source code corresponding to the underlying tree.
To get the effect you want, you judiciously choose the standard string templates on AST nodes where you don't want changes, and variant templates where you do want changes.
IMHO, it is better to modify the AST, and then simply apply the standard templates.

What is the meaning of the bScan parameter value 0x45 in keybd_event?

Many examples of using keybd_event, have the value 0x45 for the bScan parameter.
What is the meaning of that 0x45 value?
I was under the impression 0x45 was a keyboard scancode, but since it is used for a various number of keys, I'm not so sure about that any more.
My goal is to use keybd_event either from .NET P/Invoke, or from Delphi, and make the types more restrictive (using for instance enums or flagged enums) so my code becomes easier to maintain.
It is indeed a scan code and for many keyboards it is the scan code for the NumLock key.
The example code attached to the documentation of keybd_event is an example of how to toggle the NumLock state. And so naturally 0x45 is used as the scan code. My guess is that lots of the other examples that you found simply copied blindly that value from the keybd_event MSDN example. Since applications typically ignore the scan code and respond to the virtual key code, it usually doesn't matter what value is passed as the scan code.
Finally, you'll want to use SendInput rather than keybd_event. The reason being that that former allows you to place a sequence of events in the queue. With keybd_event you place the events in the queue one at a time and it's possible that your faked events can get interspersed with real events. And that problem is one of the main reasons why SendInput was introduced.

unifying model for 'static' / 'historical' /streaming data in F#

An API I use exposes data with different characteristics :
'Static' reference data, that is you ask for them, get one value which supposedly does not change
'historical' values, where you can query for a date range
'subscription' values, where you register yourself for receiving updates
From a semantic point of view, though, those fields are one and the same, and only the consumption mode differs. Reference data can be viewed as a constant function yielding the same result through time. Historical data is just streaming data that happened in the past.
I am trying to find a unifying model against which to program all the semantic of my queries, and distinguish it from its consumption mode.
That mean, the same quotation could evaluated in a "real-time" way which would turn fields into their appropriate IObservable form (when available), or in 'historical' way, which takes a 'clock' as an argument and yield values when ticked, or a 'reference' way, which just yield 1 value (still decorated by the historical date at which the query is ran..)
I am not sure which programming tools in F# would be the most natural fit for that purpose, but I am thinking of quotation, which I never really used.
Would it be well suited for such a task ?
you said it yourself: just go with IObservable
your static case is just OnNext with 1 value
in your historical case you OnNext for each value in your query (at once when a observer is registered)
and the subscription case is just the ordinary IObservable pattern - you don't need something like quotations for this.
I have done something very similar (not the static case, but the streaming and historical case), and IObservable is definitely the right tool for the job. In reality, IEnumerable and IObservable are dual and most things you can write for one you can also write for the other. However, a push based model (IObservable) is more flexible, and the operators you get as part of Rx are more complete and appropriate than those as part of regular IEnumerable LINQ.
Using quotations just means you need to build the above from scratch.
You'll find the following useful:
Observable.Return(value) for a single static value
list.ToObservable() for turning a historical enumerable to an observable
Direct IObservable for streaming values into IObservable
Also note that you can use virtual schedulers for ticking the observable if this helps (most of the above accept a scheduler). I imagine this is what you want for the historical case.
http://channel9.msdn.com/Series/Rx-Workshop/Rx-Workshop-Schedulers

Why build an AST walker instead of having the nodes responsible for their own output?

Given an AST, what would be the reason behind making a Walker class that walks over the tree and does the output, as opposed to giving each Node class a compile() method and having it responsible for its own output?
Here are some examples:
Doctrine 2 (an ORM) uses a SQLWalker to walk over an AST and generate SQL from nodes.
Twig (a templating language) has the nodes output their own code (this is an if statement node).
Using a separate Walker for code generation avoids combinatorial explosion in the number of AST node classes as the number of target representations increases. When a Walker is responsible for code generation, you can retarget it to a different representation just by altering the Walker class. But when the AST nodes themselves are responsible for compilation, you need a different version of each node for each separate target representation.
Mostly because of old literature and available tools. Experimenting with both methods you can easily find that AST traversal produces very slow and convoluted code. Moreover, code separated from immediate syntax doesn't resemble it anymore. It's very much like supporting two synchronized code bases, which is always a bad idea. Debugging, maintenance become difficult.
Of course, it can be also difficult to process semantics on the nodes unless you have a well designed state machine. In fact you are never worse than having to traverse AST after the fact, because it's just one particular case of processing semantics on nodes.
You can often hear that AST traversal allows for implementation of multiple semantics for the same syntax. In reality you would never want that, not only because it's rarely needed, but also for performance reasons. And frankly, there is no difficulty in writing separate syntax for a different semantics. The results were always better when both designed together.
And finally, in every non-trivial task, get syntax parsed is the easiest part, getting semantics correct and process actions fast is a challenge. Focusing on AST is approaching the task backwards.
To have support for a feature that the "internal AST walker" doesn't have.
For example, there are several ways to trasnverse a "hierarchical" or "tre" structure,
like "walk thru the leafs first", or "walk thru the branches first".
Or if the nodes siblings have a sort index, and you want to "walk" / "visit" them decremantally by their index, instead of incrementally.
If the AST class or structure you have only works with one method, you may want to use another method using your custom "walker" / "visitor".

does systemverilog support linked lists?

I tried implementing a circular doubly-linked list class (with a single sentinel node) in systemverilog. The list itself seems to work as expected but ends up crashing the simulator (corrupting stack?)
This led me to wonder if this is something fundamentally unsupported by the language (in terms of allocation)? SV does have a "queue" construct that can be made to work in the same way (probably more efficient in both access and insertion time).
Any ideas?
SystemVerilog does have a queue construct. They're declared a bit like arrays, but use the $ symbol:
int myqueue[$]; // $ indicates a queue
myqueue.push_front(14);
some_int = myqueue.pop_back();
Depending how you use combinations of methods push_front(), push_back(), pop_front() and pop_back(), you can implement stacks & FIFOs and the like. A quick internet search should give you a full list of methods and declaration options.
I doubt that SystemVerilog queues are synthesizable. And I'm not 100% sure how you'd go about making a circular buffer from one without checking indices first...
Nothing inherently missing from the language that I'm away of. Pretty much everything is pass by reference, so that's the main thing you need. Only gotcha I can think of is to remember that SV is garbage collected, so it's important to null out your references to instances when they're removed from your list (but you'd probably do that anyway)
I'm pretty sure the queue would be implemented as a linked list internally. That said I've had some issues on different simulators when I've wanted to use queues in weird and wonderful ways.
SystemVerilog is a garbage-collected language. Circularly linked lists have the potential to cause issues if the garbage collection scheme implemented by the simulator you are using is buggy.

Resources