mescc: Remove duplication.
* module/language/c99/compiler.mes (expr->arg): Use expr->accu for most expressions.
This commit is contained in:
parent
da768a9f12
commit
71da0bfb78
|
@ -177,6 +177,7 @@ mini-mes: scaffold/mini-mes.c
|
||||||
rm -f mes.o
|
rm -f mes.o
|
||||||
chmod +x $@
|
chmod +x $@
|
||||||
|
|
||||||
|
guile-mini-mes: module/language/c99/compiler.mes # and others...
|
||||||
guile-mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i
|
guile-mini-mes: mini-mes.h mini-mes.i mini-mes.environment.i mini-mes.symbols.i
|
||||||
guile-mini-mes: gc.c mini-gc.h mini-gc.i mini-gc.environment.i
|
guile-mini-mes: gc.c mini-gc.h mini-gc.i mini-gc.environment.i
|
||||||
guile-mini-mes: vector.c mini-vector.h mini-vector.i mini-vector.environment.i
|
guile-mini-mes: vector.c mini-vector.h mini-vector.i mini-vector.environment.i
|
||||||
|
|
|
@ -255,28 +255,18 @@
|
||||||
(if local ((push-local-de-ref (.locals info)) local)
|
(if local ((push-local-de-ref (.locals info)) local)
|
||||||
((push-global-de-ref (.globals info)) o)))))
|
((push-global-de-ref (.globals info)) o)))))
|
||||||
|
|
||||||
|
(define (expr->arg info)
|
||||||
|
(lambda (o)
|
||||||
|
(let ((info ((expr->accu info) o)))
|
||||||
|
(clone info #:text (append (.text info)
|
||||||
|
(list (lambda (f g ta t d)
|
||||||
|
(i386:push-accu))))))))
|
||||||
|
|
||||||
(define (expr->arg info) ;; FIXME: get Mes curried-definitions
|
(define (expr->arg info) ;; FIXME: get Mes curried-definitions
|
||||||
(lambda (o)
|
(lambda (o)
|
||||||
(let ((text (.text info)))
|
(let ((text (.text info)))
|
||||||
;;(stderr "expr->arg o=~s\n" o)
|
;;(stderr "expr->arg o=~s\n" o)
|
||||||
(pmatch o
|
(pmatch o
|
||||||
((p-expr (fixed ,value))
|
|
||||||
(let ((value (cstring->number value)))
|
|
||||||
(clone info #:text (append text
|
|
||||||
(list
|
|
||||||
(lambda (f g ta t d)
|
|
||||||
(append
|
|
||||||
(i386:value->accu value)
|
|
||||||
(i386:push-accu))))))))
|
|
||||||
|
|
||||||
((neg (p-expr (fixed ,value)))
|
|
||||||
(let ((value (- (cstring->number value))))
|
|
||||||
(clone info #:text (append text
|
|
||||||
(list
|
|
||||||
(lambda (f g ta t d)
|
|
||||||
(append
|
|
||||||
(i386:value->accu value)
|
|
||||||
(i386:push-accu))))))))
|
|
||||||
|
|
||||||
((p-expr (string ,string))
|
((p-expr (string ,string))
|
||||||
(clone info #:text (append text ((push-global-address info) (add-s:-prefix string)))))
|
(clone info #:text (append text ((push-global-address info) (add-s:-prefix string)))))
|
||||||
|
@ -284,45 +274,10 @@
|
||||||
((p-expr (ident ,name))
|
((p-expr (ident ,name))
|
||||||
(clone info #:text (append text ((push-ident info) name))))
|
(clone info #:text (append text ((push-ident info) name))))
|
||||||
|
|
||||||
;; g_cells[0]
|
((cast (type-name (decl-spec-list (type-spec (fixed-type _)))
|
||||||
((array-ref (p-expr (fixed ,index)) (p-expr (ident ,array)))
|
(abs-declr (pointer)))
|
||||||
(let* ((index (cstring->number index))
|
,cast)
|
||||||
(type (ident->type info array))
|
((expr->arg info) cast))
|
||||||
(size (type->size info type)))
|
|
||||||
(clone info
|
|
||||||
#:text (append text
|
|
||||||
((ident->base info) array)
|
|
||||||
(list
|
|
||||||
(lambda (f g ta t d)
|
|
||||||
(append
|
|
||||||
(i386:value->accu (* size index))
|
|
||||||
(if (eq? size 1)
|
|
||||||
(i386:byte-base-mem->accu)
|
|
||||||
(i386:base-mem->accu))
|
|
||||||
(i386:push-accu))))))))
|
|
||||||
|
|
||||||
;; g_cells[i]
|
|
||||||
((array-ref (p-expr (ident ,index)) (p-expr (ident ,array)))
|
|
||||||
(let* ((type (ident->type info array))
|
|
||||||
(size (type->size info type)))
|
|
||||||
(clone info #:text (append text
|
|
||||||
((ident->base info) index)
|
|
||||||
(list (lambda (f g ta t d)
|
|
||||||
(append
|
|
||||||
(i386:base->accu)
|
|
||||||
(if (< size 4) '()
|
|
||||||
(append ;; FIXME
|
|
||||||
(i386:accu+accu)
|
|
||||||
(if (= size 12) (i386:accu+base)
|
|
||||||
'()))))))
|
|
||||||
((ident->base info) array)
|
|
||||||
(list (lambda (f g ta t d)
|
|
||||||
(if (eq? size 1)
|
|
||||||
(i386:byte-base-mem->accu)
|
|
||||||
(i386:base-mem->accu))))
|
|
||||||
(list
|
|
||||||
(lambda (f g ta t d)
|
|
||||||
(i386:push-accu)))))))
|
|
||||||
|
|
||||||
((de-ref (p-expr (ident ,name)))
|
((de-ref (p-expr (ident ,name)))
|
||||||
(clone info #:text (append text ((push-ident-de-ref info) name))))
|
(clone info #:text (append text ((push-ident-de-ref info) name))))
|
||||||
|
@ -330,63 +285,11 @@
|
||||||
((ref-to (p-expr (ident ,name)))
|
((ref-to (p-expr (ident ,name)))
|
||||||
(clone info #:text (append text ((push-ident-address info) name))))
|
(clone info #:text (append text ((push-ident-address info) name))))
|
||||||
|
|
||||||
;; f (car (x))
|
(_ (let* ((info ((expr->accu info) o))
|
||||||
((fctn-call . ,call)
|
(text (.text info)))
|
||||||
(let* (;;(empty (clone info #:text '()))
|
(clone info #:text (append text
|
||||||
;;(info ((ast->info empty) o))
|
(list (lambda (f g ta t d)
|
||||||
(info ((ast->info info) o))
|
(i386:push-accu)))))))))))
|
||||||
(text (.text info)))
|
|
||||||
(clone info
|
|
||||||
#:text (append text
|
|
||||||
(list
|
|
||||||
(lambda (f g ta t d)
|
|
||||||
(i386:push-accu)))))))
|
|
||||||
|
|
||||||
;; f (CAR (x))
|
|
||||||
((d-sel . ,d-sel)
|
|
||||||
(let* (;;(empty (clone info #:text '()))
|
|
||||||
;;(expr ((expr->accu empty) `(d-sel ,@d-sel)))
|
|
||||||
(expr ((expr->accu info) `(d-sel ,@d-sel)))
|
|
||||||
(text (.text expr)))
|
|
||||||
(clone info
|
|
||||||
#:text (append text
|
|
||||||
(list (lambda (f g ta t d)
|
|
||||||
(i386:push-accu)))))))
|
|
||||||
|
|
||||||
|
|
||||||
((p-expr (char ,char))
|
|
||||||
(let ((char (char->integer (car (string->list char)))))
|
|
||||||
(clone info
|
|
||||||
#:text (append text
|
|
||||||
(list (lambda (f g ta t d)
|
|
||||||
(append
|
|
||||||
(i386:value->accu char)
|
|
||||||
(i386:push-accu)))))))
|
|
||||||
)
|
|
||||||
;; f (0 + x)
|
|
||||||
;;; aargh
|
|
||||||
;;;((add (p-expr (fixed ,value)) (d-sel (ident cdr) (array-ref (p-expr (ident x)) (p-expr (ident g_cells))))))
|
|
||||||
|
|
||||||
((cast (type-name (decl-spec-list (type-spec (fixed-type _)))
|
|
||||||
(abs-declr (pointer)))
|
|
||||||
,cast)
|
|
||||||
((expr->arg info) cast))
|
|
||||||
|
|
||||||
(_
|
|
||||||
;; (stderr "catch: expr->arg=~s\n" o)
|
|
||||||
(let* ((info ((expr->accu info) o))
|
|
||||||
(text (.text info)))
|
|
||||||
(clone info
|
|
||||||
#:text (append text
|
|
||||||
(list (lambda (f g ta t d)
|
|
||||||
(append
|
|
||||||
(i386:accu-zero?)
|
|
||||||
(i386:push-accu))))))))
|
|
||||||
|
|
||||||
(_
|
|
||||||
(stderr "SKIP: expr->arg=~s\n" o)
|
|
||||||
barf
|
|
||||||
0)))))
|
|
||||||
|
|
||||||
;; FIXME: see ident->base
|
;; FIXME: see ident->base
|
||||||
(define (ident->accu info)
|
(define (ident->accu info)
|
||||||
|
|
Loading…
Reference in New Issue