From 19b9feb02dded5cca51777d70680c35180e7f515 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Fri, 2 May 2025 22:26:08 +0200 Subject: [PATCH] Begin serious work on User-Side Compiler (USC) --- wip-duuqnd/compiler.lisp | 11 +++++-- wip-duuqnd/instruction-list.txt | Bin 0 -> 7057 bytes wip-duuqnd/instruction.lisp | 54 ++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 wip-duuqnd/instruction-list.txt create mode 100644 wip-duuqnd/instruction.lisp diff --git a/wip-duuqnd/compiler.lisp b/wip-duuqnd/compiler.lisp index 415c672..66926ea 100644 --- a/wip-duuqnd/compiler.lisp +++ b/wip-duuqnd/compiler.lisp @@ -1,7 +1,8 @@ -(defpackage #:compiler +(defpackage #:user-side-compiler + (:nicknames #:usc) (:use #:cl)) -(in-package #:compiler) +(in-package #:user-side-compiler) (defvar *label-counter* 0) @@ -13,9 +14,14 @@ (defclass reference () ()) +(defgeneric ref-constantp (reference) (:method (reference) nil)) + (defclass reference-constant (reference) ((%value :accessor ref-value :initarg :value))) +(defmethod ref-constantp ((reference reference-constant)) + t) + (defmethod print-object ((object reference-constant) stream) (print-unreadable-object (object stream :type t) (format stream "~D" (ref-value object)))) @@ -34,7 +40,6 @@ (format-inst t "LDY #~D" (ref-index ref)) (format-inst t "LDA VARVEC,Y")) - (defclass node () ((%next :accessor next :accessor normal-next :initform nil))) diff --git a/wip-duuqnd/instruction-list.txt b/wip-duuqnd/instruction-list.txt new file mode 100644 index 0000000000000000000000000000000000000000..0ff29c85085f91d4182dd92b5495d049781cb791 GIT binary patch literal 7057 zcmbW6O_Sm_5Qg{cU*W3gFk7<+V{BuN{-TD2Vc0RX1-TK{n@oinHef21f1j4rElXZH z8O&i8)(G<1ebEzn(vO^Viqr>&vcf)U&KC{GUV= zX;36n-w)w^=>6K9j{a)*dxsgy7fGzKaff}9V@Yd(srSAwCWu8|_S^Y*xZs$C1%Vn> zB&F|<;cbU$186M>)J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kkRL0q%mGSiK=ug1tkHoC#1&sb6M$sEF`hyrnFCby*>5sv5^hSjB^{3;M z{){;Nk({MJ0i!>Jq5h0I{ed8J+Yx!pmDglSER&Abw>)$Yn_e`;Qvw-&!8msk{;H($cT`SQxcDupq(mRU9C7RQ8#TYJo{HRd#h zG2xrtnEG34%ru2D;bAwX^{}{Q@8MSJ^OJM25}M>Sf}^rpVpgt⩔`5xi)4h6*0=S zkf~II>0BERsMNl*jw~gtvyLn!tg{LuXD6()3L|F|)>*`~vy%bNy0Y}Vo~xzPe?$Zw z2dV~cuWpeg`-bCrUE2neK?d#X=^8qXbv<1%IwvtJ_bNu`5ToUoF*=7BEeGuC@eJ(t zM1$$&m=V_3xsFphH{*0pa+c0jjLs2;IyZB4?w!8@xRqP4oi34b(bE`3Z^}haV-&rV z!qV#!I4JEXrijHICZpwdm=47)O%3)REdmo-{)8fbK3Q+z zmeFkpb-UaD>3?tGHWQ?O3X&0e>)LKAhA_=Vmj?wj)&F2>L8uBAI!5ui1Nfi(sTm9_VaKtG+F?Rbi!*WZrU uYlYEve2Q3qgNm3*CltNt294@Z&)Gkx%>KDvE6ij&vwud+Opi9kp7$?2l=(aW literal 0 HcmV?d00001 diff --git a/wip-duuqnd/instruction.lisp b/wip-duuqnd/instruction.lisp new file mode 100644 index 0000000..ba20b59 --- /dev/null +++ b/wip-duuqnd/instruction.lisp @@ -0,0 +1,54 @@ +(in-package #:user-side-compiler) + +(defgeneric check-arguments (instruction)) + +(defclass instruction () + ((%mnemonic :allocation :class :reader mnemonic :initarg :mnemonic) + (%operand :accessor operand :initarg :operand) + (%next :accessor next :accessor normal-next :initarg :next))) + +(defclass complete-mixin () + ((%opcode :allocation :class :reader opcode :initarg :opcode))) + +(defclass immediate-mixin () ()) +(defclass implied-mixin () ()) +(defclass zero-page-mixin () ()) +(defclass zero-page-x-mixin (zero-page-mixin) ()) +(defclass absolute-mixin () ()) +(defclass absolute-x-mixin (absolute-mixin) ()) +(defclass absolute-y-mixin (absolute-mixin) ()) +(defclass indirect-x-mixin (zero-page-mixin) ()) +(defclass indirect-y-mixin (zero-page-mixin) ()) + +(defun addressing-mode-to-class-name (mode-keyword) + (cadr (assoc mode-keyword + '((:implied implied-mixin) + (:immediate immediate-mixin) + (:zero-page zero-page-mixin) + (:zero-page-x zero-page-x-mixin) + (:zero-page-y zero-page-y-mixin) + (:absolute absolute-mixin) + (:absolute-x absolute-x-mixin) + (:absolute-y absolute-y-mixin) + (:indirect-x indirect-x-mixin) + (:indirect-y indirect-y-mixin))))) + +(defclass branching-mixin () + ((%branch-next :accessor branch-next :initarg :branch-next))) + +(defmacro define-instruction (mnemonic branching-p &rest modes-and-codes) + (let* ((name (string-upcase mnemonic)) + (base-name (intern (format nil "INST-~A" name)))) + `(progn + (defclass ,base-name (instruction) + ((%mnemonic :allocation :class :initform ',mnemonic))) + ,@(loop :for (mode code) :in modes-and-codes + :collect `(defclass ,(intern (format nil "INST-~A-~A" + name mode)) + ,(append + `(,base-name + ,(addressing-mode-to-class-name mode) + complete-mixin) + (when branching-p + '(branching-mixin))) + ((%opcode :allocation :class :initform ,code)))))))