Open haxscramper opened 3 years ago
Make wrapper analyze build environment to provide necessary information for a wrapper to function properly or fail
Directly related - https://github.com/nim-lang/RFCs/issues/414
Technically I'm aiming to produce a wrapper, not drag the whole build system together with me, so #20 is related
Configuration for more sophisticated wrapper logic. A lot of additional information that is not accessible even to the C compiler (like magical int returns values) that should be handled. Previous clang-based implementation allowed passing a series of callbacks for automatically altering generation and handling of the code, but this must be generalized for tree-sitter as well.
.requiresinit.
annotation if there is no default constructor provided (or default constructor is implicitly deleted etc. This information should be stored inCxxObject
in form of flags, like 'copyable', 'default-constructible' etc.)tuple[]
returns :: Need to know which parameters arein
, which areout
. Sometimes this is mentioned in documentation, but in general this is a "dark knowledge", not formally noted down anywhere.int
return and someenum
definition.#define PAPI_OK 0
,#define PAPI_EINVAL -1
) :: It is possible to infer macro enum boundaries to some degree (if they follow certain naming pattern), but grouping based on "enum begin" and "enum end" seems less error-prone.1 << N
enum values. Provideset[E]
helper interfaces for these..
- (e.g.struct A { struct {int x, y;}; };
can be used asobjectOfA.x
). This might interfere with #7, so it needs to be configurable if possible.+
operator and other low-level C mechanicsfree
functions that could be used for it. Does not really make sense to wrap everything inwhen
, unless it is a single-file library.ptr T
can be wrapped in newly declared nim objects. This way, we can get proper memory management semantics using=destroy
hooks. For example,git_pathspec
can be wrapped asgit_pathspec_c
and then put intogit_pathspec
object as aptr git_pathspec_c
field. All low-level C library API procs are wrapped asgit_pathspec_create_raw
(added_raw
suffix) and then additionally wrapped in theassert arg != nil
checks. For example#include
directive, so it is only a matter of a single predicate that controls how imports are handled.In addition to regular source code enhancement features, it is also possible to automatically generate
.nimble
project files that would automatically handle installation/build and other project-related parts of the process. Similar to the https://github.com/nimterop/nimterop#build-api, but again, without the need to depend on the hcparse run/compile-time framework. An alternative solution would be to put all of this logic into a small no-dependency package and make all generated wrappers depend on this. Basically, I want to decrease 'bus factor' of the generated wrappers as much as possible. Ideally, I should be able to make build and installation of the wrapped library optional. Related - https://github.com/nim-lang/RFCs/issues/398 and #11