forked from smarr/SOMpp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for LexicalScopes, Variables, and SourceCoordinates (#32)
This PR is adding infrastructure to enable inlining on the bytecode level. It introduces the notion of LexicalScopes, Variables, and SourceCoordinates. LexicalScopes encode the info needed about the program structure/relationship between methods and blocks. Variables encode the location of arguments and locals, in terms of SourceCoordinates. This PR also reduces the number of symbols that need to be created by relying on std::strings for aspects that won't be exposed to the language level. There's also a bit extra support here for debugging the GCs and interactive debugging, for instance printing/dumping of methods. This is split out as a PR to be able to assess the performance impact.
- Loading branch information
Showing
35 changed files
with
451 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "../vmobjects/ObjectFormats.h" | ||
#include "Variable.h" | ||
|
||
class LexicalScope { | ||
friend class MethodGenerationContext; | ||
|
||
public: | ||
LexicalScope(LexicalScope* outer, vector<Variable> arguments, vector<Variable> locals) : outer(outer), arguments(arguments), locals(locals) {} | ||
|
||
inline size_t GetNumberOfArguments() const { | ||
return arguments.size(); | ||
} | ||
|
||
inline size_t GetNumberOfLocals() const { | ||
return locals.size(); | ||
} | ||
|
||
void AddInlinedLocal(Variable& var) { | ||
assert(var.GetIndex() == locals.size()); | ||
locals.push_back(var); | ||
} | ||
|
||
const Variable* GetLocal(size_t index, uint8_t ctxLevel) { | ||
if (ctxLevel > 0) { | ||
return outer->GetLocal(index, ctxLevel - 1); | ||
} | ||
return &locals.at(index); | ||
} | ||
|
||
/** | ||
* This removes the inlined scope from the chain. | ||
* Removal is done exactly once, after all embedded blocks | ||
* were adapted. | ||
*/ | ||
void DropInlinedScope() { | ||
assert(outer != nullptr); | ||
assert(outer->outer != nullptr); | ||
|
||
LexicalScope* newOuter = outer->outer; | ||
outer = newOuter; | ||
} | ||
|
||
private: | ||
LexicalScope* outer; | ||
vector<Variable> arguments; | ||
vector<Variable> locals; | ||
}; |
Oops, something went wrong.