|
1460 | 1460 | (if (length= e 3) |
1461 | 1461 | `(const ,(cadr e) ,(expand-forms (caddr e))) |
1462 | 1462 | (let ((arg (cadr e))) |
1463 | | - (case (car arg) |
1464 | | - ((global) (let ((asgn (cadr arg))) |
1465 | | - (check-assignment asgn) |
1466 | | - `(block |
1467 | | - ,.(map (lambda (v) `(global ,v)) |
1468 | | - (lhs-bound-names (cadr asgn))) |
1469 | | - ,(expand-assignment asgn #t)))) |
1470 | | - ((=) (check-assignment arg) |
1471 | | - (expand-assignment arg #t)) |
1472 | | - (else (error "expected assignment after \"const\"")))))) |
| 1463 | + (cond |
| 1464 | + ((symbol? arg) |
| 1465 | + ;; Undefined constant: Expr(:const, :a) (not available in surface syntax) |
| 1466 | + `(block ,e (latestworld))) |
| 1467 | + ((eq? (car arg) 'global) |
| 1468 | + (let ((asgn (cadr arg))) |
| 1469 | + (check-assignment asgn) |
| 1470 | + `(block |
| 1471 | + ,.(map (lambda (v) `(global ,v)) |
| 1472 | + (lhs-bound-names (cadr asgn))) |
| 1473 | + ,(expand-assignment asgn #t)))) |
| 1474 | + ((eq? (car arg) '=) |
| 1475 | + (check-assignment arg) |
| 1476 | + (expand-assignment arg #t)) |
| 1477 | + (else |
| 1478 | + (error "expected assignment after \"const\"")))))) |
1473 | 1479 |
|
1474 | 1480 | (define (expand-atomic-decl e) |
1475 | 1481 | (error "unimplemented or unsupported atomic declaration")) |
|
3043 | 3049 | (set! vars (cons (cadr e) vars))) |
3044 | 3050 | ((= const) |
3045 | 3051 | (let ((v (decl-var (cadr e)))) |
3046 | | - (find-assigned-vars- (caddr e)) |
| 3052 | + (unless (and (eq? (car e) 'const) (null? (cddr e))) |
| 3053 | + (find-assigned-vars- (caddr e))) |
3047 | 3054 | (if (or (ssavalue? v) (globalref? v) (underscore-symbol? v)) |
3048 | 3055 | '() |
3049 | 3056 | (set! vars (cons v vars))))) |
|
3460 | 3467 | (vinfo:set-sa! vi #f) |
3461 | 3468 | (vinfo:set-sa! vi #t)) |
3462 | 3469 | (vinfo:set-asgn! vi #t)))) |
3463 | | - (analyze-vars (caddr e) env captvars sp tab)) |
| 3470 | + (unless (null? (cddr e)) |
| 3471 | + (analyze-vars (caddr e) env captvars sp tab))) |
3464 | 3472 | ((call) |
3465 | 3473 | (let ((vi (get tab (cadr e) #f))) |
3466 | 3474 | (if vi |
@@ -4070,8 +4078,6 @@ f(x) = yt(x) |
4070 | 4078 | '(null) |
4071 | 4079 | `(newvar ,(cadr e)))))) |
4072 | 4080 | ((const) |
4073 | | - ;; Check we've expanded surface `const` (1 argument form) |
4074 | | - (assert (and (length= e 3))) |
4075 | 4081 | (when (globalref? (cadr e)) |
4076 | 4082 | (put! globals (cadr e) #f)) |
4077 | 4083 | e) |
@@ -4642,10 +4648,15 @@ f(x) = yt(x) |
4642 | 4648 | (list cnd)))))) |
4643 | 4649 | tests)) |
4644 | 4650 | (define (emit-assignment-or-setglobal lhs rhs (op '=)) |
4645 | | - ;; (const (globalref _ _) _) does not use setglobal! |
4646 | | - (if (and (globalref? lhs) (eq? op '=)) |
4647 | | - (emit `(call (top setglobal!) ,(cadr lhs) (inert ,(caddr lhs)) ,rhs)) |
4648 | | - (emit `(,op ,lhs ,rhs)))) |
| 4651 | + ;; (= (globalref _ _) _) => setglobal! |
| 4652 | + ;; (const (globalref _ _) _) => setconst! |
| 4653 | + (cond ((and (globalref? lhs) (eq? op '=)) |
| 4654 | + (emit `(call (top setglobal!) ,(cadr lhs) (inert ,(caddr lhs)) ,rhs))) |
| 4655 | + ((and (globalref? lhs) (eq? op 'const)) |
| 4656 | + (emit `(call (core setconst!) ,(cadr lhs) (inert ,(caddr lhs)) ,rhs))) |
| 4657 | + (else |
| 4658 | + (assert (eq? op '=)) |
| 4659 | + (emit `(= ,lhs ,rhs))))) |
4649 | 4660 | (define (emit-assignment lhs rhs (op '=)) |
4650 | 4661 | (if rhs |
4651 | 4662 | (if (valid-ir-rvalue? lhs rhs) |
@@ -4726,21 +4737,26 @@ f(x) = yt(x) |
4726 | 4737 | (when (pair? (cadr lam)) |
4727 | 4738 | (error (string "`global const` declaration not allowed inside function" (format-loc current-loc))))) |
4728 | 4739 | (let ((lhs (cadr e))) |
4729 | | - (if (and (symbol? lhs) (underscore-symbol? lhs)) |
4730 | | - (compile (caddr e) break-labels value tail) |
4731 | | - (let* ((rhs (compile (caddr e) break-labels #t #f)) |
4732 | | - (lhs (if (and arg-map (symbol? lhs)) |
4733 | | - (get arg-map lhs lhs) |
4734 | | - lhs))) |
4735 | | - (if (and value rhs) |
4736 | | - (let ((rr (if (or (atom? rhs) (ssavalue? rhs) (eq? (car rhs) 'null)) |
4737 | | - rhs (make-ssavalue)))) |
4738 | | - (if (not (eq? rr rhs)) |
4739 | | - (emit `(= ,rr ,rhs))) |
4740 | | - (emit-assignment-or-setglobal lhs rr (car e)) |
4741 | | - (if tail (emit-return tail rr)) |
4742 | | - rr) |
4743 | | - (emit-assignment lhs rhs (car e))))))) |
| 4740 | + (cond ((and (symbol? lhs) (underscore-symbol? lhs)) |
| 4741 | + (compile (caddr e) break-labels value tail)) |
| 4742 | + ((and (eq? (car e) 'const) (null? (cddr e)) (globalref? (cadr e))) |
| 4743 | + ;; No RHS - make undefined constant |
| 4744 | + (let ((lhs (cadr e))) |
| 4745 | + (emit `(call (core setconst!) ,(cadr lhs) (inert ,(caddr lhs)))))) |
| 4746 | + (else |
| 4747 | + (let* ((rhs (compile (caddr e) break-labels #t #f)) |
| 4748 | + (lhs (if (and arg-map (symbol? lhs)) |
| 4749 | + (get arg-map lhs lhs) |
| 4750 | + lhs))) |
| 4751 | + (if (and value rhs) |
| 4752 | + (let ((rr (if (or (atom? rhs) (ssavalue? rhs) (eq? (car rhs) 'null)) |
| 4753 | + rhs (make-ssavalue)))) |
| 4754 | + (if (not (eq? rr rhs)) |
| 4755 | + (emit `(= ,rr ,rhs))) |
| 4756 | + (emit-assignment-or-setglobal lhs rr (car e)) |
| 4757 | + (if tail (emit-return tail rr)) |
| 4758 | + rr) |
| 4759 | + (emit-assignment lhs rhs (car e)))))))) |
4744 | 4760 | ((block) |
4745 | 4761 | (let* ((last-fname filename) |
4746 | 4762 | (fnm (first-non-meta e)) |
|
0 commit comments