2014-07-29 17:33:11 +02:00
|
|
|
#Salama
|
2014-05-30 13:49:34 +02:00
|
|
|
|
2014-04-14 14:51:44 +02:00
|
|
|
|
2014-07-29 17:33:11 +02:00
|
|
|
Salama is about native code generation in and of ruby. In is done.
|
2014-04-14 15:46:17 +02:00
|
|
|
|
2014-05-30 13:49:34 +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
|
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
I even polished the dsl and so (from the tests), this is a valid hello world:
|
2014-04-27 21:19:32 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
hello = "Hello World\n"
|
|
|
|
@program.main do
|
2014-04-27 21:19:32 +02:00
|
|
|
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
|
2014-05-30 13:49:34 +02:00
|
|
|
end
|
|
|
|
write(7 + hello.length/4 + 1 , 'hello')
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +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.
|
2014-08-22 17:00:23 +02:00
|
|
|
Full rationale on the web pages, but it means starting an extra step.
|
2014-04-21 16:27:05 +02:00
|
|
|
|
2014-05-07 14:20:25 +02:00
|
|
|
Above Hello World can be linked and run. And will say its thing.
|
2014-04-27 21:19:32 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 3 - syscalls
|
2014-04-21 16:27:05 +02:00
|
|
|
|
2014-05-07 14:20:25 +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
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 4 -Parse ruby
|
2014-05-07 14:20:25 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
I spent some time on the parse testing framework, so it is safe to fiddle and add.
|
2014-05-07 14:20:25 +02:00
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
### Step 5 - Virtual: Compile the Ast
|
2014-05-07 14:20:25 +02:00
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
Since we now have an Abstact syntax tree, it needs to be compiled to a virtual machine Instruction format.
|
2014-05-07 14:20:25 +02:00
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
It took me a while to come up with a decent but simple machine model. I had tried to map straight to hardware
|
|
|
|
but failed. The current Virtual directory represent a machine with basic oo features.
|
2014-05-07 14:20:25 +02:00
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
Instead of having more Layers to go from virtual to arm, i opted to have passes that go over the data structure
|
|
|
|
and modify it.
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-08-22 17:00:23 +02:00
|
|
|
This is where it's at really :-)
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-07 14:20:25 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 9 - Compound types
|
|
|
|
|
|
|
|
Arrays and Hash parse. Good. But this means The Actual datastructures should be implemented. AWIP ( a work in progress)
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
Implement Core library of arrays/hash/string , memory definition and access
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 10
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
Implement Blocks, stack/external frames
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 11
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
Implement Exceptions, frame walking
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 12
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-27 18:19:55 +02:00
|
|
|
Implement a way to call libc
|
|
|
|
|
2014-05-30 13:49:34 +02:00
|
|
|
### Step 13
|
|
|
|
|
|
|
|
Iterate from one:
|
|
|
|
|
|
|
|
1. more cpus (ie intel)
|
|
|
|
2. more systems (ie mac)
|
|
|
|
3. more syscalls, there are after all some hundreds
|
|
|
|
4. Ruby is full of nicities that are not done, also negative tests are non existant
|
|
|
|
5. A lot of modern cpu's functionality has to be mapped to ruby and implemented in assembler to be useful
|
|
|
|
6. Different sized machines, with different register types ?
|
|
|
|
7. on 64bit, there would be 8 bits for types and thus allow for rational, complex, and whatnot
|
|
|
|
8. Housekeeping (the superset of gc) is abundant
|
|
|
|
9. Any amount of time could be spent on a decent digital tree (see judy). Also better string/arrays would be good.
|
|
|
|
10. Inlining would be good
|
|
|
|
|
|
|
|
And generally optimize and work towards that perfect world (we never seem to be able to attain).
|
|
|
|
|
|
|
|
### Step 14
|
2014-04-16 11:45:36 +02:00
|
|
|
|
2014-05-07 14:20:25 +02:00
|
|
|
Celebrate New year 2030
|
2014-04-16 11:45:36 +02:00
|
|
|
|
|
|
|
|
2014-04-14 15:46:17 +02:00
|
|
|
|
2014-07-29 17:33:11 +02:00
|
|
|
Contributing to salama
|
2014-04-14 15:46:17 +02:00
|
|
|
-----------------------
|
|
|
|
|
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.
|
|
|
|
|