X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/418752c55a29e2380d6d1aef767b7cfba02cf4be..ed00691544c3b6d4ad15b1c7ef975964ea72b0b6:/src/codegen-proto.lisp diff --git a/src/codegen-proto.lisp b/src/codegen-proto.lisp index 29ff35b..7c8f65c 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,7 +167,10 @@ (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. @@ -173,15 +178,22 @@ (definst var (stream :export t) (name type init) (pprint-c-type type stream name) (when init - (format stream " = ~A" init))) + (format stream " = ~A" init)) + (write-char #\; stream)) (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)) +(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 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) (pprint-logical-block (stream nil) @@ -254,6 +266,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