Implements complex tables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-12 15:19:28 +02:00
parent ba4fe888fa
commit c022c91777
21 changed files with 272 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
#include <memory>
#include "Binder.hpp"
#include "../TableScriptType.hpp"
#include "BoundExpressions/BoundTableExpression.hpp"
#include <memory>
BoundScriptStatement *Binder::Bind(Script* script, ParsedScriptStatement *s, BoundScope* scriptScope) {
@@ -71,7 +71,7 @@ std::shared_ptr<ScriptType> ParseTypeIdentifier(HashedString s){
switch (s.GetHash()){
case HashedString::ConstHash("number"): return std::make_shared<NumericScriptType>(false, false);
case HashedString::ConstHash("bool"): return std::make_shared<ScriptType>(TypeClass::Bool);
case HashedString::ConstHash("string"): return std::make_shared<ScriptType>(TypeClass::String);
case HashedString::ConstHash("string"): return std::make_shared<StringScriptType>(false, 0);
default: return std::make_shared<ScriptType>(TypeClass::Error); // todo: change to userdata
}
}
@@ -178,6 +178,8 @@ BoundExpression* Binder::BindExpression(ParsedExpression* expression){
return this->BindIndexExpression((IndexExpression*)expression);
case ParsedExpressionKind::NumericalTable:
return this -> BindNumericalTableExpression((ParsedNumericalTableExpression*)expression);
case ParsedExpressionKind ::Table:
return this -> BindTableExpression((ParsedTableExpression*)expression);
case ParsedExpressionKind ::Bad:
return new BoundBadExpression(expression->GetStartPosition(), expression-> GetLength());
@@ -220,7 +222,8 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
expression->GetStartPosition(), expression->GetLength());
}
} else if (boundLeftType->GetClass() == TypeClass::String){
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Concatenation, std::make_shared<ScriptType>(TypeClass::String),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Concatenation, std::make_shared<StringScriptType>(false,
0),
expression->GetStartPosition(), expression->GetLength());
}
break;
@@ -412,7 +415,19 @@ BoundExpression* Binder::BindNumericalTableExpression(ParsedNumericalTableExpres
if (valueType == nullptr){
valueType = std::make_shared<ScriptType>(TypeClass::Nil);
}
auto keyType = std::make_shared<ScriptType>(TypeClass::Number);
auto tableType = std::make_shared<TableScriptType>(keyType, valueType);
auto tableType = std::make_shared<NumericalTableScriptType>(valueType);
return new BoundNumericalTableExpression(boundExpressions, tableType, expression->GetStartPosition(), expression->GetLength());
}
}
BoundExpression *Binder::BindTableExpression(ParsedTableExpression *expression) {
auto tableScope = new unordered_map<int, BoundVariable*>();
auto innerScope = new BoundScope(tableScope);
auto currentScope = this -> _scope;
this -> _scope = innerScope;
auto block = this -> BindBlockStatement(expression -> GetBlock());
this -> _scope = currentScope;
auto tableType = shared_ptr<TableScriptType>(new TableScriptType(tableScope, innerScope->GetDeepestScope()));
return new BoundTableExpression((BoundBlockStatement*)block, tableType, expression->GetStartPosition(), expression->GetLength());
}