PasteRack.org
Paste # 24542
2020-07-13 02:15:02

Fork as a new paste.

Paste viewed 213 times.


Embed:

#lang racket/base

(require ; racket/fixnum
         (rename-in racket/flonum
                    (fl+ safe-fl+))
         disassemble
         (rename-in racket/unsafe/ops
                    (unsafe-fx= fx=)
                    (unsafe-fx- fx-)
                    (unsafe-fl+ fl+)
                    (unsafe-fx> fx>)
                    ))

(define (count init)
  (let loop ([i 1000] [x init])
    (if (fx= i 0)
        x
        (loop (fx- i 1) (fl+ x 1.0)))))

(define (count1 init)
  (let loop ([i 1000] [x (safe-fl+ init)]) ; <-- force `init` as a flonum
    (if (fx= i 0)
        (safe-fl+ x) ;; <-- hint to allocate result flonum here
        (loop (fx- i 1) (fl+ x 1.0)))))

(define eloop #f)
(define (count2 u su v sv)
  (let loop ([i 1000]
             [u (safe-fl+ u)]
             [v (safe-fl+ v)]
             [su (safe-fl+ su)]
             [sv (safe-fl+ sv)]
             )
    (set! eloop loop)
    (if (fx> i 0)
        (loop (fx- i 1)
              (fl+ u su)
              (fl+ v sv)
              su
              sv
              )
        (safe-fl+ u v))))

(disassemble count2)
(count2 1.0 1.0 1.0 1.0)
(disassemble eloop)

=>

standard-module-name-resolver: collection not found
  for module path: disassemble
  collection: "disassemble"
  in collection directories:
   /home/pasterack/.racket/7.3/collects
   /home/pasterack/racket73/collects
   ... [166 additional linked and package directories]
  context...:
   show-collection-err
   standard-module-name-resolver
   syntax-local-module-exports
   /home/pasterack/racket73/collects/racket/require-transform.rkt:266:2: expand-import
   /home/pasterack/racket73/collects/racket/private/reqprov.rkt:571:24
   /home/pasterack/racket73/collects/racket/private/reqprov.rkt:559:5
   /home/pasterack/racket73/collects/racket/require-transform.rkt:266:2: expand-import
   /home/pasterack/racket73/collects/racket/private/reqprov.rkt:266:21: try-next
   /home/pasterack/racket73/collects/racket/private/reqprov.rkt:348:21: try-next
   /home/pasterack/racket73/collects/racket/private/reqprov.rkt:243:2: require
   apply-transformer-in-context
   apply-transformer52
   dispatch-transformer41
   do-local-expand50
   /home/pasterack/racket73/collects/syntax/wrap-modbeg.rkt:46:4: do-wrapping-module-begin
   apply-transformer-in-context
   ...