chiark / gitweb /
src/codegen-proto.lisp: New instruction types `cond' and `for',
authorMark Wooding <mdw@distorted.org.uk>
Wed, 16 Dec 2015 07:39:30 +0000 (07:39 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:09:03 +0000 (15:09 +0100)
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.

doc/SYMBOLS
doc/clang.tex
src/codegen-proto.lisp

index b73d8a9915f143f4b3f2ff6d9bda7913f448b0ab..f580864b02b546729493c91625a1820abdeb76cd 100644 (file)
@@ -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
index 87e8d470380cb569b320ba8507ce326bee827d69..0a89a904b4503bd14e6d5b1bcee35161ba0afeb8 100644 (file)
@@ -917,6 +917,8 @@ Temporary names are represented by objects which implement a simple protocol.
     @|set|      & @<var> @<expr>           & @<var> = @<expr>;  \\ \hlx{v}
     @|update|   & @<var> @<op> @<expr>     & @<var> @<op>= @<expr>;
                                                                 \\ \hlx{v}
+    @|cond|     & @<cond> @<conseq> @<alt> & @<cond> ? @<conseq> : @<alt>
+                                                                \\ \hlx{v}
     @|return|   & @<expr>                  & return @[@<expr>@];
                                                                 \\ \hlx{v}
     @|break|    & ---                      & break;             \\ \hlx{v}
@@ -933,6 +935,8 @@ Temporary names are represented by objects which implement a simple protocol.
     @|if|       & @<cond> @<conseq> @|\&optional| @<alt>
                                            & if (@<cond>) @<conseq>
                                              @[else @<alt>@]    \\ \hlx{v}
+    @|for|      & @<init> @<cond> @<update> @<body> &
+      for (@<init>; @<cond>; @<update>) @<body>                 \\ \hlx{v}
     @|while|    & @<cond> @<body>          & while (@<cond>) @<body>
                                                                 \\ \hlx{v}
     @|do-while| & @<body> @<cond>          & do @<body> while (@<cond>);
index 186f22583eb7c187a4b49c6733c05acf3a2722b9..e663fb566b9a2d4252785d4be9d691421785fa04 100644 (file)
@@ -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~@_~@<? ~A ~_: ~A~:>~:>" #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.