From 4c0019ef1bf58ccb782e52bc3db5032e3df45e77 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Mon, 12 Mar 2018 23:54:42 -0700
Subject: asm: support gensym labels.

Remove restriction that labels are keywords; a compiler
cannot pollute the keyword space to generate labels.
We allow them to be uninterned symbols also.

* share/txr/stdlib/asm.tl (assembler parse-args, assembler
asm-one): Use is-label instead of keywordp.
(is-label): New function.
(op-label): Use is-label test.
---
 share/txr/stdlib/asm.tl | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/share/txr/stdlib/asm.tl b/share/txr/stdlib/asm.tl
index 4871dd4f..be83a0e3 100644
--- a/share/txr/stdlib/asm.tl
+++ b/share/txr/stdlib/asm.tl
@@ -116,7 +116,7 @@
                              (when me.(immediate-fits-type arg type)
                                arg))
                             (l (cond
-                                 ((keywordp arg) me.(lookup-label arg oc))
+                                 ((is-label arg) me.(lookup-label arg oc))
                                  ((integerp arg) arg)))
                             (n (if (integerp arg) arg))
                             (o arg)
@@ -142,7 +142,7 @@
 
   (:method asm-one (me syntax)
     (let ((oc (cond
-                ((keywordp syntax) [%oc-hash% 'label])
+                ((is-label syntax) [%oc-hash% 'label])
                 ((consp syntax) [%oc-hash% (car syntax)]))))
       (unless oc
         (error "assembler: invalid instruction ~s" syntax))
@@ -196,6 +196,11 @@
   (set [%oc-hash% oc.symbol] oc)
   (set [%oc-hash% oc.code] oc))
 
+(defun is-label (obj)
+  (or (keywordp obj)
+      (and (symbolp obj)
+           (not (symbol-package obj)))))
+
 (defun parse-operand (str)
   (cond
     ((r^$ #/t[0-9A-Fa-f][0-9A-Fa-f]?/ str)
@@ -242,8 +247,8 @@
 
 (defopcode op-label label nil
   (:method asm (me asm syntax)
-    (unless (keywordp syntax)
-      asm.(synerr "label must be keyword"))
+    (unless (is-label syntax)
+      asm.(synerr "label must be keyword or gensym"))
     asm.(define-label syntax))
 
   (:method dis (me asm extension operand)))
-- 
cgit v1.2.3