Up to Main Index Up to Journal for September, 2022 JOURNAL FOR SATURDAY 17TH SEPTEMBER, 2022 ______________________________________________________________________________ SUBJECT: Mere v0.0.4 — bug fixes and improvements DATE: Sat 17 Sep 19:25:50 BST 2022 I’ve just updated Mere & Mere ICE in the annexed works[1] to v0.0.4 for people to play with. A lot of the changes have been bug fixes and improvements to the debugging facilities. First up is a new assert built-in, so that I can write tests for Mere using Mere itself. This has already paid off, hence many of the bug fixes. If an assert failes then execution stops and an exit code of 4 is returned. Additional context has been added to state dumps and traces. The state dump has a new tokenized form of the program. Traces also include tokenized lines of code before the compiled lines. For example: >cat assert.mr trace true if !trace; goto skipDump dump skipDump: x:int = 5 x-- // Oops... trace false assert x==5, "x: want 5, have "+string x >bin/mere assert.mr trace/0 1: if ! trace trace/0 1: M M B[24:trace] O[8:not] B[11:if] trace/0 1: | trace trace/0 1: | not b[true] trace/0 1: | if b[false] trace/0 3: dump trace/0 3: M B[3:dump] trace/0 3: | dump ====================== Start State Dump ===================== pc: 3 inst: 5/- stacks: 0/0/- trace: true --itab------------------------------------------------------- skipDump(l): 1 x(i): 2 --ltab------------------------------------------------------- 1:skipDump: 4 --heap------------------------------------------------------- --call stack------------------------------------------------- 0: 3: dump --tokend----------------------------------------------------- 0: trace true 1: if ! trace 2: goto skipDump 3: dump skipDump: (1) 4: x:int = 5 5: x -- 6: trace false 7: assert x == 5 , "x: want 5, have " + string x --code------------------------------------------------------- 0: M b[true] B[24:trace] 1: M M B[24:trace] O[8:not] B[11:if] 2: M Iu[1:] B[6:goto] 3: M B[3:dump] skipDump: (1) 4: Ii[2:x] i[5] O[31:=] 5: Ii[2:x] O[10:--] 6: M b[false] B[24:trace] 7: M Ii[2:x] i[5] O[24:==] s["x: want 5, have "] Ii[2:x] O[5:string] O[15:+] O[39:,] B[1:assert] ======================== End State Dump ====================== trace/0 4: x:int = 5 trace/0 4: Ii[2:x] i[5] O[31:=] trace/0 4: | = Ii[2:x] i[5] trace/0 5: x -- trace/0 5: Ii[2:x] O[10:--] trace/0 5: | -- Ii[2:x] trace/0 6: trace false trace/0 6: M b[false] B[24:trace] trace/0 6: | trace b[false] assertion failed: x: want 5, have 4 2: goto skipDump 3: dump 4: x:int = 5 5: x -- 6: trace false 7: assert x == 5 , "x: want 5, have " + string x >echo $? 4 > I then began writing tests, starting with the int and []int data types. After a while I had 419 tests that took a reasonable time to run on the desktop. I then wondered what the performance would be, compared to the desktop, across my various Raspberry Pi: --Machine---------- ---Test Time--- --Diff-- PC @3.4Ghz 64-bit: 228μs 0.0002s Pi4 @1.8GHz 64-bit: 568μs 0.0005s +340μs Pi4 @1.5GHz 32-bit: 927μs 0.0009s +699μs Pi3 @1.2GHz 32-bit: 1899μs 0.0019s +1671μs Pi0 @1.0GHz 32-bit: 5816μs 0.0058s +2222μs Looks like I have a ways to go on optimizing Mere once it is more capable. I already have some thoughts on that :) The type, ×=, ÷=, &= and |= operators have been added. There is now proper unary minus handling. This means the following now works: a:int = 5 c:[]int = []int 7 a = -a c[0] = -c[0] b:int = -(a+c[0]) printf "a: %d, b: %d, c: %d" a b c Results in: a: -5, b: 12, c: [-7] From the Mere ICE “What’s New” section: • Fix -= using addition instead of subtraction in some instances. • Add omitted &= and |= operators. • Add missing ×= and ÷= operator aliases • Add context for state dumps, traces & asserts. • Add missing array comparisons for != operator. • New assert built-in. • Fix undefined type, later defined, corrupting other identifier references. • New type operator to return type as a string. • Implement array handling for string operator. • Fix parsing quotes when quote preceded by '\'. • Fix return type of int operator for strings. • Properly support unary negation for integer constants, variables and array elements. -- Diddymus [1] ../../../annex Up to Main Index Up to Journal for September, 2022