Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add c-name meta field #1398

Merged
merged 11 commits into from
Mar 18, 2022
Merged

feat: add c-name meta field #1398

merged 11 commits into from
Mar 18, 2022

Conversation

scolsen
Copy link
Contributor

@scolsen scolsen commented Mar 15, 2022

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:

(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.

fixes #1389

scolsen and others added 11 commits November 29, 2021 10:22
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]>
Make sure we free the box!
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.
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]>
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.
Adds a section on using the c-name meta field to override identifiers
exclusively defined in Carp. Also performs some minor editorial.
@scolsen
Copy link
Contributor Author

scolsen commented Mar 15, 2022

I'm not sure why the commit history here contains a bunch of old stuff. afaict the change set is correct.

I can re-branch and cherrypick if we want to discard these old commits.

@scolsen scolsen requested a review from a team March 15, 2022 17:07
Copy link
Collaborator

@eriksvedang eriksvedang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Nice feature 💪

@eriksvedang
Copy link
Collaborator

@scolsen I'll squash merge so I think it's fine to leave the history. Do you know if the Windows build failing is a real problem?

@TimDeve
Copy link
Contributor

TimDeve commented Mar 17, 2022

@scolsen I'll squash merge so I think it's fine to leave the history. Do you know if the Windows build failing is a real problem?

Seems to be unrelated, I'll try to raise a PR for that separetely.

Copy link
Member

@hellerve hellerve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks especially for the doc rewrite! <3

@eriksvedang eriksvedang merged commit 35edce7 into carp-lang:master Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

permit overriding emitted C names
4 participants