mescc: Tinycc support: multi-line strings.

* module/language/c99/compiler.mes (initzer->data, expr->global):
  Handle multi-line strings.
* scaffold/tests/74-multi-line-string.c: New file.
* make.scm (add-scaffold-test): Build it.
This commit is contained in:
Jan Nieuwenhuizen 2017-07-16 22:59:07 +02:00
parent 3ae27f52e4
commit 9b66421ce8
3 changed files with 45 additions and 1 deletions

View File

@ -152,7 +152,8 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
'("70-printf"
"71-struct-array"
"72-typedef-struct-def"
"73-union"))
"73-union"
"74-multi-line-string"))
(add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))

View File

@ -1847,6 +1847,7 @@
((initzer (neg (p-expr (fixed ,value)))) (int->bv32 (- (cstring->number value))))
((initzer (ref-to (p-expr (ident ,name)))) `(,name #f #f #f))
((initzer (p-expr (string ,string))) `((#:string ,string) #f #f #f))
((initzer (p-expr (string . ,strings))) `((#:string ,(string-join strings "")) #f #f #f))
((initzer (initzer-list . ,initzers)) (append-map (initzer->data info) initzers))
(() (int->bv32 0))
(_ (error "initzer->data: unsupported: " o)))))
@ -1867,6 +1868,11 @@
(let ((g `(#:string ,string)))
(or (assoc g globals)
(string->global-entry string))))
((p-expr (string . ,strings))
(let* ((string (string-join strings ""))
(g `(#:string ,string)))
(or (assoc g globals)
(string->global-entry string))))
;;((p-expr (fixed ,value)) (int->global-entry (cstring->number value)))
(_ #f))))

View File

@ -0,0 +1,37 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include "30-test.i"
#include <stdio.h>
#include <string.h>
char const* help =
"All"
" your"
" base"
" are";
int
test ()
{
if (strcmp (help, "All your base are")) return 1;
return 0;
}