151 karma · joined April 29, 2017
https://github.com/true-grue/python-dsls/blob/main/datalog/d...
https://www.researchgate.net/profile/Peter-Sovietov/publicat...
Still, the idea of Fortik is to encourage students to learn how simple interpreters work and to extend the language.
[1] https://en.wikipedia.org/wiki/Asynchronous_array_of_simple_p...
Again, thank you very much for all your education reverse engineering works!
https://github.com/true-grue/terrain
Looks like Python+Tkinter is a good demoscene platform where you have performance of graphics close to 286/EGA :)
And here is a toy term rewriting system [2].
[1] https://github.com/true-grue/raddsl
[2] https://github.com/true-grue/code-snippets/blob/master/ttrs....
It would be interesting to see how this rule ("x = (y + c1) + c2 => x = y + (с1 + с2)") was encoded in the compiler. I guess it has more complicated form than a (simple and declarative) term rewriting rule, which you may use on AST transform stage.
There is a quote from Muchnik's textbook: "Like constant folding, algebraic simplifications and reassociation are best structured in a compiler as a subroutine that can be called from any other phase that can make use of it".
But it seems that in some cases, on the later phases with lower IRs, you just can't use this "subroutine" as is.
As a side note. It would be interesting to investigate power of a Prolog-like language which has terms, term variables, pattern matching (maybe even without full unification) and only local backtracking. Plus an ability to make user-defined execution strategies (tree traversals etc) in the form of combinators. I already use most of these constucts in dsl_match module and I got my inspiration mostly from Stratego/XT. Still it would be good to see similiar general-purpose language and compare its expressiveness with Prolog.
1. BNF notation. Yes, it could be surprising, but in a BNF-like language we use function-level representation and white spaces here denote sequential composition of functions -- nonterminals.
2. In a some Lisp-like language one may use spaces to describe "abstract" composition. So, for sequential composition: "(seq func1 func2 func3)". And for parallel composition, for example: "(par func1 func2 func3)".
But in the case of real concatenative programming, which has its origin in Forth, you mostly deal with stacks and stack machines.
Still, the whole "concatenative" movement is interesting as a try to formalize the semantics and "improve" Forth language. See also Postscript and Henry Backer's articles [3].
Thanks for showing your code! I just placed my minimalist DSL tools and decided to use "Halt Problem" as an example. Here is my code: https://github.com/true-grue/dsl-tools
There is a good reason for using Prolog-like language in a compiler-related project. Prolog was used for rapid prototyping of compilers since the end of 70s and it's still ahead of the time. And if you take a look at a code from old Warren article [1], for example, you'll see that even today almost nobody uses so high-level description of a compiler. The main power of Prolog is not in parsing. Prolog is unbeatable in a program analysis and transformations. See Datalog (you may find it even in a Dragon book nowadays!), see Stratego/XT, they all inspired by good old Prolog.
By the way, Prolog is also good in describing formal semantics of PLs. Good PL reference or a standard should include clean formal notation for semanics of the language, not some bureaucratic English text... Because it's already 2018, we need it for compiler developers and for deeper understanding of a language.
[1] http://sovietov.com/tmp/warren1980.pdf (this is excellent article, but, sadly, almost unknown one)
"Comment by Vladimir N. Makarov: Another good book to start to study compilers from parser to code generation and basic optimizations. I especially like the version in ML (Modern compiler implementation in ML).
Comment by Steven Bosscher: The version in ML is the best of the three. The other two look too much like "had to do this"-books where algorithms are translated from ML, which makes them look very unnatural in C/Java." [1]
P.S. Thanks for the real perfomance data!
Ok, better for what? Let's take a practical example: AST transformations inside a compiler. You may find Visitor pattern use only in a few Java-related compiler textbooks. For some reason almost every good compiler/compiler textbook uses pattern matching: Appel, nanopass, CompCert, DMS etc.
Ok, but the real point of the article is not that "visitors" are more readable and easy to use, but they are more perfomant, right? Do we have any profiling here? Maybe with a good GC it will cost almost nothing for us to build another tree in terms of speed? We remember the words about "premature optimization", and any "manual optimization" which makes the algorithm structure foggy is evil so (necessary evil -- in some rare cases). In some declarative languages pattern matching constructs are converted to a fast decision trees by compiler. There are some "lazy" approaches to pattern matching.
Or you can just provide a list of transforming (maybe some composition of transformations) functions to your generic pattern matching function. It's almost the same as using "visitors", but you don't need to call "The Team Architect™, for supervising the object oriented quality of your software" :)
Sorry, if I reveal this link too early, but this is very impressive work of you and StarFlight game/engine really deserves more popularity!