ruby-x.github.io/_posts/2014-05-20-first-fibo.md

30 lines
1.5 KiB
Markdown
Raw Normal View History

2014-05-26 21:04:19 +02:00
---
layout: news
author: Torsten
---
2017-04-07 13:57:12 +02:00
Both "ends", parsing and machine code, were relatively clear cut. Now it is into unknown territory.
2014-05-26 21:04:19 +02:00
I had ported the Kaleidescope llvm tutorial language to ruby-llvm last year, so thee were some ideas floating.
The idea of basic blocks, as the smallest unit of code without branches was pretty clear. Using those as jump
2014-05-26 21:13:49 +02:00
targets was also straight forward. But how to get from the AST to arm Intructions was not, and took some trying out.
2014-05-26 21:04:19 +02:00
2014-05-26 21:13:49 +02:00
In the end, or rather now, it is the AST layer that "compiles" itself into the Vm layer. The Vm layer then assembles
2017-04-07 13:57:12 +02:00
itself into Instructions.
2014-05-26 21:04:19 +02:00
General instructions are part of the Vm layer, but the code picks up derived classes and thus makes machine
2017-04-07 13:57:12 +02:00
dependent code possible. So far so ok.
2014-05-26 21:04:19 +02:00
2017-04-07 13:57:12 +02:00
Register allocation was (and is) another story. Argument passing and local variables do work now, but there is definitely
2014-05-26 21:04:19 +02:00
room for improvement there.
2017-04-07 13:57:12 +02:00
To get anything out of a running program i had to implement putstring (easy) and putint (difficult). Surprisingly
2014-05-26 21:04:19 +02:00
division is not easy and when pinned to 10 (divide by 10) quite strange. Still it works. While i was at writing
2017-04-07 13:57:12 +02:00
assembler i found a fibonachi in 10 or so instructions.
2014-05-26 21:04:19 +02:00
2017-04-07 13:57:12 +02:00
To summarise, function definition and calling (including recursion) works.
If and and while structures work and also some operators and now it's easy to add more.
2014-05-26 21:04:19 +02:00
2014-07-29 17:28:11 +02:00
So we have a Fibonacchi in ruby using a while implementation that can be executed by salama and outputs the
2014-05-26 21:13:49 +02:00
correct result. After a total of 7 weeks this is much more than expected!