Browse Source

Added export-and-evaluate

This is for cases where the exporter also wants those statements
evaluated in its context.
master
Macoy Madson 1 month ago
parent
commit
793ebbbfbc
  1. 12
      src/Generators.cpp
  2. 9
      src/Metadata.cpp

12
src/Generators.cpp

@ -2716,6 +2716,17 @@ bool ExportScopeGenerator(EvaluatorEnvironment& environment, const EvaluatorCont
newExport.startTokenIndex = startTokenIndex;
context.module->exportScopes.push_back(newExport);
// We also want to evaluate the scope in the current module
if (tokens[startTokenIndex + 1].contents.compare("export-and-evaluate") == 0)
{
EvaluatorContext exportEvaluateContext = context;
int numErrors =
EvaluateGenerateAll_Recursive(environment, exportEvaluateContext, tokens,
startTokenIndex + EXPORT_SCOPE_START_EVAL_OFFSET, output);
if (numErrors)
return false;
}
return true;
}
@ -3147,6 +3158,7 @@ void importFundamentalGenerators(EvaluatorEnvironment& environment)
environment.generators["comptime-cond"] = ComptimeCondGenerator;
environment.generators["comptime-define-symbol"] = ComptimeDefineSymbolGenerator;
environment.generators["export"] = ExportScopeGenerator;
environment.generators["export-and-evaluate"] = ExportScopeGenerator;
// Dispatches based on invocation name
const char* cStatementKeywords[] = {

9
src/Metadata.cpp

@ -131,7 +131,14 @@ GeneratorMetadata g_generatorMetadata[] = {
EvaluationTime_EvaluatedOnImport, 1, 99,
"When any other module imports the current module, evaluate the statements within this export "
"scope in the context of the other module. This allows modules to e.g. 'infect' other modules "
"with settings necessary for the importer to build"},
"with settings necessary for the importer to build. Compare to (export-and-evaluate), which "
"evaluates both in the export-defining module and in importer contexts."},
{"export-and-evaluate", GeneratorCategory_Uncategorized, LanguageRequirement_Evaluated,
(EvaluationTime_EvaluatedImmediately | EvaluationTime_EvaluatedOnImport), 1, 99,
"Evaluate the contained statements. Additionally, when any other module imports the current "
"module, evaluate the statements within this export scope in the context of the other module. "
"This allows modules to e.g. 'infect' other modules with settings necessary for the importer "
"to build. Compare to (export), which only evaluates in importer contexts."},
//
// Math

Loading…
Cancel
Save