Up to Main Index Up to Journal for October, 2022
JOURNAL FOR SATURDAY 22ND OCTOBER, 2022
______________________________________________________________________________
SUBJECT: Falling down a mere rabbit hole…
DATE: Sat 22 Oct 17:27:54 BST 2022
Forgive me, for it has been nearly three weeks since my last update…
While working on Mere I found I’d coded myself into a corner. I had nearly 90%
of the core language implemented. There was but a single major issue left to
resolve. Try as I might, addressing entries in nested maps just didn’t work
properly. I came up with hacks which nearly worked, these ideas quickly died.
They didn’t fit the rest of the language. I also didn’t want to have to use
built-ins and temporary variables just to manipulate maps. I wanted to write:
M:[int] = [int](
1 [int](
2 [int] 3 3, 5 6,
),
7 8,
)
M[1][2][3]++
M[1][2][5] = "six"
println M
And have it print “1 2 3 4 5 six 7 8” dammit!
Eventually, with Mere executing programs ever slower, the situation snowballed
into a rewrite of the Mere internals. Having 90% of the core implemented and
working, the mere thought of a rewrite was very demoralising.
It isn’t a complete rewrite. The tokeniser only needed a minor addition. The
actual compiler and execution engine only required minor tweaks. However, I
had to rework the main variable heap storage and all of the runtime code for
the language’s operators and built-ins. Which I am still rewriting.
One good result is that performance has improved overall. The counter example
I use for benchmarking has improved at least:
# A mere counting example...
#
# Useful for benchmarking.
#
end:int; start:int = time
loop:int = 0
println "123456789%"
next:
if loop++ % 1000000 == 0; print "."
if loop < 10000000; goto next
println "✓"
end = time; printf "Out: %dμs\n", (end-start)/1000
Running this a couple of times produces:
>mere count
123456789%
..........✓
Out: 3038ms
>mere count
123456789%
..........✓
Out: 3057ms
>
Still can’t quite break the 3 second mark, yet! :( The last version of Mere,
before the rewrite, took four seconds to run the same program and was getting
slower. A difference of only one second may not seem like a lot, however the
performance of other examples I’ve written suffered a lot worse.
Having said that, I’ve just managed to get the bubble sort running again:
/*
A mere bubble sort…
This program generates an array of integers and
then sorts the array element values from smallest
to largest.
*/
maxN:int = 15 // numer of ints to sort
s:[]int // array to be sorted
// fill array with random ints
f:int
fill:
s = []int s rnd (maxN * 10)
if f++ < maxN; goto "fill"
println " In: " s
// some additional initialisation
l:int = len(s) - 1
end:int
start:int = time
// main bubble sort
swapped:
swap:bool = false
x:int = 0
xloop:
if s[x] <= s[x+1]; goto "next"
s[x] += s[x+1]
s[x+1] = s[x] - s[x+1]
s[x] -= s[x+1]
swap = true
next:
if x++ < l; goto "xloop"
l--
if swap; goto "swapped"
end = time
printf "Out: %v %dμs\n" s end-start
Five random runs produces:
>mere bubble
In: 9 74 20 99 110 9 43 72 79 70 69 27 31 121 54
Out: [9 9 20 27 31 43 54 69 70 72 74 79 99 110 121] 91μs
>mere bubble
In: 52 128 108 50 42 41 8 15 29 35 14 10 51 126 74
Out: [8 10 14 15 29 35 41 42 50 51 52 74 108 126 128] 103μs
>mere bubble
In: 58 31 11 99 79 98 37 83 144 22 37 100 149 132 128
Out: [11 22 31 37 37 58 79 83 98 99 100 128 132 144 149] 74μs
>mere bubble
In: 73 75 146 134 111 85 83 60 127 118 69 67 65 92 51
Out: [51 60 65 67 69 73 75 83 85 92 111 118 127 134 146] 214μs
>mere bubble
In: 27 16 68 67 123 16 143 80 4 87 113 24 125 89 78
Out: [4 16 16 24 27 67 68 78 80 87 89 113 123 125 143] 84μs
>
Previously, five runs produced: 103, 150, 166, 275 and 223. Admittedly this is
a tiny sample size, but an average of 113μs compared to 183μs isn’t bad.
The initial code snippet I showed now runs and prints “1 2 3 4 5 six 7 8” :P
I’ve still got a ways to go before Mere v0.0.5. But! I’m not giving up. I know
people want me working on WolfMUD, but I want my own programming language…
--
Diddymus
Up to Main Index Up to Journal for October, 2022