aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-11-28 16:06:15 -0600
committerGanesh Viswanathan <dev@genotrance.com>2018-11-28 16:06:15 -0600
commita2ff8ea64c5ff4cd54157ce3c35cbeef59d3187e (patch)
tree2fcaf48cc110f2d0e7637cb87ed242f2f79c93a3
parent77fafa0adaa83c3eb73ce28e4a2a93631c721deb (diff)
downloadnimterop-a2ff8ea64c5ff4cd54157ce3c35cbeef59d3187e.tar.gz
nimterop-a2ff8ea64c5ff4cd54157ce3c35cbeef59d3187e.zip
Update README [ci skip]
-rw-r--r--README.md18
1 files changed, 11 insertions, 7 deletions
diff --git a/README.md b/README.md
index c9625ba..38b2f1d 100644
--- a/README.md
+++ b/README.md
@@ -6,19 +6,21 @@ Nimterop is a [Nim](https://nim-lang.org/) package that aims to make C/C++ inter
Nim has one of the best FFI you can find - importing C/C++ is supported out of the box. All you need to provide is type and proc definitions for Nim to interop with C/C++ binaries. Generation of these wrappers is easy for simple libraries but quickly gets out of hand. [c2nim](https://github.com/nim-lang/c2nim) greatly helps here by parsing and converting C/C++ into Nim but is limited due to the complex and constantly evolving C/C++ grammar. [nimgen](https://github.com/genotrance/nimgen) mainly focuses on automating the wrapping process and fills some holes but is again limited to c2nim's capabilities.
-The goal of nimterop is to leverage the [tree-sitter](http://tree-sitter.github.io/tree-sitter/) engine to parse C/C++ code and then convert relevant portions of the AST into Nim definitions using compile-time macros. [tree-sitter](https://github.com/tree-sitter) is a Github sponsored project that can parse a variety of languages into an AST which is then leveraged by the [Atom](https://atom.io/) editor for syntax highlighting and code folding. The advantages of this approach are multifold:
+The goal of nimterop is to leverage the [tree-sitter](http://tree-sitter.github.io/tree-sitter/) engine to parse C/C++ code and then convert relevant portions of the AST into Nim definitions. [tree-sitter](https://github.com/tree-sitter) is a Github sponsored project that can parse a variety of languages into an AST which is then leveraged by the [Atom](https://atom.io/) editor for syntax highlighting and code folding. The advantages of this approach are multifold:
- Benefit from the tree-sitter community's investment into language parsing
-- Leverage Nim macros which are a user API and relatively stable
-- Avoid depending on Nim compiler API which is evolving constantly
+- Avoid depending on Nim compiler API which is evolving constantly and makes backwards compatibility a bit challenging
+
+Most of the functionality is contained within the `toast` binary that is built when nimterop is installed and can be used standalone similar to how c2nim can be used today. In addition, nimterop also offers an API to pull in the generated Nim content directly into an application.
The nimterop feature set is still limited when compared with c2nim. Supported language constructs include:
- `#define NAME VALUE` where `VALUE` is a number (int, float, hex)
- `struct X`, `typedef struct`, `enum X`, `typedef enum`
- Functions with primitive types, structs, enums and typedef structs/enums as params and return values
+- Pointers to data types
Given the simplicity and success of this approach so far, it seems feasible to continue on for more complex code. The goal is to make interop seamless so nimterop will focus on wrapping headers and not the outright conversion of C/C++ implementation.
-C++ constructs are still TBD depending on the results of the C interop.
+C++ constructs such as classes and templats are still TBD depending on the results of the C interop.
__Installation__
@@ -37,7 +39,7 @@ git clone http://github.com/genotrance/nimterop && cd nimterop
nimble installWithDeps
```
-This will download and install nimterop in the standard Nimble package location, typically ~/.nimble. Once installed, it can be imported into any Nim program.
+This will download and install nimterop in the standard Nimble package location, typically `~/.nimble`. Once installed, it can be imported into any Nim program. Note that the `~/.nimble/bin` directory needs to be added to the `PATH` for nimterop to work.
__Usage__
@@ -55,6 +57,8 @@ cCompile("clib/src/*.c")
Refer to the ```tests``` directory for examples on how the library can be used.
+The `toast` binary can also be used directly on the CLI. The `--help` flag provides more details.
+
__Documentation__
Detailed documentation is still forthcoming.
@@ -77,9 +81,9 @@ Detailed documentation is still forthcoming.
__Implementation Details__
-In order to use the tree-sitter C library at compile-time, it has to be compiled into a separate binary called `toast` (to AST) since the Nim VM doesn't yet support FFI. `toast` takes a C/C++ file and runs it through the tree-sitter API which returns an AST data structure. This is then printed out to stdout in a Lisp S-Expression format.
+In order to use the tree-sitter C library at compile-time, it has to be compiled into a separate binary called `toast` (to AST) since the Nim VM doesn't yet support FFI. `toast` takes a C/C++ file and runs it through the tree-sitter API which returns an AST data structure. This can then be printed out to stdout in a Lisp S-Expression format or the relevant Nim wrapper output. This content can be saved to a `.nim` file and imported if so desired.
-The `cImport()` proc runs `toast` on the specified header file and parses the resulting S-Expression back into an AST data structure at compile time. This AST is then processed to generate the relevant Nim definitions to interop with the code accordingly. A few other helper procs are provided to influence this process.
+Alternatively, the `cImport()` macro allows easier creation of wrappers in code. It runs `toast` on the specified header file and injects the generated wrapper content into the application at compile time. A few other helper procs are provided to influence this process.
The tree-sitter library is limited as well - it may fail on some advanced language constructs but is designed to handle them gracefully since it is expected to have bad code while actively typing in an editor. When an error is detected, tree-sitter includes an ERROR node at that location in the AST. At this time, `cImport()` will complain and continue if it encounters any errors. Depending on how severe the errors are, compilation may succeed or fail. Glaring issues will be communicated to the tree-sitter team but their goals may not always align with those of this project.