Commit Graph

11 Commits

Author SHA1 Message Date
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
Veit Heller
d3a6ca562f
docs: document core modules (#1271) 2021-07-05 14:48:35 +02:00
Tim Dévé
cbda258fcc Moves StdInt functions with dependency on String into String.carp
This allows to import StdInt.carp by itself in --no-core situations
2020-10-26 19:14:50 +00:00
hellerve
06607c2203 core: make bit-* interfaces 2020-07-08 21:11:28 +02:00
Erik Svedäng
aae743fb35
Merge pull request #769 from scolsen/implement-prim
Add an `implements` primitive, update core
2020-05-12 21:45:29 +02:00
Jorge Acereda
de89be2bb5 Use system-include like the rest. 2020-05-11 16:08:40 +02:00
Scott Olsen
f13a2fdd9d Add some more calls to implement to make tests pass 2020-05-10 13:32:22 -04:00
scottolsen
040e9e4391 Add an implements primitive, update core
This change adds a new primitive Implements which changes interface
implementations from being implicit to being explicit. Going forward,
users will have to declare (implements <interface> <implementation>) to
explicitly add a function to an interface. This provides two benefits:

- Prevents unwitting name clashes. Previously, if one defined a function
  that happened to have the same name as an interface, it was
  automatically assumed the function implemented that interface when this
  is not always the intention, especially in large programs.
- Name flexibility. One can now implement an interface with a function
  that has a different name than the interface, which allows for greater
  flexibility.

I've updated core to make the necessary calls to the new primitive.

Since str and copy are derived automatically for types, we treat these
functions as a special case and auto-implement the interfaces.
2020-05-09 12:59:47 -04:00
Scott Olsen
32b61fbced Add zero for other StdInt types 2020-02-20 23:39:25 -05:00
Scott Olsen
03d93f7b65 Add zero values for unsigned int types 2020-02-20 14:12:14 -05:00
hellerve
657f27c6ac core: add stdint types 2020-02-17 10:42:07 +01:00