So you've added a new feature, but how do you even begin to integrate it with the rest of Nanoverse? Start by understanding the build process of Nanoverse.
Understanding how Nanoverse works will allow us to better understand how to add functionality. At its simplest, Nanosyntax interprets texts arguments from clients into constructor arguments for Java Objects.
1. User writes instructions in a `.nano` file.
2. The `.nano` file is interpreted and parsed into an abstract grammatical tree.
Implementation Note: This step is generic, so only one interpreter is needed for the entire project.
3. Each “syntax token” is given a unique identifier and symbol table.
4. Each symbol is loaded (by a unique `Loader`) as a Java Object.
5. If any unspecificed arguments have default values, the default values will need to be supplied with an symbol `Interpolator`, i.e. a unique `Interpolator` is necessary for every symbol type with default values.
6. After all values are supplied (either by the user or as default values), an appropriate `Factory` initializes an appropriate Java Object. The object is instantiated by a `FactoryHelper`. Implementation Note: A `Factory` sets parameters as a `Loader` supplies them, i.e., in arbitrary order.
Now understanding the Nanoverse lifespan, we can work backwards to add your new feature.
1. Create a Java Object that implements your desired functionality. If you're reading this page, you've probably already done this step!
2. Add a constructor argument to expose the Java logic you just wrote.
3. Automatically generate the `Factory` object for the modified class. \\ Implementation Note: `meta/factory/GenerateFactoryTree` will, as its name suggests, create a factory for each `@FactoryTarget`. Your new factories will appear in `meta/out/…` (see below for further details).
4. Copy your factory to `src/nanoverse/compiler/pipeline/instantiate/factory/…`
5. Create and/or modify the corresponding `Loader` and/or `Interpolator` at `src/nanoverse/compiler/pipeline/instantiate/loader`.
6. Create and/or modify the corresponding instance symbol table at `src/nanoverse/compiler/pipeline/translate/symbol`.
7. If you have added an instance type, modify the appropriate class symbol table. Implementation Note: The class symbol table should be in the same package as your instance symbol table.
8. For the sanity of Nanoverse's maintainer: add tests for the `Interpolator`, instance symbol table, and class symbol table as necessary.
This is easier done than said: it's a pattern, and you just keep cascading similar changes up a series of files. There are numerous examples to follow in the code itself.
- The factory generator works by reflection. By default, Java does not preserve parameter names in compiled classes. Because of this, the factory generator produces methods with dangerously inspecific names like “arg0”. To prevent this, add the `–parameters` argument to javac. This is easily done in IntelliJ from the settings/preferences window. Search for `javac` and add `–parameters` as input.
- Currently, there is an error in the template for factories that `import`s the wrong package name. As a result, the Nanoverse maintainer has to manually correct it each time a factory is regenerated. When creating facotries, make sure to examine the imports and correct the incorrect one.