-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce LexicalScope, Variable, and SourceCoordinate
This is in preparation of adding inlining. Signed-off-by: Stefan Marr <[email protected]>
- Loading branch information
Showing
23 changed files
with
368 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "../memory/Heap.h" | ||
#include "../vmobjects/ObjectFormats.h" | ||
#include "LexicalScope.h" | ||
|
||
|
||
void LexicalScope::WalkObjects(walk_heap_fn walk) { | ||
for (auto& var : arguments) { | ||
var.WalkObjects(walk); | ||
} | ||
|
||
for (auto& var : locals) { | ||
var.WalkObjects(walk); | ||
} | ||
} |
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,52 @@ | ||
#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); | ||
} | ||
|
||
void WalkObjects(walk_heap_fn walk); | ||
|
||
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; | ||
delete outer; | ||
outer = newOuter; | ||
} | ||
|
||
private: | ||
LexicalScope* outer; | ||
vector<Variable> arguments; | ||
vector<Variable> locals; | ||
}; |
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
Oops, something went wrong.