sasm-mode.el 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;;; -*- mode: emacs-lisp; lexical-binding: t -*-
  2. ;;; sasm-mode.el -- Major mode for Saturn assembly language
  3. ;; Copyright (C) 2015 Paul Onions
  4. ;; Author: Paul Onions <paul.onions@acm.org>
  5. ;; Keywords: Saturn, HP48, HP49, HP50, calculator
  6. ;; This file is free software, see the LICENCE file in this directory
  7. ;; for copying terms.
  8. ;;; Commentary:
  9. ;; A major mode for Saturn assembly language, the processor (perhaps
  10. ;; emulated) in HP48/49/50-series calculators.
  11. ;;; Code:
  12. (require 'cl-lib)
  13. (require 'rpl-base)
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ;; Customizations
  16. ;;
  17. (defcustom sasm-assembler-program "sasm"
  18. "External SASM assembler program name."
  19. :type 'string
  20. :group 'rpl)
  21. (defcustom sasm-assembler-output-bufname "*sasm*"
  22. "Buffer name in which to capture SASM assembler output."
  23. :type 'string
  24. :group 'rpl)
  25. (defface sasm-label '((t :foreground "darkblue"))
  26. "Face used for displaying SASM labels."
  27. :group 'rpl)
  28. (defface sasm-mnemonic '((t :foreground "purple"))
  29. "Face used for displaying SASM mnemonics."
  30. :group 'rpl)
  31. (defface sasm-comment '((t :foreground "darkgreen"))
  32. "Face used for displaying SASM comments."
  33. :group 'rpl)
  34. (defcustom sasm-font-lock-label-face 'sasm-label
  35. "Name of face to use for displaying SASM labels."
  36. :type 'symbol
  37. :group 'rpl)
  38. (defcustom sasm-font-lock-keyword-face 'sasm-mnemonic
  39. "Name of face to use for displaying SASM mnemonics."
  40. :type 'symbol
  41. :group 'rpl)
  42. (defcustom sasm-font-lock-comment-face 'sasm-comment
  43. "Name of face to use for displaying SASM comments."
  44. :type 'symbol
  45. :group 'rpl)
  46. (defvar sasm-mode-syntax-table
  47. (let ((table (make-syntax-table prog-mode-syntax-table)))
  48. (modify-syntax-entry ?? "w" table)
  49. (modify-syntax-entry ?# "w" table)
  50. (modify-syntax-entry ?= "w" table)
  51. (modify-syntax-entry ?< "w" table)
  52. (modify-syntax-entry ?> "w" table)
  53. (modify-syntax-entry ?+ "w" table)
  54. (modify-syntax-entry ?- "w" table)
  55. (modify-syntax-entry ?! "w" table)
  56. (modify-syntax-entry ?& "w" table)
  57. (modify-syntax-entry ?\( "w" table)
  58. (modify-syntax-entry ?\) "w" table)
  59. table)
  60. "The SASM syntax table.")
  61. (defvar sasm-font-lock-keywords
  62. (list (list "^\\*.*$" (list 0 'sasm-font-lock-comment-face))
  63. ;; !!! TODO !!!
  64. ))
  65. (defun sasm-compile-buffer ()
  66. "Assemble the current buffer."
  67. (interactive)
  68. (let ((tmp-filename (make-temp-file "sasm" nil ".a"))
  69. (rtn-code 0))
  70. (write-region (point-min) (point-max) tmp-filename)
  71. (with-current-buffer (get-buffer-create sasm-assembler-output-bufname)
  72. (setq buffer-read-only nil)
  73. (erase-buffer)
  74. (setq rtn-code (call-process sasm-assembler-program tmp-filename t nil)))
  75. (display-buffer sasm-assembler-output-bufname)
  76. (if (eql rtn-code 0)
  77. (message "Assembly complete")
  78. (message "*** Assembled with ERRORS ***"))))
  79. (defun sasm-get-eldoc-message ()
  80. (interactive)
  81. ;; !!! TODO !!!
  82. "")
  83. (defvar sasm-mode-map
  84. (let ((map (make-sparse-keymap))
  85. (menu-map (make-sparse-keymap)))
  86. (set-keymap-parent map rpl-common-keymap)
  87. ;; Menu items
  88. (define-key map [menu-bar rpl-menu] (cons "RPL" menu-map))
  89. (define-key menu-map [sasm-menu-separator-1]
  90. '(menu-item "--"))
  91. ;; !!! TODO !!!
  92. map)
  93. "The SASM mode local keymap.")
  94. (defvar sasm-mode-hook nil
  95. "Hook for customizing SASM mode.")
  96. (define-derived-mode sasm-mode asm-mode "SASM"
  97. "Major mode for SASM assembler language."
  98. :group 'rpl
  99. (make-local-variable 'eldoc-documentation-function)
  100. (setq eldoc-documentation-function 'sasm-get-eldoc-message)
  101. (setq font-lock-defaults (list 'sasm-font-lock-keywords))
  102. (setq rpl-menu-compile-buffer-enable t))
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. ;; End of file
  105. ;;
  106. (provide 'sasm-mode)