cs: fix variable-reference->module-... on reference to primitive

This commit is contained in:
Matthew Flatt 2019-06-28 08:02:39 -06:00
parent 032ab4e374
commit ff94c6d8d8
3 changed files with 29 additions and 22 deletions

View File

@ -114,18 +114,18 @@
(eval `(define primitive-table ',primitive-table))
;; For interpretation of the outer shell of a linklet:
(install-linklet-primitive-tables! kernel-table
unsafe-table
flfxnum-table
paramz-table
extfl-table
network-table
futures-table
place-table
foreign-table
linklet-table
internal-table
schemify-table)
(install-linklet-primitive-tables! (cons '|#%kernel| kernel-table)
(cons '|#%unsafe| unsafe-table)
(cons '|#%flfxnum| flfxnum-table)
(cons '|#%paramz| paramz-table)
(cons '|#%extfl| extfl-table)
(cons '|#%network| network-table)
(cons '|#%futures| futures-table)
(cons '|#%place| place-table)
(cons '|#%foreign| foreign-table)
(cons '|#%linklet| linklet-table)
(cons 'internal internal-table)
(cons 'schemify schemify-table))
;; ----------------------------------------

View File

@ -219,11 +219,15 @@
mode
(compile* e)))
(define primitives (make-hasheq))
(define primitives (make-hasheq)) ; hash of sym -> known
(define primitive-tables '()) ; list of (cons sym hash)
;; Arguments are `(cons <sym> <hash-table>)`
(define (install-linklet-primitive-tables! . tables)
(set! primitive-tables tables)
(for-each
(lambda (table)
(hash-for-each table (lambda (k v) (hash-set! primitives k v))))
(hash-for-each (cdr table) (lambda (k v) (hash-set! primitives k v))))
tables)
;; prropagate table to the rumble layer
(install-primitives-table! primitives))
@ -999,7 +1003,7 @@
;; --------------------------------------------------
(define-record variable-reference (instance ; the use-site instance
var-or-info)) ; the referenced variable, 'constant, 'mutable, #f, or 'primitive
var-or-info)) ; the referenced variable, 'constant, 'mutable, #f, or primitive name
(define variable-reference->instance
(case-lambda
@ -1017,13 +1021,16 @@
(if (eq? i #!bwp)
(variable-reference->instance vr #t)
i))]
[(eq? v 'primitive)
;; FIXME: We don't have the right primitive instance name
;; ... but '#%kernel is usually right.
'|#%kernel|]
[else
[(or (eq? v 'constant) (eq? v 'mutable))
;; Local variable, so same as use-site
(variable-reference->instance vr #t)]))]))
(variable-reference->instance vr #t)]
[else
(or (#%ormap (lambda (table)
(and (hash-ref (cdr table) v #f)
(car table)))
primitive-tables)
;; Fallback, just in case
'|#%kernel|)]))]))
(define (variable-reference-constant? vr)
(let ([v (variable-reference-var-or-info vr)])

View File

@ -595,7 +595,7 @@
instance-variable-reference
',(cond
[(hash-ref mutated u #f) 'mutable]
[(hash-ref prim-knowns u #f) 'primitive]
[(hash-ref prim-knowns u #f) u] ; assuming that `mutable` and `constant` are not primitives
[else 'constant])))]
[`(equal? ,exp1 ,exp2)
(let ([exp1 (schemify exp1)]