1. 9
  1. 3

    I love continuing to watch your work over the years :)

    Always good to see more stdlibs containing the parser for the language itself!

    1. 1

      I love this project. Since it’s original in Ruby is something I’m very familiar with.

      However, I don’t quite understand how the code gen works? Would you love to put up some comment on how you generate binary with inkoc ?

      1. 2

        The parser produces an AST, which is then converted into an intermediate representation called “Typed Intermediate Representation”, TIR for short. I know, I am not very creative when it comes to naming. This IR is very close to the VM instruction set, uses registers (just like the VM), and stores the types of input/output registers. For example, 10 + 5 would be converted to something like this:

        SetLiteral  0, 10        # 0 is the target register
        SetLiteral  1, 5         # 1 is the target register
        SendMessage 2, 0, "+", 1 # this translates to 10.+(5)

        Of course the actual implementation is a bit different from this simple example. For example, literals (integers, floats, etc) are stored separately and the SetLiteral instruction refers to them by their index in the storage list.

        Once we have the list of instructions for a block of code, we convert this IR into a flat list of “Instruction” objects. These objects just use integers to represent the various arguments, instruction types, etc. So from the above, we’d go to something like this (using Ruby here):

        literals = [10, 5, "+"]
        Instruction.new(type: 0, arguments: [0, 0])       # SetLiteral 0, 10
        Instruction.new(type: 0, arguments: [1, 1])       # SetLiteral 1, 5
        Instruction.new(type: 1, arguments: [2, 0, 2, 1]) # SendMessage 2, 0, "+", 1

        This is done here.

        Once we have this list, we convert it to a binary format. This is done here.

        You can find some more information about the bytecode and instruction set here:

      2. 1

        @yorickpeterse The Inko code base is is a mix of Ruby, Rust, and Inko. What’s the plan here? Do you eventually plan to have it all in Inko? Or are you only planning on replacing just the Ruby portions in Inko?

        1. 2

          The VM will stay in Rust. The compiler will be ported over to Inko, removing the need for Ruby.