mescc: Remove jump calculation, use labels: for.

* module/language/c99/compiler.mes (ast->info): Refactor (for ...)
  using test-jump-label->info.
This commit is contained in:
Jan Nieuwenhuizen 2017-06-12 19:46:35 +02:00
parent 0f19aba1a8
commit 4e564c3ce3

View file

@ -1481,43 +1481,29 @@
clauses-info)) clauses-info))
((for ,init ,test ,step ,body) ((for ,init ,test ,step ,body)
(let* ((info (clone info #:text '())) ;; FIXME: goto in body... (let* ((source (with-output-to-string (lambda () (pretty-print-c99 `(for ,init ,test ,step (ellipsis))))))
(info (append-text info (wrap-as `(#:comment ,source))))
(here (number->string (length text)))
(loop-label (string-append (.function info) "_loop_" here))
(continue-label (string-append (.function info) "_continue_" here))
(initial-skip-label (string-append (.function info) "_initial_skip_" here))
(break-label (string-append (.function info) "_break_" here))
(info ((ast->info info) init)) (info ((ast->info info) init))
(info (clone info #:break (cons break-label (.break info))))
(init-text (.text info)) (info (clone info #:continue (cons continue-label (.continue info))))
(init-locals (.locals info)) (info (append-text info (wrap-as (i386:jump-label `(#:local ,initial-skip-label)))))
(info (clone info #:text '())) (info (append-text info (wrap-as `(#:label ,loop-label))))
(info ((ast->info info) body))
(body-info ((ast->info info) body)) (info (append-text info (wrap-as `(#:label ,continue-label))))
(body-text (.text body-info)) (info ((expr->accu info) step))
(body-length (length (object->list body-text))) (info (append-text info (wrap-as `(#:label ,initial-skip-label))))
(info ((test-jump-label->info info break-label) test))
(step-info ((expr->accu info) step)) (info (append-text info (wrap-as (i386:jump-label `(#:local ,loop-label)))))
(step-text (.text step-info)) (info (append-text info (wrap-as `(#:label ,break-label)))))
(step-length (length (object->list step-text))) (clone info
#:locals locals
(test-jump->info ((test->jump->info info) test)) #:break (cdr (.break info))
(test+jump-info (test-jump->info 0)) #:continue (cdr (.continue info)))))
(test-length (length (object->list (.text test+jump-info))))
(skip-body-text (wrap-as (i386:Xjump (+ body-length step-length))))
(jump-text (wrap-as (i386:Xjump (- (+ body-length step-length test-length)))))
(jump-length (length (object->list jump-text)))
(test-text (.text (test-jump->info jump-length))))
(clone info #:text
(append text
init-text
skip-body-text
body-text
step-text
test-text
jump-text)
#:globals (append globals (list-tail (.globals body-info) (length globals)))
#:locals locals)))
((while ,test ,body) ((while ,test ,body)
(let* ((source (with-output-to-string (lambda () (pretty-print-c99 `(while ,test (ellipsis)))))) (let* ((source (with-output-to-string (lambda () (pretty-print-c99 `(while ,test (ellipsis))))))