[Feat] 详细区分左值(LvObject)与右值(RvObject -> ObjectPtr)

[Impl] 重构evaluator.cpp + hpp 全部
[Feat] 增加对于IndexExpr的解析
[Fix][Impl] 现在点运算符不由BinaryExpr负责,增加MemberExpr,单独实现解析
[Impl] 项目目录全部翻修, src/目录下单独文件夹放置每一个模块
This commit is contained in:
2025-12-24 17:51:49 +08:00
parent 3227230aa2
commit fc35368d85
70 changed files with 1558 additions and 1233 deletions

View File

@@ -0,0 +1,46 @@
#pragma once
#include <Ast/astBase.hpp>
namespace Fig::Ast
{
class ReturnSt final : public StatementAst
{
public:
Expression retValue;
ReturnSt()
{
type = AstType::ReturnSt;
}
ReturnSt(Expression _retValue) :
retValue(_retValue)
{
type = AstType::ReturnSt;
}
};
using Return = std::shared_ptr<ReturnSt>;
class BreakSt final : public StatementAst
{
public:
BreakSt()
{
type = AstType::BreakSt;
}
};
using Break = std::shared_ptr<BreakSt>;
class ContinueSt final : public StatementAst
{
public:
ContinueSt()
{
type = AstType::ContinueSt;
}
};
using Continue = std::shared_ptr<ContinueSt>;
};

View File

