From 345d0d841322dc3767038075bac37b97f4a54035 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 14 May 2018 22:37:53 +0200 Subject: [PATCH] mescc: Tinycc support: Compound strings as function argument. * module/language/c99/compiler.mes (expr->accu): Handle compound strings as function argument. * module/mes/M1.mes (object->M1): Call error when string not found. * scaffold/tests/t.c: Test it. --- module/language/c99/compiler.mes | 9 ++++++--- module/mes/M1.mes | 2 +- scaffold/tests/t.c | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 90d24f27..a544757e 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -942,6 +942,12 @@ (info (clone info #:globals globals))) (append-text info (list (i386:label->accu `(#:string ,string)))))) + ((p-expr (string . ,strings)) + (let* ((string (apply string-append strings)) + (globals ((globals:add-string globals) string)) + (info (clone info #:globals globals))) + (append-text info (list (i386:label->accu `(#:string ,string)))))) + ((p-expr (fixed ,value)) (let ((value (cstring->number value))) (append-text info (wrap-as (i386:value->accu value))))) @@ -954,9 +960,6 @@ (let ((char (char->integer (car (string->list char))))) (append-text info (wrap-as (i386:value->accu char))))) - ((p-expr (string . ,strings)) - (append-text info (list (i386:label->accu `(#:string ,(apply string-append strings)))))) - (,char (guard (char? char)) (append-text info (wrap-as (i386:value->accu char)))) ((p-expr (ident ,name)) diff --git a/module/mes/M1.mes b/module/mes/M1.mes index 3280cd58..2713df2d 100644 --- a/module/mes/M1.mes +++ b/module/mes/M1.mes @@ -110,7 +110,7 @@ (let ((index (list-index (lambda (s) (equal? s o)) strings))) (if index (string-append "_string_" file-name "_" (number->string index)) - ""))) + (error "no such string:" o)))) (define (text->M1 o) (cond ((char? o) (text->M1 (char->integer o))) diff --git a/scaffold/tests/t.c b/scaffold/tests/t.c index a92504c0..9dad4c89 100644 --- a/scaffold/tests/t.c +++ b/scaffold/tests/t.c @@ -153,6 +153,8 @@ main (int argc, char* argv[]) if (lst[i+1] != i) return 30 + i; } + puts ("foo" + "bar"); return 0; }