rubyx/README.markdown

136 lines
3.8 KiB
Markdown
Raw Normal View History

2014-04-14 15:46:17 +02:00
Crystal
2014-04-14 14:51:44 +02:00
=======
2014-04-27 21:19:32 +02:00
Crystal is about native code generation in and of ruby. In is done.
2014-04-14 15:46:17 +02:00
Step 1 - Assembly
-----------------
2014-04-16 11:45:36 +02:00
2014-04-27 21:19:32 +02:00
Produce binary that represents code.
Traditionally called assembling, but there is no need for an external file representation.
2014-04-16 11:45:36 +02:00
Ie only in ruby code do i want to create machine code.
2014-04-27 21:19:32 +02:00
Most instructions are in fact assembling correctly. Meaning i have tests, and i can use objbump to verify the correct assembler code is disasembled
I even polished the dsl an so (from the tests), this is a valid hello world:
hello = "Hello World\n"
@program.main do
mov r7, 4 # 4 == write
mov r0 , 1 # stdout
add r1 , pc , hello # address of "hello World"
mov r2 , hello.length
swi 0 #software interupt, ie kernel syscall
mov r7, 1 # 1 == exit
swi 0
end
write(7 + hello.length/4 + 1 , 'hello')
2014-04-16 11:45:36 +02:00
Step 2 -Link to system
----------------------
2014-04-16 11:45:36 +02:00
2014-04-21 16:27:05 +02:00
Package the code into an executable. Run that and verify it's output. But full elf support (including externs) is eluding me for now.
2014-04-16 11:45:36 +02:00
2014-04-21 16:27:05 +02:00
Still, this has proven to be a good review point for the arcitecture and means no libc for now.
Full rationale on the web (pages rep for now), but it means starting an extra step
Above Hello World can be linked and run. And will say its thing.
2014-04-27 21:19:32 +02:00
Step 2.1 -syscalls
------------------
2014-04-21 16:27:05 +02:00
Start implementing some syscalls and add the functionality we actually need from c (basic io only really)
2014-04-16 11:45:36 +02:00
Step 3 -Parse ruby
------------------
Parse simple code, using Parslet.
Parsing is a surprisingly fiddly process, very space and order sensitive. But Parslet is great and simple
expressions (including function definitions and calls) are starting to work.
I Spent some time on the parse testing framework, so it is safe to fiddle and add.
Step 4 - Vm: Compile the Ast
---------------------------
Since we now have an Abstact syntax tree, it needs to be compiled to a machine Instruction format.
The machine/instruction/data definitions make up the Virtual Machine layer (vm directory)
After some trying around, something has emerged. As it uses the instructions from Step 1, we are ready to say
our hellos in ruby
2014-04-16 11:45:36 +02:00
puts("Hello World")
2014-04-16 11:45:36 +02:00
was the first to make the trip: parsed to ast, compiled to Instructions/Code, linked and assembled to binary
and executed, gives the surprising output of "Hello World"
2014-04-27 21:19:32 +02:00
Time to add some meat.
2014-04-27 21:19:32 +02:00
Step 5 - Register allocation
----------------------------
2014-04-16 11:45:36 +02:00
2014-05-27 18:19:55 +02:00
A first version of register allocation is done. I moved away from the standard c calling convention to pin a
type register and also not have passing and return overlapping.
That at least simplified thinking about register allocation. One has to remember the machine level is completely
value and pass by value based.
2014-05-27 18:19:55 +02:00
As a side i got a return statement done now, and implicit return at the end has been working. Just making sure all
branches actually return implicitly is not done. But no rush there, as one can always write the return explicitly.
Step 6 - Basic type instructions
--------------------------------
As we want to work on values, all the value methods have to be implemented to map to machine instructions.
2014-05-27 18:19:55 +02:00
Some are done, most are not. But they are straightforward.
Step 7 - Compound types
-----------------------
2014-05-27 18:19:55 +02:00
Arrays and Hash parse. Good. But this means The Actual datastructures should be implemented. AWIP ( a work in progress)
Step 8
2014-04-16 11:45:36 +02:00
------
Implement classes, implement Core library of arrays/hash
2014-05-27 18:19:55 +02:00
Step 9
2014-04-16 11:45:36 +02:00
------
Implement Blocks
Step 11
2014-04-16 11:45:36 +02:00
------
Implement Exceptions
Step 12
2014-04-16 11:45:36 +02:00
-------
2014-05-27 18:19:55 +02:00
Implement a way to call libc
Step 13
-------
2014-04-16 11:45:36 +02:00
Celebrate New year 2030
2014-04-16 11:45:36 +02:00
2014-04-14 15:46:17 +02:00
Contributing to crystal
-----------------------
2014-04-27 21:19:32 +02:00
Probably best to talk to me, if it's not a typo or so.
I do have a todo, for the adventurous.
Fork and create a branch before sending pulls.
2014-04-14 15:46:17 +02:00
== Copyright
Copyright (c) 2014 Torsten Ruger. See LICENSE.txt for
further details.