From: Mark Wooding Date: Wed, 16 Dec 2015 07:39:30 +0000 (+0000) Subject: src/codegen-proto.lisp: New instruction types `cond' and `for', X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/2d8d81c52aded8f15e37b061971d493742f55751 src/codegen-proto.lisp: New instruction types `cond' and `for', The `cond' instruction makes a ternary conditional expression of the `COND ? CONSEQ : ALT' variety. The `for' instruction makes one of C's fancy loops. Maybe the format strings are interesting. --- diff --git a/doc/SYMBOLS b/doc/SYMBOLS index b73d8a9..f580864 100644 --- a/doc/SYMBOLS +++ b/doc/SYMBOLS @@ -340,6 +340,7 @@ codegen-proto.lisp codegen-pop-block generic codegen-pop-function generic codegen-push generic + cond-inst class continue-inst class convert-stmts function definst macro @@ -353,6 +354,7 @@ codegen-proto.lisp emit-insts generic ensure-var generic expr-inst class + for-inst class format-banner-comment function format-compound-statement macro format-temporary-name generic @@ -375,14 +377,17 @@ codegen-proto.lisp inst-name generic inst-op generic inst-type generic + inst-update generic inst-var generic make-banner-inst function make-block-inst function make-break-inst function make-call-inst function + make-cond-inst function make-continue-inst function make-do-while-inst function make-expr-inst function + make-for-inst function make-function-inst function make-if-inst function make-return-inst function @@ -616,10 +621,12 @@ cl:t block-inst break-inst call-inst + cond-inst continue-inst convert-to-ilayout-inst do-while-inst expr-inst + for-inst function-inst if-inst return-inst @@ -1047,6 +1054,7 @@ ilayout-class ilayout-ichains ilayout inst-alt + cond-inst if-inst inst-args banner-inst @@ -1058,6 +1066,7 @@ inst-banner-args inst-body block-inst do-while-inst + for-inst function-inst while-inst inst-chain-head @@ -1065,10 +1074,13 @@ inst-chain-head inst-class convert-to-ilayout-inst inst-cond + cond-inst do-while-inst + for-inst if-inst while-inst inst-conseq + cond-inst if-inst inst-control banner-inst @@ -1083,6 +1095,7 @@ inst-expr inst-func call-inst inst-init + for-inst var-inst inst-metric cl:list @@ -1092,10 +1105,12 @@ inst-metric block-inst break-inst call-inst + cond-inst continue-inst convert-to-ilayout-inst do-while-inst expr-inst + for-inst function-inst if-inst return-inst @@ -1111,6 +1126,8 @@ inst-op inst-type function-inst var-inst +inst-update + for-inst inst-var set-inst update-inst @@ -1206,12 +1223,14 @@ cl:print-object call-inst t chain-offset t class-pointer t + cond-inst t continue-inst t convert-to-ilayout-inst t do-while-inst t effective-method t effective-slot t expr-inst t + for-inst t function-inst t ichain t if-inst t diff --git a/doc/clang.tex b/doc/clang.tex index 87e8d47..0a89a90 100644 --- a/doc/clang.tex +++ b/doc/clang.tex @@ -917,6 +917,8 @@ Temporary names are represented by objects which implement a simple protocol. @|set| & @ @ & @ = @; \\ \hlx{v} @|update| & @ @ @ & @ @= @; \\ \hlx{v} + @|cond| & @ @ @ & @ ? @ : @ + \\ \hlx{v} @|return| & @ & return @[@@]; \\ \hlx{v} @|break| & --- & break; \\ \hlx{v} @@ -933,6 +935,8 @@ Temporary names are represented by objects which implement a simple protocol. @|if| & @ @ @|\&optional| @ & if (@) @ @[else @@] \\ \hlx{v} + @|for| & @ @ @ @ & + for (@; @; @) @ \\ \hlx{v} @|while| & @ @ & while (@) @ \\ \hlx{v} @|do-while| & @ @ & do @ while (@); diff --git a/src/codegen-proto.lisp b/src/codegen-proto.lisp index 186f225..e663fb5 100644 --- a/src/codegen-proto.lisp +++ b/src/codegen-proto.lisp @@ -247,6 +247,8 @@ (definst update (stream :export t) (var op #1=#:expr) ;; Special kinds of expressions. (definst call (stream :export t) (#1=#:func &rest args) (format stream "~A(~@<~{~A~^, ~_~}~:>)" #1# args)) +(definst cond (stream :export t) (#1=#:cond conseq alt) + (format stream "~@<~A ~2I~@_~@~:>" #1# conseq alt)) ;; Simple statements. (definst return (stream :export t) (#1=#:expr) @@ -320,6 +322,11 @@ (definst do-while (stream :export t) (body #1=#:cond) (write-string "do" stream)) (format stream "while (~A);" #1#)) +(definst for (stream :export t) (init #1=#:cond update body) + (format-compound-statement (stream body) + (format stream "for (~@<~@[~A~];~@[ ~_~A~];~@[ ~_~A~]~:>)" + init #1# update))) + ;;;-------------------------------------------------------------------------- ;;; Code generation.