Skip to content

Interim report of the Grant Program 2020 of Ruby Association

HASUMI Hitoshi edited this page Jan 15, 2021 · 1 revision

Summary

I have implemented mini mruby compiler in order to cover major syntax of Ruby for microcontroller.

I submit this document as the interim report of the Grant Program 2020 of Ruby Association.

It consists of three parts:

  • The first part is explaining my outcome as of today
  • The second is a summary of difference between mruby2 and mruby3 in terms of syntax and VM code
  • The third is a TODO list which I should implement by the deadline of the final report

Submit date

January 15th, 2021

Implementations so far

This link shows the progress of the period: https://github.com/hasumikin/mmruby/compare/9c776f4...9670063

OP codes relating to conditional jump

  • if (unless) elsif then end
  • if modifier, unless modifier
  • while/until, break, next, redo
  • case when then end
  • and, or, ||, &&

OP codes relating to block (IREP) and conditional block (like while)

  • OP_BLOCK
  • OP_ENTER (setups only mandatory parameters)
  • Generating nested IREP records
  • Keywords which control block things like next break redo

Investigation of differences between mruby2 and mruby3

NEW OP codes

  • OP_LOADI16
  • OP_LOADI32
  • OP_LOADL16
  • OP_LOADSYM16

OP codes whose spec is amended

  • OP_SETUPVAR
  • OP_GETUPVAR
  • Relative value of operand for JMP (used to be absolute value)

IREP record structure

  • Abolishment of ISEQ’s 4-byte-alignment
  • 2 bytes for representing number of literal/symbol (used to be 4 bytes)
  • Literal kinds:
  • 0x00 for string literal
  • 0x01 abolished (used to be for string-formed integer)
  • 0x02 abolished (used to be for string-formed float)
  • 0x03 for integer which is more than 0x7FFFFFFF or less than -0x80000000
  • 0x04 ??? (to be studied)
  • 0x05 for float whose width is 8 bytes

TODO from now

  • Parsing and generating lambda, yield, class, def, alias, rescue, ensure
  • Improvement generating block parameters to generate def sentence
  • Correspondence to mruby3
  • Reducing RAM consumption