- [sum (cadr info)])
- (when (not (stack-expr? res))
- (error #f "codegened something that wasn't a stack expression"))
- ;TODO handle stack types
- (emit "movq ~a(%rbp), %rax"
- (- si (data-product-offset (env-data-layouts env) type sum index)))))
+ [sum (cadr info)]
+ [index (caddr info)]
+ [product-type (cadddr info)]
+ [product-type-size (type-size dls product-type)]
+
+ [safe-space-offset (- si (type-size dls type))]
+
+ [inner-offset (- si (data-product-offset dls type sum index))])
+
+ (when (not (on-stack? (cadr e)))
+ (error #f "trying to destruct something that isn't a stack expression"))
+ (emit "# deconstructing")
+
+ (if (stack-type? (env-data-layouts env) product-type)
+ ; if copying from the stack, need to first copy
+ ; to a safe space above to avoid overwriting
+ ; the original result on the stack
+ ; this is bad. please remove this in the rewrite.
+ (begin
+ (emit-stack-copy inner-offset safe-space-offset product-type-size)
+ (emit-stack-copy safe-space-offset si product-type-size))
+ (emit "movq ~a(%rbp), %rax" inner-offset))))