Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

External types #95

Merged
merged 8 commits into from
Jul 17, 2015
Merged

External types #95

merged 8 commits into from
Jul 17, 2015

Conversation

mknejp
Copy link
Contributor

@mknejp mknejp commented May 27, 2015

This is the implementation foreshadowed in #52 based on the latest and greatest master.

Long story short: This allows Djinni to generate YAML files for storing all the information necessary to integrate the generated types in a different project. The directive @extern "mylib.yaml" makes the types within available to your Djinni project.

These YAML files can also be created by hand and, provided with the necessary translators, allow the integration of types not generated by Djinni (e.g. std::chrono::duration<-> NSTimeInterval <-> java.time.Duration).

I added a section to the README and there are some examples in the test suite. One of them mimics the builtin "date" type, showing that complexity can be removed from the generators for types that don't require special magic. However that leaves the open question of how to inject these "standard" types. The other example is duration:

@extern "duration.yaml"

r = record {
  h: duration<i32, h>;
  min: duration<i32, min>;
  ns: duration<i32, ns>;
}

Something to keep in mind is the YAML file stores all the include paths as they were specified in the Djinni invocation. For some types that includes paths to the support lib, so maybe it would be wise to make a standard include directory for the "standard" headers and require people to set their search paths to it.

This feature does not change the output of existing stuff.

@mknejp
Copy link
Contributor Author

mknejp commented Jun 8, 2015

rebased

@zaren678
Copy link

zaren678 commented Jul 6, 2015

+1

Marshals use the respective members to resolve typenames, signatures, parameter types etc.
All names in MExtern are expected to be fully qualified.
These YAML files generated by Djinni hold all the necessary information to integrate these types with other Djinni projects, thus making (precompiled) libraries with possible.

There are still limitations:
- Extern enums/records cannot be used as constants as their enumerant/field information is not yet preserved.
- Include paths are fixed at the point of YAML generation, including paths do Djinni's support-lib. This may require some form of placeholders, or being smart about project structure in general.

Generation is controlled with following options
- --yaml-out: The output folder for YAML files (Generator disabled if unspecified).
- --yaml-out-file: If specified all types are merged into a single YAML file instead of generating one file per type  (relative to --yaml-out).
- --yaml-prefix: The prefix to add to type names stored in YAML files (default: "").
This is a demonstration that the generator can be further simplified by moving types which do not require dedicated generator magic to externally declared types.
This demonstrates some fancy template usage to provide a std::chrono::duration<rep, period> capable external type. It is mapped to NSTimeInterval and java.time.Duration.

It can be used after importing "duration.yaml" as follows:
- duration<i32, s> => std::chrono::duration<i32, std::ratio<1>>
- duration<f64, ns> => std::chrono::duration<double, std::nano>
@mknejp
Copy link
Contributor Author

mknejp commented Jul 13, 2015

rebased

j4cbo added a commit that referenced this pull request Jul 17, 2015
Awesome. Thanks for all the rebasing!
@j4cbo j4cbo merged commit 708d621 into dropbox:master Jul 17, 2015
@mknejp mknejp deleted the feature/extern-types-2 branch July 20, 2015 23:03
@pwais pwais mentioned this pull request Jul 27, 2015
@j4cbo j4cbo mentioned this pull request Jul 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants