Browse Source

Started work on SASM mode for Saturn assembler source.

Paul Onions 9 năm trước cách đây
mục cha
commit
1ca1e4d546
4 tập tin đã thay đổi với 139 bổ sung3 xóa
  1. 3 1
      rpl-base.el
  2. 5 1
      rpl-tools.el
  3. 129 0
      sasm-mode.el
  4. 2 1
      sysrpl-mode.el

+ 3 - 1
rpl-base.el

@@ -91,7 +91,9 @@ string (either relative or absolute)."
   "Call the appropriate compile-buffer command, depending on major mode."
   (interactive)
   (cond ((eql major-mode 'sysrpl-mode)
-         (call-interactively 'sysrpl-compile-buffer))))
+         (call-interactively 'sysrpl-compile-buffer))
+        ((eql major-mode 'sasm-mode)
+         (call-interactively 'sasm-compile-buffer))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Developer utils

+ 5 - 1
rpl-tools.el

@@ -26,7 +26,10 @@
 ;; `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.
+;; Also work-in-progress is `sasm-mode' for Saturn assembler buffers.
+;;
+;; See also the ``RPL'' menu added to all `sysrpl-mode' and
+;; `sasm-mode' buffers.
 
 ;;; Code:
 
@@ -34,6 +37,7 @@
 (require 'rpl-base)
 (require 'rpl-edb)
 (require 'sysrpl-mode)
+(require 'sasm-mode)
 
 ;; Acknowledge we're loaded
 (provide 'rpl-tools)

+ 129 - 0
sasm-mode.el

@@ -0,0 +1,129 @@
+;;; -*- mode: emacs-lisp; lexical-binding: t -*-
+
+;;; sasm-mode.el -- Major mode for Saturn assembly language
+
+;; Copyright (C) 2015 Paul Onions
+
+;; Author: Paul Onions <paul.onions@acm.org>
+;; Keywords: Saturn, HP48, HP49, HP50, calculator
+
+;; This file is free software, see the LICENCE file in this directory
+;; for copying terms.
+
+;;; Commentary:
+
+;; A major mode for Saturn assembly language, the processor (perhaps
+;; emulated) in HP48/49/50-series calculators.
+
+;;; Code:
+(require 'cl-lib)
+(require 'rpl-base)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Customizations
+;;
+(defcustom sasm-assembler-program "sasm"
+  "External SASM assembler program name."
+  :type 'string
+  :group 'rpl)
+
+(defcustom sasm-assembler-output-bufname "*sasm*"
+  "Buffer name in which to capture SASM assembler output."
+  :type 'string
+  :group 'rpl)
+
+(defface sasm-label '((t :foreground "darkblue"))
+  "Face used for displaying SASM labels."
+  :group 'rpl)
+
+(defface sasm-mnemonic '((t :foreground "purple"))
+  "Face used for displaying SASM mnemonics."
+  :group 'rpl)
+
+(defface sasm-comment '((t :foreground "darkgreen"))
+  "Face used for displaying SASM comments."
+  :group 'rpl)
+
+(defcustom sasm-font-lock-label-face 'sasm-label
+  "Name of face to use for displaying SASM labels."
+  :type 'symbol
+  :group 'rpl)
+
+(defcustom sasm-font-lock-keyword-face 'sasm-mnemonic
+  "Name of face to use for displaying SASM mnemonics."
+  :type 'symbol
+  :group 'rpl)
+
+(defcustom sasm-font-lock-comment-face 'sasm-comment
+  "Name of face to use for displaying SASM comments."
+  :type 'symbol
+  :group 'rpl)
+
+(defvar sasm-mode-syntax-table
+  (let ((table (make-syntax-table prog-mode-syntax-table)))
+    (modify-syntax-entry ??  "w" table)
+    (modify-syntax-entry ?#  "w" table)
+    (modify-syntax-entry ?=  "w" table)
+    (modify-syntax-entry ?<  "w" table)
+    (modify-syntax-entry ?>  "w" table)
+    (modify-syntax-entry ?+  "w" table)
+    (modify-syntax-entry ?-  "w" table)
+    (modify-syntax-entry ?!  "w" table)
+    (modify-syntax-entry ?&  "w" table)
+    (modify-syntax-entry ?\( "w" table)
+    (modify-syntax-entry ?\) "w" table)
+    table)
+  "The SASM syntax table.")
+
+(defvar sasm-font-lock-keywords
+  (list (list "^\\*.*$" (list 0 'sasm-font-lock-comment-face))
+        ;; !!! TODO !!!
+        ))
+
+(defun sasm-compile-buffer ()
+  "Assemble the current buffer."
+  (interactive)
+  (let ((tmp-filename (make-temp-file "sasm" nil ".a"))
+        (rtn-code 0))
+    (write-region (point-min) (point-max) tmp-filename)
+    (with-current-buffer (get-buffer-create sasm-assembler-output-bufname)
+      (setq buffer-read-only nil)
+      (erase-buffer)
+      (setq rtn-code (call-process sasm-assembler-program tmp-filename t nil)))
+    (display-buffer sasm-assembler-output-bufname)
+    (if (eql rtn-code 0)
+        (message "Assembly complete")
+      (message "*** Assembled with ERRORS ***"))))
+
+(defun sasm-get-eldoc-message ()
+  (interactive)
+  ;; !!! TODO !!!
+  "")
+
+(defvar sasm-mode-map
+  (let ((map (make-sparse-keymap))
+        (menu-map (make-sparse-keymap)))
+    (set-keymap-parent map rpl-common-keymap)
+    ;; Menu items
+    (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
+    (define-key menu-map [sasm-menu-separator-1]
+      '(menu-item "--"))
+    ;; !!! TODO !!!
+    map)
+  "The SASM mode local keymap.")
+
+(defvar sasm-mode-hook nil
+  "Hook for customizing SASM mode.")
+
+(define-derived-mode sasm-mode asm-mode "SASM"
+  "Major mode for SASM assembler language."
+  :group 'rpl
+  (make-local-variable 'eldoc-documentation-function)
+  (setq eldoc-documentation-function 'sasm-get-eldoc-message)
+  (setq font-lock-defaults (list 'sasm-font-lock-keywords))
+  (setq rpl-menu-compile-buffer-enable t))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; End of file
+;;
+(provide 'sasm-mode)

+ 2 - 1
sysrpl-mode.el

@@ -243,7 +243,8 @@ point."
   (make-local-variable 'eldoc-documentation-function)
   (setq eldoc-documentation-function 'sysrpl-get-eldoc-message)
   (setq font-lock-defaults (list 'sysrpl-font-lock-keywords))
-  (setq rpl-menu-compile-buffer-enable t))
+  (setq rpl-menu-compile-buffer-enable t)
+  (setq rpl-menu-assemble-buffer-enable nil))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; End of file