Carp/examples
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
..
headers chore: Move some examples to test/produces-output (#989) 2020-11-23 06:30:43 +01:00
benchmark_mandelbrot.carp fix: re-add benchmarks (#1166) 2021-02-04 08:35:48 +01:00
benchmark_n-body.carp fix: re-add benchmarks (#1166) 2021-02-04 08:35:48 +01:00
bugs.carp Bug example. 2020-05-05 15:48:56 +02:00
carp_demo.carp feat: Remove address (#1223) 2021-05-27 22:04:46 +02:00
derive.carp feat: Derive (#1120) 2021-01-15 10:48:34 +01:00
drop.carp feat: Add drop interface (#1088) 2021-01-31 21:15:10 +01:00
external_struct.carp chore: Move some examples to test/produces-output (#989) 2020-11-23 06:30:43 +01:00
fonts.carp chore: Move some examples to test/produces-output (#989) 2020-11-23 06:30:43 +01:00
functor.carp feat: add box type (#1358) 2021-11-30 10:35:22 +01:00
game_of_life.carp feat: Remove address (#1223) 2021-05-27 22:04:46 +02:00
generic_structs.carp Fix all nth usage 2019-10-31 06:23:23 -03:00
glfw.carp chore: Move some examples to test/produces-output (#989) 2020-11-23 06:30:43 +01:00
guessing_game.carp chore: Move some examples to test/produces-output (#989) 2020-11-23 06:30:43 +01:00
langtons_ant.carp (and) and (or) now handle any number of parameters (#1251) 2021-06-20 21:44:04 +02:00
maps.carp Renamed example/map.carp because it got loaded by core.carp when 2019-03-21 14:31:19 +01:00
minimal_sdl.carp Added dynamic function 'Project.no-echo' to disable echoing in examples. 2018-06-05 10:05:33 +02:00
mutual_recursion.carp Updates mutual recursion example (#983) 2020-11-20 15:12:49 +01:00
nested_lambdas.carp Fixed lambda capture in presence of let bindings 2020-06-15 21:44:11 +02:00
no_core.carp refactor: Move code out of Macros.carp into other files (#1014) 2020-11-28 12:53:18 +01:00
quasiquote.carp feat: Quasiquotation (#1129) 2021-01-15 10:50:04 +01:00
reptile.carp feat: Remove address (#1223) 2021-05-27 22:04:46 +02:00
sorting.carp Add some more calls to implement to make tests pass 2020-05-10 13:32:22 -04:00
sounds.carp Merge 2020-05-11 16:10:35 +02:00
static_array.carp Remove bad example. 2020-04-29 11:29:39 +02:00
sumtypes.carp More bugfixes concerning wildcards. 2019-02-12 23:01:33 +01:00
unicode.carp Allow unicode identifiers 2020-05-11 16:10:41 +02:00
updating.carp Deftype generates 'update' functions that expect refs to functions too. 2018-11-14 14:21:12 +01:00
vector.carp The '(load)' command will work relative to the file containing it, if 2019-03-22 20:33:06 +01:00