forked from PuqiAR/Fig-TreeWalker
规范 include
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
#include <Ast/astBase.hpp>
|
||||
#include <Compiler/Compiler.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
void Compiler::compile(Ast::Statement stmt)
|
||||
{
|
||||
using enum Ast::AstType;
|
||||
using namespace Ast;
|
||||
Ast::AstType type = stmt->getType();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case VarDefSt: {
|
||||
auto vd = std::static_pointer_cast<VarDefAst>(stmt);
|
||||
const FString name = vd->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}; // namespace Fig
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Ast/astBase.hpp"
|
||||
#include <Ast/ast.hpp>
|
||||
#include <Bytecode/Bytecode.hpp>
|
||||
#include <VMValue/VMValue.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
class Compiler
|
||||
{
|
||||
private:
|
||||
std::vector<Ast::Statement> source;
|
||||
std::vector<OpCodeType> output; // std::vector<uint8_t>
|
||||
|
||||
std::vector<Value> constants;
|
||||
public:
|
||||
std::vector<OpCodeType> getOutput() const { return output; }
|
||||
std::vector<Value> getConstantPool() const { return constants; }
|
||||
|
||||
Compiler() {}
|
||||
Compiler(std::vector<Ast::Statement> _source) : source(std::move(_source)) {}
|
||||
|
||||
void compile_expr(Ast::Expression);
|
||||
|
||||
void compile(Ast::Statement);
|
||||
|
||||
void CompileAll();
|
||||
};
|
||||
}; // namespace Fig
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Ast/Expressions/BinaryExpr.hpp"
|
||||
#include <Ast/Expressions/BinaryExpr.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
#include <Evaluator/Value/IntPool.hpp>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Ast/functionParameters.hpp"
|
||||
#include "Evaluator/Value/value.hpp"
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Ast/Expressions/FunctionCall.hpp>
|
||||
#include <Evaluator/Value/function.hpp>
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Evaluator/Value/value.hpp"
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
#include <Evaluator/evaluator.hpp>
|
||||
#include <Evaluator/evaluator_error.hpp>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Evaluator/Value/value.hpp"
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
#include <Evaluator/evaluator.hpp>
|
||||
#include <Evaluator/evaluator_error.hpp>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "Ast/AccessModifier.hpp"
|
||||
#include "Ast/Expressions/FunctionCall.hpp"
|
||||
#include "Ast/astBase.hpp"
|
||||
#include "Ast/functionParameters.hpp"
|
||||
#include "Core/fig_string.hpp"
|
||||
#include "Evaluator/Core/StatementResult.hpp"
|
||||
#include "Evaluator/Value/Type.hpp"
|
||||
#include "Evaluator/Value/value.hpp"
|
||||
#include <Ast/AccessModifier.hpp>
|
||||
#include <Ast/Expressions/FunctionCall.hpp>
|
||||
#include <Ast/astBase.hpp>
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Evaluator/Core/StatementResult.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
#include <Evaluator/Value/structType.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
#include <Evaluator/evaluator.hpp>
|
||||
#include <Evaluator/evaluator_error.hpp>
|
||||
@@ -236,6 +237,15 @@ namespace Fig
|
||||
add(l, r) {...}
|
||||
}
|
||||
*/
|
||||
if (ValueType::isTypeBuiltin(structType))
|
||||
{
|
||||
throw EvaluatorError(
|
||||
u8"BadUserError",
|
||||
std::format("Don't overload built-in type operators plz! `{}`", prettyType(structTypeObj).toBasicString()),
|
||||
ip
|
||||
);
|
||||
}
|
||||
|
||||
using enum Ast::Operator;
|
||||
static const std::unordered_map<FString, std::pair<Ast::Operator, size_t>> magic_name_to_op = {
|
||||
// 算术
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Evaluator/Value/value.hpp"
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
#include <Evaluator/evaluator.hpp>
|
||||
#include <Evaluator/evaluator_error.hpp>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "Core/fig_string.hpp"
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Evaluator/Value/function.hpp>
|
||||
#include <Evaluator/Value/interface.hpp>
|
||||
#include <Evaluator/Value/structType.hpp>
|
||||
@@ -623,7 +623,7 @@ namespace Fig
|
||||
friend Object operator!(const Object &v)
|
||||
{
|
||||
if (!v.is<ValueType::BoolClass>())
|
||||
throw ValueError(
|
||||
throw ValueError(
|
||||
FString(std::format("Logical NOT requires bool: '{}'", v.getTypeInfo().name.toBasicString())));
|
||||
return Object(!v.as<ValueType::BoolClass>());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Ast/astBase.hpp"
|
||||
#include "Core/fig_string.hpp"
|
||||
#include "Evaluator/Core/StatementResult.hpp"
|
||||
#include "Evaluator/Value/value.hpp"
|
||||
#include <Ast/astBase.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Evaluator/Core/StatementResult.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Utils/utils.hpp>
|
||||
#include <Parser/parser.hpp>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Ast/Expressions/VarExpr.hpp"
|
||||
#include <Ast/Expressions/VarExpr.hpp>
|
||||
#include <Ast/Statements/ErrorFlow.hpp>
|
||||
#include <Ast/Statements/ImplementSt.hpp>
|
||||
#include <Ast/astBase.hpp>
|
||||
@@ -194,7 +194,8 @@ namespace Fig
|
||||
else if (isThis(TokenType::Colon)) // :
|
||||
{
|
||||
next(); // skip `:`
|
||||
Ast::Expression type_exp = parseExpression(0, TokenType::Comma, TokenType::RightParen, TokenType::Assign);
|
||||
Ast::Expression type_exp =
|
||||
parseExpression(0, TokenType::Comma, TokenType::RightParen, TokenType::Assign);
|
||||
if (isThis(TokenType::Assign)) // =
|
||||
{
|
||||
next(); // skip `=`
|
||||
@@ -927,10 +928,7 @@ namespace Fig
|
||||
}
|
||||
expect(TokenType::RightBrace);
|
||||
next(); // consume `}`
|
||||
return makeAst<Ast::InitExprAst>(
|
||||
structe,
|
||||
args,
|
||||
static_cast<Ast::InitExprAst::InitMode>(mode));
|
||||
return makeAst<Ast::InitExprAst>(structe, args, static_cast<Ast::InitExprAst::InitMode>(mode));
|
||||
}
|
||||
|
||||
Ast::Expression Parser::__parseTupleOrParenExpr()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Token/token.hpp"
|
||||
#include <Token/token.hpp>
|
||||
#include <Ast/astBase.hpp>
|
||||
#include <Ast/ast.hpp>
|
||||
#include <Lexer/lexer.hpp>
|
||||
@@ -154,10 +154,8 @@ namespace Fig
|
||||
tokenPruduced++;
|
||||
if (tok == IllegalTok) throw lexer.getError();
|
||||
currentTokenIndex = tokenPruduced - 1;
|
||||
setCurrentAAI(Ast::AstAddressInfo{.line = tok.line,
|
||||
.column = tok.column,
|
||||
.sourcePath = sourcePathPtr,
|
||||
.sourceLines = sourceLinesPtr});
|
||||
setCurrentAAI(Ast::AstAddressInfo{
|
||||
.line = tok.line, .column = tok.column, .sourcePath = sourcePathPtr, .sourceLines = sourceLinesPtr});
|
||||
|
||||
previousTokens.push_back(tok);
|
||||
}
|
||||
@@ -314,16 +312,18 @@ namespace Fig
|
||||
Ast::MapExpr __parseMapExpr(); // entry: current is `{`
|
||||
|
||||
Ast::InitExpr __parseInitExpr(Ast::Expression); // entry: current is `{`, ahead is struct type exp.
|
||||
|
||||
|
||||
Ast::Expression __parseTupleOrParenExpr(); // entry: current is `(`
|
||||
Ast::Expression __parseTupleOrParenExpr(); // entry: current is `(`
|
||||
|
||||
Ast::FunctionLiteralExpr __parseFunctionLiteralExpr(); // entry: current is Token::LParen after Token::Function
|
||||
|
||||
Ast::Import __parseImport(); // entry: current is Token::Import
|
||||
|
||||
Ast::Statement __parseStatement(bool = true); // entry: (idk)
|
||||
Ast::Expression parseExpression(Precedence, TokenType = TokenType::Semicolon, TokenType = TokenType::Semicolon, TokenType = TokenType::Semicolon);
|
||||
Ast::Expression parseExpression(Precedence,
|
||||
TokenType = TokenType::Semicolon,
|
||||
TokenType = TokenType::Semicolon,
|
||||
TokenType = TokenType::Semicolon);
|
||||
std::vector<Ast::AstBase> parseAll();
|
||||
};
|
||||
}; // namespace Fig
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "Ast/astBase.hpp"
|
||||
#include "Error/error.hpp"
|
||||
#include "Error/errorLog.hpp"
|
||||
#include <Ast/astBase.hpp>
|
||||
#include <Error/error.hpp>
|
||||
#include <Error/errorLog.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Repl/Repl.hpp>
|
||||
#include <vector>
|
||||
@@ -31,10 +31,7 @@ namespace Fig
|
||||
ostream << Object::getNullInstance()->toString().toBasicString();
|
||||
continue;
|
||||
}
|
||||
if (line == u8"!exit")
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (line == u8"!exit") { break; }
|
||||
|
||||
Lexer lexer(line, sourcePath, sourceLines);
|
||||
Parser parser(lexer, sourcePath, sourceLines);
|
||||
@@ -50,7 +47,7 @@ namespace Fig
|
||||
}
|
||||
catch (AddressableError &e)
|
||||
{
|
||||
ostream << "Oops!\n";
|
||||
ostream << "Oops!\n";
|
||||
ErrorLog::logAddressableError(e);
|
||||
ostream << "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user