[Oberon] New Oberon to Lua Transpiler

Luca Boasso luke.boasso at gmail.com
Mon Oct 14 02:01:12 CEST 2019


@Rochus

To emulate variable parameters in the JVM, I am using a lighter approach
than your thunk based method.
Given the following example:

MODULE VarParam;
  IMPORT Out;
  VAR
    i: INTEGER;

  PROCEDURE P(VAR i: INTEGER);
  BEGIN
    i := 10
  END P;

BEGIN
  P(i);
  Out.Int(i, 3); Out.Ln (* It prints 10 *)
END VarParam.

oberonc will emit the bytecode of an equivalent Java class as follows:

public final class VarParam {
  public static int i;

  public static final void P(int[] var0) {
    var0[0] = 10;
  }

  static {
    int[] var0 = new int[]{i};
    P(var0);
    i = var0[0];
    Out.Int(i, 3);
    Out.Ln();
  }
}

As you can see, I wrap a var parameter in a one element array before the
call, and unwrap it after the call. It is possible to generate the code
above in one pass. Maybe you could see if a similar approach is faster in
LuaJit.

I did not manage to compile your project nor, OBNC, so I cannot compare the
performance of Hennessy.Mod.
Using oberonc, on my machine I get:
Perm       16
Towers        5
Queens        6
Intmm       12
Mm       10
Quick       13
Bubble       19
Tree       17
FFT       30
Nonfloating point composite is 166.500000
Floating point composite is 328.899994

If I measure the total execution time, I get about 122 milliseconds.
I have found some corner case bugs in my compiler while trying out OBNC
tests. I will fix them soon.

Cheers,
Luca


On Sat, Oct 12, 2019 at 6:26 AM rochus.keller at bluewin.ch <
rochus.keller at bluewin.ch> wrote:

> @ Luca Boasso:
>
> Meanwhile I found some time to further analyze the generated IR and
> machine code using the -jdump option of LuaJIT.
>
> If you have this Lua code "increment(function(set,val) if set then x =
> val else return x end end)" as in LuaDemo2 of my article then LuaJIT indeed
> finds the following trace into increment() and the thunk but then aborts
> because it cannot handle traces including the FNEW opcode as it seems:
>
> ---- TRACE 2 start 1/0 VarDemo1.lua:10
> 0001  ISF          0
> 0002  JMP      2 => 0005
> 0005  UGET     2   0      ; x
> 0006  RET1     2   2
> 0005  ADDVN    3   3   0  ; 1
> 0006  CALL     1   1   3
> 0000  . JFUNCF   3   1         ; VarDemo1.lua:10
> 0001  . ISF          0
> 0002  . JMP      2 => 0005
> 0003  . USETV    0   1      ; x
> 0004  . JMP      2 => 0007
> 0007  . RET0     0   1
> 0007  RET0     0   1
> 0014  FORL     3 => 0011
> 0011  MOV      7   1
> 0012  FNEW     8   3      ; VarDemo1.lua:10
> ---- TRACE 2 abort VarDemo1.lua:10 -- NYI: bytecode 49 ; FNEW
>
> If I don't define the thunk inline but use a local variable for the thunk
> instead, full inlining works and the runtime is as fast as corresponding C
> code.
>
> I therefore need to redesign my Lua code generator to no longer inline the
> thunk definitions and to even take the thunk declarations out of loops. To
> do that I likely need a separate optimization pass to rewrite the AST which
> is not feasible with my current, syntax directed approach. I will come back
> with results.
>
> Best
> R.
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20191013/4ab46330/attachment.html>


More information about the Oberon mailing list