mescc: Refactor expr->base.

* module/language/c99/compiler.mes (expr->base): Rename from
  expr->+base.  Use throughout.
This commit is contained in:
Jan Nieuwenhuizen 2017-04-07 14:41:47 +02:00
parent c4697b0e9d
commit 1eeec4a327

View file

@ -633,10 +633,8 @@
(when (not (equal? op "=")) (when (not (equal? op "="))
(stderr "OOOPS0.0: op=~s\n" op) (stderr "OOOPS0.0: op=~s\n" op)
barf) barf)
(let* ((empty (clone info #:text '())) (let ((info ((expr->base info) b)))
(base ((expr->base empty) b))) (append-text info (append ((base->ident-address info) name)
(append-text info (append (.text base)
((base->ident-address info) name)
((ident->accu info) name) ((ident->accu info) name)
((ident-add info) name 1))))) ((ident-add info) name 1)))))
@ -645,10 +643,8 @@
(when (not (equal? op "=")) (when (not (equal? op "="))
(stderr "OOOPS0.0: op=~s\n" op) (stderr "OOOPS0.0: op=~s\n" op)
barf) barf)
(let* ((empty (clone info #:text '())) (let ((info ((expr->base info) b)))
(base ((expr->base empty) b))) (append-text info (append ((base->ident-address info) name)
(append-text info (append (.text base)
((base->ident-address info) name)
((ident->accu info) name) ((ident->accu info) name)
((ident-add info) name -1))))) ((ident-add info) name -1)))))
@ -658,17 +654,18 @@
(when (not (equal? op "=")) (when (not (equal? op "="))
(stderr "OOOPS0: op=~s\n" op) (stderr "OOOPS0: op=~s\n" op)
barf) barf)
(let* ((empty (clone info #:text '())) (let* (;;(empty (clone info #:text '()))
(expr ((expr->accu* empty) `(d-sel (ident ,field) ,@d-sel))) ;; <-OFFSET ;;(expr ((expr->accu* empty) `(d-sel (ident ,field) ,@d-sel))) ;; <-OFFSET
(base ((expr->base empty) b)) (info ((expr->accu info) b))
(info (append-text info (wrap-as (i386:push-accu))))
(info ((expr->accu* info) `(d-sel (ident ,field) ,@d-sel))) ;; <-OFFSET
(info (append-text info (wrap-as (i386:pop-base))))
(type (list "struct" "scm")) ;; FIXME (type (list "struct" "scm")) ;; FIXME
(fields (type->description info type)) (fields (type->description info type))
(size (type->size info type)) (size (type->size info type))
(field-size 4) ;; FIXME:4, not fixed (field-size 4) ;; FIXME:4, not fixed
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b)))))))) ) (offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b)))))))) )
(append-text info (append (.text expr) (append-text info (wrap-as (i386:base->accu-address))))) ; FIXME: size
(.text base)
(wrap-as (i386:base->accu-address)))))) ; FIXME: size
;; i = 0; ;; i = 0;
@ -681,10 +678,8 @@
(not (equal? op "-="))) (not (equal? op "-=")))
(stderr "OOOPS1: op=~s\n" op) (stderr "OOOPS1: op=~s\n" op)
barf) barf)
(let* ((empty (clone info #:text '())) (let ((info ((expr->base info) b)))
(base ((expr->base empty) b))) (append-text info (append (if (equal? op "=") '()
(append-text info (append (.text base)
(if (equal? op "=") '()
(append ((ident->accu info) name) (append ((ident->accu info) name)
(wrap-as (append (if (equal? op "+=") (i386:accu+base) (wrap-as (append (if (equal? op "+=") (i386:accu+base)
(i386:accu-base)) (i386:accu-base))
@ -698,10 +693,8 @@
(when (not (equal? op "=")) (when (not (equal? op "="))
(stderr "OOOPS2: op=~s\n" op) (stderr "OOOPS2: op=~s\n" op)
barf) barf)
(let* ((empty (clone info #:text '())) (let ((info ((expr->base info) b)))
(base ((expr->base empty) b))) (append-text info (append ;;assign:
(append-text info (append (.text base)
;;assign:
((base->ident-address info) array) ((base->ident-address info) array)
(wrap-as (i386:base->accu)))))) (wrap-as (i386:base->accu))))))
@ -711,7 +704,7 @@
(stderr "OOOPS3: op=~s\n" op) (stderr "OOOPS3: op=~s\n" op)
barf) barf)
(let* ((info ((expr->accu* info) `(array-ref ,index (p-expr (ident ,array))))) (let* ((info ((expr->accu* info) `(array-ref ,index (p-expr (ident ,array)))))
(info ((expr->+base info) b)) (info ((expr->base info) b))
(type (ident->type info array)) (type (ident->type info array))
(size (type->size info type)) (size (type->size info type))
(ptr (ident->pointer info array))) (ptr (ident->pointer info array)))
@ -733,7 +726,7 @@
barf barf
info))))) info)))))
(define (expr->+base info) (define (expr->base info)
(lambda (o) (lambda (o)
(let* ((info (append-text info (wrap-as (i386:push-accu)))) (let* ((info (append-text info (wrap-as (i386:push-accu))))
(info ((expr->accu info) o)) (info ((expr->accu info) o))
@ -743,7 +736,7 @@
(define (binop->accu info) (define (binop->accu info)
(lambda (a b c) (lambda (a b c)
(let* ((info ((expr->accu info) a)) (let* ((info ((expr->accu info) a))
(info ((expr->+base info) b))) (info ((expr->base info) b)))
(append-text info (wrap-as c))))) (append-text info (wrap-as c)))))
(define (append-text info text) (define (append-text info text)
@ -752,15 +745,6 @@
(define (wrap-as o) (define (wrap-as o)
(list (lambda (f g ta t d) o))) (list (lambda (f g ta t d) o)))
(define (expr->base info) ;; JUNKME
(lambda (o)
(let ((info ((expr->accu info) o)))
(clone info
#:text (append (wrap-as (i386:push-accu))
(.text info)
(wrap-as (append (i386:accu->base)
(i386:pop-accu))))))))
(define (expr->accu* info) (define (expr->accu* info)
(lambda (o) (lambda (o)
;; (stderr "expr->accu* o=~s\n" o) ;; (stderr "expr->accu* o=~s\n" o)