Commit 89ec4c18 authored by Guy Watson's avatar Guy Watson
Browse files

Split reinterpret instruction into multiple parts depending on type

parent b6847b3e
......@@ -154,7 +154,10 @@
[Extend TypeConversion ([sign = (< (random) 0.5)])] ;; i32 -> i64
[Demote TypeConversion ()] ;; f64 -> f32
[Promote TypeConversion ()] ;; f32 -> f64
[Reinterpret TypeConversion ()] ;; float -> int, or int -> float, but only with the same bit-width
[ReinterpretIntThirtyTwo TypeConversion ()]
[ReinterpretIntSixtyFour TypeConversion ()]
[ReinterpretFloatThirtyTwo TypeConversion ()]
[ReinterpretFloatSixtyFour TypeConversion ()]
;; Idiomatic Generation
......@@ -292,43 +295,14 @@
(hash 'expr f64))]]
[Promote [f64 (λ (n t)
(hash 'expr f32))]]
[Reinterpret [(fresh-type-variable i32 i64 f32 f64) ;;constrain to concrete types
(λ (n t) ;; int to float or float to int, but only in the same bitwidth
(begin
(printf (format "node: ~a, type: ~a" n t))
;; This type rule will break in funny
;; ways. This is probably something that I
;; need to document more clearly. But at
;; any rate, the problem is that multiple
;; of these cases can match (eg against
;; a non-concretized type variable),
;; and it will return a type from the
;; first case that matches, which may
;; influence generation. But then if the
;; type variable is unified (successfully,
;; because it was still an option) with
;; a type in a lower branch, that lower
;; branch will then succeed. So unification
;; elsewhere in the tree can change the
;; result of this rule. So you really want
;; to either:
;;
;; * Have different re-interpret node types
;;that fulfill different types so this
;;confusion doesn't happen
;;
;; * Concretize the type before doing
;;this match, and SAVE the result
;;of concretizing in a field of the
;;Reinterpret node. Then during type
;;checking, unify with the saved type each
;;time.
(cond
[(can-unify? t i32) (hash 'expr f32)]
[(can-unify? t f32) (hash 'expr i32)]
[(can-unify? t i64) (hash 'expr f64)]
[(can-unify? t f64) (hash 'expr i64)]
[else (eprintf "bad reinterpret, got ~v\n" t)])))]]
[ReinterpretIntThirtyTwo [f32 (λ (n t)
(hash 'expr i32))]]
[ReinterpretIntSixtyFour [f64 (λ (n t)
(hash 'expr i64))]]
[ReinterpretFloatThirtyTwo [i32 (λ (n t)
(hash 'expr f32))]]
[ReinterpretFloatSixtyFour [i64 (λ (n t)
(hash 'expr f64))]]
)
;; Define structured control instruction property
......@@ -533,23 +507,32 @@
(append
'(FIXME)))]
[Convert (λ (n)
(append
'(FIXME)))]
(append
'(FIXME)))]
[Wrap (λ (n)
(append
'(FIXME)))]
(append
'(FIXME)))]
[Extend (λ (n)
(append
'(FIXME)))]
(append
'(FIXME)))]
[Demote (λ (n)
(append
'(FIXME)))]
(append
'(FIXME)))]
[Promote (λ (n)
(append
'(FIXME)))]
[Reinterpret (λ (n)
(append
'(FIXME)))]
(append
'(FIXME)))]
[ReinterpretIntThirtyTwo (λ (n)
(append
'(FIXME)))]
[ReinterpretIntSixtyFour (λ (n)
(append
'(FIXME)))]
[ReinterpretFloatThirtyTwo (λ (n)
(append
'(FIXME)))]
[ReinterpreFloatSixtyFour (λ (n)
(append
'(FIXME)))]
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment