Skip to content

Commit

Permalink
add inline attributes to number conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
YarinHeffes authored and stylewarning committed Feb 13, 2025
1 parent 1befb28 commit 7f92e13
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/math/conversions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ supported 64-bit implementation."))))
"An alist which pairs the names of Coalton's native integer types with equivalent Common Lisp type specifiers."))

(coalton-toplevel
(inline)
(declare unsafe-cast (:any -> :other))
(define (unsafe-cast x)
"Both :ANY and :OTHER must be natively represented by a subtype of `cl:integer', and X must be a valid member of :OTHER."
(lisp :other (x) x))

(inline)
(declare unify (:ty -> :ty -> :ty))
(define (unify _ use)
"Declare a constraint that two values are of the same type.
Expand Down Expand Up @@ -84,6 +86,7 @@ Used in `cast-if-inbounds' to force the type inference engine to read minBound a
Emitted by `define-integer-conversions' only if every element of FROM-TYPE can be represented in TO-TYPE."
`(define-instance (Into ,from-type ,to-type)
(inline)
(define into unsafe-cast)))

(cl:defun define-integer-try-into-instance (from-type to-type)
Expand All @@ -92,6 +95,7 @@ Emitted by `define-integer-conversions' only if every element of FROM-TYPE can b
Emitted by `define-integer-conversions' when some elements of FROM-TYPE cannot be represented in TO-TYPE,
either because FROM-TYPE is signed and TO-TYPE is unsigned, or because FROM-TYPE is wider than TO-TYPE."
`(define-instance (TryInto ,from-type ,to-type String)
(inline)
(define tryInto cast-if-inbounds)))

(cl:defun definitely-subtype? (sub super)
Expand Down Expand Up @@ -146,6 +150,7 @@ cannot be represented in :TO. These fall into a few categories:
(cl:defmacro integer-into-float (integer coalton-float lisp-float)
`(coalton-toplevel
(define-instance (Into ,integer ,coalton-float)
(inline)
(define (into x)
(lisp ,coalton-float (x)
(cl:coerce x ',lisp-float))))))
Expand Down

0 comments on commit 7f92e13

Please sign in to comment.