diff options
author | bd <bdunahu@operationnull.com> | 2025-04-08 01:56:18 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-08 01:56:18 -0400 |
commit | b85c10ba1c53f1b442fea6bde4c2a2f73cfe5d6b (patch) | |
tree | 643d37db692c19d1ef64223eadcac7a28dbbd7db /src/util.lisp | |
parent | 4c76966b49e8559f710013463dac04143c1f4e09 (diff) |
Simplify lexer-error handling, skeletion parsing functions for types
Diffstat (limited to 'src/util.lisp')
-rw-r--r-- | src/util.lisp | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/util.lisp b/src/util.lisp index 1ea6dfc..5edee4a 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -11,27 +11,17 @@ (declare (type (integer 0 *) len)) (format nil "~V,'0b" len num)) -(defmacro generate-type-map (type opsize ops) - "Generates an alist where the key corresponds to an element in -OPS, while the value is the index of that key (padded to OPSIZE) -concatenated with TYPE." - `(let ((i 0)) - (mapcar (lambda (x) - (incf i) - (cons x (concatenate 'string ,type - (format-as-binary i ,opsize)))) - ,ops))) +(defparameter type-r + '(ADD SUB MUL QUOT REM SFTR SFTL AND OR NOT XOR ADDV SUBV MULV DIVV CMP CEV) + "R-type instructions.") + +(defparameter type-i + '(LOAD LOADV ADDI SUBI SFTRI SFTLI ANDI ORI XORI STORE STOREV) + "I-type instructions.") + +(defparameter type-j + '(JMP JRL JAL BEQ BGT BUF BOF PUSH POP) + "J-type instructions.") (defparameter label-loc '() "A symbol table mapping label names to line indices.") - -(defparameter mnemonic-loc - `(,@(generate-type-map "00" 5 - '(ADD SUB MUL QUOT REM SFTR SFTL AND OR NOT - XOR ADDV SUBV MULV DIVV CMP CEV)) - ,@(generate-type-map "01" 4 - '(LOAD LOADV ADDI SUBI SFTRI SFTLI ANDI ORI - XORI STORE STOREV)) - ,@(generate-type-map "10" 4 - '(JMP JRL JAL BEQ BGT BUF BOF PUSH POP))) - "An alist mapping known mnemonics to their binary representation.") |