mirror of
https://bitbucket.org/pdo/rpl-tools.git
synced 2024-11-16 19:49:22 +01:00
Added ability to create SASM entry tables from edb data.
This commit is contained in:
parent
f083adb758
commit
5da9020e6d
9 changed files with 104 additions and 27 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,7 @@
|
|||
|
||||
;;; rpl-base.el -- basic setup for the RPL tools
|
||||
|
||||
;; Copyright (C) 2014 Paul Onions
|
||||
;; Copyright (C) 2014 - 2018 Paul Onions
|
||||
|
||||
;; Author: Paul Onions <paul.onions@acm.org>
|
||||
;; Keywords: RPL, SysRPL, HP48, HP49, HP50
|
||||
|
@ -27,7 +27,8 @@
|
|||
;; Utility functions for generating/loading pre-computed data
|
||||
;;
|
||||
(defvar rpl-tools-data-dir
|
||||
(and load-file-name (concat (file-name-directory load-file-name) "data/"))
|
||||
(concat (file-name-directory (or load-file-name (buffer-file-name)))
|
||||
"data/")
|
||||
"RPL tools data directory.")
|
||||
|
||||
(defun rpl-write-data-file (obj filename)
|
||||
|
|
54
rpl-edb.el
54
rpl-edb.el
|
@ -2,7 +2,7 @@
|
|||
|
||||
;;; rpl-edb.el -- utilities to parse the entries database
|
||||
|
||||
;; Copyright (C) 2014 Paul Onions
|
||||
;; Copyright (C) 2014 - 2018 Paul Onions
|
||||
|
||||
;; Author: Paul Onions <paul.onions@acm.org>
|
||||
;; Keywords: RPL, UserRPL, SysRPL, HP48, HP49, HP50
|
||||
|
@ -20,10 +20,11 @@
|
|||
(require 'rpl-base)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Functions for parsing the EDB file
|
||||
;;; Functions for parsing the EDB (entries.db) file
|
||||
|
||||
(defun rpl-edb-get-line ()
|
||||
"Get line that point is on from the current buffer.
|
||||
|
||||
Return a string containing the line, or nil if at end of buffer.
|
||||
As a side-effect set point to the start of the next line."
|
||||
(cond ((eobp)
|
||||
|
@ -60,6 +61,7 @@ As a side-effect set point to the start of the next line."
|
|||
|
||||
(defun rpl-edb-consume-ident-line ()
|
||||
"Consume an EDB identifier line.
|
||||
|
||||
Return a list of two strings: the identifier and its stack effect
|
||||
description. Move point to the start of the next line."
|
||||
(let ((line (rpl-edb-get-line)))
|
||||
|
@ -80,6 +82,7 @@ description. Move point to the start of the next line."
|
|||
;;;
|
||||
(defun rpl-edb-parse-keyword-line (line)
|
||||
"Parse the given EDB keyword line.
|
||||
|
||||
Return a list consisting of the EDB keyword as a keyword symbol
|
||||
and a parameter string (to be further parsed later)."
|
||||
(cond ((string-match "\\.[[:blank:]]+\\([[:alnum:]]+\\):" line)
|
||||
|
@ -137,6 +140,7 @@ and a parameter string (to be further parsed later)."
|
|||
;;;
|
||||
(defun rpl-edb-consume-description-line ()
|
||||
"Consume an EDB extended description line.
|
||||
|
||||
Return a string. Move point to the start of the next line."
|
||||
(let ((line (rpl-edb-get-line)))
|
||||
(substring line 80)))
|
||||
|
@ -148,6 +152,7 @@ Return a string. Move point to the start of the next line."
|
|||
|
||||
(defun rpl-edb-parse-buffer ()
|
||||
"Parse the current buffer, assumed to be the ``entries.db'' file.
|
||||
|
||||
Set `rpl-edb-entries' to the parsed results, a list of EDB
|
||||
entries, where each entry has the format:
|
||||
(NAMES STACK-EFFECT DESCRIPTION CALC-INFOS)
|
||||
|
@ -209,13 +214,15 @@ flags for this calculator."
|
|||
(setq rpl-edb-entries (reverse entries))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Functions to create calculator data files
|
||||
;;; Functions to create elisp calculator data files
|
||||
|
||||
(defun rpl-edb-generate-calculator-data (calculator)
|
||||
"Generate data for CALCULATOR (a keyword identifying the model).
|
||||
|
||||
Return a hash-table whose entries are keyed by entry name and
|
||||
whose values are lists of the form:
|
||||
(STACK-EFFECT DESCRIPTION ADDRESS &rest FLAGS).
|
||||
|
||||
Assumes `rpl-edb-entries' has been set by calling
|
||||
`rpl-edb-parse-buffer'."
|
||||
(cl-assert (keywordp calculator))
|
||||
|
@ -241,6 +248,7 @@ Assumes `rpl-edb-entries' has been set by calling
|
|||
|
||||
(defun rpl-edb-make-data-filename (calculator)
|
||||
"Make the SysRPL data filename used for CALCULATOR.
|
||||
|
||||
Where CALCULATOR should be a keyword symbol identifying the
|
||||
calculator model, e.g. :48G, :49G etc."
|
||||
(cl-assert (keywordp calculator))
|
||||
|
@ -248,6 +256,7 @@ calculator model, e.g. :48G, :49G etc."
|
|||
|
||||
(defun rpl-edb-make-calculator-data-file (calculator)
|
||||
"Make the appropriate SysRPL data file for CALCULATOR.
|
||||
|
||||
The CALCULATOR is identified by keyword: :38G, :39G, :48G
|
||||
or :49G."
|
||||
(cl-assert (keywordp calculator))
|
||||
|
@ -256,6 +265,7 @@ or :49G."
|
|||
|
||||
(defun rpl-edb-make-all-data-files ()
|
||||
"Create all SysRPL data files.
|
||||
|
||||
Assumes the current buffer contains the ``entries.db'' file
|
||||
created by Carsten Dominik, parsing it if necessary to set the
|
||||
`rpl-edb-entries' variable, then writing captured data to the
|
||||
|
@ -282,7 +292,8 @@ SysRPL data files, one for each calculator type."
|
|||
"SysRPL data for the 49G calculator.")
|
||||
|
||||
(defun rpl-edb-data (calculator)
|
||||
"Get SysRPL data for the specified CALCULATOR.
|
||||
"Get SysRPL data for the specified CALCULATOR.
|
||||
|
||||
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))
|
||||
|
@ -327,6 +338,41 @@ have the form (STACK-EFFECT DESCRIPTION ADDRESS &rest FLAGS)."
|
|||
(defun rpl-edb-get-flags (calculator name)
|
||||
(cadddr (gethash name (rpl-edb-data calculator))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Functions to create assembler EQU files for SASM
|
||||
|
||||
(defvar rpl-edb-tables-dir
|
||||
(concat (file-name-directory (or load-file-name (buffer-file-name)))
|
||||
"tables/")
|
||||
"RPL EDB tables directory.")
|
||||
|
||||
(defun rpl-edb-make-sasm-table-filename (calculator)
|
||||
(cl-assert (keywordp calculator))
|
||||
(concat "entries" (downcase (substring (symbol-name calculator) 1)) ".a"))
|
||||
|
||||
(defun rpl-edb-make-sasm-table (calculator)
|
||||
(cl-assert (keywordp calculator))
|
||||
(let ((default-directory rpl-edb-tables-dir))
|
||||
(with-temp-buffer
|
||||
(insert "* -*- mode: sasm -*-\n")
|
||||
(insert "*\n")
|
||||
(insert "* Entries database for calculator: "
|
||||
(substring (symbol-name calculator) 1) "\n")
|
||||
(insert "*\n")
|
||||
(insert "* Created by Gnu Emacs rpl-tools on "
|
||||
(current-time-string) "\n")
|
||||
(insert "*\n")
|
||||
(let ((names (rpl-edb-all-names calculator)))
|
||||
(dolist (name names)
|
||||
(insert "=" name " EQU #" (rpl-edb-get-address calculator name) "\n")))
|
||||
(write-region (point-min) (point-max)
|
||||
(rpl-edb-make-sasm-table-filename calculator)))))
|
||||
|
||||
(defun rpl-edb-make-all-sasm-tables ()
|
||||
(interactive)
|
||||
(dolist (calculator '(:38G :39G :48G :49G))
|
||||
(rpl-edb-make-sasm-table calculator)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; End of file
|
||||
;;
|
||||
|
|
27
sasm-mode.el
27
sasm-mode.el
|
@ -2,7 +2,7 @@
|
|||
|
||||
;;; sasm-mode.el -- Major mode for Saturn assembly language
|
||||
|
||||
;; Copyright (C) 2015 Paul Onions
|
||||
;; Copyright (C) 2015 - 2018 Paul Onions
|
||||
|
||||
;; Author: Paul Onions <paul.onions@acm.org>
|
||||
;; Keywords: Saturn, HP48, HP49, HP50, calculator
|
||||
|
@ -27,8 +27,8 @@
|
|||
:type 'string
|
||||
:group 'rpl)
|
||||
|
||||
(defcustom sasm-assembler-output-bufname "*sasm*"
|
||||
"Buffer name in which to capture SASM assembler output."
|
||||
(defcustom sasm-assembler-listing-bufname "*sasm-listing*"
|
||||
"Buffer name in which to capture SASM assembler listing."
|
||||
:type 'string
|
||||
:group 'rpl)
|
||||
|
||||
|
@ -83,16 +83,23 @@
|
|||
(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)
|
||||
(let* ((src-filename (make-temp-file "sasm" nil ".a"))
|
||||
(obj-filename (concat (file-name-sans-extension src-filename) ".o"))
|
||||
(rtn-code 0))
|
||||
(write-region (point-min) (point-max) src-filename)
|
||||
(with-current-buffer (get-buffer-create sasm-assembler-listing-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)
|
||||
(setq rtn-code (call-process sasm-assembler-program nil t nil
|
||||
"-A" "-o" obj-filename src-filename))
|
||||
(fundamental-mode)
|
||||
(beginning-of-buffer)
|
||||
(setq buffer-read-only t))
|
||||
(let ((win (display-buffer sasm-assembler-listing-bufname)))
|
||||
(when sysrpl-select-popup-windows
|
||||
(select-window win)))
|
||||
(if (eql rtn-code 0)
|
||||
(message "Assembly complete")
|
||||
(message "Assembly complete")
|
||||
(message "*** Assembled with ERRORS ***"))))
|
||||
|
||||
(defun sasm-get-eldoc-message ()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
;;; sysrpl-mode.el -- Major mode for the SysRPL programming language
|
||||
|
||||
;; Copyright (C) 2014 Paul Onions
|
||||
;; Copyright (C) 2014 - 2018 Paul Onions
|
||||
|
||||
;; Author: Paul Onions <paul.onions@acm.org>
|
||||
;; Keywords: RPL, SysRPL, HP48, HP49, HP50, calculator
|
||||
|
@ -33,11 +33,16 @@
|
|||
:type 'string
|
||||
:group 'rpl)
|
||||
|
||||
(defcustom sysrpl-compiler-output-bufname "*rplcomp*"
|
||||
(defcustom sysrpl-compiler-output-bufname "*rplcomp-output*"
|
||||
"Buffer name in which to capture SysRPL compiler output."
|
||||
:type 'string
|
||||
:group 'rpl)
|
||||
|
||||
(defcustom sysrpl-select-popup-windows t
|
||||
"Set non-nil to automatically switch to popup windows."
|
||||
:type 'boolean
|
||||
:group 'rpl)
|
||||
|
||||
(defface sysrpl-name '((t :inherit font-lock-builtin-face))
|
||||
"Face used for displaying SysRPL names (e.g DROP)."
|
||||
:group 'rpl)
|
||||
|
@ -171,6 +176,7 @@
|
|||
|
||||
(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-edb-calculator sysrpl-selected-calculator))
|
||||
|
@ -196,14 +202,19 @@ point."
|
|||
(defun sysrpl-compile-buffer ()
|
||||
"Compile the current buffer."
|
||||
(interactive)
|
||||
(let ((tmp-filename (make-temp-file "sysrpl" nil ".s"))
|
||||
(let ((tmp-filename-s (make-temp-file "sysrpl" nil ".s"))
|
||||
(rtn-code 0))
|
||||
(write-region (point-min) (point-max) tmp-filename)
|
||||
(write-region (point-min) (point-max) tmp-filename-s)
|
||||
(with-current-buffer (get-buffer-create sysrpl-compiler-output-bufname)
|
||||
(setq buffer-read-only nil)
|
||||
(erase-buffer)
|
||||
(setq rtn-code (call-process sysrpl-compiler-program tmp-filename t nil "-" "-")))
|
||||
(display-buffer sysrpl-compiler-output-bufname)
|
||||
(setq rtn-code (call-process sysrpl-compiler-program tmp-filename-s t nil "-" "-"))
|
||||
(sasm-mode)
|
||||
(beginning-of-buffer)
|
||||
(setq buffer-read-only t))
|
||||
(let ((win (display-buffer sysrpl-compiler-output-bufname)))
|
||||
(when sysrpl-select-popup-windows
|
||||
(select-window win)))
|
||||
(if (eql rtn-code 0)
|
||||
(message "Compilation complete")
|
||||
(message "*** Compiled with ERRORS ***"))))
|
||||
|
|
12
tables/README
Normal file
12
tables/README
Normal file
|
@ -0,0 +1,12 @@
|
|||
To populate this directory with assembler files containing SysRPL
|
||||
entry points, issue the following command in Gnu Emacs:-
|
||||
|
||||
M-x rpl-edb-make-all-sasm-tables
|
||||
|
||||
This will create a SASM assembly file for each of the calculator
|
||||
models described by the rpl-tools data files (which are generated from
|
||||
Carsten Dominik's entries database). See rpl-edb.el for details.
|
||||
|
||||
--
|
||||
PDO
|
||||
25 November 2018
|
Loading…
Reference in a new issue