aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-12-08 17:33:30 +0000
committerGinger Bill <bill@gingerbill.org>2016-12-08 17:33:30 +0000
commitfa89d2775a61b1e6943909ff5c96a1e01892d8c9 (patch)
treed4e9fee9e27851a8eccc60913f9de7fe26832bfe /src/parser.c
parent60b6538a7a54d7b2af8142e127116939a7444646 (diff)
`build_dll`; Require an entry point procedure `main`
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/parser.c b/src/parser.c
index 9bb9e088a..708d336ed 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -65,15 +65,15 @@ typedef enum ProcTag {
ProcTag_no_bounds_check = GB_BIT(1),
ProcTag_foreign = GB_BIT(10),
- ProcTag_link_name = GB_BIT(11),
+ ProcTag_export = GB_BIT(11),
ProcTag_inline = GB_BIT(12),
ProcTag_no_inline = GB_BIT(13),
ProcTag_dll_import = GB_BIT(14),
ProcTag_dll_export = GB_BIT(15),
- ProcTag_stdcall = GB_BIT(16),
- ProcTag_fastcall = GB_BIT(17),
- // ProcTag_cdecl = GB_BIT(18),
+ ProcTag_stdcall = GB_BIT(20),
+ ProcTag_fastcall = GB_BIT(21),
+ // ProcTag_cdecl = GB_BIT(22),
} ProcTag;
typedef enum VarDeclTag {
@@ -106,7 +106,7 @@ AstNodeArray make_ast_node_array(AstFile *f) {
AstNode *body; \
u64 tags; \
String foreign_name; \
- String link_name; \
+ String export_name; \
}) \
AST_NODE_KIND(CompoundLit, "compound literal", struct { \
AstNode *type; \
@@ -246,7 +246,7 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
AstNode *body; \
u64 tags; \
String foreign_name; \
- String link_name; \
+ String export_name; \
AstNode *note; \
}) \
AST_NODE_KIND(TypeDecl, "type declaration", struct { \
@@ -686,13 +686,13 @@ AstNode *make_ellipsis(AstFile *f, Token token, AstNode *expr) {
}
-AstNode *make_proc_lit(AstFile *f, AstNode *type, AstNode *body, u64 tags, String foreign_name, String link_name) {
+AstNode *make_proc_lit(AstFile *f, AstNode *type, AstNode *body, u64 tags, String foreign_name, String export_name) {
AstNode *result = make_node(f, AstNode_ProcLit);
result->ProcLit.type = type;
result->ProcLit.body = body;
result->ProcLit.tags = tags;
result->ProcLit.foreign_name = foreign_name;
- result->ProcLit.link_name = link_name;
+ result->ProcLit.export_name = export_name;
return result;
}
@@ -926,14 +926,14 @@ AstNode *make_proc_type(AstFile *f, Token token, AstNodeArray params, AstNodeArr
return result;
}
-AstNode *make_proc_decl(AstFile *f, AstNode *name, AstNode *proc_type, AstNode *body, u64 tags, String foreign_name, String link_name) {
+AstNode *make_proc_decl(AstFile *f, AstNode *name, AstNode *proc_type, AstNode *body, u64 tags, String foreign_name, String export_name) {
AstNode *result = make_node(f, AstNode_ProcDecl);
result->ProcDecl.name = name;
result->ProcDecl.type = proc_type;
result->ProcDecl.body = body;
result->ProcDecl.tags = tags;
result->ProcDecl.foreign_name = foreign_name;
- result->ProcDecl.link_name = link_name;
+ result->ProcDecl.export_name = export_name;
return result;
}
@@ -1364,10 +1364,10 @@ bool is_foreign_name_valid(String name) {
return true;
}
-void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name, String *link_name) {
+void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name, String *export_name) {
// TODO(bill): Add this to procedure literals too
GB_ASSERT(foreign_name != NULL);
- GB_ASSERT(link_name != NULL);
+ GB_ASSERT(export_name != NULL);
while (f->curr_token.kind == Token_Hash) {
AstNode *tag_expr = parse_tag_expr(f, NULL);
@@ -1390,13 +1390,13 @@ void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name, String *link_n
next_token(f);
}
- } else if (str_eq(tag_name, str_lit("link_name"))) {
- check_proc_add_tag(f, tag_expr, tags, ProcTag_link_name, tag_name);
+ } else if (str_eq(tag_name, str_lit("export"))) {
+ check_proc_add_tag(f, tag_expr, tags, ProcTag_export, tag_name);
if (f->curr_token.kind == Token_String) {
- *link_name = f->curr_token.string;
+ *export_name = f->curr_token.string;
// TODO(bill): Check if valid string
- if (!is_foreign_name_valid(*link_name)) {
- syntax_error_node(tag_expr, "Invalid alternative link procedure name `%.*s`", LIT(*link_name));
+ if (!is_foreign_name_valid(*export_name)) {
+ syntax_error_node(tag_expr, "Invalid alternative link procedure name `%.*s`", LIT(*export_name));
}
next_token(f);
@@ -1420,8 +1420,8 @@ void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name, String *link_n
#undef ELSE_IF_ADD_TAG
}
- if ((*tags & ProcTag_foreign) && (*tags & ProcTag_link_name)) {
- syntax_error(f->curr_token, "You cannot apply both #foreign and #link_name to a procedure");
+ if ((*tags & ProcTag_foreign) && (*tags & ProcTag_export)) {
+ syntax_error(f->curr_token, "You cannot apply both #foreign and #export to a procedure");
}
if ((*tags & ProcTag_inline) && (*tags & ProcTag_no_inline)) {
@@ -1534,23 +1534,24 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
u64 tags = 0;
String foreign_name = {0};
- String link_name = {0};
- parse_proc_tags(f, &tags, &foreign_name, &link_name);
+ String export_name = {0};
+ parse_proc_tags(f, &tags, &foreign_name, &export_name);
if (tags & ProcTag_foreign) {
syntax_error(f->curr_token, "#foreign cannot be applied to procedure literals");
}
- if (tags & ProcTag_link_name) {
- syntax_error(f->curr_token, "#link_name cannot be applied to procedure literals");
+ if (tags & ProcTag_export) {
+ syntax_error(f->curr_token, "#export cannot be applied to procedure literals");
}
if (f->curr_token.kind == Token_OpenBrace) {
AstNode *body;
- f->expr_level++;
- body = parse_body(f);
- f->expr_level--;
+ if ((tags & ProcTag_foreign) != 0) {
+ syntax_error(f->curr_token, "A procedure tagged as `#foreign` cannot have a body");
+ }
- type = make_proc_lit(f, type, body, tags, foreign_name, link_name);
+ body = parse_body(f);
+ type = make_proc_lit(f, type, body, tags, foreign_name, export_name);
} else if (type != NULL && type->kind == AstNode_ProcType) {
type->ProcType.tags = tags;
}
@@ -2425,9 +2426,9 @@ AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name) {
AstNode *body = NULL;
u64 tags = 0;
String foreign_name = {0};
- String link_name = {0};
+ String export_name = {0};
- parse_proc_tags(f, &tags, &foreign_name, &link_name);
+ parse_proc_tags(f, &tags, &foreign_name, &export_name);
AstNode *curr_proc = f->curr_proc;
f->curr_proc = proc_type;
@@ -2442,7 +2443,7 @@ AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name) {
}
f->curr_proc = curr_proc;
- return make_proc_decl(f, name, proc_type, body, tags, foreign_name, link_name);
+ return make_proc_decl(f, name, proc_type, body, tags, foreign_name, export_name);
}
AstNode *parse_if_stmt(AstFile *f) {