breck7 / scrollsdk

Build on top of Scroll.
https://sdk.scroll.pub
382 stars 17 forks source link

Question: how does treenotation differ from IR? #53

Closed xmclark closed 4 years ago

xmclark commented 5 years ago

How does is this project different from a intermediate representation like JVM byte code or .net IR?

The FAQ for this project says treenotation is like a base level notation which allows for some cross-platform tooling and interoperability which are qualities of intermediate representations.

breck7 commented 5 years ago

You could define a Tree Language that compiles to JVM byte code or .net IR.

breck7 commented 5 years ago

For example, I copied and pasted some JVM bytecode and generated a basic grammar:

https://treenotation.org/designer/#grammar%0A%20inferredLanguageNode%0A%20%20root%0A%20%20inScope%20iconst_952Node%20istore_951Node%20iload_951Node%20sipushNode%20if_95icmpgeNode%20istore_952Node%20iload_952Node%20iremNode%20ifneNode%20gotoNode%20iincNode%20commentNode%20getstaticNode%20invokevirtualNode%20returnNode%0A%20anyCell%0A%20intCell%0A%20bitCell%0A%20floatCell%0A%20iconst_952Node%0A%20%20match%20iconst_2%0A%20istore_951Node%0A%20%20match%20istore_1%0A%20iload_951Node%0A%20%20match%20iload_1%0A%20sipushNode%0A%20%20cells%20intCell%0A%20if_95icmpgeNode%0A%20%20match%20if_icmpge%0A%20%20cells%20intCell%0A%20istore_952Node%0A%20%20match%20istore_2%0A%20iload_952Node%0A%20%20match%20iload_2%0A%20iremNode%0A%20ifneNode%0A%20%20cells%20intCell%0A%20gotoNode%0A%20%20cells%20intCell%0A%20iincNode%0A%20%20cells%20intCell%20bitCell%0A%20commentNode%0A%20%20cells%20anyCell%20anyCell%0A%20getstaticNode%0A%20%20cells%20floatCell%0A%20invokevirtualNode%0A%20%20cells%20floatCell%0A%20returnNode%0Asample%0A%20iconst_2%0A%20istore_1%0A%20iload_1%0A%20sipush%201000%0A%20if_icmpge%2044%0A%20iconst_2%0A%20istore_2%0A%20iload_2%0A%20iload_1%0A%20if_icmpge%2031%0A%20iload_1%0A%20iload_2%0A%20irem%0A%20ifne%2025%0A%20goto%2038%0A%20iinc%202%201%0A%20goto%2011%0A%20comment%20Field%20java%2Flang%2FSystem.out%3ALjava%2Fio%2FPrintStream%3B%0A%20getstatic%20%2384%0A%20iload_1%0A%20comment%20Method%20java%2Fio%2FPrintStream.println%3A(I)V%0A%20invokevirtual%20%2385%0A%20iinc%201%201%0A%20goto%202%0A%20return

Obviously this can be improved, but bytecodes (and assemblys and IRs) make GREAT places to use Tree Notation. You can add syntax highlighting, autocomplete, documentation, write in a Grammar, and it becomes much easier to write bytecode or assembly by hand.