src/debug.lisp: New small utility function for interactive testing.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 29 Aug 2015 12:19:33 +0000 (13:19 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 29 Aug 2015 12:19:58 +0000 (13:19 +0100)
Testing at the command line is OK when things can be expected to work,
but it's annoying when they're likely to break.  This simple function
makes things pleasant to debug from inside SLIME.

src/Makefile.am
src/debug.lisp [new file with mode: 0644]
src/sod.asd

index 856d0c1..fd70ab3 100644 (file)
@@ -87,6 +87,9 @@ dist_pkglispsrc_DATA  += method-proto.lisp method-impl.lisp
 dist_pkglispsrc_DATA   += sod-frontend.asd
 dist_pkglispsrc_DATA   += frontend.lisp optparse.lisp
 
+## Interactive testing.
+dist_pkglispsrc_DATA   += debug.lisp
+
 ###--------------------------------------------------------------------------
 ### Constructing an output image.
 
diff --git a/src/debug.lisp b/src/debug.lisp
new file mode 100644 (file)
index 0000000..e281397
--- /dev/null
@@ -0,0 +1,38 @@
+;;; -*-lisp-*-
+;;;
+;;; Debugging utilities for Sod
+;;;
+;;; (c) 2015 Straylight/Edgeware
+;;;
+
+;;;----- Licensing notice ---------------------------------------------------
+;;;
+;;; This file is part of the Sensble Object Design, an object system for C.
+;;;
+;;; SOD is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; SOD is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with SOD; if not, write to the Free Software Foundation,
+;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+(cl:in-package #:sod)
+
+(export 'test-module)
+(defun test-module (path reason)
+  "Reset the translator's state, read a module from PATH and output it with
+   REASON, returning the result as a string."
+  (unless *builtin-module* (make-builtin-module))
+  (clear-the-decks)
+  (setf *module-map* (make-hash-table :test #'equal))
+  (with-output-to-string (out)
+    (output-module (read-module path) reason out)))
+
+;;;----- That's all, folks --------------------------------------------------
index a618e39..986615f 100644 (file)
          ("classes" "class-layout-proto" "class-layout-impl"
           "method-proto" "method-impl" "output-proto"))))
 
+   ;; Debugging and interactive testing.
+   (:file "debug" :depends-on ("builtin" "module-output"))))
+
 ;;;--------------------------------------------------------------------------
 ;;; Testing.