Up to Main Index                             Up to Journal for April, 2023

                     JOURNAL FOR SUNDAY 16TH APRIL, 2023
______________________________________________________________________________

SUBJECT: Progress and future thinking
   DATE: Sun 16 Apr 16:28:52 BST 2023

A quiet Sunday afternoon and I’m still busy updating all of the Mere tests
where I have added the unsigned integer data type. That’s the thing with
adding something that impacts the whole language — it impacts all the tests as
well. However, it will mean there is a commit in the repository anyone can
look at and use as a guide to add their own types if they want…

While reworking the tests, and adding some missing ones, I’ve been thinking
about what needs to be done next. I think it will be the addition of user
functions. A close second is a change to vids.

What is a vid? A vid is an unsigned integer identifier used internally by Mere
to identify variables. Every variable has one, exceptions are array elements
and map elements that are not nested arrays or maps.

One performance pain at the moment is a type switch that is used a lot and can
account for 10% or more of a Mere program’s runtime. However, it is possible
to encode a variable’s type in its vid. Then checking the type is a quick and
simple bit test. I did try this in the earlier version of Mere. While I did
get some good results the overall performance was still poor. This time I
think it will have a more dramatic effect.

The trade off here is a reduction in the number of live variables you can have
at one time. On a 32-bit platform it would drop from 4294967295 to 134217728,
assuming 5 bits are used for the type. On a 64-bit platform it would drop from
18446744073709551616 to 576460752303423488. Hrm, it would be worth seeing what
the performance impact is of using uint64 instead of uint for vids on both of
the platforms…

A vid is also useful for another feature. If we have the vid of a variable
then we have a reference to that variable. Let’s say we use the unary operator
‘&’ to get the reference. We can then access the variable referenced with
another operator. Let’s use the unary operator ‘*’. How would that look?


     x = &y
    *x = 5


Looks like we just added pointers to Mere ;) In fact I’ve already done some
preliminary work on this, but I used an addr built-in — the unary code in Mere
needs to be cleaned up and sorted out before I starting poking it. As I knew
the type of the variable was a vid I automatically dereferenced it. My final
experiment therefore looked like:


    y = 1
    x = addr y
    x = 5
    assert y 5


I didn’t take the experiment any further, you then need to start thinking
about variable lifetimes and having multiple references to the same data. I’m
going to have to look at variable scopes and lifetimes when functions are
implemented anyway. So, that will be some of the work done.

But for now, I’m just focused on getting all the tests updated :| I think this
will be a big enough change as to warrant a new release of Mere and Mere ICE…

--
Diddymus


  Up to Main Index                             Up to Journal for April, 2023