Large overhaul of pointers to shared_ptrs, implemented function evaluation

This commit is contained in:
2019-06-01 19:20:31 +02:00
parent 8b70eed516
commit 4408cf00cd
17 changed files with 261 additions and 129 deletions

View File

@@ -51,8 +51,8 @@ BoundStatement* Binder::BindAssignmentStatement(ParsedStatement *statement){
auto boundExpression = this->BindExpression(s->GetExpression());
VariableAssignment assignment =
s->IsLocal() ?
this->_scope->CreateExplicitLocal(s->GetIdentifier().GetHash(), *boundExpression->GetType())
: this->_scope->AssignVariable(s->GetIdentifier().GetHash(), *boundExpression->GetType());
this->_scope->CreateExplicitLocal(s->GetIdentifier().GetHash(), boundExpression->GetType())
: this->_scope->AssignVariable(s->GetIdentifier().GetHash(), boundExpression->GetType());
if (assignment.GetResult() == VariableAssignmentResult::Ok){
auto key = assignment.GetKey();
return new BoundAssignmentStatement(key, boundExpression);
@@ -63,28 +63,28 @@ BoundStatement* Binder::BindAssignmentStatement(ParsedStatement *statement){
}
}
ScriptType* ParseTypeIdentifier(HashedString s){
std::shared_ptr<ScriptType> ParseTypeIdentifier(HashedString s){
switch (s.GetHash()){
case HashedString::ConstHash("number"): return new NumericScriptType(false, false);
case HashedString::ConstHash("bool"): return new ScriptType(TypeClass::Bool);
case HashedString::ConstHash("string"): return new ScriptType(TypeClass::String);
default: return new ScriptType(TypeClass::Error); // todo: change to userdata
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);
default: return std::make_shared<ScriptType>(TypeClass::Error); // todo: change to userdata
}
}
BoundStatement *Binder::BindFunctionDeclarationStatement(ParsedStatement *statement) {
auto functionStatement = (ParsedFunctionDeclarationStatement*) statement;
auto parameters = functionStatement->GetParameters();
vector<std::shared_ptr<ScriptType>> parameterTypes = vector<std::shared_ptr<ScriptType>>(parameters.size());
vector<std::shared_ptr<BoundVariableKey>> parameterKeys = vector<std::shared_ptr<BoundVariableKey>>(parameters.size());
auto parameterTypes = new vector<std::shared_ptr<ScriptType>>(parameters.size());
auto parameterKeys = new vector<std::shared_ptr<BoundVariableKey>>(parameters.size());
this->_scope->GoInnerScope();
for (int i = 0; i < parameters.size(); i++){
auto var = parameters[i];
auto parsedType = ParseTypeIdentifier(var->GetType());
parameterTypes[i] = std::shared_ptr<ScriptType>(parsedType);
auto parameterAssignment = this->_scope->CreateExplicitLocal(var->GetIdentifier().GetHash(), *parsedType);
parameterTypes->at(i) = parsedType;
auto parameterAssignment = this->_scope->CreateExplicitLocal(var->GetIdentifier().GetHash(), parsedType);
if (parameterAssignment.GetResult() == VariableAssignmentResult::Ok){
parameterKeys[i] = std::shared_ptr<BoundVariableKey>(parameterAssignment.GetKey());
parameterKeys -> at(i) = std::shared_ptr<BoundVariableKey>(parameterAssignment.GetKey());
}
else{
//TODO: log error
@@ -95,8 +95,10 @@ BoundStatement *Binder::BindFunctionDeclarationStatement(ParsedStatement *statem
this->_scope->GoOuterScope();
auto identifier = functionStatement->GetIdentifier();
auto returnType = std::make_shared<ScriptType>(TypeClass::Nil);
auto type = new FunctionScriptType(returnType, parameterTypes, parameterKeys);
auto assignment = this->_scope->AssignVariable(identifier.GetHash(), *type);
auto parameterTypesPtr = std::shared_ptr<std::vector<std::shared_ptr<ScriptType>>>(parameterTypes);
auto parameterKeysPtr = std::shared_ptr<std::vector<std::shared_ptr<BoundVariableKey>>>(parameterKeys);
auto type = make_shared<FunctionScriptType>(returnType, parameterTypesPtr, parameterKeysPtr);
auto assignment = this->_scope->AssignVariable(identifier.GetHash(), type);
if (assignment.GetResult() == VariableAssignmentResult::Ok){
return new BoundFunctionDeclarationStatement(type, assignment.GetKey(), (BoundBlockStatement*)boundBlock);
}
@@ -123,6 +125,8 @@ BoundExpression* Binder::BindExpression(ParsedExpression* expression){
case ParsedExpressionKind ::Parenthesized:
return BindExpression(((ParenthesizedExpression*)expression)->GetInnerExpression());
case ParsedExpressionKind ::FunctionCall:
return this->BindFunctionCall((FunctionCallExpression*)expression);
case ParsedExpressionKind ::Bad:
return new BoundBadExpression(expression->GetStartPosition(), expression-> GetLength());
@@ -151,84 +155,89 @@ BoundExpression* Binder::BindBinaryOperator(BinaryExpression* expression){
switch (expression->GetOperatorKind()){
case BinaryOperatorKind ::Addition:
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number){
auto leftNumeric = (NumericScriptType*)boundLeftType;
auto rightNumeric = (NumericScriptType*)boundRightType;
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Addition, new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
BoundBinaryOperation::Addition,
std::make_shared<NumericScriptType>(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Addition, new NumericScriptType(false, false),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Addition,
std::make_shared<NumericScriptType>(false, false),
expression->GetStartPosition(), expression->GetLength());
}
} else if (boundLeftType->GetClass() == TypeClass::String){
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Concatenation, new ScriptType(TypeClass::String),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Concatenation, std::make_shared<ScriptType>(TypeClass::String),
expression->GetStartPosition(), expression->GetLength());
}
break;
case BinaryOperatorKind ::Subtraction:
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number){
auto leftNumeric = (NumericScriptType*)boundLeftType;
auto rightNumeric = (NumericScriptType*)boundRightType;
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Subtraction,
new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
std::make_shared<NumericScriptType>(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Subtraction, new NumericScriptType(false, false),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Subtraction,
std::make_shared<NumericScriptType>(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
break;
case BinaryOperatorKind ::Multiplication:
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number){
auto leftNumeric = (NumericScriptType*)boundLeftType;
auto rightNumeric = (NumericScriptType*)boundRightType;
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Multiplication,
new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
std::make_shared<NumericScriptType>(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Multiplication, new NumericScriptType(false, false),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Multiplication,
std::make_shared<NumericScriptType>(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
break;
case BinaryOperatorKind ::Division:
if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number){
auto leftNumeric = (NumericScriptType*)boundLeftType;
auto rightNumeric = (NumericScriptType*)boundRightType;
auto leftNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundLeftType);
auto rightNumeric = std::dynamic_pointer_cast<NumericScriptType>(boundRightType);
if (leftNumeric->IsAwareOfFloat() && rightNumeric->IsAwareOfFloat()){
return new BoundBinaryExpression(boundLeft, boundRight,
BoundBinaryOperation::Division,
new NumericScriptType(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
std::make_shared<NumericScriptType>(true, leftNumeric->IsFloat() || rightNumeric->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
else{
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Division, new NumericScriptType(false, false),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Division,
std::make_shared<NumericScriptType>(false, false),
expression->GetStartPosition(), expression->GetLength());
}
}
break;
case BinaryOperatorKind ::Equality:
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Equality, new ScriptType(TypeClass::Bool),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Equality, std::make_shared<ScriptType>(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
case BinaryOperatorKind ::Inequality:
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Inequality, new ScriptType(TypeClass::Bool),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::Inequality, std::make_shared<ScriptType>(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
case BinaryOperatorKind ::LogicalAnd:
if (boundLeftType->GetClass() == TypeClass::Bool && boundRightType->GetClass() == TypeClass::Bool)
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalAnd, new ScriptType(TypeClass::Bool),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalAnd, std::make_shared<ScriptType>(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
break;
case BinaryOperatorKind ::LogicalOr:
if (boundLeftType->GetClass() == TypeClass::Bool && boundRightType->GetClass() == TypeClass::Bool)
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalOr, new ScriptType(TypeClass::Bool),
return new BoundBinaryExpression(boundLeft, boundRight, BoundBinaryOperation::LogicalOr, std::make_shared<ScriptType>(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
break;
}
@@ -248,14 +257,16 @@ BoundExpression* Binder::BindUnaryOperator(UnaryExpression* expression){
break;
case UnaryOperatorKind ::Negation:
if (operandType->GetClass() == TypeClass::Number){
auto innerType = (NumericScriptType*)operandType;
return new BoundUnaryExpression(operand, BoundUnaryOperation::Negation, new NumericScriptType(innerType->IsAwareOfFloat(),
innerType->IsFloat()), expression->GetStartPosition(), expression->GetLength());
auto innerType = std::dynamic_pointer_cast<NumericScriptType>(operandType);
return new BoundUnaryExpression(operand, BoundUnaryOperation::Negation,
std::make_shared<NumericScriptType>(innerType.get()->IsAwareOfFloat(), innerType.get()->IsFloat()),
expression->GetStartPosition(), expression->GetLength());
}
break;
case UnaryOperatorKind ::LogicalNegation:
if (operandType->GetClass() == TypeClass::Bool){
return new BoundUnaryExpression(operand, BoundUnaryOperation::LogicalNegation, new ScriptType(TypeClass::Bool),
return new BoundUnaryExpression(operand, BoundUnaryOperation::LogicalNegation,
std::make_shared<ScriptType>(TypeClass::Bool),
expression->GetStartPosition(), expression->GetLength());
}
break;
@@ -267,4 +278,34 @@ BoundExpression* Binder::BindUnaryOperator(UnaryExpression* expression){
}
BoundExpression* Binder::BindFunctionCall(FunctionCallExpression* expression){
auto functionExpression = BindExpression(expression->GetFunction());
auto type = functionExpression->GetType();
if (type->GetClass() != TypeClass::Function){
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ExpressionIsNotAFunction, expression->GetStartPosition(),
expression->GetLength());
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
}
auto functionType = std::dynamic_pointer_cast<FunctionScriptType>(type);
auto parameterTypes = functionType->GetParameterTypes();
auto givenParameters = expression->GetParameters();
if (parameterTypes->size() != givenParameters.size()){
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ParameterCountMismatch, expression->GetStartPosition(),
expression->GetLength());
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
}
vector<BoundExpression*> boundParameters = vector<BoundExpression*>(givenParameters.size());
for (int i = 0; i < givenParameters.size(); i++){
auto parameter = givenParameters[i];
auto boundParameter = this -> BindExpression(parameter);
if (boundParameter->GetType().get()->operator!=(parameterTypes.get()-> at(i).get())){
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ParameterTypeMismatch, parameter->GetStartPosition(),
parameter->GetLength());
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
}
boundParameters[i] = boundParameter;
}
return new BoundFunctionCallExpression(functionExpression, boundParameters, functionType.get()->GetReturnType(),
expression->GetStartPosition(), expression->GetLength());
}

View File

@@ -23,6 +23,7 @@ class Binder {
BoundExpression *BindVariableExpression(VariableExpression *expression);
BoundExpression *BindBinaryOperator(BinaryExpression *expression);
BoundExpression *BindUnaryOperator(UnaryExpression *expression);
BoundExpression *BindFunctionCall(FunctionCallExpression *expression);
public:
static BoundScriptStatement* Bind(Script* script, ParsedScriptStatement* s, BoundScope* scriptScope);

View File

@@ -1,10 +1,13 @@
#include <utility>
#include <utility>
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
#define PORYGONLANG_BOUNDEXPRESSION_HPP
#include <string>
#include <memory>
#include "../../ScriptType.hpp"
#include "../BoundOperators.hpp"
#include "../BoundVariables/BoundVariableKey.hpp"
@@ -22,24 +25,23 @@ enum class BoundExpressionKind{
Unary,
Binary,
FunctionCall,
};
class BoundExpression{
unsigned int _start;
unsigned int _length;
ScriptType* _type;
std::shared_ptr<ScriptType> _type;
public:
BoundExpression(unsigned int start, unsigned int length, ScriptType* type){
BoundExpression(unsigned int start, unsigned int length, std::shared_ptr<ScriptType> type){
_start = start;
_length = length;
_type = type;
}
virtual ~BoundExpression(){
delete _type;
};
virtual ~BoundExpression() = default;
virtual BoundExpressionKind GetKind() = 0;
virtual ScriptType* GetType(){
virtual std::shared_ptr<ScriptType> GetType(){
return _type;
};
@@ -56,7 +58,7 @@ public:
class BoundBadExpression : public BoundExpression{
public:
BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, new ScriptType(TypeClass::Error)){}
BoundBadExpression(unsigned int start, unsigned int length) : BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Error)){}
BoundExpressionKind GetKind() final{
return BoundExpressionKind ::Bad;
@@ -67,7 +69,7 @@ class BoundLiteralIntegerExpression : public BoundExpression{
long _value;
public:
BoundLiteralIntegerExpression(long value, unsigned int start, unsigned int length)
: BoundExpression(start, length, new NumericScriptType(true, false)){
: BoundExpression(start, length, make_shared<NumericScriptType>(true, false)){
_value = value;
}
@@ -84,7 +86,7 @@ class BoundLiteralFloatExpression : public BoundExpression{
double _value;
public:
BoundLiteralFloatExpression(double value, unsigned int start, unsigned int length)
: BoundExpression(start, length, new NumericScriptType(true, true)){
: BoundExpression(start, length, make_shared<NumericScriptType>(true, true)){
_value = value;
}
@@ -101,7 +103,7 @@ class BoundLiteralStringExpression : public BoundExpression{
string _value;
public:
BoundLiteralStringExpression(string value, unsigned int start, unsigned int length)
: BoundExpression(start, length, new ScriptType(TypeClass::String)){
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::String)){
_value = std::move(value);
}
@@ -118,7 +120,7 @@ class BoundLiteralBoolExpression : public BoundExpression{
bool _value;
public:
BoundLiteralBoolExpression(bool value, unsigned int start, unsigned int length)
: BoundExpression(start, length, new ScriptType(TypeClass::Bool)){
: BoundExpression(start, length, make_shared<ScriptType>(TypeClass::Bool)){
_value = value;
}
@@ -134,20 +136,15 @@ public:
class BoundVariableExpression : public BoundExpression{
int _scope;
int _id;
ScriptType _type;
public:
BoundVariableExpression(int scope, int id, const ScriptType& type, unsigned int start, unsigned int length)
: BoundExpression(start, length, nullptr), _type(type){
BoundVariableExpression(int scope, int id, shared_ptr<ScriptType> type, unsigned int start, unsigned int length)
: BoundExpression(start, length, std::move(type)){
_scope = scope;
_id = id;
}
~BoundVariableExpression() override = default;
ScriptType* GetType() final{
return &_type;
};
BoundExpressionKind GetKind() final{
return BoundExpressionKind ::Variable;
}
@@ -166,7 +163,7 @@ class BoundBinaryExpression : public BoundExpression {
BoundExpression* _right;
BoundBinaryOperation _operation;
public:
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, ScriptType* result,
BoundBinaryExpression(BoundExpression* left, BoundExpression* right, BoundBinaryOperation op, shared_ptr<ScriptType> result,
unsigned int start, unsigned int length)
: BoundExpression(start, length, result){
_left = left;
@@ -199,7 +196,7 @@ class BoundUnaryExpression : public BoundExpression {
BoundExpression* _operand;
BoundUnaryOperation _operation;
public:
BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, ScriptType* result, unsigned int start, unsigned int length)
BoundUnaryExpression(BoundExpression* operand, BoundUnaryOperation op, shared_ptr<ScriptType> result, unsigned int start, unsigned int length)
:BoundExpression(start, length, result){
_operand = operand;
_operation = op;
@@ -222,6 +219,33 @@ public:
}
};
class BoundFunctionCallExpression : public BoundExpression {
BoundExpression* _functionExpression;
vector<BoundExpression*> _parameters;
public:
BoundFunctionCallExpression(BoundExpression *functionExpression, vector<BoundExpression *> parameters, shared_ptr<ScriptType> result,
unsigned int start, unsigned int length)
: BoundExpression(start, length, result), _functionExpression(functionExpression), _parameters(std::move(parameters)) {}
~BoundFunctionCallExpression() final{
delete _functionExpression;
for (auto p : _parameters){
delete p;
}
}
BoundExpressionKind GetKind() final{
return BoundExpressionKind ::FunctionCall;
}
BoundExpression* GetFunctionExpression(){
return _functionExpression;
}
vector<BoundExpression*> GetParameters(){
return _parameters;
}
};
#endif //PORYGONLANG_BOUNDEXPRESSION_HPP

View File

@@ -8,9 +8,9 @@
class BoundFunctionDeclarationStatement : public BoundStatement{
BoundVariableKey* _key;
std::shared_ptr<BoundBlockStatement> _block;
FunctionScriptType* _type;
std::shared_ptr<FunctionScriptType> _type;
public:
BoundFunctionDeclarationStatement(FunctionScriptType* type, BoundVariableKey* key, BoundBlockStatement* block){
BoundFunctionDeclarationStatement(std::shared_ptr<FunctionScriptType> type, BoundVariableKey* key, BoundBlockStatement* block){
_key = key;
_block = shared_ptr<BoundBlockStatement>(block);
_type = type;
@@ -18,7 +18,6 @@ public:
~BoundFunctionDeclarationStatement() final{
delete _key;
delete _type;
}
BoundStatementKind GetKind() final{
@@ -33,7 +32,7 @@ public:
return _block;
}
FunctionScriptType* GetType(){
std::shared_ptr<FunctionScriptType> GetType(){
return _type;
}
};

View File

@@ -1,3 +1,5 @@
#include <utility>
#include "BoundScope.hpp"
@@ -70,16 +72,16 @@ BoundVariable *BoundScope::GetVariable(int scope, int identifier) {
}
}
VariableAssignment BoundScope::CreateExplicitLocal(int identifier, const ScriptType& type) {
VariableAssignment BoundScope::CreateExplicitLocal(int identifier, std::shared_ptr<ScriptType> type) {
auto scope = this->_localScope.at(this->_currentScope - 1);
if (scope -> find(identifier) != scope -> end()){
return VariableAssignment(VariableAssignmentResult::ExplicitLocalVariableExists, nullptr);
}
scope -> insert({identifier, new BoundVariable(type)});
scope -> insert({identifier, new BoundVariable(std::move(type))});
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, this->_currentScope, true));
}
VariableAssignment BoundScope::AssignVariable(int identifier, const ScriptType& type) {
VariableAssignment BoundScope::AssignVariable(int identifier, const std::shared_ptr<ScriptType>& type) {
int exists = this->Exists(identifier);
if (exists == -1){
// Creation

View File

@@ -5,6 +5,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <memory>
#include "BoundVariable.hpp"
#include "BoundVariableKey.hpp"
#include "VariableAssigmentResult.hpp"
@@ -26,8 +27,8 @@ public:
int Exists(int key);
BoundVariable* GetVariable(int scope, int identifier);
VariableAssignment CreateExplicitLocal(int identifier, const ScriptType& type);
VariableAssignment AssignVariable(int identifier, const ScriptType& type);
VariableAssignment CreateExplicitLocal(int identifier, std::shared_ptr<ScriptType> type);
VariableAssignment AssignVariable(int identifier, const std::shared_ptr<ScriptType>& type);
int GetDeepestScope(){
return _deepestScope;

View File

@@ -2,17 +2,20 @@
#ifndef PORYGONLANG_BOUNDVARIABLE_HPP
#define PORYGONLANG_BOUNDVARIABLE_HPP
#include <memory>
#include "../../ScriptType.hpp"
using namespace std;
class BoundVariable{
ScriptType _type;
std::shared_ptr<ScriptType> _type;
public:
explicit BoundVariable(const ScriptType& type) : _type(type){
explicit BoundVariable(std::shared_ptr<ScriptType> type) : _type(type){
}
~BoundVariable(){
}
ScriptType& GetType(){
std::shared_ptr<ScriptType> GetType(){
return _type;
}
};