From fb056029e86b0c21d362d623a851a7c89c12ff8b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 12 Mar 2018 23:57:32 -0700 Subject: asm: allow compound syntax reg operands. In additon to the encoded notation like t13 and v013f, we allow forms like (t 19) and (v 1 63) which mean the same thing. These are a much more convenient representation for a compiler. * share/txr/stdlib/asm.tl (assembler parse-operand): Recognize a compound expression as an operand, and handle via parse-compound-operand function. (parse-compound-operand): New function. --- share/txr/stdlib/asm.tl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/share/txr/stdlib/asm.tl b/share/txr/stdlib/asm.tl index be83a0e3..911f65de 100644 --- a/share/txr/stdlib/asm.tl +++ b/share/txr/stdlib/asm.tl @@ -123,6 +123,8 @@ ((r rs d ds) (cond ((null arg) 0) + ((consp arg) + (parse-compound-operand arg)) ((symbolp arg) (parse-operand (symbol-name arg))))) (t (error "assembler: invalid arg type spec"))))) @@ -201,6 +203,19 @@ (and (symbolp obj) (not (symbol-package obj))))) +(defun parse-compound-operand (cons) + (tree-case cons + ((sym arg) + (when (<= 0 arg 255) + (caseq sym + ((t) arg) + (d (+ arg 256))))) + ((sym arg1 arg2) + (when (and (<= 0 arg1 253) + (<= 0 arg2 255)) + (caseq sym + (v (+ (* arg1 256) arg2))))))) + (defun parse-operand (str) (cond ((r^$ #/t[0-9A-Fa-f][0-9A-Fa-f]?/ str) -- cgit v1.2.3