Carp/core/Interfaces.carp
Scott Olsen 5d530b7491
feat: register MAX and MIN macros for stdint types (#1412)
* feat: register MAX and MIN macros for stdint types

Adds MAX and MIN for each INT<N> type and MAX for each UINT<N> type.
These are macros defined by stdint.h and are sometimes useful for bounds
determinations and conversions and such.

* feat: make MAX and MIN interfaces

Since several numeric types define maximum and minimum values, it makes
sense for these to be defined as interfaces. This commit also makes
existing definitions of MAX and MIN for Carp's numeric types implement
the interfaces.

* fix: respect let binding shadowing in memory management (#1413)

* fix: respect let binding shadowing in memory management

Previously, we didn't account for shadowing in let bindings in our
memory management routines. This led to rare situations in which
multiple deleters might be added for a single variable name, for
example:

```clojure
(defn n [xs]
  (let [xs [1 2 3]
        n &xs]
    n))
```

The borrow checker would fail on this code since it would assign `xs`
two deleters, one for the untyped argument and another for the let
binding.

Instead, we now perform *exclusive* ownership transfer for the duration
of the let scope--when a shadow is introduced, the previous deleters for
that variable name are dropped until the end of the let scope, since we
evaluate all instances of the shadowed name to the more local binding.
At the end of the let scope, the original deleter is restored.

Fixes issue #597

* refactor: improved dead reference error for let

Since let scopes resolve to their bodies, we can report the body of the
let as the xobj producing an error when a dead reference is returned.

* test: update error message for dead refs in let

* test: add regression test for issue #597

Ensure we don't regress and fail to manage memory when let bindings
shadow function argument names.

* fix: respect symbol modes on interface concretization (#1415)

* fix: respect symbol modes on interface concretization

When concretizing interfaces (finding the appropriate implementation at
a call site) we previously set the lookup mode of all such resolved
symbols to CarpLand AFunction. This incorrectly overwrites the lookup
mode of Externally registered types, causing them to emit incorrect C
when the user specifies an override.

We now preserve whatever lookup mode is assigned to the implementation
the concretization resolves the interface to. This not only fixes the
external override emission issue, but should be more correct in general.

fixes #1414

* test: add regression test for issue #1414
2022-04-13 09:32:46 +02:00

74 lines
2.0 KiB
Plaintext

;; The 'copy' and 'str' interfaces are defined internally:
;;(definterface copy (λ [&a] a))
;;(definterface str (λ [a] String))
(definterface = (λ [a a] Bool))
(definterface add-ref (λ [&a &a] a))
(definterface sub-ref (λ [&a &a] a))
(definterface mul-ref (λ [&a &a] a))
(definterface div-ref (λ [&a &a] a))
(definterface + (λ [a a] a))
(definterface - (λ [a a] a))
(definterface * (λ [a a] a))
(definterface / (λ [a a] a))
(definterface mod (λ [a a] a))
(definterface bit-and (λ [a a] a))
(definterface bit-or (λ [a a] a))
(definterface bit-xor (λ [a a] a))
(definterface bit-not (λ [a] a))
(definterface bit-shift-left (λ [a a] a))
(definterface bit-shift-right (λ [a a] a))
(definterface < (λ [a a] Bool))
(definterface > (λ [a a] Bool))
(definterface zero (λ [] a))
(definterface inc (λ [a] a))
(definterface dec (λ [a] a))
(definterface neg (λ [a] a))
(definterface to-int (λ [a] Int))
(definterface from-int (λ [Int] a))
(definterface format (λ [&String a] String))
(definterface from-string (λ [&String] a))
(definterface random (Fn [] a))
(definterface random-between (Fn [a a] a))
(definterface pi a)
(definterface abs (λ [a] a))
(definterface acos (λ [a] a))
(definterface asin (λ [a] a))
(definterface atan (λ [a] a))
(definterface atan2 (λ [a a] a))
(definterface ceil (λ [a] a))
(definterface cos (λ [a] a))
(definterface cosh (λ [a] a))
(definterface exp (λ [a] a))
(definterface floor (λ [a] a))
(definterface frexp (λ [a (Ref Int)] a))
(definterface ldexp (λ [a Int] a))
(definterface log (λ [a] a))
(definterface log10 (λ [a] a))
(definterface mod (λ [a a] a))
(definterface modf (λ [a (Ref a)] a))
(definterface pow (λ [a a] a))
(definterface sin (λ [a] a))
(definterface sinh (λ [a] a))
(definterface sqrt (λ [a] a))
(definterface tan (λ [a] a))
(definterface tanh (λ [a] a))
(definterface MAX a)
(definterface MIN a)
(definterface slice (Fn [&a Int Int] a))
(definterface blit (Fn [a] a)) ; For types that can be freely memcopied -- exact name is up for discussion
(definterface empty? (Fn [&a] Bool))