Carp/test/interop.carp
Scott Olsen 1175bb795b
fix: permit registering types in modules (#1362)
Historically, we did not support calling (register-type) within a
module--while there were instances of such calls (even in our core
library!) they were not properly handled in two ways:

1. They weren't added to the right place in the type environment.
2. Their corresponding emitted code wasn't correct.

This commit enables registering types in modules by making a few fixes:

1. Fix the logic in environment mutations -- before, adding a type to an
   environment would result in traversing the environment chain
   incorrectly. This is now fixed (we traverse modules and retrieve a
   type environment only at the end of the traversal).
2. Fix the typedef emission for registered types--it previously emitted
   the C code for the type path, not for the type definition (it called
   pathToC not tyToC).

This will now allow authors of wrapper libraries to add more structure
to their Carp wrapper APIs.

This commit also adds a test to check the behavior.
2021-12-12 14:56:41 +01:00

18 lines
418 B
Plaintext

(relative-include "interop.h")
(load "Test.carp")
(use Test)
(defmodule Wrap
(register-type Nested "NESTED")
(register make-nested (Fn [] Wrap.Nested) "make_nested")
(register test-nested (Fn [Wrap.Nested] Int) "test_nested")
)
(deftest test
(assert-equal test
&1
&(Wrap.test-nested (Wrap.make-nested))
"Types registered in modules are emitted correctly.")
)