Skip to content

Commit 4630e0e

Browse files
authored
feat: allow C types to satisfy all type constraints (#1306)
This commit builds on the emit-c feature by permitting C typed values to be used anywhere in Carp code. For example, if one wants to use the literal C macro `EDOM`: ```clojure (register EDOM C "EDOM") (Int.+ 1 EDOM) => 34 ``` when compiled, this will produce the call: ```c Int__PLUS(1, EDOM) ``` So it provides a quite flexible means of using C macros directly. It is, of course, also radically unsafe. Anyone registering and using values of the C type better be cautious. One can get pretty crazy with this feature: ```clojure (register comment-it C "// commented out;") (Int.+ 1 comment-it) => int _11 = Int__PLUS_(1, // commented out;) int* _12 = &_11; // ref String _13 = IntRef_str(_12); ```
1 parent d0a98a5 commit 4630e0e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/Constraints.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ solveOneInternal mappings constraint =
177177
Left err -> Left err
178178
Right ok -> foldM (\m (aa, bb) -> solveOneInternal m (Constraint aa bb i1 i2 ctx ord)) ok (zip args [b, ltB])
179179
-- Else
180+
Constraint _ CTy _ _ _ _ -> Right mappings
181+
Constraint CTy _ _ _ _ _ -> Right mappings
180182
Constraint aTy bTy _ _ _ _ ->
181183
if aTy == bTy
182184
then Right mappings

src/Types.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ areUnifiable (FuncTy argTysA retTyA ltA) (FuncTy argTysB retTyB ltB)
291291
ltBool = areUnifiable ltA ltB
292292
in all (== True) (ltBool : retBool : argBools)
293293
areUnifiable FuncTy {} _ = False
294+
areUnifiable CTy _ = True
295+
areUnifiable _ CTy = True
294296
areUnifiable a b
295297
| a == b = True
296298
| otherwise = False

0 commit comments

Comments
 (0)