diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/cps/CodeGen.h | 4 | ||||
| -rw-r--r-- | include/cps/Parser.h | 1 | ||||
| -rw-r--r-- | include/cps/TypeAST.h | 11 | ||||
| -rw-r--r-- | include/cps/TypeSystem.h | 5 |
4 files changed, 20 insertions, 1 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 1813d9d..a70d191 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -25,6 +25,7 @@ class FileHandler; class MemoryHandler; class ExceptionHandler; class CastExprAST; +class NewExprAST; class CodeGen { std::unique_ptr<llvm::LLVMContext> TheContext; @@ -127,6 +128,9 @@ class CodeGen { const std::vector<std::unique_ptr<ExprAST>> &ArgExprs, int Line, std::vector<llvm::Value*> &Out); + llvm::Value *symbolAddress(const SymbolInfo &Info); + void emitAssignment(const LValueInfo &Target, ExprAST *Expr, + const SymbolInfo *Symbol = nullptr); void emitDeclareStmt(DeclareStmtAST *Stmt); void emitOutputValue(llvm::Value *Val, const TypeInfo *TypeInfo, bool AppendNewline = true); diff --git a/include/cps/Parser.h b/include/cps/Parser.h index 4874d7a..9a53e95 100644 --- a/include/cps/Parser.h +++ b/include/cps/Parser.h @@ -34,6 +34,7 @@ class Parser { int GetTokPrecedence(); std::unique_ptr<ExprAST> ParseExpression(); + std::unique_ptr<ExprAST> ParseAssignmentRHS(); std::unique_ptr<ExprAST> ParseUnaryImpl(); std::unique_ptr<ExprAST> ParseUnary(); std::unique_ptr<ExprAST> ParsePrimaryImpl(); diff --git a/include/cps/TypeAST.h b/include/cps/TypeAST.h index de5d12c..a5e40a1 100644 --- a/include/cps/TypeAST.h +++ b/include/cps/TypeAST.h @@ -9,6 +9,17 @@ namespace cps { +// Only an assignment may own this expression. +class NewExprAST : public ExprAST { + std::string ClassName; + std::vector<std::unique_ptr<ExprAST>> Args; +public: + NewExprAST(std::string ClassName, std::vector<std::unique_ptr<ExprAST>> Args, int Line) + : ExprAST(Line), ClassName(std::move(ClassName)), Args(std::move(Args)) {} + const std::string &getClassName() const { return ClassName; } + const auto &getArgs() const { return Args; } +}; + class CastExprAST : public ExprAST { std::string TypeName; std::unique_ptr<ExprAST> Operand; diff --git a/include/cps/TypeSystem.h b/include/cps/TypeSystem.h index 8bee6b9..d358794 100644 --- a/include/cps/TypeSystem.h +++ b/include/cps/TypeSystem.h @@ -66,6 +66,7 @@ struct TypeInfo { std::string Name; llvm::Type *LLVMType = nullptr; TypeKind Kind = TypeKind::Void; + bool IsClass = false; RecordPayload Record; // Kind == Record only EnumPayload Enum; // Kind == Enum only @@ -109,6 +110,7 @@ struct SymbolInfo { bool IsArray = false; llvm::Constant *ConstantValue = nullptr; // Non-null for CONSTANT; no storage. unsigned ScopeID = 0; + bool IsReference = false; // Storage is a slot containing the current object address. }; class TypeSystem { @@ -130,7 +132,8 @@ public: // order). Pass A reserves every name so pointer pointees may forward- // reference; pass B fills definitions. On failure Err carries the // diagnostic and nothing is (further) registered. - bool declareUserType(const std::string &Name, TypeKind Kind, std::string &Err); + bool declareUserType(const std::string &Name, TypeKind Kind, std::string &Err, + bool IsClass = false); bool defineEnum(const std::string &Name, const std::vector<std::string> &Values, std::string &Err); |
