From 2828f6f3ec9fa76e7bb38f03d8dbd54c40369898 Mon Sep 17 00:00:00 2001
From: Noah Lavine <noah.b.lavine@gmail.com>
Date: Sat, 20 Apr 2013 19:04:32 -0400
Subject: [PATCH 3/3] Better Exception in RTL VM

 * libguile/vm-engine.c: in box-set!, throw an exception instead of
   aborting if the register does not contain a variable.
 * test-suite/tests/rtl.test: test this behavior.
---
 libguile/vm-engine.c      |    3 ++-
 test-suite/tests/rtl.test |    9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index f5f1617..fa8c8fc 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -1889,7 +1889,8 @@ RTL_VM_NAME (SCM vm, SCM program, SCM *argv, size_t nargs_)
       SCM var;
       SCM_UNPACK_RTL_12_12 (op, dst, src);
       var = LOCAL_REF (dst);
-      VM_ASSERT (SCM_VARIABLEP (var), abort ());
+      VM_ASSERT (SCM_VARIABLEP (var),
+		 vm_error_not_a_variable ("box-ref (VM instruction)", var));
       VARIABLE_SET (var, LOCAL_REF (src));
       NEXT (1);
     }
diff --git a/test-suite/tests/rtl.test b/test-suite/tests/rtl.test
index 633425c..e97a801 100644
--- a/test-suite/tests/rtl.test
+++ b/test-suite/tests/rtl.test
@@ -256,3 +256,12 @@
         (box-ref 0 1)
         (return 0)
         (end-program))))))
+
+(with-test-prefix "box-set!"
+  (pass-if-exception "bad variable" exception:not-a-variable
+    ((assemble-program
+      '((begin-program foo)
+        (assert-nargs-ee/locals 0 2)
+        (box-ref 0 1)
+        (return 0)
+        (end-program))))))
-- 
1.7.10.4

