aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cps/AST.h8
-rw-r--r--include/cps/FunctionAST.h13
-rw-r--r--include/cps/Lexer.h3
-rw-r--r--include/cps/Parser.h1
4 files changed, 25 insertions, 0 deletions
diff --git a/include/cps/AST.h b/include/cps/AST.h
index 8c8c3be..2b78aaa 100644
--- a/include/cps/AST.h
+++ b/include/cps/AST.h
@@ -107,6 +107,14 @@ public:
const std::string &getPath() const { return Path; }
};
+// INCLUDE_OBJ "path" adds an object file (or the built-in "__libc") to the link.
+class IncludeObjStmtAST : public StmtAST {
+ std::string Path;
+public:
+ explicit IncludeObjStmtAST(std::string Path) : Path(std::move(Path)) {}
+ const std::string &getPath() const { return Path; }
+};
+
class GlobalBlockAST : public StmtAST {
std::vector<std::unique_ptr<StmtAST>> Body;
public:
diff --git a/include/cps/FunctionAST.h b/include/cps/FunctionAST.h
index 9995a4c..716f004 100644
--- a/include/cps/FunctionAST.h
+++ b/include/cps/FunctionAST.h
@@ -33,6 +33,7 @@ class PrototypeAST {
bool IsOverload;
std::string OwnerClass;
bool IsPublic;
+ bool IsVariadic = false;
public:
PrototypeAST(const std::string &Name,
@@ -47,6 +48,8 @@ public:
const std::string &getReturnType() const { return ReturnType; }
bool isOverload() const { return IsOverload; }
bool isExternal() const { return IsExternal; }
+ bool isVariadic() const { return IsVariadic; }
+ void setVariadic(bool V) { IsVariadic = V; }
const std::string &getOwnerClass() const { return OwnerClass; }
bool isPublic() const { return IsPublic; }
std::string getLinkName() const {
@@ -68,6 +71,16 @@ public:
const std::vector<std::unique_ptr<StmtAST>> &getBody() const { return Body; }
};
+// EXTERN "C" EXTERN_FUNCTION/EXTERN_PROCEDURE: a body-less C prototype whose
+// name is the exact C symbol.
+class ExternDeclAST : public StmtAST {
+ std::unique_ptr<PrototypeAST> Proto;
+
+public:
+ explicit ExternDeclAST(std::unique_ptr<PrototypeAST> Proto) : Proto(std::move(Proto)) {}
+ PrototypeAST *getProto() const { return Proto.get(); }
+};
+
class CallExprAST : public ExprAST {
std::string Callee;
std::vector<std::unique_ptr<ExprAST>> Args;
diff --git a/include/cps/Lexer.h b/include/cps/Lexer.h
index 40f168e..e2f5fdc 100644
--- a/include/cps/Lexer.h
+++ b/include/cps/Lexer.h
@@ -103,6 +103,9 @@ enum Token {
tok_new = -613, tok_delete = -614,
tok_include = -650, tok_global = -651, tok_endglobal = -652,
+ tok_include_obj = -653, tok_extern = -654,
+ tok_extern_function = -655, tok_extern_procedure = -656,
+ tok_ellipsis = -657, // ...
tok_try = -700,
tok_catch = -701,
diff --git a/include/cps/Parser.h b/include/cps/Parser.h
index d9e8358..f877ae6 100644
--- a/include/cps/Parser.h
+++ b/include/cps/Parser.h
@@ -75,6 +75,7 @@ class Parser {
std::unique_ptr<FunctionDefAST> ParseFunction(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false);
std::unique_ptr<FunctionDefAST> ParseProcedure(const std::string &OwnerClass = {}, bool IsPublic = true, bool IsOverload = false);
+ std::unique_ptr<StmtAST> ParseExternDecl();
std::unique_ptr<StmtAST> ParseCallStmt();
std::unique_ptr<StmtAST> ParseReturnStmt();
std::optional<std::vector<ParamDecl>> ParsePrototypeArgs(bool AllowByRef);