|
| 1 | +# File Organization |
| 2 | + |
| 3 | +This document outlines the organization of files in the project. |
| 4 | + |
| 5 | +## Search Paths |
| 6 | + |
| 7 | +The search paths for a project are as follows and in this order: |
| 8 | + - The current directory, or the directory passed as the non-option argument to |
| 9 | + the compiler. |
| 10 | + - The paths specified in the `--search-path=<paths>` options. |
| 11 | + - The paths created by downloading packages specified in the `hic.toml` |
| 12 | + file, recursively. |
| 13 | + |
| 14 | +The search path is a `;` separated list of: |
| 15 | + - directories, |
| 16 | + - .zip files, |
| 17 | + - git repository URLs |
| 18 | + |
| 19 | +The `hic.toml` file includes the `[dependencies]` section |
| 20 | +which specifies the packages to be downloaded and their versions. |
| 21 | +Here is an example of a dependencies section: |
| 22 | + |
| 23 | +```toml |
| 24 | +[dependencies] |
| 25 | +foo = { url = "https://github.com/example/foo.git", branch = "v1.0" } |
| 26 | +``` |
| 27 | + |
| 28 | +> [!NOTE] |
| 29 | +> It is a reportable error if a repository URL is used more than once from |
| 30 | +> different branches. |
| 31 | +
|
| 32 | +> [!NOTE] |
| 33 | +> It is a reportable error if the same module is found in the search path. |
| 34 | +
|
| 35 | +## File Structure |
| 36 | +The file structure of a project or package is completely arbitrary. Each |
| 37 | +.hic file in the directory hierarchy is read by the compiler to determine |
| 38 | +its module name and what modules it imports. |
| 39 | + |
| 40 | +Directories and files that have a dot `.` prefix are ignored by the compiler. |
| 41 | +The compiler uses this to place downloaded packages in a `.hic/packages` |
| 42 | +directory. |
| 43 | + |
| 44 | +## A .hic source file |
| 45 | +A .hic file is a source file that contains code that implements a module or |
| 46 | +application. |
| 47 | + |
| 48 | +The first statement in a .hic file is either a `module` or `application` |
| 49 | +statement. This is followed by zero or more `import` statements. This forms |
| 50 | +the prologue of the file. Any other statements in the file terminates the |
| 51 | +prologue and starts the body of the file. |
| 52 | + |
| 53 | +The compiler will read the prologue of each .hic file in the directory hierarchy |
| 54 | +for each package listed in the search path. From this it will determine |
| 55 | +which files need to be compiled and in which order. |
| 56 | + |
| 57 | +A `module` or `application` statement may include an expression for conditional |
| 58 | +compilation which will be evaluated during the prologue scan to determine if the |
| 59 | +file should be compiled for the current platform, architecture, build-phase, or |
| 60 | +other conditions. |
| 61 | + |
| 62 | +> [!NOTE] |
| 63 | +> It is a reportable error if two .hic files have the same module or |
| 64 | +> application name after evaluation of the conditional compilation expression. |
| 65 | +
|
| 66 | +## Application executable |
| 67 | +An application executable is created by compiling a .hic file that contains an |
| 68 | +`application` statement. The executable is named with the name specified in the |
| 69 | +`application` statement and is placed next to the .hic file. |
| 70 | + |
| 71 | +Like the `module` statement, the `application` statement may include an |
| 72 | +expression for conditional compilation which will be evaluated during the |
| 73 | +prologue scan to determine if the file should be compiled for the current |
| 74 | +platform, architecture, build-phase, or other conditions. |
| 75 | + |
| 76 | +There are a set of special conditions which must be part of the conditional |
| 77 | +compilation expression for an application to be compiled in the current build |
| 78 | +phase. These conditions are: |
| 79 | + - `download`: This application is used for downloading data from the |
| 80 | + internet before generating code. |
| 81 | + - `generate` : This application is used for generating code. |
| 82 | + |
| 83 | +## Build Phases |
| 84 | + |
| 85 | + 1. **Package Download Phase**: The compiler will download the packages |
| 86 | + specified in the `hic.toml` file, recursively. This includes downloading |
| 87 | + the source code from the specified URLs, and .zip files and adding them |
| 88 | + to the search path. Each package will be placed in a |
| 89 | + `.hic/packages/<package_name>` directory of the current package being |
| 90 | + compiled. The package name is derived from the URL or .zip file name. |
| 91 | + 2. **Per Package**: For each package in depth-first order: |
| 92 | + - Compile the package with the `download` build phase, any application with |
| 93 | + the `download` condition will be compiled and executed in alphabetical |
| 94 | + order. |
| 95 | + - Compile the package with the `generate` build phase, any application with |
| 96 | + the `generate` condition will be compiled and executed in alphabetical |
| 97 | + order. |
| 98 | + - Compile the package normally. |
0 commit comments