X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/b559689bf01c399ac0a15e8b73da7488dded72f4..9eb66c6efbb1e44b52063245df48b810f2ff4d15:/src/codegen-proto.lisp diff --git a/src/codegen-proto.lisp b/src/codegen-proto.lisp index 602b51e..535839c 100644 --- a/src/codegen-proto.lisp +++ b/src/codegen-proto.lisp @@ -49,7 +49,7 @@ ;; Root class. -(export 'temporary-name) +(export '(temporary-name temp-tag)) (defclass temporary-name () ((tag :initarg :tag :reader temp-tag)) (:documentation @@ -74,6 +74,8 @@ (make-instance 'temporary-name :tag "sod__ap")) (defparameter *sod-master-ap* (make-instance 'temporary-name :tag "sod__master_ap")) +(defparameter *sod-tmp-ap* + (make-instance 'temporary-name :tag "sod__tmp_ap")) ;;;-------------------------------------------------------------------------- ;;; Instructions. @@ -165,34 +167,42 @@ (format stream "~@<~@{~S ~@_~S~^ ~_~}~:>" ,@(mappend #'list keys args))) (progn ,@body)))) - ,@(and export `((export '(,class-name ,constructor-name)))) + ,@(and export `((export '(,class-name ,constructor-name + ,@(mapcar (lambda (arg) + (symbolicate 'inst- arg)) + args))))) ',code))) ;; Important instruction classes. -(definst var (stream :export t) (name type init) - (pprint-c-type type stream name) +;; HACK: use a gensym for the `expr' and `type' slots to avoid leaking the +;; slot names, since the symbol `expr' is exported from our package and +;; `type' belongs to the `common-lisp' package. + +(definst var (stream :export t) (name #1=#:type init) + (pprint-c-type #1# stream name) (when init - (format stream " = ~A" init))) -(definst set (stream :export t) (var expr) - (format stream "~@<~A = ~@_~2I~A;~:>" var expr)) -(definst update (stream :export t) (var op expr) - (format stream "~@<~A ~A= ~@_~2I~A;~:>" var op expr)) -(definst return (stream :export t) (expr) - (format stream "return~@[ (~A)~];" expr)) + (format stream " = ~A" init)) + (write-char #\; stream)) +(definst set (stream :export t) (var #1=#:expr) + (format stream "~@<~A = ~@_~2I~A;~:>" var #1#)) +(definst update (stream :export t) (var op #1=#:expr) + (format stream "~@<~A ~A= ~@_~2I~A;~:>" var op #1#)) +(definst return (stream :export t) (#1=#:expr) + (format stream "return~@[ (~A)~];" #1#)) (definst break (stream :export t) () (format stream "break;")) (definst continue (stream :export t) () (format stream "continue;")) -(definst expr (stream :export t) (expr) - (format stream "~A;" expr)) +(definst expr (stream :export t) (#1=#:expr) + (format stream "~A;" #1#)) (definst block (stream :export t) (decls body) - (format stream "{~:@_~@< ~2I~@[~{~A;~:@_~}~:@_~]~{~A~^~:@_~}~:>~:@_}" + (format stream "{~:@_~@< ~2I~@[~{~A~:@_~}~:@_~]~{~A~^~:@_~}~:>~:@_}" decls body)) -(definst function (stream :export t) (name type body) +(definst function (stream :export t) (name #1=#:type body) (pprint-logical-block (stream nil) (princ "static " stream) - (pprint-c-type type stream name) + (pprint-c-type #1# stream name) (format stream "~:@_~A~:@_~:@_" body))) ;; Formatting utilities. @@ -260,6 +270,14 @@ (:method (codegen insts) (dolist (inst insts) (emit-inst codegen inst)))) +(export '(emit-decl emit-decls)) +(defgeneric emit-decl (codegen inst) + (:documentation + "Add INST to the end of CODEGEN's list of declarations.")) +(defgeneric emit-decls (codegen insts) + (:documentation + "Add a list of INSTS to the end of CODEGEN's list of declarations.")) + (export 'codegen-push) (defgeneric codegen-push (codegen) (:documentation