* passes tests, but fails to compile psyntax.
This commit is contained in:
		
							parent
							
								
									fa6e499b22
								
							
						
					
					
						commit
						f766ca1148
					
				|  | @ -117,19 +117,57 @@ | ||||||
|   (Program x)) |   (Program x)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| (module (must-open-code? prim-context) | (module (must-open-code? prim-context  | ||||||
|   (define prims |          library-primitive?) | ||||||
|     '([$vector-ref       v] |   (define core-prims | ||||||
|  |     '([pair?             p] | ||||||
|  |       [vector?           p] | ||||||
|  |       [null?             p] | ||||||
|  |       [eof-object?       p] | ||||||
|  |       [procedure?        p] | ||||||
|  |       [symbol?           p] | ||||||
|  |       [boolean?          p] | ||||||
|  |       [string?           p] | ||||||
|  |       [char?             p] | ||||||
|  |       [fixnum?           p] | ||||||
|  |       [string?           p] | ||||||
|  |       [immediate?        p] | ||||||
|  |       [char?             p] | ||||||
|  |       [eq?               p] | ||||||
|  |       [not             not] | ||||||
|  |       [void              v] | ||||||
|  |       [cons              v] | ||||||
|  |       [$car              v] | ||||||
|  |       [$cdr              v] | ||||||
|  |       [$vector-ref       v] | ||||||
|       [$vector-set!      e] |       [$vector-set!      e] | ||||||
|  | 
 | ||||||
|  |       ;;; ports | ||||||
|  |       [output-port?      p] | ||||||
|  |       [input-port?       p] | ||||||
|  |       [port?             p] | ||||||
|  | 
 | ||||||
|       [$cpref            v] |       [$cpref            v] | ||||||
|       [$cpset!           e] |       [$cpset!           e] | ||||||
|       [$make-cp          v])) |       [$make-cp          v] | ||||||
|  |       [$closure-code     v] | ||||||
|  |       [$code-freevars    v] | ||||||
|  |       [primitive-set!    e] | ||||||
|  |       )) | ||||||
|  |   (define library-prims | ||||||
|  |     '(vector | ||||||
|  |       list | ||||||
|  |       not | ||||||
|  |       car cdr | ||||||
|  |       )) | ||||||
|   (define (must-open-code? x) |   (define (must-open-code? x) | ||||||
|     (and (assq x prims) #t)) |     (and (assq x core-prims) #t)) | ||||||
|  |   (define (library-primitive? x) | ||||||
|  |     (memq x library-prims)) | ||||||
|   (define (prim-context x) |   (define (prim-context x) | ||||||
|     (cond |     (cond | ||||||
|       [(assq x prims) => cadr] |       [(assq x core-prims) => cadr] | ||||||
|       [else (error 'prim-context "~s is not a prim" x)]))) |       [else (error 'prim-context "~s is not a core prim" x)]))) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ;;; the program so far includes both primcalls and funcalls to | ;;; the program so far includes both primcalls and funcalls to | ||||||
|  | @ -163,6 +201,20 @@ | ||||||
|        (for-each check-var free*)] |        (for-each check-var free*)] | ||||||
|       [else (error who "invalid closure ~s" x)])) |       [else (error who "invalid closure ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|  |   (define (mkfuncall op arg*) | ||||||
|  |     (record-case op | ||||||
|  |       [(primref name) | ||||||
|  |        (cond | ||||||
|  |          [(must-open-code? name) | ||||||
|  |           (make-primcall name arg*)] | ||||||
|  |          [(library-primitive? name) | ||||||
|  |           (make-funcall op arg*)] | ||||||
|  |          [(open-codeable? name) | ||||||
|  |           (error 'chaitin-compiler "primitive ~s is not supported" | ||||||
|  |                  name)] | ||||||
|  |          [else (make-funcall op arg*)])] | ||||||
|  |       [else (make-funcall op arg*)])) | ||||||
|  |   ;;; | ||||||
|   (define (Expr x) |   (define (Expr x) | ||||||
|     (record-case x |     (record-case x | ||||||
|       [(constant) x] |       [(constant) x] | ||||||
|  | @ -178,15 +230,11 @@ | ||||||
|        (make-seq (Expr e0) (Expr e1))] |        (make-seq (Expr e0) (Expr e1))] | ||||||
|       [(closure) x] |       [(closure) x] | ||||||
|       [(primcall op arg*) |       [(primcall op arg*) | ||||||
|        (cond |        (mkfuncall (make-primref op) (map Expr arg*))] | ||||||
|          [(must-open-code? op) |  | ||||||
|           (make-primcall op (map Expr arg*))] |  | ||||||
|          [else |  | ||||||
|           (make-funcall (make-primref op) (map Expr arg*))])] |  | ||||||
|       [(forcall op arg*) |       [(forcall op arg*) | ||||||
|        (make-forcall op (map Expr arg*))] |        (make-forcall op (map Expr arg*))] | ||||||
|       [(funcall rator arg*) |       [(funcall rator arg*) | ||||||
|        (make-funcall (Expr rator) (map Expr arg*))] |        (mkfuncall (Expr rator) (map Expr arg*))] | ||||||
|       [(jmpcall label rator arg*) |       [(jmpcall label rator arg*) | ||||||
|        (make-jmpcall label (Expr rator) (map Expr arg*))] |        (make-jmpcall label (Expr rator) (map Expr arg*))] | ||||||
|       [(appcall rator arg*) |       [(appcall rator arg*) | ||||||
|  | @ -377,6 +425,11 @@ | ||||||
|               [(null? rands) (make-constant #t)] |               [(null? rands) (make-constant #t)] | ||||||
|               [else |               [else | ||||||
|                (mkseq (E (car rands)) (f (cdr rands)))]))] |                (mkseq (E (car rands)) (f (cdr rands)))]))] | ||||||
|  |          [(not)  | ||||||
|  |           (make-conditional  | ||||||
|  |             (P (car rands))  | ||||||
|  |             (make-constant #f) | ||||||
|  |             (make-constant #t))] | ||||||
|          [else (error who "invalid context for ~s" op)])]  |          [else (error who "invalid context for ~s" op)])]  | ||||||
|       [else (error who "invalid pred ~s" x)])) |       [else (error who "invalid pred ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|  | @ -404,7 +457,7 @@ | ||||||
|        (make-jmpcall label (V rator) (map V rand*))] |        (make-jmpcall label (V rator) (map V rand*))] | ||||||
|       [(primcall op rands) |       [(primcall op rands) | ||||||
|        (case (prim-context op) |        (case (prim-context op) | ||||||
|          [(p v)  |          [(p v not)  | ||||||
|           (let f ([rands rands]) |           (let f ([rands rands]) | ||||||
|             (cond |             (cond | ||||||
|               [(null? rands) nop] |               [(null? rands) nop] | ||||||
|  | @ -441,6 +494,11 @@ | ||||||
|               [(null? rands) (make-constant (void))] |               [(null? rands) (make-constant (void))] | ||||||
|               [else |               [else | ||||||
|                (mkseq (E (car rands)) (f (cdr rands)))]))] |                (mkseq (E (car rands)) (f (cdr rands)))]))] | ||||||
|  |          [(not)  | ||||||
|  |           (make-conditional  | ||||||
|  |             (P (car rands))  | ||||||
|  |             (make-constant #f) | ||||||
|  |             (make-constant #t))] | ||||||
|          [else (error who "invalid context for ~s" op)])] |          [else (error who "invalid context for ~s" op)])] | ||||||
|       [else (error who "invalid value ~s" x)])) |       [else (error who "invalid value ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|  | @ -472,6 +530,9 @@ | ||||||
|   (define who 'specify-representation) |   (define who 'specify-representation) | ||||||
|   ;;; |   ;;; | ||||||
|   (define fixnum-scale 4) |   (define fixnum-scale 4) | ||||||
|  |   (define fixnum-tag 0) | ||||||
|  |   (define fixnum-mask 3) | ||||||
|  |   (define pcb-dirty-vector-offset 28) | ||||||
|   ;;; |   ;;; | ||||||
|   (define nop (make-primcall 'nop '())) |   (define nop (make-primcall 'nop '())) | ||||||
|   ;;; |   ;;; | ||||||
|  | @ -488,7 +549,28 @@ | ||||||
|         [(null? c) (make-constant nil)] |         [(null? c) (make-constant nil)] | ||||||
|         [else (make-constant (make-object c))]))) |         [else (make-constant (make-object c))]))) | ||||||
|   ;;; |   ;;; | ||||||
|  |   (define (K x) (make-constant x)) | ||||||
|  |   (define (prm op . rands) (make-primcall op rands)) | ||||||
|  |   (define-syntax tbind | ||||||
|  |     (lambda (x)  | ||||||
|  |       (syntax-case x () | ||||||
|  |         [(_ ([lhs* rhs*] ...) b b* ...) | ||||||
|  |          #'(let ([lhs* (unique-var 'lhs*)] ...) | ||||||
|  |              (make-bind (list lhs* ...) | ||||||
|  |                         (list rhs* ...) | ||||||
|  |                 b b* ...))]))) | ||||||
|  |   (define-syntax seq* | ||||||
|  |     (syntax-rules () | ||||||
|  |       [(_ e) e] | ||||||
|  |       [(_ e* ... e)  | ||||||
|  |        (make-seq (seq* e* ...) e)])) | ||||||
|   (define (Effect x) |   (define (Effect x) | ||||||
|  |     (define (mem-assign v x i) | ||||||
|  |       (tbind ([q v]) | ||||||
|  |         (tbind ([t (prm 'int+ x (K i))]) | ||||||
|  |           (make-seq  | ||||||
|  |             (prm 'mset! t (K 0) q) | ||||||
|  |             (prm 'record-effect t))))) | ||||||
|     (record-case x |     (record-case x | ||||||
|       [(bind lhs* rhs* body) |       [(bind lhs* rhs* body) | ||||||
|        (make-bind lhs* (map Value rhs*) (Effect body))] |        (make-bind lhs* (map Value rhs*) (Effect body))] | ||||||
|  | @ -506,13 +588,15 @@ | ||||||
|             (record-case i |             (record-case i | ||||||
|               [(constant i)  |               [(constant i)  | ||||||
|                (unless (fixnum? i) (err x)) |                (unless (fixnum? i) (err x)) | ||||||
|                (make-primcall 'mset! |                (prm 'mset! x  | ||||||
|                  (list x |                   (K (+ (* i wordsize)  | ||||||
|                        (make-constant  |                         (- disp-closure-data closure-tag))) | ||||||
|                          (+ (* i wordsize)  |                   v)] | ||||||
|                           (- disp-closure-data closure-tag))) |  | ||||||
|                        v))] |  | ||||||
|               [else (err x)]))] |               [else (err x)]))] | ||||||
|  |          [(primitive-set!) | ||||||
|  |           (let ([x (Value (car arg*))] [v (Value (cadr arg*))]) | ||||||
|  |             (mem-assign v x  | ||||||
|  |                (- disp-symbol-system-value symbol-tag)))] | ||||||
|          [($vector-set!) |          [($vector-set!) | ||||||
|           (let ([x (Value (car arg*))]  |           (let ([x (Value (car arg*))]  | ||||||
|                 [i (cadr arg*)] |                 [i (cadr arg*)] | ||||||
|  | @ -520,30 +604,13 @@ | ||||||
|             (record-case i |             (record-case i | ||||||
|               [(constant i)  |               [(constant i)  | ||||||
|                (unless (fixnum? i) (err x)) |                (unless (fixnum? i) (err x)) | ||||||
|                (make-primcall 'mset! |                (mem-assign v x  | ||||||
|                  (list x |                   (+ (* i wordsize) | ||||||
|                        (make-constant  |                      (- disp-vector-data vector-tag)))] | ||||||
|                          (+ (* i wordsize)  |  | ||||||
|                           (- disp-vector-data vector-tag))) |  | ||||||
|                        v))] |  | ||||||
|               [else |               [else | ||||||
|                (record-case v |                (mem-assign v  | ||||||
|                  [(constant)  |                   (prm 'int+ x (Value i)) | ||||||
|                   (make-primcall 'mset! |                   (- disp-vector-data vector-tag))]))] | ||||||
|                     (list (make-primcall 'int+  |  | ||||||
|                             (list x (Value i))) |  | ||||||
|                           (make-constant |  | ||||||
|                             (- disp-vector-data vector-tag)) |  | ||||||
|                           v))] |  | ||||||
|                  [else |  | ||||||
|                   (let ([t (unique-var 't)]) |  | ||||||
|                     (make-bind (list t) (list v) |  | ||||||
|                       (make-primcall 'mset! |  | ||||||
|                         (list (make-primcall 'int+  |  | ||||||
|                                 (list x (Value i))) |  | ||||||
|                               (make-constant |  | ||||||
|                                 (- disp-vector-data vector-tag)) |  | ||||||
|                               t))))])]))] |  | ||||||
|          [else (error who "invalid effect prim ~s" op)])] |          [else (error who "invalid effect prim ~s" op)])] | ||||||
|       [(forcall op arg*) |       [(forcall op arg*) | ||||||
|        (error who "effect forcall not supported" op)] |        (error who "effect forcall not supported" op)] | ||||||
|  | @ -557,6 +624,22 @@ | ||||||
|        (make-mvcall (Value rator) (Clambda x Effect))] |        (make-mvcall (Value rator) (Clambda x Effect))] | ||||||
|       [else (error who "invalid pred expr ~s" x)])) |       [else (error who "invalid pred expr ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|  |   (define (tag-test x mask tag) | ||||||
|  |     (if mask | ||||||
|  |         (make-primcall '=  | ||||||
|  |           (list (make-primcall 'logand  | ||||||
|  |                   (list x (make-constant mask))) | ||||||
|  |                 (make-constant tag))) | ||||||
|  |         (make-primcall '= | ||||||
|  |            (list x (make-constant tag))))) | ||||||
|  |   (define (sec-tag-test x pmask ptag smask stag) | ||||||
|  |     (let ([t (unique-var 'tmp)]) | ||||||
|  |       (make-bind (list t) (list x) | ||||||
|  |         (make-conditional  | ||||||
|  |           (tag-test t pmask ptag) | ||||||
|  |           (tag-test (prm 'mref t (K (- ptag))) smask stag) | ||||||
|  |           (make-constant #f))))) | ||||||
|  |   ;;; | ||||||
|   (define (Pred x) |   (define (Pred x) | ||||||
|     (record-case x |     (record-case x | ||||||
|       [(constant) x] |       [(constant) x] | ||||||
|  | @ -569,7 +652,35 @@ | ||||||
|       [(primcall op arg*) |       [(primcall op arg*) | ||||||
|        (case op |        (case op | ||||||
|          [(eq?)  (make-primcall '= (map Value arg*))] |          [(eq?)  (make-primcall '= (map Value arg*))] | ||||||
|  |          [(null?) (prm '= (Value (car arg*)) (K nil))] | ||||||
|  |          [(eof-object?) (prm '= (Value (car arg*)) (K eof))] | ||||||
|          [(neq?) (make-primcall '!= (map Value arg*))] |          [(neq?) (make-primcall '!= (map Value arg*))] | ||||||
|  |          [(pair?)  | ||||||
|  |           (tag-test (Value (car arg*)) pair-mask pair-tag)] | ||||||
|  |          [(procedure?) | ||||||
|  |           (tag-test (Value (car arg*)) closure-mask closure-tag)] | ||||||
|  |          [(symbol?) | ||||||
|  |           (tag-test (Value (car arg*)) symbol-mask symbol-tag)] | ||||||
|  |          [(string?) | ||||||
|  |           (tag-test (Value (car arg*)) string-mask string-tag)] | ||||||
|  |          [(char?) | ||||||
|  |           (tag-test (Value (car arg*)) char-mask char-tag)] | ||||||
|  |          [(boolean?) | ||||||
|  |           (tag-test (Value (car arg*)) bool-mask bool-tag)] | ||||||
|  |          [(fixnum?) | ||||||
|  |           (tag-test (Value (car arg*)) fixnum-mask fixnum-tag)] | ||||||
|  |          [(vector?) | ||||||
|  |           (sec-tag-test (Value (car arg*))  | ||||||
|  |              vector-mask vector-tag fixnum-mask fixnum-tag)] | ||||||
|  |          [(output-port?) | ||||||
|  |           (sec-tag-test (Value (car arg*)) | ||||||
|  |              vector-mask vector-tag #f output-port-tag)] | ||||||
|  |          [(immediate?) | ||||||
|  |           (tbind ([t (Value (car arg*))]) | ||||||
|  |             (make-conditional  | ||||||
|  |               (tag-test t fixnum-mask fixnum-tag) | ||||||
|  |               (make-constant #t) | ||||||
|  |               (tag-test t 7 7)))] | ||||||
|          [else (error who "pred prim ~a not supported" op)])] |          [else (error who "pred prim ~a not supported" op)])] | ||||||
|       [(mvcall rator x) |       [(mvcall rator x) | ||||||
|        (make-mvcall (Value rator) (Clambda x Pred))] |        (make-mvcall (Value rator) (Clambda x Pred))] | ||||||
|  | @ -583,11 +694,9 @@ | ||||||
|       [(constant) (constant-rep x)] |       [(constant) (constant-rep x)] | ||||||
|       [(var)      x] |       [(var)      x] | ||||||
|       [(primref name)   |       [(primref name)   | ||||||
|        (make-primcall 'mref |        (prm 'mref | ||||||
|          (list |            (K (make-object name)) | ||||||
|            (make-constant (make-object name)) |            (K (- disp-symbol-system-value symbol-tag)))] | ||||||
|            (make-constant  |  | ||||||
|              (- disp-symbol-system-value symbol-tag))))] |  | ||||||
|       [(code-loc) (make-constant x)] |       [(code-loc) (make-constant x)] | ||||||
|       [(closure)  (make-constant x)] |       [(closure)  (make-constant x)] | ||||||
|       [(bind lhs* rhs* body) |       [(bind lhs* rhs* body) | ||||||
|  | @ -598,36 +707,42 @@ | ||||||
|        (make-seq (Effect e0) (Value e1))] |        (make-seq (Effect e0) (Value e1))] | ||||||
|       [(primcall op arg*) |       [(primcall op arg*) | ||||||
|        (case op |        (case op | ||||||
|  |          [(void) (K void-object)] | ||||||
|  |          [($car)  | ||||||
|  |           (prm 'mref (Value (car arg*)) (K (- disp-car pair-tag)))] | ||||||
|  |          [($cdr)  | ||||||
|  |           (prm 'mref (Value (car arg*)) (K (- disp-cdr pair-tag)))] | ||||||
|          [($make-cp) |          [($make-cp) | ||||||
|           (let ([label (car arg*)] [len (cadr arg*)]) |           (let ([label (car arg*)] [len (cadr arg*)]) | ||||||
|             (record-case len |             (record-case len | ||||||
|               [(constant i) |               [(constant i) | ||||||
|                (unless (fixnum? i) (err x)) |                (unless (fixnum? i) (err x)) | ||||||
|                (let ([t (unique-var 't)]) |                (tbind ([t (prm 'alloc  | ||||||
|                  (make-bind (list t) |                                (K (align (+ disp-closure-data | ||||||
|                             (list (make-primcall 'alloc |                                             (* i wordsize)))) | ||||||
|                                     (list (make-constant |                                (K closure-tag))]) | ||||||
|                                             (align  |                  (seq* | ||||||
|                                               (+ disp-closure-data |                    (prm 'mset! t  | ||||||
|                                                  (* i wordsize)))) |                         (K (- disp-closure-code closure-tag)) | ||||||
|                                           (make-constant closure-tag)))) |                         (Value label)) | ||||||
|                     (make-seq  |                    t))] | ||||||
|                       (make-primcall 'mset!  |  | ||||||
|                         (list t  |  | ||||||
|                               (make-constant (- disp-closure-code closure-tag)) |  | ||||||
|                               (Value label))) |  | ||||||
|                       t)))] |  | ||||||
|               [else (err x)]))] |               [else (err x)]))] | ||||||
|  |          [(cons) | ||||||
|  |           (tbind ([a (Value (car arg*))] | ||||||
|  |                   [d (Value (cadr arg*))]) | ||||||
|  |             (tbind ([t (prm 'alloc (K pair-size) (K pair-tag))]) | ||||||
|  |               (seq* | ||||||
|  |                 (prm 'mset! t (K (- disp-car pair-tag)) a) | ||||||
|  |                 (prm 'mset! t (K (- disp-cdr pair-tag)) d) | ||||||
|  |                 t)))] | ||||||
|          [($cpref)  |          [($cpref)  | ||||||
|           (let ([a0 (car arg*)] [a1 (cadr arg*)]) |           (let ([a0 (car arg*)] [a1 (cadr arg*)]) | ||||||
|             (record-case a1 |             (record-case a1 | ||||||
|               [(constant i)  |               [(constant i)  | ||||||
|                (unless (fixnum? i) (err x)) |                (unless (fixnum? i) (err x)) | ||||||
|                (make-primcall 'mref  |                (prm 'mref (Value a0)  | ||||||
|                   (list (Value a0)  |                   (K (+ (- disp-closure-data closure-tag)  | ||||||
|                         (make-constant  |                         (* i wordsize))))] | ||||||
|                           (+ (- disp-closure-data closure-tag) |  | ||||||
|                              (* i wordsize) ))))] |  | ||||||
|               [else (err x)]))] |               [else (err x)]))] | ||||||
|          [($vector-ref)  |          [($vector-ref)  | ||||||
|           (let ([a0 (car arg*)] [a1 (cadr arg*)]) |           (let ([a0 (car arg*)] [a1 (cadr arg*)]) | ||||||
|  | @ -646,6 +761,16 @@ | ||||||
|                                 (Value a1))) |                                 (Value a1))) | ||||||
|                         (make-constant  |                         (make-constant  | ||||||
|                           (- disp-vector-data vector-tag))))]))] |                           (- disp-vector-data vector-tag))))]))] | ||||||
|  |          [($closure-code) | ||||||
|  |           (prm 'int+  | ||||||
|  |                (prm 'mref | ||||||
|  |                     (Value (car arg*))  | ||||||
|  |                     (K (- disp-closure-code closure-tag))) | ||||||
|  |                (K (- vector-tag disp-code-data)))] | ||||||
|  |          [($code-freevars) | ||||||
|  |           (prm 'mref  | ||||||
|  |                (Value (car arg*)) | ||||||
|  |                (K (- disp-code-freevars vector-tag)))] | ||||||
|          [else (error who "value prim ~a not supported" (unparse x))])] |          [else (error who "value prim ~a not supported" (unparse x))])] | ||||||
|       [(forcall op arg*) |       [(forcall op arg*) | ||||||
|        (error who "value forcall not supported" op)] |        (error who "value forcall not supported" op)] | ||||||
|  | @ -681,7 +806,6 @@ | ||||||
|          (Value body))] |          (Value body))] | ||||||
|       [else (error who "invalid program ~s" x)])) |       [else (error who "invalid program ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|   (print-code x) |  | ||||||
|   (Program x)) |   (Program x)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -714,7 +838,8 @@ | ||||||
|       [else |       [else | ||||||
|        (cond |        (cond | ||||||
|          [(or (constant? x) (var? x)) (k x)] |          [(or (constant? x) (var? x)) (k x)] | ||||||
|          [(or (funcall? x) (primcall? x)) |          [(or (funcall? x) (primcall? x) (jmpcall? x) | ||||||
|  |               (conditional? x)) | ||||||
|           (let ([t (unique-var 'tmp)]) |           (let ([t (unique-var 'tmp)]) | ||||||
|             (do-bind (list t) (list x) |             (do-bind (list t) (list x) | ||||||
|               (k t)))] |               (k t)))] | ||||||
|  | @ -739,25 +864,28 @@ | ||||||
|             (values (cons (car regs) r*) |             (values (cons (car regs) r*) | ||||||
|                     (cons (car args) rl*) |                     (cons (car args) rl*) | ||||||
|                     f*))]))) |                     f*))]))) | ||||||
|  |   (define (do-bind-frmt* nf* v* ac) | ||||||
|  |     (cond | ||||||
|  |       [(null? nf*) ac] | ||||||
|  |       [else | ||||||
|  |        (let ([t (unique-var 't)]) | ||||||
|  |          (do-bind (list t) (list (car v*)) | ||||||
|  |            (make-seq | ||||||
|  |              (make-set (car nf*) t) | ||||||
|  |              (do-bind-frmt* (cdr nf*) (cdr v*) ac))))])) | ||||||
|  |   ;;; | ||||||
|   (define (handle-nontail-call rator rands value-dest call-targ) |   (define (handle-nontail-call rator rands value-dest call-targ) | ||||||
|     (let-values ([(reg-locs reg-args frm-args) |     (let-values ([(reg-locs reg-args frm-args) | ||||||
|                   (nontail-locations (cons rator rands))]) |                   (nontail-locations (cons rator rands))]) | ||||||
|       (let ([regt* (map (lambda (x) (unique-var 'rt)) reg-args)] |       (let ([regt* (map (lambda (x) (unique-var 'rt)) reg-args)] | ||||||
|             [frmt* (map (lambda (x) (make-nfvar #f #f)) frm-args)]) |             [frmt* (map (lambda (x) (make-nfvar #f #f)) frm-args)]) | ||||||
|         (let* ([call  |         (let* ([call  | ||||||
|                 (cond |                 (make-ntcall call-targ value-dest  | ||||||
|                   [call-targ |                   (cons argc-register (append reg-locs frmt*)) | ||||||
|                    (make-primcall 'direct-call |                   #f #f)] | ||||||
|                      (cons call-targ  |  | ||||||
|                        (cons argc-register |  | ||||||
|                          (append reg-locs frmt*))))] |  | ||||||
|                   [else |  | ||||||
|                    (make-primcall 'indirect-call  |  | ||||||
|                      (cons argc-register  |  | ||||||
|                            (append reg-locs frmt*)))])] |  | ||||||
|                [body |                [body | ||||||
|                 (make-nframe frmt* #f |                 (make-nframe frmt* #f | ||||||
|                   (do-bind frmt* frm-args |                   (do-bind-frmt* frmt* frm-args | ||||||
|                     (do-bind regt* reg-args |                     (do-bind regt* reg-args | ||||||
|                       (assign* reg-locs regt* |                       (assign* reg-locs regt* | ||||||
|                         (make-seq  |                         (make-seq  | ||||||
|  | @ -785,7 +913,7 @@ | ||||||
|       [(funcall rator rands)  |       [(funcall rator rands)  | ||||||
|        (handle-nontail-call rator rands d #f)] |        (handle-nontail-call rator rands d #f)] | ||||||
|       [(jmpcall label rator rands)  |       [(jmpcall label rator rands)  | ||||||
|        (handle-nontail-call rator rands d (make-code-loc label))] |        (handle-nontail-call rator rands d label)] | ||||||
|       [else (error who "invalid value ~s" x)])) |       [else (error who "invalid value ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|   (define (assign* lhs* rhs* ac) |   (define (assign* lhs* rhs* ac) | ||||||
|  | @ -806,6 +934,8 @@ | ||||||
|       [(seq e0 e1) (make-seq (E e0) (E e1))] |       [(seq e0 e1) (make-seq (E e0) (E e1))] | ||||||
|       [(conditional e0 e1 e2) |       [(conditional e0 e1 e2) | ||||||
|        (make-conditional (P e0) (E e1) (E e2))] |        (make-conditional (P e0) (E e1) (E e2))] | ||||||
|  |       [(bind lhs* rhs* e) | ||||||
|  |        (do-bind lhs* rhs* (E e))] | ||||||
|       [(primcall op rands) |       [(primcall op rands) | ||||||
|        (S* rands |        (S* rands | ||||||
|            (lambda (rands) |            (lambda (rands) | ||||||
|  | @ -813,14 +943,17 @@ | ||||||
|       [(funcall rator rands)  |       [(funcall rator rands)  | ||||||
|        (handle-nontail-call rator rands #f #f)] |        (handle-nontail-call rator rands #f #f)] | ||||||
|       [(jmpcall label rator rands)  |       [(jmpcall label rator rands)  | ||||||
|        (handle-nontail-call rator rands #f (make-code-loc label))] |        (handle-nontail-call rator rands #f label)] | ||||||
|       [else (error who "invalid effect ~s" x)])) |       [else (error who "invalid effect ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|   (define (P x) |   (define (P x) | ||||||
|     (record-case x |     (record-case x | ||||||
|  |       [(constant) x] | ||||||
|       [(seq e0 e1) (make-seq (E e0) (P e1))] |       [(seq e0 e1) (make-seq (E e0) (P e1))] | ||||||
|       [(conditional e0 e1 e2) |       [(conditional e0 e1 e2) | ||||||
|        (make-conditional (P e0) (P e1) (P e2))] |        (make-conditional (P e0) (P e1) (P e2))] | ||||||
|  |       [(bind lhs* rhs* e) | ||||||
|  |        (do-bind lhs* rhs* (P e))] | ||||||
|       [(primcall op rands) |       [(primcall op rands) | ||||||
|        (S* rands |        (S* rands | ||||||
|            (lambda (rands) |            (lambda (rands) | ||||||
|  | @ -1058,9 +1191,12 @@ | ||||||
|              s)) |              s)) | ||||||
|          (set-nframe-live! x s) |          (set-nframe-live! x s) | ||||||
|          (E body s)] |          (E body s)] | ||||||
|  |         [(ntcall targ value args mask size) | ||||||
|  |          (add-rands args s)] | ||||||
|         [else (error who "invalid effect ~s" x)])) |         [else (error who "invalid effect ~s" x)])) | ||||||
|     (define (P x st sf su) |     (define (P x st sf su) | ||||||
|       (record-case x |       (record-case x | ||||||
|  |         [(constant c) (if c st sf)] | ||||||
|         [(seq e0 e1) |         [(seq e0 e1) | ||||||
|          (E e0 (P e1 st sf su))] |          (E e0 (P e1 st sf su))] | ||||||
|         [(conditional e0 e1 e2) |         [(conditional e0 e1 e2) | ||||||
|  | @ -1197,16 +1333,31 @@ | ||||||
|         [(nfvar confs loc)  |         [(nfvar confs loc)  | ||||||
|          (or loc (error who "LHS not set ~s" x))] |          (or loc (error who "LHS not set ~s" x))] | ||||||
|         [else x])) |         [else x])) | ||||||
|     (define (NFE idx x) |     (define (NFE idx mask x) | ||||||
|       (record-case x |       (record-case x | ||||||
|         [(seq e0 e1) (make-seq (E e0) (NFE idx e1))] |         [(seq e0 e1) (make-seq (E e0) (NFE idx mask e1))] | ||||||
|         [(primcall op rands)  |         [(ntcall target value args mask^ size) | ||||||
|          (case op |          (make-ntcall target value  | ||||||
|            [(indirect-call direct-call) |             (map (lambda (x)  | ||||||
|             (make-primcall op  |                    (if (symbol? x) | ||||||
|               (cons (make-constant idx) (map Rand rands)))] |                        x | ||||||
|            [else (error who "invalid NFE ~s" x)])] |                        (Lhs x))) | ||||||
|  |                  args) | ||||||
|  |             mask idx)] | ||||||
|         [else (error who "invalid NF effect ~s" x)])) |         [else (error who "invalid NF effect ~s" x)])) | ||||||
|  |     (define (make-mask n live*) | ||||||
|  |       (let ([v (make-vector (fxsra (fx+ n 7) 3) 0)]) | ||||||
|  |         (for-each  | ||||||
|  |           (lambda (x) | ||||||
|  |             (record-case x | ||||||
|  |               [(fvar idx)  | ||||||
|  |                (let ([q (fxsra idx 3)] | ||||||
|  |                      [r (fxlogand idx 7)]) | ||||||
|  |                  (vector-set! v q | ||||||
|  |                    (fxlogor (vector-ref v q) (fxsll 1 r))))] | ||||||
|  |               [else (void)])) | ||||||
|  |           live*) | ||||||
|  |         v)) | ||||||
|     (define (E x) |     (define (E x) | ||||||
|       (record-case x |       (record-case x | ||||||
|         [(set lhs rhs)  |         [(set lhs rhs)  | ||||||
|  | @ -1225,15 +1376,16 @@ | ||||||
|         [(primcall op rands)  |         [(primcall op rands)  | ||||||
|          (make-primcall op (map Rand rands))] |          (make-primcall op (map Rand rands))] | ||||||
|         [(nframe vars live body) |         [(nframe vars live body) | ||||||
|          ;;; 1 is for the rp address |          (let ([live-fv* (map Lhs live)]) | ||||||
|          ;(printf "live=~s\n" live) |            (let ([i (actual-frame-size vars | ||||||
|          (let ([i (actual-frame-size vars |                       (fx+ 2 (max-live live-fv* 0)))]) | ||||||
|                     (fx+ 2 (max-live (map Lhs live) 0)))]) |              (assign-frame-vars! vars i) | ||||||
|            (assign-frame-vars! vars i) |              (NFE (fxsub1 i) (make-mask i live-fv*) body)))] | ||||||
|            (NFE (fxsub1 i) body))] |         [(ntcall) x] | ||||||
|         [else (error who "invalid effect ~s" x)])) |         [else (error who "invalid effect ~s" x)])) | ||||||
|     (define (P x) |     (define (P x) | ||||||
|       (record-case x |       (record-case x | ||||||
|  |         [(constant) x] | ||||||
|         [(primcall op rands)  |         [(primcall op rands)  | ||||||
|          (make-primcall op (map Rand rands))] |          (make-primcall op (map Rand rands))] | ||||||
|         [(conditional e0 e1 e2)  |         [(conditional e0 e1 e2)  | ||||||
|  | @ -1284,12 +1436,15 @@ | ||||||
|            (S* (cdr ls)  |            (S* (cdr ls)  | ||||||
|                (lambda (d) |                (lambda (d) | ||||||
|                  (cond |                  (cond | ||||||
|                    [(fvar? a)  |                    [(or (constant? a) | ||||||
|  |                         (var? a) | ||||||
|  |                         (symbol? a)) | ||||||
|  |                     (k (cons a d))] | ||||||
|  |                    [else | ||||||
|                     (let ([u (mku)]) |                     (let ([u (mku)]) | ||||||
|                       (make-seq  |                       (make-seq  | ||||||
|                         (make-set u a) |                         (E (make-set u a)) | ||||||
|                         (k (cons u d))))] |                         (k (cons u d))))]))))])) | ||||||
|                    [else (k (cons a d))]))))])) |  | ||||||
|     (define (E x) |     (define (E x) | ||||||
|       (record-case x |       (record-case x | ||||||
|         [(set lhs rhs)  |         [(set lhs rhs)  | ||||||
|  | @ -1315,16 +1470,16 @@ | ||||||
|         [(primcall op rands)  |         [(primcall op rands)  | ||||||
|          (case op |          (case op | ||||||
|            [(nop) x] |            [(nop) x] | ||||||
|            [(indirect-call) x] |            [(mset! record-effect) | ||||||
|            [(direct-call) x] |  | ||||||
|            [(mset!) |  | ||||||
|             (S* rands |             (S* rands | ||||||
|                 (lambda (s*) |                 (lambda (s*) | ||||||
|                   (make-primcall op s*)))] |                   (make-primcall op s*)))] | ||||||
|            [else (error who "invalid op in ~s" x)])] |            [else (error who "invalid op in ~s" x)])] | ||||||
|  |         [(ntcall) x] | ||||||
|         [else (error who "invalid effect ~s" x)])) |         [else (error who "invalid effect ~s" x)])) | ||||||
|     (define (P x) |     (define (P x) | ||||||
|       (record-case x |       (record-case x | ||||||
|  |         [(constant) x] | ||||||
|         [(primcall op rands) |         [(primcall op rands) | ||||||
|          (let ([a0 (car rands)] [a1 (cadr rands)]) |          (let ([a0 (car rands)] [a1 (cadr rands)]) | ||||||
|            (cond |            (cond | ||||||
|  | @ -1332,7 +1487,7 @@ | ||||||
|               (let ([u (mku)]) |               (let ([u (mku)]) | ||||||
|                 (make-seq  |                 (make-seq  | ||||||
|                   (make-set u a0) |                   (make-set u a0) | ||||||
|                   (make-primcall op u a1)))] |                   (make-primcall op (list u a1))))] | ||||||
|              [else x]))] |              [else x]))] | ||||||
|         [(conditional e0 e1 e2) |         [(conditional e0 e1 e2) | ||||||
|          (make-conditional (P e0) (P e1) (P e2))] |          (make-conditional (P e0) (P e1) (P e2))] | ||||||
|  | @ -1354,18 +1509,24 @@ | ||||||
|       [(locals sp* body) |       [(locals sp* body) | ||||||
|        (let ([frame-g (build-graph body fvar?)]) |        (let ([frame-g (build-graph body fvar?)]) | ||||||
|          (let loop ([sp* sp*] [un* '()] [body body]) |          (let loop ([sp* sp*] [un* '()] [body body]) | ||||||
|  |       ;       (printf "a") | ||||||
|            (let ([g (build-graph body symbol?)]) |            (let ([g (build-graph body symbol?)]) | ||||||
|                   ;  (printf "loop:\n") |                   ;  (printf "loop:\n") | ||||||
|                   ;  (print-code body) |                   ;  (print-code body) | ||||||
|              ;(print-graph g) |              ;(print-graph g) | ||||||
|  |       ;       (printf "b") | ||||||
|              (let-values ([(spills sp* env) (color-graph sp* un* g)]) |              (let-values ([(spills sp* env) (color-graph sp* un* g)]) | ||||||
|  |       ;       (printf "c") | ||||||
|                (cond |                (cond | ||||||
|                  [(null? spills) (substitute env body frame-g)] |                  [(null? spills) (substitute env body frame-g)] | ||||||
|                  [else  |                  [else  | ||||||
|  |       ;       (printf "d") | ||||||
|                   (let* ([env (do-spill spills frame-g)] |                   (let* ([env (do-spill spills frame-g)] | ||||||
|                          [body (substitute env body frame-g)]) |                          [body (substitute env body frame-g)]) | ||||||
|  |       ;       (printf "e") | ||||||
|                     (let-values ([(un* body) |                     (let-values ([(un* body) | ||||||
|                                   (add-unspillables un* body)]) |                                   (add-unspillables un* body)]) | ||||||
|  |       ;       (printf "f") | ||||||
|                        (loop sp* un* body)))])))))])) |                        (loop sp* un* body)))])))))])) | ||||||
|   ;;; |   ;;; | ||||||
|   (define (color-by-chaitin x) |   (define (color-by-chaitin x) | ||||||
|  | @ -1420,7 +1581,29 @@ | ||||||
|            x |            x | ||||||
|            (error who "invalid rand ~s" x))])) |            (error who "invalid rand ~s" x))])) | ||||||
|   ;;; |   ;;; | ||||||
|  |   (define (indep? x y) | ||||||
|  |     (define (reg-not-in x y) | ||||||
|  |       (cond | ||||||
|  |         [(symbol? y) (not (eq? x y))] | ||||||
|  |         [(primcall? y) | ||||||
|  |          (andmap (lambda (y) (reg-not-in x y)) (primcall-arg* y))] | ||||||
|  |         [else #t])) | ||||||
|  |     (cond | ||||||
|  |       [(symbol? x) (reg-not-in x y)] | ||||||
|  |       [(symbol? y) (reg-not-in y x)] | ||||||
|  |       [else #t])) | ||||||
|   (define (Rhs x d ac) |   (define (Rhs x d ac) | ||||||
|  |     (define (UNARG op d a1 a2 ac) | ||||||
|  |       (cond | ||||||
|  |         [(eq? a1 d) | ||||||
|  |          `([,op ,(Rand a2) ,d] . ,ac)] | ||||||
|  |         [(eq? a2 d) | ||||||
|  |          `([,op ,(Rand a1) ,d] . ,ac)] | ||||||
|  |         [(indep? d a1)  | ||||||
|  |          `([movl ,(Rand a2) ,(Rand d)] [,op ,(Rand a1) ,(Rand d)] . ,ac)] | ||||||
|  |         [(indep? d a2)  | ||||||
|  |          `([movl ,(Rand a1) ,(Rand d)] [,op ,(Rand a2) ,(Rand d)] . ,ac)] | ||||||
|  |         [else (error 'UNARG "cannot handle ~s ~s ~s" d a1 a2)])) | ||||||
|     (record-case x |     (record-case x | ||||||
|       [(constant c) |       [(constant c) | ||||||
|        (cons `(movl ,(Rand x) ,d) ac)] |        (cons `(movl ,(Rand x) ,d) ac)] | ||||||
|  | @ -1433,6 +1616,10 @@ | ||||||
|                              ,(Rand (cadr rands)))  |                              ,(Rand (cadr rands)))  | ||||||
|                        ,d) |                        ,d) | ||||||
|                 ac)] |                 ac)] | ||||||
|  |          [(logand)  | ||||||
|  |           (UNARG 'andl d (car rands) (cadr rands) ac)] | ||||||
|  |          [(int+)  | ||||||
|  |           (UNARG 'addl d (car rands) (cadr rands) ac)] | ||||||
|          [(alloc)  |          [(alloc)  | ||||||
|           (let ([sz (Rand (car rands))] |           (let ([sz (Rand (car rands))] | ||||||
|                 [tag (Rand (cadr rands))]) |                 [tag (Rand (cadr rands))]) | ||||||
|  | @ -1457,30 +1644,54 @@ | ||||||
|             (E e1  |             (E e1  | ||||||
|                (list* `(jmp ,le) lf |                (list* `(jmp ,le) lf | ||||||
|                   (E e2 (cons le ac))))))] |                   (E e2 (cons le ac))))))] | ||||||
|  |       [(ntcall target value args mask size)  | ||||||
|  |        (let ([LCALL (unique-label)]) | ||||||
|  |          (define (rp-label value) | ||||||
|  |            (if value | ||||||
|  |                (label-address SL_multiple_values_error_rp) | ||||||
|  |                (label-address SL_multiple_values_ignore_rp))) | ||||||
|  |          (cond | ||||||
|  |            [target ;;; known call | ||||||
|  |             (list* `(subl ,(* (fxsub1 size) wordsize) ,fpr) | ||||||
|  |                    `(jmp ,LCALL) | ||||||
|  |                    `(byte-vector ,mask) | ||||||
|  |                    `(int ,(* size wordsize)) | ||||||
|  |                    `(current-frame-offset) | ||||||
|  |                    (rp-label value) | ||||||
|  |                    LCALL | ||||||
|  |                    `(call (label ,target)) | ||||||
|  |                    `(addl ,(* (fxsub1 size) wordsize) ,fpr) | ||||||
|  |                    ac)] | ||||||
|  |            [else | ||||||
|  |             (list* `(subl ,(* (fxsub1 size) wordsize) ,fpr) | ||||||
|  |                    `(jmp ,LCALL) | ||||||
|  |                    `(byte-vector ,mask) | ||||||
|  |                    `(int ,(* size wordsize)) | ||||||
|  |                    `(current-frame-offset) | ||||||
|  |                    (rp-label value) | ||||||
|  |                    '(byte 0) | ||||||
|  |                    '(byte 0) | ||||||
|  |                    LCALL | ||||||
|  |                    `(call (disp ,(fx- disp-closure-code closure-tag) ,cp-register)) | ||||||
|  |                    `(addl ,(* (fxsub1 size) wordsize) ,fpr) | ||||||
|  |                    ac)]))] | ||||||
|       [(primcall op rands) |       [(primcall op rands) | ||||||
|        (case op |        (case op | ||||||
|          [(nop) ac] |          [(nop) ac] | ||||||
|  |          [(record-effect)  | ||||||
|  |           (let ([a (car rands)]) | ||||||
|  |             (unless (symbol? a)  | ||||||
|  |               (error who "invalid arg to record-effect ~s" a)) | ||||||
|  |             (list* `(shrl ,pageshift ,a) | ||||||
|  |                    `(sall ,wordshift ,a) | ||||||
|  |                    `(addl ,(pcb-ref 'dirty-vector) ,a) | ||||||
|  |                    `(movl ,dirty-word (disp 0 ,a)) | ||||||
|  |                    ac))] | ||||||
|          [(mset!)  |          [(mset!)  | ||||||
|           (cons `(movl ,(Rand (caddr rands))  |           (cons `(movl ,(Rand (caddr rands))  | ||||||
|                        (disp ,(Rand (car rands)) |                        (disp ,(Rand (car rands)) | ||||||
|                              ,(Rand (cadr rands)))) |                              ,(Rand (cadr rands)))) | ||||||
|                 ac)] |                 ac)] | ||||||
|          [(direct-call) |  | ||||||
|           (record-case (car rands) |  | ||||||
|             [(constant i)  |  | ||||||
|              (list* `(subl ,(* (fxsub1 i) wordsize) ,fpr) |  | ||||||
|                     `(call (label ,(code-loc-label (cadr rands)))) |  | ||||||
|                     `(addl ,(* (fxsub1 i) wordsize) ,fpr) |  | ||||||
|                     ac)] |  | ||||||
|             [else (error who "invalid ~s" x)])] |  | ||||||
|          [(indirect-call)  |  | ||||||
|           (record-case (car rands) |  | ||||||
|             [(constant i)  |  | ||||||
|              (list* `(subl ,(* (fxsub1 i) wordsize) ,fpr) |  | ||||||
|                     `(call (disp ,(fx- disp-closure-code closure-tag) ,cp-register)) |  | ||||||
|                     `(addl ,(* (fxsub1 i) wordsize) ,fpr) |  | ||||||
|                     ac)] |  | ||||||
|             [else (error who "invalid ~s" x)])] |  | ||||||
|          [else (error who "invalid effect ~s" x)])] |          [else (error who "invalid effect ~s" x)])] | ||||||
|       [else (error who "invalid effect ~s" x)])) |       [else (error who "invalid effect ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|  | @ -1489,6 +1700,10 @@ | ||||||
|   ;;; |   ;;; | ||||||
|   (define (P x lt lf ac) |   (define (P x lt lf ac) | ||||||
|     (record-case x |     (record-case x | ||||||
|  |       [(constant c)  | ||||||
|  |        (if c | ||||||
|  |            (if lt (cons `(jmp ,lt) ac) ac) | ||||||
|  |            (if lf (cons `(jmp ,lf) ac) ac))] | ||||||
|       [(seq e0 e1) |       [(seq e0 e1) | ||||||
|        (E e0 (P e1 lt lf ac))] |        (E e0 (P e1 lt lf ac))] | ||||||
|       [(conditional e0 e1 e2) |       [(conditional e0 e1 e2) | ||||||
|  | @ -1570,29 +1785,102 @@ | ||||||
|         [else (error who "invalid tail ~s" x)])] |         [else (error who "invalid tail ~s" x)])] | ||||||
|       [else (error who "invalid tail ~s" x)])) |       [else (error who "invalid tail ~s" x)])) | ||||||
|   ;;; |   ;;; | ||||||
|  |   (define (handle-vararg fml-count ac) | ||||||
|  |     (define CONTINUE_LABEL (unique-label)) | ||||||
|  |     (define DONE_LABEL (unique-label)) | ||||||
|  |     (define CONS_LABEL (unique-label)) | ||||||
|  |     (define LOOP_HEAD (unique-label)) | ||||||
|  |     (define L_CALL (unique-label)) | ||||||
|  |     (list* (cmpl (int (argc-convention (fxsub1 fml-count))) eax) | ||||||
|  |            (jg (label SL_invalid_args)) | ||||||
|  |            (jl CONS_LABEL) | ||||||
|  |            (movl (int nil) ebx) | ||||||
|  |            (jmp DONE_LABEL) | ||||||
|  |            CONS_LABEL | ||||||
|  |            (movl (pcb-ref 'allocation-redline) ebx) | ||||||
|  |            (addl eax ebx) | ||||||
|  |            (addl eax ebx) | ||||||
|  |            (cmpl ebx apr) | ||||||
|  |            (jle LOOP_HEAD) | ||||||
|  |            ; overflow | ||||||
|  |            (addl eax esp) ; advance esp to cover args | ||||||
|  |            (pushl cpr)    ; push current cp | ||||||
|  |            (pushl eax)    ; push argc | ||||||
|  |            (negl eax)     ; make argc positive | ||||||
|  |            (addl (int (fx* 4 wordsize)) eax) ; add 4 words to adjust frame size | ||||||
|  |            (pushl eax)    ; push frame size | ||||||
|  |            (addl eax eax) ; double the number of args | ||||||
|  |            (movl eax (mem (fx* -2 wordsize) fpr)) ; pass it as first arg | ||||||
|  |            (movl (int (argc-convention 1)) eax) ; setup argc | ||||||
|  |            (movl (primref-loc 'do-vararg-overflow) cpr) ; load handler | ||||||
|  |            (jmp L_CALL)   ; go to overflow handler | ||||||
|  |            ; NEW FRAME | ||||||
|  |            '(int 0)        ; if the framesize=0, then the framesize is dynamic | ||||||
|  |            '(current-frame-offset) | ||||||
|  |            '(int 0)        ; multiarg rp | ||||||
|  |            (byte 0) | ||||||
|  |            (byte 0) | ||||||
|  |            L_CALL | ||||||
|  |            (indirect-cpr-call) | ||||||
|  |            (popl eax)     ; pop framesize and drop it | ||||||
|  |            (popl eax)     ; reload argc | ||||||
|  |            (popl cpr)     ; reload cp | ||||||
|  |            (subl eax fpr) ; readjust fp | ||||||
|  |            LOOP_HEAD | ||||||
|  |            (movl (int nil) ebx) | ||||||
|  |            CONTINUE_LABEL | ||||||
|  |            (movl ebx (mem disp-cdr apr)) | ||||||
|  |            (movl (mem fpr eax) ebx) | ||||||
|  |            (movl ebx (mem disp-car apr)) | ||||||
|  |            (movl apr ebx) | ||||||
|  |            (addl (int pair-tag) ebx) | ||||||
|  |            (addl (int pair-size) apr) | ||||||
|  |            (addl (int (fxsll 1 fx-shift)) eax) | ||||||
|  |            (cmpl (int (fx- 0 (fxsll fml-count fx-shift))) eax) | ||||||
|  |            (jle CONTINUE_LABEL) | ||||||
|  |            DONE_LABEL | ||||||
|  |            (movl ebx (mem (fx- 0 (fxsll fml-count fx-shift)) fpr)) | ||||||
|  |            ac)) | ||||||
|  |   ;;; | ||||||
|   (define (properize args proper ac) |   (define (properize args proper ac) | ||||||
|     (cond |     (cond | ||||||
|       [proper ac] |       [proper ac] | ||||||
|       [else |       [else | ||||||
|        (error 'properize "not yet") |        (handle-vararg (length (cdr args)) ac)])) | ||||||
|        ac])) |  | ||||||
|   ;;; |   ;;; | ||||||
|   (define (ClambdaCase x)  |   (define (ClambdaCase x ac)  | ||||||
|     (record-case x |     (record-case x | ||||||
|       [(clambda-case info body) |       [(clambda-case info body) | ||||||
|        (record-case info |        (record-case info | ||||||
|          [(case-info L args proper) |          [(case-info L args proper) | ||||||
|           (properize args proper |           (let ([lothers (unique-label)]) | ||||||
|             (cons (label L) (T body '())))])])) |             (list* `(cmpl ,(argc-convention  | ||||||
|  |                              (if proper  | ||||||
|  |                                  (length (cdr args)) | ||||||
|  |                                  (length (cddr args)))) | ||||||
|  |                           ,argc-register) | ||||||
|  |                    (cond | ||||||
|  |                      [proper `(jne ,lothers)] | ||||||
|  |                      [(> (argc-convention 0) (argc-convention 1)) | ||||||
|  |                       `(jle ,lothers)] | ||||||
|  |                      [else | ||||||
|  |                       `(jge ,lothers)]) | ||||||
|  |                (properize args proper | ||||||
|  |                   (cons (label L)  | ||||||
|  |                         (T body (cons lothers ac))))))])])) | ||||||
|   ;;; |   ;;; | ||||||
|   (define (Clambda x) |   (define (Clambda x) | ||||||
|     (record-case x |     (record-case x | ||||||
|       [(clambda L case* free*) |       [(clambda L case* free*) | ||||||
|        (unless (fx= (length case*) 1) |  | ||||||
|          (error who "not a lambda")) |  | ||||||
|        (list* (length free*)  |        (list* (length free*)  | ||||||
|               (label L) |               (label L) | ||||||
|               (ClambdaCase (car case*)))])) |           (let f ([case* case*]) | ||||||
|  |             (cond | ||||||
|  |               [(null? case*) (invalid-args-error)] | ||||||
|  |               [else | ||||||
|  |                (ClambdaCase (car case*) (f (cdr case*)))])))])) | ||||||
|  |   (define (invalid-args-error) | ||||||
|  |     `((jmp (label ,SL_invalid_args)))) | ||||||
|   ;;; |   ;;; | ||||||
|   (define (Program x) |   (define (Program x) | ||||||
|     (record-case x  |     (record-case x  | ||||||
|  | @ -1613,13 +1901,19 @@ | ||||||
|   (let* ( |   (let* ( | ||||||
|          ;[foo (print-code x)] |          ;[foo (print-code x)] | ||||||
|          [x (remove-primcalls x)] |          [x (remove-primcalls x)] | ||||||
|          ;[foo (print-code x)] |          ;[foo (printf "1")] | ||||||
|          [x (eliminate-fix x)] |          [x (eliminate-fix x)] | ||||||
|  |          ;[foo (printf "2")] | ||||||
|          [x (normalize-context x)] |          [x (normalize-context x)] | ||||||
|  |          ;[foo (printf "3")] | ||||||
|  |          ;[foo (print-code x)] | ||||||
|          [x (specify-representation x)] |          [x (specify-representation x)] | ||||||
|  |          ;[foo (printf "4")] | ||||||
|          [x (impose-calling-convention/evaluation-order x)] |          [x (impose-calling-convention/evaluation-order x)] | ||||||
|  |          ;[foo (printf "5")] | ||||||
|          ;[foo (print-code x)] |          ;[foo (print-code x)] | ||||||
|          [x (color-by-chaitin x)] |          [x (color-by-chaitin x)] | ||||||
|  |          ;[foo (printf "6")] | ||||||
|          ;[foo (print-code x)] |          ;[foo (print-code x)] | ||||||
|          [ls (flatten-codes x)]) |          [ls (flatten-codes x)]) | ||||||
|     (when #t |     (when #t | ||||||
|  |  | ||||||
|  | @ -260,6 +260,7 @@ | ||||||
| (define-record locals (vars body)) | (define-record locals (vars body)) | ||||||
| (define-record nframe (vars live body)) | (define-record nframe (vars live body)) | ||||||
| (define-record nfvar (conf loc)) | (define-record nfvar (conf loc)) | ||||||
|  | (define-record ntcall (target value args mask size)) | ||||||
| 
 | 
 | ||||||
| (define mkfvar | (define mkfvar | ||||||
|   (let ([cache '()]) |   (let ([cache '()]) | ||||||
|  | @ -479,6 +480,7 @@ | ||||||
|       [else x])) |       [else x])) | ||||||
|   (E x)) |   (E x)) | ||||||
| 
 | 
 | ||||||
|  | (define open-mvcalls (make-parameter #t)) | ||||||
| 
 | 
 | ||||||
| (define (optimize-direct-calls x) | (define (optimize-direct-calls x) | ||||||
|   (define who 'optimize-direct-calls) |   (define who 'optimize-direct-calls) | ||||||
|  | @ -545,7 +547,7 @@ | ||||||
|          ;;; FIXME HERE |          ;;; FIXME HERE | ||||||
|          [(call-with-values) |          [(call-with-values) | ||||||
|           (cond |           (cond | ||||||
|             [(fx= (length rand*) 2) |             [(and (open-mvcalls) (fx= (length rand*) 2)) | ||||||
|              (let ([producer (inline (car rand*) '())]  |              (let ([producer (inline (car rand*) '())]  | ||||||
|                    [consumer (cadr rand*)]) |                    [consumer (cadr rand*)]) | ||||||
|                (cond |                (cond | ||||||
|  | @ -4524,8 +4526,10 @@ | ||||||
|        (if c |        (if c | ||||||
|            (if Lt (cons (jmp Lt) ac) ac) |            (if Lt (cons (jmp Lt) ac) ac) | ||||||
|            (if Lf (cons (jmp Lf) ac) ac))] |            (if Lf (cons (jmp Lf) ac) ac))] | ||||||
|      [(fix lhs* rhs* body) |       [(closure)  | ||||||
|       (do-fix lhs* rhs* (Pred body Lt Lf ac))] |        (if Lt (cons (jmp Lt) ac) ac)] | ||||||
|  |       [(fix lhs* rhs* body) | ||||||
|  |        (do-fix lhs* rhs* (Pred body Lt Lf ac))] | ||||||
|       [(primcall op rand*) |       [(primcall op rand*) | ||||||
|        (do-pred-prim op rand* Lt Lf ac)] |        (do-pred-prim op rand* Lt Lf ac)] | ||||||
|       [(conditional test conseq altern) |       [(conditional test conseq altern) | ||||||
|  | @ -5181,7 +5185,8 @@ | ||||||
|   (let* ([p (parameterize ([assembler-output #f]) |   (let* ([p (parameterize ([assembler-output #f]) | ||||||
|               (expand expr))] |               (expand expr))] | ||||||
|          [p (recordize p)] |          [p (recordize p)] | ||||||
|          [p (optimize-direct-calls p)] |          [p (parameterize ([open-mvcalls #f]) | ||||||
|  |               (optimize-direct-calls p))] | ||||||
|          [p (optimize-letrec p)] |          [p (optimize-letrec p)] | ||||||
|          [p (uncover-assigned/referenced p)] |          [p (uncover-assigned/referenced p)] | ||||||
|          [p (copy-propagate p)] |          [p (copy-propagate p)] | ||||||
|  |  | ||||||
|  | @ -264,7 +264,8 @@ reference-implementation: | ||||||
|                "" |                "" | ||||||
|                (fill s ($make-string len) n m 0))))))) |                (fill s ($make-string len) n m 0))))))) | ||||||
| 
 | 
 | ||||||
| (primitive-set! 'not (lambda (x) (not x))) | (primitive-set! 'not  | ||||||
|  |   (lambda (x) (if x #f #t))) | ||||||
|    |    | ||||||
| (primitive-set! 'symbol->string | (primitive-set! 'symbol->string | ||||||
|   (lambda (x) |   (lambda (x) | ||||||
|  |  | ||||||
|  | @ -230,6 +230,7 @@ | ||||||
|     ["libcontrol.ss"    "libcontrol.fasl"   p0 onepass] |     ["libcontrol.ss"    "libcontrol.fasl"   p0 onepass] | ||||||
|     ["libcollect.ss"    "libcollect.fasl"   p0 onepass] |     ["libcollect.ss"    "libcollect.fasl"   p0 onepass] | ||||||
|     ["librecord.ss"     "librecord.fasl"    p0 onepass] |     ["librecord.ss"     "librecord.fasl"    p0 onepass] | ||||||
|  |     ;["libcxr.ss"        "libcxr.fasl"       p0 chaitin] | ||||||
|     ["libcxr.ss"        "libcxr.fasl"       p0 onepass] |     ["libcxr.ss"        "libcxr.fasl"       p0 onepass] | ||||||
|     ["libnumerics.ss"   "libnumerics.fasl"  p0 onepass] |     ["libnumerics.ss"   "libnumerics.fasl"  p0 onepass] | ||||||
|     ["libguardians.ss"  "libguardians.fasl" p0 onepass] |     ["libguardians.ss"  "libguardians.fasl" p0 onepass] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Abdulaziz Ghuloum
						Abdulaziz Ghuloum