-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 <[email protected]> * 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 70ec6d4. * 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 <[email protected]> * feat: add c-name meta key for code emission overrides This commit adds a new special compiler meta key, c-name, that enables users to explicitly c the C identifier Carp should emit for a given symbol. For now, it is only explicitly supported for Def and Defn forms. For example: ```clojure (defn foo-bar [] 2) (c-name foo-bar "foo_bar") ``` Will cause foo-bar in emitted C code to be emitted as `foo_bar` instead of `foo_MINUS_bar`. I've also refactored some of the meta code to be a bit more principled about keys that are understood by the compiler. * docs: update CInterop docs Adds a section on using the c-name meta field to override identifiers exclusively defined in Carp. Also performs some minor editorial. Co-authored-by: Veit Heller <[email protected]> Co-authored-by: Erik Svedäng <[email protected]> Co-authored-by: TimDeve <[email protected]>
- Loading branch information
1 parent
3148703
commit 35edce7
Showing
5 changed files
with
128 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters