-
Notifications
You must be signed in to change notification settings - Fork 2
/
sasm-mode.el
146 lines (121 loc) · 4.47 KB
/
sasm-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
;;; -*- 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 '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 :inherit font-lock-constant-face))
"Face used for displaying SASM labels."
:group 'rpl)
(defface sasm-mnemonic '((t :inherit font-lock-keyword-face))
"Face used for displaying SASM mnemonics."
:group 'rpl)
(defface sasm-comment '((t :inherit font-lock-comment-face))
"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 ?\( "()" table)
(modify-syntax-entry ?\) "()" table)
(modify-syntax-entry ?\n ">" table)
table)
"The SASM syntax table.")
(defalias 'sasm-mode-syntax-propertize
(syntax-propertize-rules
("^*" (0 "<"))
("\\((\\)\s" (1 "<1b"))
("\\({\\)\s" (1 "(}"))
("\s\\(}\\)" (1 "){"))))
(defvar sasm-keywords '("BSS" "CON" "REL" "NIBASC" "STRING" "NIBHEX"
"NIBFS" "LINK" "SLINK" "INC" "ASC" "ASCM"
"HEX" "HEXM" "NIBBIN" "NIBGRB"
"TITLE" "STITLE" "EJECT" "UNLIST"
"LIST" "LISTM" "LISTALL" "CLRLIST" "SETLIST"
"END")
"Keywords used by the SASM assembler.")
(defvar sasm-font-lock-keywords
`(("^[^\s\t\n]+" (0 sasm-font-lock-label-face))
(,(concat "\\<" (regexp-opt sasm-keywords) "\\>")
(0 sasm-font-lock-keyword-face))))
(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.")
;;;###autoload
(define-derived-mode sasm-mode prog-mode "SASM"
"Major mode for SASM assembler language."
:group 'rpl
:syntax-table sasm-mode-syntax-table
(setq-local eldoc-documentation-function #'sasm-get-eldoc-message
syntax-propertize-function #'sasm-mode-syntax-propertize)
(setq font-lock-defaults (list 'sasm-font-lock-keywords))
(setq rpl-menu-compile-buffer-enable t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of file
;;
(provide 'sasm-mode)