@alderwick I can't come on irc right now, but I've been toying with an idea and I'd like to have your opinion.
I was wondering if it would be a good idea to make it so the assembler merges sequences of byte literals into literal shorts. I've made a VERY POOR implementation of that in uxnasm to test, and in left there's more than a 100 bytes saved, and it makes the rom considerably faster.
I haven't been able to implement this in a way that doesn't make an absolute mess in the source yet-
@neauoire I'd love it if this optimised use of labels, so (silly example) “,&loop .Console/write” got merged into “LIT df18”. Does your patch do that already?
If it also optimised “.Console/write LIT &value 00” then that's more of a grey area. I intend that label should point to that 00 byte for writing a different value at some other time; but even then, conversion to “LIT2 18 &value 00” wouldn't break that use of code.
@neauoire I'm starting to realise how tricky this is to implement in uxnasm! I thought I was being clever with https://paste.sr.ht/~alderwick/f7fc7ebd1da320921120d11b6d99eb9df59da96f but now I realise that only affects pass 2, so all the labels after the first optimisation are wrong. 🙄
@alderwick yeah it has to be done on both pass, it makes quite a large mess.
Ideally it would handle all the literal byte runes `#`, `.` and `,`. I think I have just found a clever way to do one of the passes, but I'll keep you posted. If we can figure this one out, it would be a pretty good improvement.
@neauoire The way asma deals with the two passes is a different approach than uxnasm, it'll be good to let you know how.
The approach is to treat the two passes as similarly as possible, so instead of just counting bytes in pass 1 à la uxnasm, it “writes” them out to the ROM: the only differences are that in pass 1 the writes don't actually go to a file and if it doesn't know the value of a label, it makes up a junk value. With this approach, a hack to pushbyte() affects both passes equally…
@alderwick @neauoire Sorry to intrude but this double-pass thing in uxnasm/asma is just to account for label/sublabel references that are declared after being referenced? Or is it necessary for something else as well? I'm writing a compiler which performs only one pass but keeps a list of "future references" that are resolved in a second stage by... patching the resulting bytecode. Not elegant, but works for this single case
@alderwick Talking about sublabels... where are File/length, File/write, et. al. defined? My compiler is not getting these right :/
projects/software/asma.tal has the File labels defined in line 5, and also it includes the other asma.tal in line 43: https://git.sr.ht/~rabbits/uxn/tree/cb30ac7c1142a205e50fdd68c14138b3d56b5d9f/item/projects/software/asma.tal#L5
@sejo @alderwick Oh! I grabbed asma from here: https://git.sr.ht/~rabbits/uxn/tree/main/item/projects/library/asma.tal
Seems like I picked the wrong source file, which does not include these definitions haha thank you
@karolbelina Perhaps without the “.Console/write” in front, 😉 but “LIT @my-value 00” is one of my favourite ways of
1️⃣ saving space for a variable that's only read in one place in the code, but can be written in many places; and
2️⃣ summoning the elder gods of self-modifying code and confusion 🦑
There's very little difference between "00" and "$1". In the middle of a Uxntal file it's all down to personal taste. At the end of the file, using only | and $ don't extend the resulting ROM, allowing labels to be placed "beyond" the end of file (which is all zeroes anyway).
Of course, if I needed 0000 then $2 is quicker to type, and $3 onwards have no equivalent.
Revel in the marvels of the universe. We are a collective of forward-thinking individuals who strive to better ourselves and our surroundings through constant creation. We express ourselves through music, art, games, and writing. We also put great value in play. A warm welcome to any like-minded people who feel these ideals resonate with them.