Work on performance improvements
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-13 16:26:10 +02:00
parent e93bcab14d
commit 1cb65f17c9
19 changed files with 84 additions and 108 deletions

View File

@@ -13,7 +13,7 @@ BoundScriptStatement *Binder::Bind(Script* script, ParsedScriptStatement *s, Bou
for (int i = 0; i < statements->size(); i++){
boundStatements[i] = binder.BindStatement(statements->at(i));
}
return new BoundScriptStatement(boundStatements, scriptScope->GetDeepestScope());
return new BoundScriptStatement(boundStatements, scriptScope->GetLocalVariableCount());
}
Binder::~Binder() {
@@ -434,7 +434,7 @@ BoundExpression *Binder::BindTableExpression(ParsedTableExpression *expression)
auto block = this -> BindBlockStatement(expression -> GetBlock());
this -> _scope = currentScope;
auto tableType = shared_ptr<TableScriptType>(new TableScriptType(tableScope, innerScope->GetDeepestScope()));
auto tableType = shared_ptr<TableScriptType>(new TableScriptType(tableScope, innerScope->GetLocalVariableCount()));
delete innerScope;
return new BoundTableExpression((BoundBlockStatement*)block, tableType, expression->GetStartPosition(), expression->GetLength());

View File

@@ -57,18 +57,19 @@ public:
};
class BoundScriptStatement : public BoundBlockStatement{
int _deepestScope;
int _localVariableCount;
public:
explicit BoundScriptStatement(vector<BoundStatement*> statements, int deepestScope) : BoundBlockStatement(std::move(statements)){
_deepestScope = deepestScope;
explicit BoundScriptStatement(vector<BoundStatement*> statements, int localVariableCount)
: BoundBlockStatement(std::move(statements)){
_localVariableCount = localVariableCount;
}
BoundStatementKind GetKind() final{
return BoundStatementKind ::Script;
}
int GetDeepestScope(){
return _deepestScope;
int GetLocalVariableCount(){
return _localVariableCount;
}
};

View File

@@ -6,7 +6,6 @@
BoundScope::BoundScope(unordered_map<int, BoundVariable *> *tableScope) {
_tableScope = tableScope;
_currentScope = 1;
_deepestScope = 1;
_lastCreatedScope = 1;
auto localUpmostScope = new unordered_map<int, BoundVariable*>();
_localScope.push_back(localUpmostScope);
@@ -28,10 +27,6 @@ void BoundScope::GoInnerScope() {
auto innerScope = new unordered_map<int, BoundVariable*>();
_localScope.push_back(innerScope);
}
/*
if (_deepestScope < _currentScope){
_deepestScope = _currentScope;
}*/
}
void BoundScope::GoOuterScope() {

View File

@@ -18,7 +18,6 @@ class BoundScope {
vector<unordered_map<int, BoundVariable*>*> _localScope;
int _currentScope;
int _lastCreatedScope;
int _deepestScope;
public:
explicit BoundScope(unordered_map<int, BoundVariable*> *tableScope);
~BoundScope();
@@ -31,8 +30,8 @@ public:
VariableAssignment CreateExplicitLocal(int identifier, std::shared_ptr<ScriptType> type);
VariableAssignment AssignVariable(int identifier, const std::shared_ptr<ScriptType>& type);
int GetDeepestScope(){
return _deepestScope;
size_t GetLocalVariableCount(){
return _localScope.size();
}
int GetCurrentScope(){

View File

@@ -1,5 +1,3 @@
#include <utility>
#ifndef PORYGONLANG_BOUNDVARIABLEKEY_HPP
#define PORYGONLANG_BOUNDVARIABLEKEY_HPP
@@ -7,39 +5,39 @@
#include <string>
class BoundVariableKey{
int _identifier;
unsigned int _scopeId;
bool _isCreation;
uint64_t _hash;
const int _identifier;
const unsigned int _scopeId;
const bool _isCreation;
const uint64_t _hash;
static uint64_t KnuthsHash(int i1, int i2)
static uint64_t KnuthsHash(unsigned int i1, unsigned int i2)
{
uint64_t ret = i1;
ret *= 2654435761U;
return ret ^ i2;
}
public:
BoundVariableKey(int id, unsigned int scope, bool creation){
_identifier = id;
_scopeId = scope;
_hash = KnuthsHash(scope, id);
_isCreation = creation;
}
BoundVariableKey(int id, unsigned int scope, bool creation)
: _identifier(id),
_scopeId(scope),
_isCreation(creation),
_hash(KnuthsHash(id, scope))
{}
int GetIdentifier(){
const int GetIdentifier(){
return _identifier;
}
unsigned int GetScopeId(){
const unsigned int GetScopeId(){
return _scopeId;
}
bool IsCreation(){
const bool IsCreation(){
return _isCreation;
}
uint64_t GetHash(){
const uint64_t GetHash(){
return _hash;
}
};