Browse Source

Tidied up calculator selection code.

Paul Onions 10 years ago
parent
commit
17c2207ceb
4 changed files with 86 additions and 53 deletions
  1. 2 2
      examples/timedone.s
  2. 14 14
      rpl-edb.el
  3. 9 0
      rpl-tools.el
  4. 61 37
      sysrpl-mode.el

+ 2 - 2
examples/timedone.s

@@ -1,4 +1,4 @@
-* -*- mode:sysrpl -*-
+* -*- mode: sysrpl -*-
 *
 * TIMEDONE example from page 41 of the book
 *
@@ -16,6 +16,6 @@
       " at "
       TOD TOD>t$ &$
     ;
-  "."
+    "."
   &$
 ;

+ 14 - 14
rpl-edb.el

@@ -262,10 +262,10 @@ calculator model, e.g. :48G, :49G etc."
 (defvar rpl-edb-data-39g nil
   "SysRPL data for the 39G calculator.")
 
-(defvar rpl-sysrpl-data-48g nil
+(defvar rpl-edb-data-48g nil
   "SysRPL data for the 48G calculator.")
 
-(defvar rpl-sysrpl-data-49g nil
+(defvar rpl-edb-data-49g nil
   "SysRPL data for the 49G calculator.")
 
 (defun rpl-edb-data (calculator)
@@ -274,25 +274,25 @@ Returns a hash table, keyed by SysRPL word name, whose values each
 have the form (STACK-EFFECT DESCRIPTION ADDRESS &rest FLAGS)."
   (cl-assert (keywordp calculator))
   (cond ((eql calculator :38G)
-         (unless rpl-sysrpl-data-38g
-           (setq rpl-sysrpl-data-38g
+         (unless rpl-edb-data-38g
+           (setq rpl-edb-data-38g
                  (rpl-read-data-file (rpl-edb-make-data-filename :38G))))
-         rpl-sysrpl-data-38g)
+         rpl-edb-data-38g)
         ((eql calculator :39G)
-         (unless rpl-sysrpl-data-39g
-           (setq rpl-sysrpl-data-39g
+         (unless rpl-edb-data-39g
+           (setq rpl-edb-data-39g
                  (rpl-read-data-file (rpl-edb-make-data-filename :39G))))
-         rpl-sysrpl-data-39g)
+         rpl-edb-data-39g)
         ((eql calculator :48G)
-         (unless rpl-sysrpl-data-48g
-           (setq rpl-sysrpl-data-48g
+         (unless rpl-edb-data-48g
+           (setq rpl-edb-data-48g
                  (rpl-read-data-file (rpl-edb-make-data-filename :48G))))
-         rpl-sysrpl-data-48g)
+         rpl-edb-data-48g)
         ((eql calculator :49G)
-         (unless rpl-sysrpl-data-49g
-           (setq rpl-sysrpl-data-49g
+         (unless rpl-edb-data-49g
+           (setq rpl-edb-data-49g
                  (rpl-read-data-file (rpl-edb-make-data-filename :49G))))
-         rpl-sysrpl-data-49g)))
+         rpl-edb-data-49g)))
 
 (defun rpl-edb-all-names (calculator)
   (cl-assert (keywordp calculator))

+ 9 - 0
rpl-tools.el

@@ -18,6 +18,15 @@
 ;;   (require 'rpl-tools)
 ;;
 ;; into your .emacs file.
+;;
+;; This will provide a major mode called `sysrpl-mode' to be used when
+;; editing System RPL program files.  This mode will highlight valid
+;; System RPL command names and also display information about them
+;; via the `sysrpl-apropos-thing-at-point' command.  It is also
+;; `eldoc' capable, so when `eldoc-mode' is enabled a stack effect
+;; string for the SysRPL word at point is displayed in the minibuffer.
+;;
+;; See also the ``RPL'' menu added to all `sysrpl-mode' buffers.
 
 ;;; Code:
 

+ 61 - 37
sysrpl-mode.el

@@ -23,9 +23,9 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Customizations
 ;;
-(defcustom rpl-sysrpl-default-calculator :48G
+(defcustom rpl-sysrpl-default-calculator :HP50G
   "Default calculator type for SysRPL mode."
-  :type '(radio :38G :39G :48G :49G)
+  :type '(radio :HP38G :HP39G :HP48G :HP49G :HP50G)
   :group 'rpl)
 
 (defface sysrpl-name '((t :foreground "darkblue"))
@@ -55,6 +55,14 @@
   :type 'symbol
   :group 'rpl)
 
+(defun sysrpl-edb-calculator (calculator)
+  "Map SysRPL calculator identifier to EDB identifier."
+  (cond ((eql calculator :HP38G) :38G)
+        ((eql calculator :HP39G) :39G)
+        ((eql calculator :HP48G) :48G)
+        ((eql calculator :HP49G) :49G)
+        ((eql calculator :HP50G) :49G)))
+
 (defvar sysrpl-mode-syntax-table
   (let ((table (make-syntax-table prog-mode-syntax-table)))
     (modify-syntax-entry ?:  "w" table)
@@ -89,60 +97,73 @@
                   names)))
 
 (defvar sysrpl-font-lock-keywords
-  (sysrpl-font-lock-compile-keywords (rpl-edb-all-names rpl-sysrpl-default-calculator)))
+  (sysrpl-font-lock-compile-keywords (rpl-edb-all-names (sysrpl-edb-calculator rpl-sysrpl-default-calculator))))
 
 (defvar sysrpl-selected-calculator rpl-sysrpl-default-calculator
   "Currently selected calculator model.")
 
-(defun sysrpl-select-38g ()
-  "Set the currently selected calculator model to be the 38G."
+(defun sysrpl-select-hp38g ()
+  "Set the currently selected calculator model to be the HP38G."
+  (interactive)
+  (setq sysrpl-selected-calculator :HP38G)
+  (setq sysrpl-font-lock-keywords
+        (sysrpl-font-lock-compile-keywords (rpl-edb-all-names (sysrpl-edb-calculator :HP38G))))
+  (sysrpl-mode))
+
+(defun sysrpl-select-hp39g ()
+  "Set the currently selected calculator model to be the HP39G."
   (interactive)
-  (setq sysrpl-selected-calculator :38G)
-  (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :38G)))
+  (setq sysrpl-selected-calculator :HP39G)
+  (setq sysrpl-font-lock-keywords
+        (sysrpl-font-lock-compile-keywords (rpl-edb-all-names (sysrpl-edb-calculator :HP39G))))
   (sysrpl-mode))
 
-(defun sysrpl-select-39g ()
-  "Set the currently selected calculator model to be the 39G."
+(defun sysrpl-select-hp48g ()
+  "Set the currently selected calculator model to be the HP48G."
   (interactive)
-  (setq sysrpl-selected-calculator :39G)
-  (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :39G)))
+  (setq sysrpl-selected-calculator :HP48G)
+  (setq sysrpl-font-lock-keywords
+        (sysrpl-font-lock-compile-keywords (rpl-edb-all-names (sysrpl-edb-calculator :HP48G))))
   (sysrpl-mode))
 
-(defun sysrpl-select-48g ()
-  "Set the currently selected calculator model to be the 48G."
+(defun sysrpl-select-hp49g ()
+  "Set the currently selected calculator model to be the HP49G."
   (interactive)
-  (setq sysrpl-selected-calculator :48G)
-  (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :48G)))
+  (setq sysrpl-selected-calculator :HP49G)
+  (setq sysrpl-font-lock-keywords
+        (sysrpl-font-lock-compile-keywords (rpl-edb-all-names (sysrpl-edb-calculator :HP49G))))
   (sysrpl-mode))
 
-(defun sysrpl-select-49g ()
-  "Set the currently selected calculator model to be the 49G."
+(defun sysrpl-select-hp50g ()
+  "Set the currently selected calculator model to be the HP50G."
   (interactive)
-  (setq sysrpl-selected-calculator :49G)
-  (setq sysrpl-font-lock-keywords (sysrpl-font-lock-compile-keywords (rpl-edb-all-names :49G)))
+  (setq sysrpl-selected-calculator :HP50G)
+  (setq sysrpl-font-lock-keywords
+        (sysrpl-font-lock-compile-keywords (rpl-edb-all-names (sysrpl-edb-calculator :HP50G))))
   (sysrpl-mode))
 
 (defun sysrpl-get-eldoc-message ()
   (interactive)
-  (rpl-edb-get-stack-effect sysrpl-selected-calculator (thing-at-point 'word)))
+  (rpl-edb-get-stack-effect (sysrpl-edb-calculator sysrpl-selected-calculator)
+                            (thing-at-point 'word)))
 
 (defun sysrpl-apropos-thing-at-point (name)
   "Show information about NAME in a popup buffer.
 When called interactively NAME defaults to the word around
 point."
-  (interactive (list (completing-read "Apropos: " (rpl-edb-all-names sysrpl-selected-calculator)
+  (interactive (list (completing-read "Apropos: " (rpl-edb-all-names (sysrpl-edb-calculator sysrpl-selected-calculator))
                                       nil nil (thing-at-point 'word))))
   (let ((bufname (format "*SysRPL: %s*" name)))
     (with-current-buffer (get-buffer-create bufname)
       (setq buffer-read-only nil)
       (erase-buffer)
-      (insert (rpl-edb-get-stack-effect sysrpl-selected-calculator name))
+      (insert (rpl-edb-get-stack-effect (sysrpl-edb-calculator sysrpl-selected-calculator) name))
       (newline)
-      (insert (rpl-edb-get-description sysrpl-selected-calculator name))
+      (insert (rpl-edb-get-description (sysrpl-edb-calculator sysrpl-selected-calculator) name))
       (newline)
-      (insert (format "Address: %s" (rpl-edb-get-address sysrpl-selected-calculator name)))
+      (insert (format "Address: %s" (rpl-edb-get-address (sysrpl-edb-calculator sysrpl-selected-calculator) name)))
       (newline)
-      (insert (format "Flags: %s" (rpl-edb-get-flags sysrpl-selected-calculator name)))
+      (insert (format "Flags: %s" (rpl-edb-get-flags (sysrpl-edb-calculator sysrpl-selected-calculator) name)))
       (newline)
       (end-of-buffer)
       (help-mode)
@@ -158,18 +179,21 @@ point."
     (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
     (define-key menu-map [sysrpl-menu-separator-1]
       '(menu-item "--"))
-    (define-key menu-map [sysrpl-menu-select-49g]
-      '(menu-item "HP49G" sysrpl-select-49g
-                  :button (:radio . (eql :49G sysrpl-selected-calculator))))
-    (define-key menu-map [sysrpl-menu-select-48g]
-      '(menu-item "HP48G" sysrpl-select-48g
-                  :button (:radio . (eql :48G sysrpl-selected-calculator))))
-    (define-key menu-map [sysrpl-menu-select-39g]
-      '(menu-item "HP39G" sysrpl-select-39g
-                  :button (:radio . (eql :39G sysrpl-selected-calculator))))
-    (define-key menu-map [sysrpl-menu-select-38g]
-      '(menu-item "HP38G" sysrpl-select-38g
-                  :button (:radio . (eql :38G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp50g]
+      '(menu-item "HP50G" sysrpl-select-hp50g
+                  :button (:radio . (eql :HP50G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp49g]
+      '(menu-item "HP49G" sysrpl-select-hp49g
+                  :button (:radio . (eql :HP49G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp48g]
+      '(menu-item "HP48G" sysrpl-select-hp48g
+                  :button (:radio . (eql :HP48G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp39g]
+      '(menu-item "HP39G" sysrpl-select-hp39g
+                  :button (:radio . (eql :HP39G sysrpl-selected-calculator))))
+    (define-key menu-map [sysrpl-menu-select-hp38g]
+      '(menu-item "HP38G" sysrpl-select-hp38g
+                  :button (:radio . (eql :HP38G sysrpl-selected-calculator))))
     map)
   "The SysRPL mode local keymap.")