update for ruby layer

This commit is contained in:
Torsten Ruger 2018-07-25 12:10:08 +03:00
parent 07fcbc0a72
commit 4982710ac1
3 changed files with 71 additions and 44 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 109 KiB

View File

@ -24,7 +24,7 @@ Concrete Tree</panel_attributes>
</coordinates>
<panel_attributes>&lt;Ruby&gt;
--
Abstract Tree</panel_attributes>
Concrete Tree</panel_attributes>
<additional_attributes/>
</element>
<element>
@ -37,8 +37,7 @@ Abstract Tree</panel_attributes>
</coordinates>
<panel_attributes>&lt;Mom&gt;
--
Concrete Tree
+ Linked List</panel_attributes>
Linked List</panel_attributes>
<additional_attributes/>
</element>
<element>
@ -47,7 +46,7 @@ Concrete Tree
<x>60</x>
<y>250</y>
<w>120</w>
<h>50</h>
<h>60</h>
</coordinates>
<panel_attributes>&lt;Risc&gt;
--
@ -58,7 +57,7 @@ Linked List</panel_attributes>
<id>UMLClass</id>
<coordinates>
<x>60</x>
<y>300</y>
<y>310</y>
<w>120</w>
<h>50</h>
</coordinates>
@ -71,13 +70,13 @@ Linked List</panel_attributes>
<id>UMLClass</id>
<coordinates>
<x>60</x>
<y>350</y>
<y>360</y>
<w>120</w>
<h>50</h>
<h>60</h>
</coordinates>
<panel_attributes>&lt;Elf&gt;
--
Binary / Array</panel_attributes>
Parfait + Binary </panel_attributes>
<additional_attributes/>
</element>
<element>
@ -85,11 +84,11 @@ Binary / Array</panel_attributes>
<coordinates>
<x>220</x>
<y>70</y>
<w>670</w>
<w>730</w>
<h>60</h>
</coordinates>
<panel_attributes>Ruby is parsed into and abstract syntax tree. "Abstract" means all nodes are
represented by one class. Compiling to Vool happens by visitor pattern.</panel_attributes>
<panel_attributes>A Ruby layer modelled after the ast. This layer transforms ruby into the lower Vool
layer, to simplify the input.</panel_attributes>
<additional_attributes/>
</element>
<element>
@ -97,12 +96,12 @@ represented by one class. Compiling to Vool happens by visitor pattern.</panel_a
<coordinates>
<x>220</x>
<y>130</y>
<w>670</w>
<w>730</w>
<h>60</h>
</coordinates>
<panel_attributes>Vool (Virtual object oriented Language) is ruby without the fluff. Just simple oo.
Vool uses a concrete syntax tree, meaning one class per kind of statement.
Code to compile to Mom is in the statement classes.
Vool also uses a concrete syntax tree, meaning one class per kind of statement.
Vool is tranforms into Mom Instructions.
</panel_attributes>
<additional_attributes/>
</element>
@ -111,12 +110,12 @@ Code to compile to Mom is in the statement classes.
<coordinates>
<x>220</x>
<y>190</y>
<w>670</w>
<w>730</w>
<h>60</h>
</coordinates>
<panel_attributes>Mom (Minimal object machine) is a very simple object oriented machine. It only deals in objects,
incuding the calling convention. A first pass still uses a tree structure to represent control.
The final representation is a list of instructions.</panel_attributes>
<panel_attributes>Mom (Minimal object machine) is a very simple object oriented machine. This means it has Instructions
that get executed, and form a Linked List. It only deals in objects, incuding the calling convention.
It transforms into Risc in a simple 1 to n manner.</panel_attributes>
<additional_attributes/>
</element>
<element>
@ -124,19 +123,20 @@ The final representation is a list of instructions.</panel_attributes>
<coordinates>
<x>220</x>
<y>250</y>
<w>670</w>
<h>50</h>
<w>730</w>
<h>60</h>
</coordinates>
<panel_attributes>The Risc (reduced intruction set computer) layer is an (sane) subset of ARM. It models only those
instructions needed to implement Mom, about 20. It deals in memory, logic and jumps.</panel_attributes>
<panel_attributes>The Risc (reduced intruction set computer) layer is a (sane) subset of ARM. It models only those
instructions needed to implement Mom, about 20. It deals in memory, logic and jumps, and has registers.
Transformation into ARM is mostly one to one.</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>220</x>
<y>300</y>
<w>670</w>
<y>310</y>
<w>730</w>
<h>50</h>
</coordinates>
<panel_attributes>The arm chip is the most sold/used in the world, so it is our first "target". Arm has a simple
@ -147,12 +147,38 @@ instruction set and we only use the part to implement what is used in Risc.</pan
<id>UMLClass</id>
<coordinates>
<x>220</x>
<y>350</y>
<w>670</w>
<h>50</h>
<y>360</y>
<w>730</w>
<h>60</h>
</coordinates>
<panel_attributes>The lowest level, achieved by assembling arm instructions, is binary code that a cpu can execute.
Elf is used to wrap it into a file so Linux can start it. Elf includes debug info too.</panel_attributes>
The Binary is stored as Parfait objects that are then wrapped into Elf.
A simple (non-c) Elf file is created so Linux can start it.</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>60</x>
<y>10</y>
<w>120</w>
<h>60</h>
</coordinates>
<panel_attributes>&lt;Parser&gt;
--
Abstract Tree</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>220</x>
<y>10</y>
<w>730</w>
<h>60</h>
</coordinates>
<panel_attributes>Ruby is parsed into and abstract syntax tree. "Abstract" means all nodes are
represented by one class. This is implemented by the parser gem.</panel_attributes>
<additional_attributes/>
</element>
</diagram>

