You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add language constructs to include source code from other Nitrogen files. I like PHP here where they have include and required and then an _once variant of each. I think that allows flexibility on how strict or loose code needs to be.
Implementation details: Can be implemented as a collection of functions or as keywords and constructs directly in the language. Either method would use the same underlying process. A map would be used to store pathnames of source code as it's included. Each path will map to an *ast.Program struct. For the _once variants, nil can be used instead as the parsed tree will never be used again. If a file couldn't be included and it's not required, an Error would be generated and returned. If the script is required, an Exception is returned causing execution to halt.
Implementing as a language keyword and direct AST node would probably be more efficient as an evaluated function call wouldn't need to get setup and invoked. Even builtins need to do a bit of type casting and argument checking. Using an AST node, the evaluator can be guaranteed the arguments and options are correct and use the node directly without a lot of extra checking. The evalInclude function would check if the path has already been included. If yes and _once, do nothing. Otherwise, lex and parse the file. Store the resulting *ast.Program in a map and execute it. If _once, store nil in the map instead as the tree is never used again.
This map is shared across the entire execution. The map will need to be prepopulated with the main script so it can't cause circular imports.
If a file has the extension .so load it as a plugin module. These can only be loaded once. Perhaps use the module keyword instead? or maybe use?
The text was updated successfully, but these errors were encountered:
Add language constructs to include source code from other Nitrogen files. I like PHP here where they have include and required and then an _once variant of each. I think that allows flexibility on how strict or loose code needs to be.
Implementation details: Can be implemented as a collection of functions or as keywords and constructs directly in the language. Either method would use the same underlying process. A map would be used to store pathnames of source code as it's included. Each path will map to an *ast.Program struct. For the _once variants, nil can be used instead as the parsed tree will never be used again. If a file couldn't be included and it's not required, an Error would be generated and returned. If the script is required, an Exception is returned causing execution to halt.
Implementing as a language keyword and direct AST node would probably be more efficient as an evaluated function call wouldn't need to get setup and invoked. Even builtins need to do a bit of type casting and argument checking. Using an AST node, the evaluator can be guaranteed the arguments and options are correct and use the node directly without a lot of extra checking. The evalInclude function would check if the path has already been included. If yes and _once, do nothing. Otherwise, lex and parse the file. Store the resulting *ast.Program in a map and execute it. If _once, store nil in the map instead as the tree is never used again.
This map is shared across the entire execution. The map will need to be prepopulated with the main script so it can't cause circular imports.
If a file has the extension
.so
load it as a plugin module. These can only be loaded once. Perhaps use themodule
keyword instead? or maybeuse
?The text was updated successfully, but these errors were encountered: