Fork me on GitHub

can anyone explain to me what a terminator is?


it's a term from LLVM


basically the last instruction in a basic block


so <! and >! and alt! are terminators


cool, thanks


because control flow is suspended there


i'm salvaging some code from core.async for a frankenstein's monster sort of thing


@sophiago have you seen the tests for core.async? They use the pluggable nature of the library to do tests on the macro without running async code. It's a good place to start if you want to hack on the macro a bit


Ooo, thanks. I'm going to take a look now. I'm working on an automatic differentiation library so need to do a lot of source transformation and so far only overrode defn to dump the ast into metadata, but then I was watching Aysylu Greenberg's talk on Loom from Conj I think three years ago and ended up rewatching (I think?) yours about analyzer and SSA in core.async. It seems it should do a lot of the work for me. Although I guess you never got to the point of writing a general SSA library since Clojure-in-Clojure never really happened?


Ha, thanks. That was not at all the directory I was looking in


The gist: 1) create a function with a signature you expect to use in the code pause in this case 2) create a terminator by adding extra parameters of state and block before the normal parameters. pause-run in this case 3) Wire it all up by copy/pasting the code you see in that test (`runner`) and replacing the terminator hash map with whatever functions you want to be replaced with termiantors


Oh, that's great. I had so far just commented out the terminator lines from parse-to-state-machine and wasn't sure what to do with the whole thing 😛


So now whenever pause is called, the code will instead call pause-run and expect you to tell it when to continue. If you need async functions you can look at these definitions to get some hints:


So essentially by playing with this test macro I can get a sense of control flow and eventually start transforming it?


yep, that's a great place to start


I see. A lot of the hard problems in this sort of stuff are considered things like dealing with complex recursion and things you've seemingly already solved.


inside the terminators state is an array of all the locals and state of the state machine. And block is a pointer to the next block to jump into once you want to continue running the machine.


I'm going to have to play with it to understand how it works I think. Mainly I'm excited that it handles unrolling local control flow into a state machine because then I should be able to do whatever I want with it, not necessarily anything asynchronous.


I did have an idea to convert local control flow to using agents in order to maximize JVM thread pools, but that was sort of a whim.


Do you have any research you can point me to that helped when writing all this? I've been looking a lot into papers on analyzing control flow. For example I have this one open right now: