Up to Main Index                           Up to Journal for January, 2023

                    JOURNAL FOR SUNDAY 22ND JANUARY, 2023

SUBJECT: Another belated status update

Another long pause since I last wrote anything here. I seem to be spending all
my waking hours working as of late…

Over the holiday period I took the opportunity to catch up on some conferences
and talks on YouTube: Donald Knuth’s Christmas lecture, some NDC talks (Dylan
Beattie’s Plain Text one is very good), some GopherFest and dotGo talks.

In doing so I started to conceive the germ of an idea. I scraped together my
ideas and wrote a little code. Hrm, the results looked quite promising. In an
afternoon I managed to write, from scratch, the guts of a new implementation
of my programming language Mere. Within a few days I had something that worked
really well and was quite performant.

This was all rather annoying! I’d just spent months on v0.0.5 of Mere and was
getting nowhere fast. I could now throw all of that work away for this young
upstart :P

Using my previous counter.mr example the new Mere is more than twice as fast.
The code is much simpler and there is a lot less of it. Even better, the code
is much easier to dip in and out of as and when I get time.

Some early performance results using Go 1.19.5:

                            OLD     NEW     DIFFERENCE
                            ------  ------  ---------------
                   Desktop: 3524ms  1494ms  -2030ms (+135%)
                  RPi4 8Gb: 7777ms  3882ms  -3895ms (+100%)

The Raspberry Pi 4 was running 64-bit RaspberryOS for the tests.

Currently I have working all of the variable storage, indexing arrays and maps,
assignment to variables and assignment to array and map elements. This was the
first thing I tackled as it’s proven to be the most problematic to get right.

Implemented and working so far:

      Operators: (, [, ]=, +, -, *, /, ++, --, %, <, == and unary minus.

          Types: int, []int, [int], float []float, [float],
                 string, []string, [string], bool, []bool, [bool]

      Built-ins: dump, exit, if, gosub, goto, print, printf, println,
                 return, sprint, sprintf, sprintln, time, trace

       Comments: “#” and “//” line comments, “/* */” block comments

  Miscellaneous: labels, continuation lines, variadic functions

The tokenizer and interpreter are new implementations. The interpreter still
uses a modified shunting yard algorithm to turn tokens into RPN. The biggest
change is the implementation of the operators and built-ins. The executor is
now based on a kind of shift reduce parser over the RPN, but not quite…

The temptation to add all of the other operators and built-ins has been huge.
I just want to see my programming language working, damn it! However, I have
resisted doing that until I have tests written for everything implemented so
far. As an example, here are the tests for the negation / unary minus operator

    // Testing for unary minus / negation "neg" operator.

    // literal ints
    assert -(-1),  1
    assert  -(0),  0
    assert  -(1), -1

    // literal floats
    assert -(-1.1),  1.1
    assert -(-0.0),  0.0
    assert  -(1.1), -1.1

    // variable ints
    in = -1
    iz =  0
    ip =  1

    assert -in,  1
    assert -iz,  0
    assert -ip, -1

    // variable floats
    fn = -1.1
    fz =  0.0
    fp =  1.1

    assert -fn,  1.1
    assert -fz,  0.0
    assert -fp, -1.1

    // int array
    ia = []int(-1, 0, 1); assert ia []int(-1, 0, 1)
    assert -ia[0],  1
    assert -ia[1],  0
    assert -ia[2], -1

    // int map
    im = [int](1, -1, 2, -1.1)
    assert -im[1], 1
    assert -im[2], 1.1

    // int int map
    iim = [int] 1 [int] 2 3
    assert -iim[1][2], -3

    // check for decrement confusion
    x = 2
    ia = []int 1 2 3
    y = x - -1  ; assert y 3
    y = x - -x  ; assert y 4
    y = x--     ; assert y 1
    x = 2
    y = ia[x--] ; assert y 2
    y = -(1+1) - -(1+1); assert y 0
    x = 5
    y = (x--) -1 ; assert y 3
                   assert x 4
    x = 5
    y = (x--) - -1 ; assert y 5
                     assert x 4

Of course, once the holiday period was over I was drowning in work again :(

Whenever I get a few minutes I write a few more tests, fix a few more bugs.
Hopefully it won’t take another month of Sundays before I can release an
updated Mere ICE. I might even be able to publish Mere’s code without being
too embarrassed by it…


  Up to Main Index                           Up to Journal for January, 2023