mescc: Tinycc support: Implement (foo--)->bar and permutations.
* module/language/c99/info.scm (clone): Add post field. (make): Handle post parameter. * module/language/c99/compiler.mes (clone): Handle post parameter. (expr->accu*): Set it to support foo--/foo--. (expr->accu): Read it to support foo--/foo--. * scaffold/tests/7o-struct-pre-post.c: Test it. * build-aux/check-mescc.sh: Run it.
This commit is contained in:
parent
330404125e
commit
057607ca0a
|
@ -111,6 +111,7 @@ t
|
|||
7l-struct-any-size-array
|
||||
7m-struct-char-array-assign
|
||||
7n-struct-struct-array
|
||||
7o-struct-pre-post
|
||||
80-setjmp
|
||||
81-qsort
|
||||
82-define
|
||||
|
|
|
@ -115,6 +115,7 @@
|
|||
(statics (.statics o))
|
||||
(function (.function o))
|
||||
(text (.text o))
|
||||
(post (.post o))
|
||||
(break (.break o))
|
||||
(continue (.continue o)))
|
||||
(let-keywords rest
|
||||
|
@ -127,9 +128,10 @@
|
|||
(statics statics)
|
||||
(function function)
|
||||
(text text)
|
||||
(post post)
|
||||
(break break)
|
||||
(continue continue))
|
||||
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:statics statics #:function function #:text text #:break break #:continue continue))))))
|
||||
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:statics statics #:function function #:text text #:post post #:break break #:continue continue))))))
|
||||
|
||||
(define (ident->constant name value)
|
||||
(cons name value))
|
||||
|
@ -810,6 +812,66 @@
|
|||
(info (expr->base array info)))
|
||||
(append-text info (wrap-as (i386:accu+base)))))
|
||||
|
||||
;;((cast (type-name (decl-spec-list (type-spec (typename "Elf32_Rel"))) (abs-declr (pointer))) (add (i-sel (ident "data") (p-expr (ident "sr"))) (p-expr (ident "a")))))
|
||||
|
||||
((cast ,type ,expr)
|
||||
(expr->accu expr info))
|
||||
|
||||
;; ((post-dec (p-expr (ident "vtop"))))
|
||||
|
||||
;; ((cast ,type ,expr)
|
||||
;; (expr->accu `(ref-to ,expr) info))
|
||||
|
||||
((pre-dec ,expr)
|
||||
(let* ((rank (expr->rank info expr))
|
||||
(size (cond ((= rank 1) (ast-type->size info expr))
|
||||
((> rank 1) 4)
|
||||
(else 1)))
|
||||
(info ((expr-add info) expr (- size)))
|
||||
(info (append (expr->accu* expr info))))
|
||||
info))
|
||||
|
||||
((pre-inc ,expr)
|
||||
(let* ((rank (expr->rank info expr))
|
||||
(size (cond ((= rank 1) (ast-type->size info expr))
|
||||
((> rank 1) 4)
|
||||
(else 1)))
|
||||
(info ((expr-add info) expr size))
|
||||
(info (append (expr->accu* expr info))))
|
||||
info))
|
||||
|
||||
((post-dec ,expr)
|
||||
(let* ((info (expr->accu* expr info))
|
||||
(info (append-text info (wrap-as (i386:push-accu))))
|
||||
(post (clone info #:text '()))
|
||||
(post (append-text post (ast->comment o)))
|
||||
(post (append-text post (wrap-as (i386:pop-base))))
|
||||
(post (append-text post (wrap-as (i386:push-accu))))
|
||||
(post (append-text post (wrap-as (i386:base->accu))))
|
||||
(rank (expr->rank post expr))
|
||||
(size (cond ((= rank 1) (ast-type->size post expr))
|
||||
((> rank 1) 4)
|
||||
(else 1)))
|
||||
(post ((expr-add post) expr (- size)))
|
||||
(post (append-text post (wrap-as (i386:pop-accu)))))
|
||||
(clone info #:post (.text post))))
|
||||
|
||||
((post-inc ,expr)
|
||||
(let* ((info (expr->accu* expr info))
|
||||
(info (append-text info (wrap-as (i386:push-accu))))
|
||||
(post (clone info #:text '()))
|
||||
(post (append-text post (ast->comment o)))
|
||||
(post (append-text post (wrap-as (i386:pop-base))))
|
||||
(post (append-text post (wrap-as (i386:push-accu))))
|
||||
(post (append-text post (wrap-as (i386:base->accu))))
|
||||
(rank (expr->rank post expr))
|
||||
(size (cond ((= rank 1) (ast-type->size post expr))
|
||||
((> rank 1) 4)
|
||||
(else 1)))
|
||||
(post ((expr-add post) expr size))
|
||||
(post (append-text post (wrap-as (i386:pop-accu)))))
|
||||
(clone info #:post (.text post))))
|
||||
|
||||
(_ (error "expr->accu*: not supported: " o))))
|
||||
|
||||
(define (expr-add info)
|
||||
|
@ -820,9 +882,9 @@
|
|||
|
||||
(define (expr->accu o info)
|
||||
(let ((locals (.locals info))
|
||||
(constants (.constants info))
|
||||
(text (.text info))
|
||||
(globals (.globals info)))
|
||||
(define (helper)
|
||||
(pmatch o
|
||||
((expr) info)
|
||||
|
||||
|
@ -1205,7 +1267,11 @@
|
|||
(_ (let ((info (expr->base* a info)))
|
||||
(accu->base-mem*n info (min size (max 4 size-b)))))))) ;; FIXME: long long = int
|
||||
|
||||
(_ (error "expr->accu: not supported: " o)))))
|
||||
(_ (error "expr->accu: not supported: " o))))
|
||||
|
||||
(let ((info (helper)))
|
||||
(if (null? (.post info)) info
|
||||
(append-text (clone info #:post '()) (.post info))))))
|
||||
|
||||
(define (expr->base o info)
|
||||
(let* ((info (append-text info (wrap-as (i386:push-accu))))
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
.function
|
||||
.statics
|
||||
.text
|
||||
.post
|
||||
.break
|
||||
.continue
|
||||
|
||||
|
@ -114,7 +115,7 @@
|
|||
(mes-use-module (mes optargs))))
|
||||
|
||||
(define-immutable-record-type <info>
|
||||
(make-<info> types constants functions globals locals statics function text break continue)
|
||||
(make-<info> types constants functions globals locals statics function text post break continue)
|
||||
info?
|
||||
(types .types)
|
||||
(constants .constants)
|
||||
|
@ -124,11 +125,12 @@
|
|||
(statics .statics)
|
||||
(function .function)
|
||||
(text .text)
|
||||
(post .post)
|
||||
(break .break)
|
||||
(continue .continue))
|
||||
|
||||
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (statics '()) (function #f) (text '()) (break '()) (continue '()))
|
||||
(make-<info> types constants functions globals locals statics function text break continue))
|
||||
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (statics '()) (function #f) (text '()) (post '()) (break '()) (continue '()))
|
||||
(make-<info> types constants functions globals locals statics function text post break continue))
|
||||
|
||||
;; ("int" . ,(make-type 'builtin 4 #f 0 #f))
|
||||
;; (make-type 'enum 4 0 fields)
|
||||
|
|
39
scaffold/tests/7o-struct-pre-post.c
Normal file
39
scaffold/tests/7o-struct-pre-post.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) 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/>.
|
||||
*/
|
||||
|
||||
// struct foo {int length; char* string; struct foo *next;};
|
||||
// struct foo stack[] = {{20, "foo", 0}, {4, "baaz", 0}, {0, 0, 0}};
|
||||
|
||||
struct info {int flag;};
|
||||
struct foo {int length; char* string; struct info info;};
|
||||
struct foo stack[] = {{3, "foo", {11}},{4, "baar", {12}}};
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
puts (stack[0].string); puts ("\n");
|
||||
puts (stack[1].string); puts ("\n");
|
||||
struct foo* top = &stack[1];
|
||||
int i;
|
||||
i = (top--)->info.flag;
|
||||
top++;
|
||||
int j = (--top)->info.flag;
|
||||
return i - j - 1;
|
||||
}
|
Loading…
Reference in a new issue