mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
add facility for specifying custom mutable globals
This commit is contained in:
parent
7c5883fc60
commit
283a349fb9
2 changed files with 14 additions and 1 deletions
|
@ -36,6 +36,10 @@ struct CompileOptions
|
|||
// global builtin to construct vectors; disabled by default
|
||||
const char* vectorLib = nullptr;
|
||||
const char* vectorCtor = nullptr;
|
||||
|
||||
// array of globals that are mutable; disables the import optimization for
|
||||
// fields accessed through them. use NULL to end the array
|
||||
const char** mutableGlobalNames;
|
||||
};
|
||||
|
||||
class CompileError : public std::exception
|
||||
|
|
|
@ -3703,7 +3703,7 @@ void compileOrThrow(BytecodeBuilder& bytecode, AstStatBlock* root, const AstName
|
|||
|
||||
Compiler compiler(bytecode, options);
|
||||
|
||||
// since access to some global objects may result in values that change over time, we block table imports
|
||||
// since access to some global objects may result in values that change over time, we block imports from non-readonly tables
|
||||
for (const char* global : kSpecialGlobals)
|
||||
{
|
||||
AstName name = names.get(global);
|
||||
|
@ -3712,6 +3712,15 @@ void compileOrThrow(BytecodeBuilder& bytecode, AstStatBlock* root, const AstName
|
|||
compiler.globals[name].special = true;
|
||||
}
|
||||
|
||||
if (options.mutableGlobalNames)
|
||||
for (const char** ptr = options.mutableGlobalNames; ptr; ptr += sizeof(const char*))
|
||||
{
|
||||
AstName name = names.get(*ptr);
|
||||
|
||||
if (name.value)
|
||||
compiler.globals[name].special = true;
|
||||
}
|
||||
|
||||
// this visitor traverses the AST to analyze mutability of locals/globals, filling Local::written and Global::written
|
||||
Compiler::AssignmentVisitor assignmentVisitor(&compiler);
|
||||
root->visit(&assignmentVisitor);
|
||||
|
|
Loading…
Add table
Reference in a new issue