Python fluent.runtime - plans

Thanks for the response, getting to an ‘exec-free’ compiler was what I had in mind.

I actually thought I should make that more tangible, so I mocked something up last night, and given it just a little bit of polish this morning.

I’ve put that code up on https://gist.github.com/Pike/1faef13e891a73c9835bf4b895c59987.

The starting point is a runtime tree, which can be instantiated either for a resource or just an entry. Most of the AST constructs in the parser have a matching runtime AST, I just dropped some abstract base classes, I think.

The __call__ methods on those would effectively be what your code generator would create, to a significant part. Only the literals and pattern are interesting. I see that my NumberLiteral is a good deal away from your implementation stil.

The Compiler class is just the visitor that transforms parser->runtime, plus an optimizer. I’ve demoed taking string literals out of placeables, and concating string literals in patterns, and fast-forwarding simple text instead of pattern expression.

Obviously, that code isn’t even trying to be complete :wink:

Ideas based on that concept that go around in my head:

  • create a class IsolatingVarRef(VariableReference) when isolation is wanted
  • keep parsed and runnable members on bundle, and only compile messages on demand
  • loop detection could be done at compile time, depending on whether we’d want loop detection to kick in on any possible loop, or just when actually triggering a loop

I did also spend more time looking at your compiler branch, and just want to emphasize that I realize how much energy you’ve put into that.