@@ -0,0 +1,21 @@
#pragma once
#include <Ast/astBase.hpp>
namespace Fig::Ast
{
class ExpressionStmtAst final : public StatementAst
{
public:
Expression exp;
ExpressionStmtAst()
{
type = AstType::ExpressionStmt;
}
ExpressionStmtAst(Expression _exp) : exp(std::move(_exp))
{
type = AstType::ExpressionStmt;
}
};
using ExpressionStmt = std::shared_ptr<ExpressionStmtAst>;
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include <Ast/astBase.hpp>
namespace Fig::Ast
{
class ForSt final : public StatementAst
{
public:
Statement initSt;
Expression condition;
Statement incrementSt;
BlockStatement body;
ForSt()
{
type = AstType::ForSt;
}
ForSt(Statement _initSt, Expression _condition, Statement _incrementSt, BlockStatement _body) :
initSt(std::move(_initSt)),
condition(std::move(_condition)),
incrementSt(std::move(_incrementSt)),
body(std::move(_body))
{
type = AstType::ForSt;
}
};
using For = std::shared_ptr<ForSt>;
};

View File

@@ -0,0 +1,45 @@
#pragma once
#include <Ast/astBase.hpp>
#include <Ast/functionParameters.hpp>
#include <Value/value.hpp>
namespace Fig::Ast
{
/*
func greet(greeting, name:String, age:Int, split:String=":") -> Null
{
io.println("{}, {}{}{}", greeting, name, split, age);
}
`greeting`, `name`, `age` -> positional parameters
`split` -> default parameter
*/
class FunctionDefSt final : public StatementAst // for definition
{
public:
FString name;
FunctionParameters paras;
bool isPublic;
FString retType;
BlockStatement body;
FunctionDefSt() :
retType(ValueType::Null.name)
{
type = AstType::FunctionDefSt;
}
FunctionDefSt(FString _name, FunctionParameters _paras, bool _isPublic, FString _retType, BlockStatement _body)
{
type = AstType::FunctionDefSt;
name = std::move(_name);
paras = std::move(_paras);
isPublic = _isPublic;
retType = std::move(_retType);
body = std::move(_body);
}
};
using FunctionDef = std::shared_ptr<FunctionDefSt>;
}; // namespace Fig

View File

@@ -0,0 +1,68 @@
#pragma once
#include <Ast/astBase.hpp>
namespace Fig::Ast
{
class ElseSt final : public StatementAst
{
public:
BlockStatement body;
ElseSt()
{
type = AstType::ElseSt;
}
ElseSt(BlockStatement _body) :
body(_body)
{
type = AstType::ElseSt;
}
virtual FString toString() override
{
return FString(std::format("<Else Ast at {}:{}>", aai.line, aai.column));
}
};
using Else = std::shared_ptr<ElseSt>;
class ElseIfSt final : public StatementAst
{
public:
Expression condition;
BlockStatement body;
ElseIfSt()
{
type = AstType::ElseIfSt;
}
ElseIfSt(Expression _condition,
BlockStatement _body) :
condition(_condition), body(_body)
{
type = AstType::ElseIfSt;
}
virtual FString toString() override
{
return FString(std::format("<ElseIf Ast at {}:{}>", aai.line, aai.column));
}
};
using ElseIf = std::shared_ptr<ElseIfSt>;
class IfSt final : public StatementAst
{
public:
Expression condition;
BlockStatement body;
std::vector<ElseIf> elifs;
Else els;
IfSt()
{
type = AstType::IfSt;
}
IfSt(Expression _condition,
BlockStatement _body,
std::vector<ElseIf> _elifs,
Else _els) :
condition(_condition), body(_body), elifs(_elifs), els(_els)
{
type = AstType::IfSt;
}
};
using If = std::shared_ptr<IfSt>;
}; // namespace Fig

View File

View File

@@ -0,0 +1,44 @@
#pragma once
#include <Ast/astBase.hpp>
#include <Ast/AccessModifier.hpp>
#include <vector>
namespace Fig::Ast
{
struct StructDefField
{
AccessModifier am;
FString fieldName;
FString tiName;
Expression defaultValueExpr;
StructDefField() {}
StructDefField(AccessModifier _am, FString _fieldName, FString _tiName, Expression _defaultValueExpr) :
am(std::move(_am)), fieldName(std::move(_fieldName)), tiName(std::move(_tiName)), defaultValueExpr(std::move(_defaultValueExpr))
{
}
};
class StructDefSt final : public StatementAst
{
public:
bool isPublic;
const FString name;
const std::vector<StructDefField> fields; // field name (:type name = default value expression)
// name / name: String / name: String = "Fig"
const BlockStatement body;
StructDefSt()
{
type = AstType::StructSt;
}
StructDefSt(bool _isPublic, FString _name, std::vector<StructDefField> _fields, BlockStatement _body) :
isPublic(std::move(_isPublic)), name(std::move(_name)), fields(std::move(_fields)), body(std::move(_body))
{
type = AstType::StructSt;
}
};
using StructDef = std::shared_ptr<StructDefSt>;
}; // namespace Fig

View File

@@ -0,0 +1,34 @@
#pragma once
#include <Ast/astBase.hpp>
#include <Value/Type.hpp>
namespace Fig::Ast
{
class VarDefAst final : public StatementAst
{
public:
bool isPublic;
bool isConst;
FString name;
FString typeName;
Expression expr;
VarDefAst() :
typeName(ValueType::Any.name)
{
type = AstType::VarDefSt;
}
VarDefAst(bool _isPublic, bool _isConst, FString _name, FString _info, Expression _expr) :
typeName(std::move(_info))
{
type = AstType::VarDefSt;
isPublic = _isPublic;
isConst = _isConst;
name = std::move(_name);
expr = std::move(_expr);
}
};
using VarDef = std::shared_ptr<VarDefAst>;
} // namespace Fig

View File

@@ -0,0 +1,26 @@
#pragma once
#include <Ast/astBase.hpp>
namespace Fig::Ast
{
class WhileSt final : public StatementAst
{
public:
Expression condition;
BlockStatement body;
WhileSt()
{
type = AstType::WhileSt;
}
WhileSt(Expression _condition, BlockStatement _body)
: condition(_condition), body(_body)
{
type = AstType::WhileSt;
}
};
using While = std::shared_ptr<WhileSt>;
};