Commit Graph

16 Commits

Author SHA1 Message Date
Scott Olsen
380945bf32
feat: add box type (#1358)
* feat: add box templates and box type

This commit adds an implementation of Boxes, memory manged heap
allocated values.

Boxes are implemented as C pointers, with no additional structure but
are treated as structs in Carp. To facilitate this, we need to add them
as a clause to our special type emissions (TypesToC) as they'd otherwise
be emitted like other struct types.

Co-authored-by: Veit Heller <veit@veitheller.de>

* fix: slight memory management fix for Box

Make sure we free the box!

* test: add tests for box (including memory checks)

* Revert "fix: Ignore clang nitpick"

This reverts commit 70ec6d46d4.

* fix: update example/functor.carp

Now that a builtin type named Box exists, the definitions in this file
cause a conflict. I've renamed the "Box" type in the functor example to
remove the conflict.

* feat: add Box.peek

Box.peek allows users to transform a reference to a box into a a
reference to the box's contained value. The returned reference will have
the same lifetime as the box. This function allows callers to manipulate
the value in a box without re-allocation, for example:

```clojure
(deftype Num [val Int])

(let-do [box (Box.init (Num.init 0))]
  (Num.set-val! (Box.peek &box) 1)
  @(Num.val (Box.peek &box)))
```

This commit also includes tests for Box.peek.

Co-authored-by: TimDeve <TimDeve@users.noreply.github.com>

Co-authored-by: Veit Heller <veit@veitheller.de>
Co-authored-by: Erik Svedäng <erik@coherence.io>
Co-authored-by: TimDeve <TimDeve@users.noreply.github.com>
2021-11-30 10:35:22 +01:00
Scott Olsen
b61a439e29 Update test to account for constrained interfaces
Constrained interfaces require little change to core carp. In rare cases
(illustrated in test/interfaces.carp) we need to make our functions
slightly more specific. This weakens inference slightly, but in my
opinion is a reasonable case of weakness and not a fault of the type
system.

Exceptional cases that were typed `a-> a` that is, cases that relied on
the previous typing errors related to interfaces, as might be expected,
no longer work (as is the case for the higher-order use of fmap in
examples/functor.carp).

Aside from that, nothing changes.
2020-06-01 23:39:19 -04:00
Scott Olsen
f13a2fdd9d Add some more calls to implement to make tests pass 2020-05-10 13:32:22 -04:00
Erik Svedäng
fe55144273 Follow convention of passing lambdas as refs as default. 2018-11-14 14:09:43 +01:00
Erik Svedäng
669aca2b96 Added dynamic function 'Project.no-echo' to disable echoing in examples. 2018-06-05 10:05:33 +02:00
Erik Svedäng
b569226919 Don't run examples by default. 2018-02-01 16:26:04 +01:00
Erik Svedäng
8281dfa109 Made inc, dec, max, min into interfaces. Changed Array.max/min to new
names. Fixed tests and removed special max/min from Statistics module.
2018-01-29 07:14:56 +01:00
Erik Svedäng
936dd8b26c Changed type of member getter method to always returning a Ref (used to be non-ref for primitive types). 2018-01-26 21:23:29 +01:00
Erik Svedäng
d0cca0062e The fmap works now. 2017-11-22 23:24:38 +01:00
Erik Svedäng
7f57e49c36 Changed names of map-functions to 'copy-map' and 'endo-map'. 2017-10-17 16:54:00 +02:00
Erik Svedäng
e08683e7d2 Relaxed the requirement for all multi symbols to be resolved. Allows for some bugs though... 2017-10-12 14:35:28 +02:00
Erik Svedäng
8cae7a7a3b A way to run all tests in one go. 2017-09-08 12:24:57 +02:00
Erik Svedäng
e37a3e679b s/import/use in carp files. 2017-09-06 10:05:19 +02:00
Erik Svedäng
571f46bd9d Give up on making range a template, was probably a bad idea... 2017-07-12 09:55:30 +02:00
Erik Svedäng
5ae8f36ee4 Fixing errors with references... 2017-07-06 13:29:13 +02:00
Erik Svedäng
c80526cfaa REPLACE WITH HASKELL VERSION 2017-06-26 11:15:03 +02:00