Greetings, I’m in the process of writing a hobby language, and was thinking of writing it in Scala because of the rather unique set of requirements my language has, what I need is a efficient way of performing delimited multi-shot continuations. Scala with it’s myriad of meta-programming tools seems like a good place to start.
At the core of what I’m looking for is a function to state machine transform like those found in C#, I know async/await exists in Scala, but I need a few more features:
-
I’d like tight control over the types inside the state machines, there are cases where I need to convert the concrete types inside the state machines. So I’ll code against a interface, but I need to convert the value before assigning it to a field. Part of the work I’m doing here involves Truffle and GraalVM where VirtualFrames can exist only on the stack, and have to be materialized before storing in the heap.
-
I’d like to only switch into this state machine code when needed. That is, if a given code path doesn’t require suspending execution then the function should return code as-is, in a perfect world this could be done by handing a box to a child function. If the box contains null, then we know a normal value was returned from the function, otherwise the box will contain the continuation.
-
I’d really like these state machines to be clone-able. I’d like to make this whole thing to mult-shot. So I should be able to get a state machine, clone it, then execute both clones without them clobbering each other (assuming the both aren’t mutating some global state or collection.
This all seems really specific, but I figured there’s some sort of Scala library that would allow me to rewrite annotated functions to do all of this. Any pointers to tools or docs would be great.
Thanks!
Timothy Baldridge