From 9b66421ce8b0d578369bda22b0d8fef2d4749b13 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 16 Jul 2017 22:59:07 +0200 Subject: [PATCH] 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. --- make.scm | 3 ++- module/language/c99/compiler.mes | 6 +++++ scaffold/tests/74-multi-line-string.c | 37 +++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 scaffold/tests/74-multi-line-string.c diff --git a/make.scm b/make.scm index 1203c121..0428fbc9 100755 --- a/make.scm +++ b/make.scm @@ -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))) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 273f33ca..c9874eb7 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -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)))) diff --git a/scaffold/tests/74-multi-line-string.c b/scaffold/tests/74-multi-line-string.c new file mode 100644 index 00000000..e3d1c875 --- /dev/null +++ b/scaffold/tests/74-multi-line-string.c @@ -0,0 +1,37 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2017 Jan Nieuwenhuizen + * + * 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 . + */ + +#include "30-test.i" +#include +#include + +char const* help = + "All" + " your" + " base" + " are"; + +int +test () +{ + if (strcmp (help, "All your base are")) return 1; + + return 0; +}