View File

@ -11,12 +11,12 @@
ruby. The argument is often made that
typed languages are faster, but i dont believe in that. I think dynamic languages
just push more functionality into the “virtual machine” and it is in fact only the
compiling to binaries that gives static languages their speed. This is the reason
compilation to binaries that gives static languages their speed. This is the reason
to compile ruby.
%p.center
= image_tag "layers.jpg" , alt: "Architectural layers"
%h3#ruby Ruby
%h3#ruby Ast + Ruby
%p
To compile and run ruby, we first need to parse ruby. While parsing ruby is quite
a difficult task, it has already been implemented in pure ruby
@ -27,15 +27,15 @@
%em Node
class.
Nodes have a type attribute (which you sometimes see in s-expressions) and a list of children.
%p There are two basic problems when working with ruby ast: one is the a in ast, the other is ruby.
%p
Since an abstract syntax tree only has one base class, one needs to employ the visitor
pattern to write a compiler. This ends up being one great class with lots of unrelated
functions, removing much of the benefit of OO.
The first layer in RubyX is the
%b Ruby Layer
that basically models the ast in a concrete syntax tree. This means there is one class
per node type.
%p
The second, possibly bigger problem, is ruby itself: Ruby is full of programmer happiness,
three ways to do this, five to do that. To simplify that, remove the duplication and
make analyis easier, Vool was created.
The Ruby layer is then used to transform the data into the Vool layer. Eg: Implicit
block passing is made explicit, conditions are simplified, arguments are simplified,
and syntactic sugar is removed.
%h3#virtual-object-oriented-language Virtual Object Oriented Language
%p
@ -45,8 +45,8 @@
be targeted by several real languages.
%p
The main purpose is to simplify existing oo languages down to its core components: mostly
calling, assignment, continuations and exceptions. Typed classes for each language construct
exist and make it easier to transform a statement into a lower level representations.
calling, assignment, continuations and exceptions. Typed classes for each language
construct exist and are responsible to transform a statement into Mom level below.
%p
Examples for things that exist in ruby but are broken down in Vool are
%em unless
@ -67,12 +67,13 @@
save state.
%p
Objects are typed, and are in fact the same objects the language operates on. Just the
functionality is expressed through instructions. Methods are in fact defined (as vool) on classes
and then compiled to Mom/Risc/Arm and the results stored in the method object.
functionality is expressed through instructions. While source methods are in defined on
classes as Vool, when they are compiled to binary, they are made type specific. These
TypedMethods hold the binary and are stored in the Type.
%p
The Mom level exists to make the transition to Risc easier. It has a very abstract,
high level instruction set, where each single instruction may resolve to many tens
of lower level instructions. But it breaks down Vool's tree into an instruction
high level instruction set, where each single instruction may resolve to many (even tens of)
lower level instructions. But it breaks down Vool's tree into an instruction
list, which is conceptually a much easier input for the next layer.
%h3#risc Risc
@ -83,7 +84,7 @@
The Risc machine has registers, indexed addressing, operators, branches and everything
needed to implement Mom. It does not try to abstract every possible machine feature
(like llvm), but rather “objectifies” the general risc view to provide what is needed for
the Mom layer, the next layer up.
the Mom layer, the next layer up (and actually Builtin functions).
%p
The machine has its own (abstract) instruction set, and the mapping to arm is quite
straightforward. Since the instruction set is implemented as derived classes, additional