about summary refs log tree commit diff stats
path: root/100array-equal.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-03-21 15:32:30 -0700
committerKartik Agaram <vc@akkartik.com>2020-03-21 16:51:52 -0700
commitdf609237c1f583544b814454efb4790a67f7fd68 (patch)
treea5302018c77b775477501f71412b475763a87979 /100array-equal.subx
parentc6886c1c97dd636750778b1cfec437056906cd38 (diff)
downloadmu-df609237c1f583544b814454efb4790a67f7fd68.tar.gz
6158 - standardize opcode names
At the lowest level, SubX without syntax sugar uses names without prepositions.
For example, 01 and 03 are both called 'add', irrespective of source and
destination operand. Horizontal space is at a premium, and we rely on the
comments at the end of each line to fully describe what is happening.

Above that, however, we standardize on a slightly different naming convention
across:
  a) SubX with syntax sugar,
  b) Mu, and
  c) the SubX code that the Mu compiler emits.

Conventions, in brief:
  - by default, the source is on the left and destination on the right.
    e.g. add %eax, 1/r32/ecx ("add eax to ecx")
  - prepositions reverse the direction.
    e.g. add-to %eax, 1/r32/ecx ("add ecx to eax")
         subtract-from %eax, 1/r32/ecx ("subtract ecx from eax")
  - by default, comparisons are left to right while 'compare<-' reverses.

Before, I was sometimes swapping args to make the operation more obvious,
but that would complicate the code-generation of the Mu compiler, and it's
nice to be able to read the output of the compiler just like hand-written
code.

One place where SubX differs from Mu: copy opcodes are called '<-' and
'->'. Hopefully that fits with the spirit of Mu rather than the letter
of the 'copy' and 'copy-to' instructions.
Diffstat (limited to '100array-equal.subx')
-rw-r--r--100array-equal.subx8
1 files changed, 4 insertions, 4 deletions
diff --git a/100array-equal.subx b/100array-equal.subx
index c6e03bf2..ca222619 100644
--- a/100array-equal.subx
+++ b/100array-equal.subx
@@ -48,7 +48,7 @@ $array-equal?:lengths:
     # var currb/edi: (addr byte) = b->data
     81 0/subop/add %edi 4/imm32
     # var i/ecx: int = 0
-    31/xor %ecx 1/r32/ecx
+    31/xor-with %ecx 1/r32/ecx
     # var vala/eax: int
     # var valb/ebx: int
 $array-equal?:loop:
@@ -213,9 +213,9 @@ parse-array-of-ints:  # ad: (addr allocation-descriptor), s: (addr string) -> re
     # . edx = s->length
     8b/-> *esi 2/r32/edx
     # . edx += curr
-    01/add %edx 1/r32/ecx
+    01/add-to %edx 1/r32/ecx
     # var size/ebx: int = 0
-    31/xor %ebx 3/r32/ebx
+    31/xor-with %ebx 3/r32/ebx
 $parse-array-of-ints:loop1:
     # if (curr >= end) break
     39/compare %ecx 2/r32/edx
@@ -235,7 +235,7 @@ $parse-array-of-ints:loop1:
 $parse-array-of-ints:break1:
     # var result/edi: (handle array int)
     89/<- %eax 3/r32/ebx
-    05/add-eax 4/imm32
+    05/add-to-eax 4/imm32
     (allocate *(ebp+8) %eax)
     89/<- %edi 0/r32/eax
     # result->size = size