clean up object module
This commit is contained in:
parent
e78885d452
commit
f8c82b7e29
68 changed files with 1223 additions and 1229 deletions
|
|
@ -1,45 +1,42 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "interpreter/ByteCode.hpp"
|
||||
#include "core/Object.hpp"
|
||||
#include "interpreter/ByteCode.hpp"
|
||||
|
||||
namespace obj {
|
||||
namespace BCgen {
|
||||
namespace tp::obj {
|
||||
|
||||
class ConstObject {
|
||||
public:
|
||||
obj::Object* mObj = nullptr;
|
||||
tp::alni mConstIdx = 0;
|
||||
class ConstObject {
|
||||
public:
|
||||
Object* mObj = nullptr;
|
||||
alni mConstIdx = 0;
|
||||
|
||||
ConstObject();
|
||||
ConstObject(obj::Object* mObj);
|
||||
};
|
||||
|
||||
|
||||
class ConstObjectsPool {
|
||||
public:
|
||||
tp::Map<std::string, ConstObject*> mMethods;
|
||||
tp::Map<std::string, ConstObject*> mStrings;
|
||||
tp::Map<tp::alni, ConstObject*> mIntegers;
|
||||
tp::Map<tp::alnf, ConstObject*> mFloats;
|
||||
ConstObject mBoolTrue;
|
||||
ConstObject mBoolFalse;
|
||||
|
||||
bool mDelete = true;
|
||||
tp::alni mTotalObjects = 0;
|
||||
|
||||
ConstObject* get(tp::alni val);
|
||||
ConstObject* get(const std::string& val);
|
||||
ConstObject* get(tp::alnf val);
|
||||
ConstObject* get(bool val);
|
||||
|
||||
ConstObject* addMethod(const std::string& method_id, obj::Object* method);
|
||||
ConstObject* registerObject(obj::Object* obj);
|
||||
void save(tp::Buffer<ConstData>& out);
|
||||
|
||||
ConstObjectsPool() = default;
|
||||
~ConstObjectsPool();
|
||||
};
|
||||
ConstObject();
|
||||
ConstObject(Object* mObj);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class ConstObjectsPool {
|
||||
public:
|
||||
Map<std::string, ConstObject*> mMethods;
|
||||
Map<std::string, ConstObject*> mStrings;
|
||||
Map<alni, ConstObject*> mIntegers;
|
||||
Map<alnf, ConstObject*> mFloats;
|
||||
ConstObject mBoolTrue;
|
||||
ConstObject mBoolFalse;
|
||||
|
||||
bool mDelete = true;
|
||||
alni mTotalObjects = 0;
|
||||
|
||||
ConstObject* get(alni val);
|
||||
ConstObject* get(const std::string& val);
|
||||
ConstObject* get(alnf val);
|
||||
ConstObject* get(bool val);
|
||||
|
||||
ConstObject* addMethod(const std::string& method_id, Object* method);
|
||||
ConstObject* registerObject(Object* obj);
|
||||
void save(Buffer<ConstData>& out);
|
||||
|
||||
ConstObjectsPool() = default;
|
||||
~ConstObjectsPool();
|
||||
};
|
||||
}
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "Buffer.hpp"
|
||||
|
||||
#include "interpreter/OperatoinCodes.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace obj::BCgen {
|
||||
namespace tp::obj {
|
||||
|
||||
struct Expression {
|
||||
enum class Type {
|
||||
|
|
@ -33,26 +31,26 @@ namespace obj::BCgen {
|
|||
};
|
||||
|
||||
struct ExpressionList : public Expression {
|
||||
tp::Buffer<Expression*> mItems;
|
||||
Buffer<Expression*> mItems;
|
||||
ExpressionList();
|
||||
~ExpressionList() override;
|
||||
};
|
||||
|
||||
struct ExpressionNew : public Expression {
|
||||
std::string mNewType;
|
||||
explicit ExpressionNew(const std::string& type);
|
||||
explicit ExpressionNew(std::string type);
|
||||
~ExpressionNew() override;
|
||||
};
|
||||
|
||||
struct ExpressionLocal : public Expression {
|
||||
std::string mLocalId;
|
||||
explicit ExpressionLocal(const std::string& id);
|
||||
explicit ExpressionLocal(std::string id);
|
||||
~ExpressionLocal() override;
|
||||
};
|
||||
|
||||
struct ExpressionFunc : public Expression {
|
||||
std::string mFuncId;
|
||||
explicit ExpressionFunc(const std::string& id);
|
||||
explicit ExpressionFunc(std::string id);
|
||||
~ExpressionFunc() override;
|
||||
};
|
||||
|
||||
|
|
@ -60,7 +58,7 @@ namespace obj::BCgen {
|
|||
Expression* mParent = nullptr;
|
||||
std::string mLocalId;
|
||||
bool mMethod = false;
|
||||
ExpressionChild(Expression* mParent, const std::string& id);
|
||||
ExpressionChild(Expression* mParent, std::string id);
|
||||
~ExpressionChild() override;
|
||||
};
|
||||
|
||||
|
|
@ -83,7 +81,7 @@ namespace obj::BCgen {
|
|||
Expression* mLeft = nullptr;
|
||||
Expression* mRight = nullptr;
|
||||
|
||||
enum class BoolType : tp::uint1 {
|
||||
enum class BoolType : uint1 {
|
||||
AND = 24U,
|
||||
OR,
|
||||
EQUAL,
|
||||
|
|
@ -103,16 +101,16 @@ namespace obj::BCgen {
|
|||
struct ExpressionConst : public Expression {
|
||||
enum ConstType { STR, INT, BOOL, FLT } mConstType;
|
||||
std::string str;
|
||||
tp::alni integer = 0;
|
||||
tp::alnf floating = 0;
|
||||
alni integer = 0;
|
||||
alnf floating = 0;
|
||||
bool boolean = false;
|
||||
|
||||
explicit ExpressionConst(const std::string& val);
|
||||
explicit ExpressionConst(std::string val);
|
||||
explicit ExpressionConst(const char* val);
|
||||
explicit ExpressionConst(tp::alni val);
|
||||
explicit ExpressionConst(tp::int4 val);
|
||||
explicit ExpressionConst(tp::flt4 val);
|
||||
explicit ExpressionConst(tp::alnf val);
|
||||
explicit ExpressionConst(alni val);
|
||||
explicit ExpressionConst(int4 val);
|
||||
explicit ExpressionConst(flt4 val);
|
||||
explicit ExpressionConst(alnf val);
|
||||
explicit ExpressionConst(bool val);
|
||||
|
||||
~ExpressionConst() override;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "List.hpp"
|
||||
#include "Map.hpp"
|
||||
|
||||
|
|
@ -9,39 +7,38 @@
|
|||
#include "Statements.hpp"
|
||||
#include "Constants.hpp"
|
||||
|
||||
namespace obj {
|
||||
#include <string>
|
||||
|
||||
namespace tp::obj {
|
||||
struct MethodObject;
|
||||
|
||||
namespace BCgen {
|
||||
struct FunctionDefinition {
|
||||
|
||||
struct FunctionDefinition {
|
||||
|
||||
FunctionDefinition* mPrnt = nullptr;
|
||||
FunctionDefinition* mPrnt = nullptr;
|
||||
|
||||
// signature
|
||||
std::string mFunctionId;
|
||||
tp::List<ConstObject*> mArgsOrder;
|
||||
// signature
|
||||
std::string mFunctionId;
|
||||
List<ConstObject*> mArgsOrder;
|
||||
|
||||
ConstObjectsPool mConstants;
|
||||
tp::Map<std::string, ConstObject*> mLocals;
|
||||
tp::List<Instruction> mInstructions;
|
||||
ConstObjectsPool mConstants;
|
||||
Map<std::string, ConstObject*> mLocals;
|
||||
List<Instruction> mInstructions;
|
||||
|
||||
FunctionDefinition(const std::string& function_id, tp::Buffer<std::string> args, FunctionDefinition* prnt);
|
||||
FunctionDefinition() {}
|
||||
FunctionDefinition(const std::string& function_id, const Buffer<std::string>& args, FunctionDefinition* prnt);
|
||||
FunctionDefinition() {}
|
||||
|
||||
void generateByteCode(ByteCode& out);
|
||||
void generateByteCode(ByteCode& out);
|
||||
|
||||
tp::List<Instruction>::Node* inst(Instruction inst);
|
||||
|
||||
void EvalExpr(Expression* expr);
|
||||
void EvalStatement(Statement* expr);
|
||||
List<Instruction>::Node* inst(Instruction inst);
|
||||
|
||||
ConstObject* defineLocal(const std::string& id);
|
||||
};
|
||||
void EvalExpr(Expression* expr);
|
||||
void EvalStatement(Statement* expr);
|
||||
|
||||
void init();
|
||||
void deinit();
|
||||
void Genereate(ByteCode& out, StatementScope* body);
|
||||
bool Compile(MethodObject* obj);
|
||||
ConstObject* defineLocal(const std::string& id);
|
||||
};
|
||||
};
|
||||
|
||||
void initialize();
|
||||
void finalize();
|
||||
void Generate(ByteCode& out, StatementScope* body);
|
||||
bool Compile(MethodObject* obj);
|
||||
}
|
||||
|
|
@ -2,52 +2,47 @@
|
|||
#pragma once
|
||||
|
||||
#include "interpreter/OperatoinCodes.hpp"
|
||||
|
||||
#include "core/Object.hpp"
|
||||
|
||||
#include "List.hpp"
|
||||
|
||||
namespace obj {
|
||||
namespace BCgen {
|
||||
namespace tp::obj {
|
||||
class ConstObject;
|
||||
|
||||
class ConstObject;
|
||||
class Instruction {
|
||||
public:
|
||||
|
||||
class Instruction {
|
||||
public:
|
||||
OpCode mOp = OpCode::NONE;
|
||||
|
||||
OpCode mOp = OpCode::NONE;
|
||||
enum class ArgType : ualni {
|
||||
NO_ARG,
|
||||
PARAM,
|
||||
CONST_ARG,
|
||||
} mArgType = ArgType::NO_ARG;
|
||||
|
||||
enum class ArgType : tp::ualni {
|
||||
NO_ARG,
|
||||
PARAM,
|
||||
CONST_ARG,
|
||||
} mArgType = ArgType::NO_ARG;
|
||||
enum class InstType : ualni {
|
||||
NONE,
|
||||
JUMP,
|
||||
JUMP_IF,
|
||||
JUMP_IF_NOT,
|
||||
EXEC,
|
||||
PURE_CONST,
|
||||
} mInstType = InstType::NONE;
|
||||
|
||||
enum class InstType : tp::ualni {
|
||||
NONE,
|
||||
JUMP,
|
||||
JUMP_IF,
|
||||
JUMP_IF_NOT,
|
||||
EXEC,
|
||||
PURE_CONST,
|
||||
} mInstType = InstType::NONE;
|
||||
alni mParam = 0;
|
||||
alni mParamBytes = 1;
|
||||
|
||||
tp::alni mParam = 0;
|
||||
tp::alni mParamBytes = 1;
|
||||
ConstObject* mConstData = nullptr;
|
||||
ConstObject* mConstData2 = nullptr;
|
||||
|
||||
ConstObject* mConstData = nullptr;
|
||||
ConstObject* mConstData2 = nullptr;
|
||||
alni mInstIdx = 0;
|
||||
Instruction* mInstTarget = nullptr;
|
||||
|
||||
tp::alni mInstIdx = 0;
|
||||
Instruction* mInstTarget = nullptr;
|
||||
|
||||
Instruction();
|
||||
Instruction(ConstObject* constData);
|
||||
Instruction(OpCode op);
|
||||
Instruction(OpCode op, ConstObject* constData);
|
||||
Instruction(OpCode op, ConstObject* constData, ConstObject* constData2);
|
||||
Instruction(OpCode op, tp::alni param, tp::alni nBytes);
|
||||
Instruction(Instruction* inst, InstType jump_type);
|
||||
};
|
||||
Instruction();
|
||||
Instruction(ConstObject* constData);
|
||||
Instruction(OpCode op);
|
||||
Instruction(OpCode op, ConstObject* constData);
|
||||
Instruction(OpCode op, ConstObject* constData, ConstObject* constData2);
|
||||
Instruction(OpCode op, alni param, alni nBytes);
|
||||
Instruction(Instruction* inst, InstType jump_type);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "Expressions.hpp"
|
||||
|
||||
namespace obj::BCgen {
|
||||
namespace tp::obj {
|
||||
struct Statement {
|
||||
|
||||
enum class Type {
|
||||
|
|
@ -28,15 +28,15 @@ namespace obj::BCgen {
|
|||
};
|
||||
|
||||
struct StatementScope : public Statement {
|
||||
tp::Buffer<Statement*> mStatements;
|
||||
Buffer<Statement*> mStatements;
|
||||
bool mPushToScopeStack = false;
|
||||
|
||||
StatementScope(tp::InitialierList<Statement*> statements, bool aPushToScopeStack);
|
||||
StatementScope(InitialierList<Statement*> statements, bool aPushToScopeStack);
|
||||
~StatementScope() override;
|
||||
};
|
||||
|
||||
struct StatementFuncDef : public Statement {
|
||||
tp::Buffer<std::string> mArgs;
|
||||
Buffer<std::string> mArgs;
|
||||
std::string mFunctionId;
|
||||
StatementScope* mStatements = nullptr;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ namespace obj::BCgen {
|
|||
ExpressionConst* mConstExpr = nullptr;
|
||||
bool mIsConstExpr = false;
|
||||
|
||||
StatementLocalDef(const std::string& id, Expression* value);
|
||||
StatementLocalDef(std::string id, Expression* value);
|
||||
~StatementLocalDef() override;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue