diff --git a/specs/GENERAL.md b/specs/GENERAL.md index 9da3181..a3745e1 100644 --- a/specs/GENERAL.md +++ b/specs/GENERAL.md @@ -12,3 +12,4 @@ void main() { puts("Hello, world!"); } ``` +. \ No newline at end of file diff --git a/specs/IMPORTS.md b/specs/IMPORTS.md new file mode 100644 index 0000000..0e5717f --- /dev/null +++ b/specs/IMPORTS.md @@ -0,0 +1,31 @@ +# Imports +The import statement allows one module access to the public declarations of another module. + +## Syntax +The import statement uses the following syntax: + +```c2 +import module_name; +``` + +They can optionally be prefixed by the `public` keyword, in which case the module will +export everything in the import transitively. + +For instance, + +```c2 +--- a.c2 +module a; +import b; + +--- b.c2 +module b; +public import c; + +--- c.c2 +module c; + +// Some declarations +``` + +In this example, both module a and b can access the declarations in module c. diff --git a/v0/ast.h b/v0/ast.h index 26b6ca2..e1990d5 100644 --- a/v0/ast.h +++ b/v0/ast.h @@ -4,11 +4,15 @@ #ifndef AST_H #define AST_H +#include #include typedef struct { /// @brief The name of the module being imported. char* module_name; + + /// @brief Whether the import is public or not. + bool is_public; } ImportDeclaration; /** @@ -21,7 +25,7 @@ typedef struct { /// @brief The list of imports in the module. ImportDeclaration* imports; - + /// @brief The number of imports in the module. size_t import_count; } Module;