summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.parse.c.swpbin94208 -> 0 bytes
-rw-r--r--abbrevs.txt2
-rw-r--r--cgen.c17
-rw-r--r--copy.c6
-rw-r--r--decls_cgen.c5
-rw-r--r--eval.c17
-rw-r--r--foreign.c12
-rw-r--r--identifiers.c4
-rw-r--r--instance_table.c10
-rw-r--r--main.c3
-rw-r--r--parse.c56
-rw-r--r--sdecls_cgen.c1
-rw-r--r--test.toc6
-rw-r--r--tokenizer.c4
-rw-r--r--types.c33
-rw-r--r--types.h50
16 files changed, 112 insertions, 114 deletions
diff --git a/.parse.c.swp b/.parse.c.swp
deleted file mode 100644
index 68b132c..0000000
--- a/.parse.c.swp
+++ /dev/null
Binary files differ
diff --git a/abbrevs.txt b/abbrevs.txt
index 8e137c9..2ee0b19 100644
--- a/abbrevs.txt
+++ b/abbrevs.txt
@@ -19,7 +19,7 @@ imptr - importer
inc - include
kw - keyword
len - length
-ns - namespace
+nms - namespace
num - number
op - operator
param - parameter
diff --git a/cgen.c b/cgen.c
index 4c86f63..bf9c5cb 100644
--- a/cgen.c
+++ b/cgen.c
@@ -86,6 +86,10 @@ static bool cgen_defs_decl(CGenerator *g, Declaration *d);
if (!block_f(g, &e->block)) \
return false; \
break; \
+ case EXPR_NMS: \
+ if (!block_f(g, &e->nms.body)) \
+ return false; \
+ break; \
case EXPR_IF: \
if (e->if_.cond) \
if (!f(g, e->if_.cond)) \
@@ -328,6 +332,7 @@ static bool cgen_type_pre(CGenerator *g, Type *t, Location where) {
case BUILTIN_BOOL: cgen_write(g, "bool"); break;
case BUILTIN_F32: cgen_write(g, "f32"); break;
case BUILTIN_F64: cgen_write(g, "f64"); break;
+ case BUILTIN_NMS:
case BUILTIN_TYPE:
assert(0); break;
} break;
@@ -536,8 +541,7 @@ static bool cgen_fn_args(CGenerator *g, FnExpr *f, U64 instance, U64 which_are_c
static bool cgen_fn_header(CGenerator *g, FnExpr *f, U64 instance, U64 which_are_const) {
bool out_param = cgen_uses_ptr(&f->ret_type);
assert(cgen_should_gen_fn(f));
- if (!f->export.id) /* local to this translation unit */
- cgen_write(g, "static ");
+ cgen_write(g, "static ");
if (out_param) {
cgen_write(g, "void ");
} else {
@@ -762,6 +766,7 @@ static bool cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents,
case EXPR_C:
case EXPR_BUILTIN:
case EXPR_TYPE:
+ case EXPR_NMS:
assert(0);
return false;
}
@@ -1230,6 +1235,7 @@ static bool cgen_expr_pre(CGenerator *g, Expression *e) {
case EXPR_FN:
case EXPR_C:
case EXPR_TYPE:
+ case EXPR_NMS:
break;
}
return true;
@@ -1581,6 +1587,8 @@ static bool cgen_expr(CGenerator *g, Expression *e) {
case EXPR_VAL:
cgen_ident_id(g, e->val_c_id);
break;
+ case EXPR_NMS:
+ break;
}
return true;
}
@@ -1845,6 +1853,7 @@ static bool cgen_val_ptr(CGenerator *g, void *v, Type *t, Location where) {
case BUILTIN_CHAR: cgen_write(g, "'\\x%02x'", *(char *)v); break;
case BUILTIN_BOOL: cgen_write(g, "%s", *(bool *)v ? "true" : "false"); break;
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
assert(0);
break;
}
@@ -1878,7 +1887,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) {
continue;
}
Value *val = decl_val_at_index(d, idx);
- if (g->block == NULL && g->fn == NULL && !i->export_name)
+ if (g->block == NULL && g->fn == NULL)
cgen_write(g, "static ");
if (has_expr) {
if (!cgen_val_pre(g, *val, type, d->where))
@@ -1905,7 +1914,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) {
for (int idx = 0; idx < nidents; ++idx) {
Identifier i = d->idents[idx];
Type *type = decl_type_at_index(d, idx);
- if (g->block == NULL && g->fn == NULL && !i->export_name) cgen_write(g, "static ");
+ if (g->block == NULL && g->fn == NULL) cgen_write(g, "static ");
if (!cgen_type_pre(g, type, d->where)) return false;
cgen_write(g, " ");
cgen_ident(g, i);
diff --git a/copy.c b/copy.c
index 7b8c24e..cbfcdcf 100644
--- a/copy.c
+++ b/copy.c
@@ -271,6 +271,9 @@ static void copy_expr(Copier *c, Expression *out, Expression *in) {
case EXPR_VAL:
copy_val(a, &out->val, &in->val, &in->type);
break;
+ case EXPR_NMS:
+ copy_block(c, &out->nms.body, &in->nms.body);
+ break;
}
}
@@ -318,9 +321,6 @@ static void copy_stmt(Copier *c, Statement *out, Statement *in) {
case STMT_DECL:
copy_decl(c, &out->decl, &in->decl);
break;
- case STMT_NAMESPACE:
- copy_block(c, &out->ns.body, &in->ns.body);
- break;
}
}
diff --git a/decls_cgen.c b/decls_cgen.c
index c62b02f..a9cbdf3 100644
--- a/decls_cgen.c
+++ b/decls_cgen.c
@@ -204,10 +204,7 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) {
Identifier ident = d->idents[i];
Type *type = decl_type_at_index(d, i);
if (!type_is_compileonly(type)) {
- if (ident->export_name) {
- cgen_write(g, "extern ");
- } else
- cgen_write(g, "static ");
+ cgen_write(g, "static ");
if (!cgen_type_pre(g, type, d->where))
return false;
cgen_write(g, " ");
diff --git a/eval.c b/eval.c
index 1eb7c1e..4995ea3 100644
--- a/eval.c
+++ b/eval.c
@@ -53,6 +53,7 @@ static size_t compiler_sizeof_builtin(BuiltinType b) {
case BUILTIN_CHAR: return sizeof(char); /* = 1 */
case BUILTIN_BOOL: return sizeof(bool);
case BUILTIN_TYPE: return sizeof(Type *);
+ case BUILTIN_NMS: return sizeof(Namespace *);
}
assert(0);
return 0;
@@ -161,6 +162,7 @@ static bool builtin_truthiness(Value *v, BuiltinType b) {
case BUILTIN_BOOL: return v->boolv;
case BUILTIN_CHAR: return v->charv != 0;
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
break;
}
assert(0); return false;
@@ -301,6 +303,9 @@ static void fprint_val_ptr(FILE *f, void *p, Type *t) {
case BUILTIN_TYPE:
fprint_type(f, *(Type **)p);
break;
+ case BUILTIN_NMS:
+ fprint_nms(f, *(Namespace **)p);
+ break;
}
break;
case TYPE_FN:
@@ -428,6 +433,7 @@ static void val_free(Value *v, Type *t) {
builtin_casts_to_num(low); \
case BUILTIN_CHAR: vout->charv = (char)vin->low; break; \
case BUILTIN_BOOL: vout->boolv = vin->low != 0; break; \
+ case BUILTIN_NMS: \
case BUILTIN_TYPE: assert(0); break; \
} break
@@ -438,6 +444,7 @@ static void val_free(Value *v, Type *t) {
case BUILTIN_BOOL: vout->boolv = vin->low != 0.0f; break; \
case BUILTIN_CHAR: \
case BUILTIN_TYPE: \
+ case BUILTIN_NMS: \
assert(0); break; \
} break
@@ -467,10 +474,12 @@ static void val_builtin_cast(Value *vin, BuiltinType from, Value *vout, BuiltinT
case BUILTIN_F64:
case BUILTIN_BOOL:
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
assert(0); break;
}
break;
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
assert(0);
break;
}
@@ -546,6 +555,7 @@ static void val_cast(Value *vin, Type *from, Value *vout, Type *to) {
case BUILTIN_F32:
case BUILTIN_F64:
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
assert(0); break;
}
break;
@@ -617,6 +627,7 @@ static void eval_deref(Value *v, void *ptr, Type *type) {
case BUILTIN_F64: v->f64 = *(F64 *)ptr; break;
case BUILTIN_CHAR: v->charv = *(char *)ptr; break;
case BUILTIN_BOOL: v->boolv = *(bool *)ptr; break;
+ case BUILTIN_NMS: v->nms = *(Namespace **)ptr; break;
case BUILTIN_TYPE:
v->type = *(Type **)ptr;
break;
@@ -655,6 +666,7 @@ static void eval_deref_set(void *set, Value *to, Type *type) {
case BUILTIN_F64: *(F64 *)set = to->f64; break;
case BUILTIN_CHAR: *(char *)set = to->charv; break;
case BUILTIN_BOOL: *(bool *)set = to->boolv; break;
+ case BUILTIN_NMS: *(Namespace **)set = to->nms; break;
case BUILTIN_TYPE:
*(Type **)set = to->type;
break;
@@ -1587,6 +1599,9 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
case EXPR_TYPE:
v->type = &e->typeval;
break;
+ case EXPR_NMS:
+ v->nms = &e->nms;
+ break;
case EXPR_VAL:
*v = e->val;
break;
@@ -1652,7 +1667,7 @@ static bool eval_stmt(Evaluator *ev, Statement *stmt) {
arr_foreach(stmt->inc.stmts, Statement, sub)
if (!eval_stmt(ev, sub))
return false;
- return false;
+ break;
}
return true;
}
diff --git a/foreign.c b/foreign.c
index 48d8d4a..36cdd82 100644
--- a/foreign.c
+++ b/foreign.c
@@ -139,6 +139,9 @@ static bool arg_list_start(av_alist *arg_list, void (*fn)(), Value *return_val,
case BUILTIN_TYPE:
av_start_ptr(*arg_list, fn, Type *, &return_val->type);
break;
+ case BUILTIN_NMS:
+ av_start_ptr(*arg_list, fn, Namespace *, &return_val->nms);
+ break;
}
break;
case TYPE_STRUCT: {
@@ -234,15 +237,18 @@ static bool arg_list_add(av_alist *arg_list, Value *val, Type *type, Location wh
case BUILTIN_BOOL:
av_uchar(*arg_list, val->boolv);
break;
- case BUILTIN_TYPE:
- av_ptr(*arg_list, Type *, val->type);
- break;
case BUILTIN_F32:
toc_av_f32(*arg_list, val->f32);
break;
case BUILTIN_F64:
toc_av_f64(*arg_list, val->f64);
break;
+ case BUILTIN_TYPE:
+ av_ptr(*arg_list, Type *, val->type);
+ break;
+ case BUILTIN_NMS:
+ av_ptr(*arg_list, Namespace *, val->nms);
+ break;
}
break;
case TYPE_SLICE:
diff --git a/identifiers.c b/identifiers.c
index 10fe844..6eb0bfa 100644
--- a/identifiers.c
+++ b/identifiers.c
@@ -130,10 +130,6 @@ static void fprint_ident_debug(FILE *out, Identifier id) {
fprintf(out, "???");
return;
}
-#ifdef TOC_DEBUG
- if (id->export_id)
- printf(U64_FMT "-", id->export_id);
-#endif
fprint_ident(out, id);
}
diff --git a/instance_table.c b/instance_table.c
index 9527cec..0f8948a 100644
--- a/instance_table.c
+++ b/instance_table.c
@@ -142,6 +142,8 @@ static U64 val_ptr_hash(void *v, Type *t) {
case BUILTIN_BOOL: return (U64)*(bool *)v;
case BUILTIN_TYPE:
return type_hash(*(Type **)v);
+ case BUILTIN_NMS:
+ return (U64)*(Namespace **)v;
}
assert(0);
return 0;
@@ -214,10 +216,10 @@ static bool val_ptr_eq(void *u, void *v, Type *t) {
case BUILTIN_F64: return *(F64 *)u == *(F64 *)v;
case BUILTIN_BOOL: return *(bool *)u == *(bool *)v;
case BUILTIN_CHAR: return *(char *)u == *(char *)v;
- case BUILTIN_TYPE: {
- bool ret = type_eq(*(Type **)u, *(Type **)v);
- return ret;
- }
+ case BUILTIN_TYPE:
+ return type_eq(*(Type **)u, *(Type **)v);
+ case BUILTIN_NMS:
+ return *(Namespace **)u == *(Namespace **)v;
}
break;
case TYPE_VOID:
diff --git a/main.c b/main.c
index 40ce416..8baf641 100644
--- a/main.c
+++ b/main.c
@@ -19,6 +19,7 @@
/*
TODO:
namespace
+make sure #export still works properly
constants in structs
#if
@@ -30,7 +31,7 @@ don't allow while {3; 5} (once break is added)
better printing of types (take was_expr into account)
any odd number of "s for a string
make sure futurely/currently-declared types are only used by pointer/slice
-allow omission of trailing ; in foo ::= fn() {}?
+allow omission of trailing ; in foo ::= fn() {...} or foo ::= nms {...} ?
*/
diff --git a/parse.c b/parse.c
index 6b0a59a..99489be 100644
--- a/parse.c
+++ b/parse.c
@@ -48,6 +48,7 @@ static const char *expr_kind_to_str(ExprKind k) {
case EXPR_SLICE: return "slice";
case EXPR_TYPE: return "type";
case EXPR_VAL: return "value";
+ case EXPR_NMS: return "namespace";
}
assert(0);
return "";
@@ -152,6 +153,7 @@ static int kw_to_builtin_type(Keyword kw) {
case KW_BOOL: return BUILTIN_BOOL;
case KW_CHAR: return BUILTIN_CHAR;
case KW_TYPE: return BUILTIN_TYPE;
+ case KW_NAMESPACE: return BUILTIN_NMS;
default: return -1;
}
return -1;
@@ -172,6 +174,7 @@ static Keyword builtin_type_to_kw(BuiltinType t) {
case BUILTIN_BOOL: return KW_BOOL;
case BUILTIN_CHAR: return KW_CHAR;
case BUILTIN_TYPE: return KW_TYPE;
+ case BUILTIN_NMS: return KW_NAMESPACE;
}
assert(0);
return KW_COUNT;
@@ -575,7 +578,6 @@ static bool parse_type(Parser *p, Type *type) {
/* help cgen out */
struc->c.id = 0;
struc->fields = NULL;
- struc->export.id = 0;
struc->where = parser_mk_loc(p);
struc->where.start = t->token;
@@ -1042,7 +1044,6 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
e->kind = EXPR_FN;
if (!parse_fn_expr(p, e->fn = parser_calloc(p, 1, sizeof *e->fn)))
return false;
- e->fn->export.id = 0;
if (t->token != end) {
if (token_is_kw(t->token, KW_LPAREN))
tokr_err(t, "Direct function calling in an expression is not supported.\nYou can wrap the function in parentheses.");
@@ -1052,6 +1053,20 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
goto success;
}
+ case KW_NMS: {
+ Namespace *n = &e->nms;
+ e->kind = EXPR_NMS;
+ ++t->token;
+ if (!parse_block(p, &n->body))
+ return false;
+ arr_foreach(e->nms.body.stmts, Statement, sub) {
+ if (sub->kind != STMT_DECL) {
+ err_print(sub->where, "Only declarations can be in namespaces.");
+ return false;
+ }
+ }
+ goto success;
+ }
case KW_IF: {
IfExpr *i = &e->if_;
e->kind = EXPR_IF;
@@ -1996,6 +2011,10 @@ static bool parse_stmt(Parser *p, Statement *s, bool *was_a_statement) {
*was_a_statement = true;
if (t->token->kind == TOKEN_KW) {
switch (t->token->kw) {
+ case KW_SEMICOLON:
+ *was_a_statement = false;
+ ++t->token;
+ return true;
case KW_RETURN: {
s->kind = STMT_RET;
++t->token;
@@ -2020,24 +2039,6 @@ static bool parse_stmt(Parser *p, Statement *s, bool *was_a_statement) {
t->token = end + 1;
return success;
}
- case KW_NAMESPACE: {
- s->kind = STMT_NAMESPACE;
- ++t->token;
- if (t->token->kind == TOKEN_IDENT) {
- s->ns.name = t->token->ident;
- ++t->token;
- } else {
- s->ns.name = NULL;
- }
- if (!parse_block(p, &s->ns.body))
- return false;
- arr_foreach(s->ns.body.stmts, Statement, sub) {
- if (sub->kind != STMT_DECL) {
- err_print(s->where, "Only declarations can be in namespaces.");
- return false;
- }
- }
- } break;
default: break;
}
} else if (t->token->kind == TOKEN_DIRECT) {
@@ -2181,6 +2182,11 @@ static void fprint_arg_exprs(FILE *out, Expression *args) {
fprintf(out, ")");
}
+static inline void fprint_nms(FILE *out, Namespace *nms) {
+ fprintf(out, "namespace ");
+ fprint_block(out, &nms->body);
+}
+
static void fprint_val(FILE *f, Value v, Type *t);
static void fprint_expr(FILE *out, Expression *e) {
@@ -2333,6 +2339,9 @@ static void fprint_expr(FILE *out, Expression *e) {
case EXPR_VAL:
fprint_val(out, e->val, &e->type);
break;
+ case EXPR_NMS:
+ fprint_nms(out, &e->nms);
+ break;
}
if (found_type) {
fprintf(out, ":");
@@ -2399,12 +2408,6 @@ static void fprint_stmt(FILE *out, Statement *s) {
fprintf(out, ";\n");
}
break;
- case STMT_NAMESPACE:
- fprintf(out, "namespace ");
- if (s->ns.name)
- fprint_ident(out, s->ns.name);
- fprint_block(out, &s->ns.body);
- break;
}
}
@@ -2460,6 +2463,7 @@ static bool expr_is_definitely_const(Expression *e) {
case EXPR_LITERAL_BOOL:
case EXPR_TYPE:
case EXPR_VAL:
+ case EXPR_NMS:
return true;
case EXPR_IF:
case EXPR_WHILE:
diff --git a/sdecls_cgen.c b/sdecls_cgen.c
index 966b22e..f6105a1 100644
--- a/sdecls_cgen.c
+++ b/sdecls_cgen.c
@@ -20,7 +20,6 @@ static bool cgen_sdecls_type(CGenerator *g, Type *type) {
/* we've already done this */
} else {
cgen_write(g, "struct ");
- if (sdef->name && sdef->name->imported) sdef->name = NULL; /* don't use imported names */
if (sdef->name) {
cgen_ident(g, sdef->name);
} else {
diff --git a/test.toc b/test.toc
index e063416..d8916ac 100644
--- a/test.toc
+++ b/test.toc
@@ -1,8 +1,6 @@
-namespace foo {
+foo ::= nms {
bar ::= 12;
-}
+};
main ::= fn() {
- x ::= do_thing();
- do_thing();
}; \ No newline at end of file
diff --git a/tokenizer.c b/tokenizer.c
index 7cd6edc..b422f9e 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -13,8 +13,8 @@ static const char *const keywords[KW_COUNT] =
"new", "del", "struct",
"int", "i8", "i16", "i32", "i64",
"u8", "u16", "u32", "u64", "float", "f32", "f64", "Type",
- "Package",
- "char", "bool", "true", "false", "namespace"};
+ "Namespace",
+ "char", "bool", "true", "false", "nms"};
static inline const char *kw_to_str(Keyword k) { return keywords[k]; }
diff --git a/types.c b/types.c
index 3e038e6..517c1b7 100644
--- a/types.c
+++ b/types.c
@@ -155,24 +155,7 @@ static bool expr_must_lval(Expression *e) {
return false;
}
return true;
- case EXPR_CAST:
- case EXPR_NEW:
- case EXPR_FN:
- case EXPR_LITERAL_FLOAT:
- case EXPR_LITERAL_CHAR:
- case EXPR_LITERAL_STR:
- case EXPR_LITERAL_INT:
- case EXPR_LITERAL_BOOL:
- case EXPR_IF:
- case EXPR_WHILE:
- case EXPR_FOR:
- case EXPR_CALL:
- case EXPR_C:
- case EXPR_BUILTIN:
- case EXPR_BLOCK:
- case EXPR_SLICE:
- case EXPR_TYPE:
- case EXPR_VAL: {
+ default: {
err_print(e->where, "Cannot use %s as l-value.", expr_kind_to_str(e->kind));
return false;
}
@@ -190,7 +173,7 @@ static bool type_is_compileonly(Type *t) {
case TYPE_UNKNOWN:
return false;
case TYPE_BUILTIN:
- return t->builtin == BUILTIN_TYPE;
+ return t->builtin == BUILTIN_TYPE || t->builtin == BUILTIN_NMS;
case TYPE_PTR:
return type_is_compileonly(t->ptr);
case TYPE_SLICE:
@@ -611,6 +594,7 @@ static bool type_can_be_truthy(Type *t) {
case TYPE_BUILTIN:
switch (t->builtin) {
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
return false;
case BUILTIN_I8:
case BUILTIN_U8:
@@ -677,6 +661,7 @@ static Status type_cast_status(Type *from, Type *to) {
case BUILTIN_CHAR:
return STATUS_NONE;
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
return STATUS_ERR;
}
assert(0);
@@ -707,6 +692,7 @@ static Status type_cast_status(Type *from, Type *to) {
return STATUS_NONE;
case BUILTIN_CHAR:
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
return STATUS_ERR;
}
assert(0);
@@ -718,6 +704,7 @@ static Status type_cast_status(Type *from, Type *to) {
case BUILTIN_BOOL:
return type_can_be_truthy(to) ? STATUS_NONE : STATUS_ERR;
case BUILTIN_TYPE:
+ case BUILTIN_NMS:
return STATUS_ERR;
}
break;
@@ -2137,6 +2124,12 @@ static bool types_expr(Typer *tr, Expression *e) {
t->kind = TYPE_BUILTIN;
t->builtin = BUILTIN_TYPE;
break;
+ case EXPR_NMS: {
+ if (!types_block(tr, &e->nms.body))
+ return false;
+ t->kind = TYPE_BUILTIN;
+ t->builtin = BUILTIN_NMS;
+ } break;
case EXPR_VAL:
assert(0);
return false;
@@ -2194,6 +2187,7 @@ static bool types_block(Typer *tr, Block *b) {
arr_remove_lasta(&b->stmts, tr->allocr);
}
}
+
}
ret:
typer_block_exit(tr);
@@ -2439,7 +2433,6 @@ static void typer_create(Typer *tr, Evaluator *ev, ErrCtx *err_ctx, Allocator *a
tr->fn = NULL;
tr->evalr = ev;
tr->err_ctx = err_ctx;
- tr->exptr = NULL; /* by default, don't set an exporter */
tr->in_decls = NULL;
tr->in_expr_decls = NULL;
tr->allocr = allocr;
diff --git a/types.h b/types.h
index 3d30a5f..f499ef8 100644
--- a/types.h
+++ b/types.h
@@ -23,7 +23,7 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
-/* NOTE: make sure you edit copy.c and package.c and cgen_recurse_subexprs/types when you make a change to expression-related types or type-related types in this file! */
+/* NOTE: make sure you edit copy.c and cgen_recurse_subexprs/types when you make a change to expression-related types or type-related types in this file! */
typedef long double Floating; /* OPTIM: Switch to double, but make sure floating-point literals are right */
@@ -163,6 +163,7 @@ typedef union Value {
union Value *tuple;
Slice slice;
struct Type *type;
+ struct Namespace *nms;
} Value;
enum {
@@ -189,10 +190,7 @@ typedef struct IdentDecl {
typedef struct IdentSlot {
char *str;
size_t len;
- bool export_name; /* is this identifier's name important? */
bool anonymous; /* is this identifier not part of a tree? */
- bool imported; /* was this identifier imported from a package? */
- U64 export_id; /* 0 if there's no exported identifier here, otherwise unique positive integer associated with this identifier */
IdentDecl *decls; /* array of declarations of this identifier */
} IdentSlot;
@@ -295,12 +293,12 @@ typedef enum {
KW_F32,
KW_F64,
KW_TYPE,
- KW_PACKAGE,
+ KW_NAMESPACE,
KW_CHAR,
KW_BOOL,
KW_TRUE,
KW_FALSE,
- KW_NAMESPACE,
+ KW_NMS,
KW_COUNT
} Keyword;
@@ -402,7 +400,8 @@ typedef enum {
BUILTIN_F64,
BUILTIN_CHAR,
BUILTIN_BOOL,
- BUILTIN_TYPE
+ BUILTIN_TYPE,
+ BUILTIN_NMS
} BuiltinType;
@@ -470,9 +469,6 @@ typedef struct StructDef {
/* if name is NULL, use this */
IdentID id;
} c;
- struct {
- U32 id; /* (index into exptr->exported_structs) + 1, or 0 if hasn't been exported */
- } export;
} StructDef;
@@ -509,6 +505,7 @@ typedef enum {
EXPR_BUILTIN,
EXPR_SLICE,
EXPR_TYPE,
+ EXPR_NMS,
/*
a value (it's useful to have this).
right now they don't work with cgen_set_tuple
@@ -630,11 +627,6 @@ typedef struct FnExpr {
if the ith semi-constant parameter is constant.
*/
struct {
- U32 id; /* (index of function in ex->exported_fns) + 1,
- or 0 if this function has not been
- added to the exporting array yet */
- } export;
- struct {
/* if name = NULL, this is an anonymous function, and id will be the ID of the fn. */
Identifier name;
IdentID id;
@@ -703,6 +695,10 @@ const char *const builtin_val_names[BUILTIN_VAL_COUNT] =
"sizeof float", "target sizeof float", "sizeof double", "target sizeof double",
"sizeof long double", "target sizeof long double", "compiling"};
+typedef struct Namespace {
+ Block body;
+} Namespace;
+
enum {
EXPR_FOUND_TYPE = 0x01
};
@@ -743,6 +739,7 @@ typedef struct Expression {
} builtin;
Identifier ident;
NewExpr new;
+ Namespace nms;
struct {
Type type;
} del;
@@ -781,8 +778,7 @@ enum {
DECL_FOUND_VAL = 0x0040,
DECL_INFER = 0x0080, /* infer the value (e.g. fn(t::Type=, x:t)) */
DECL_EXPORT = 0x0100,
- DECL_FOREIGN = 0x0200,
- DECL_MARKED_FOR_EXPORTING = 0x0400
+ DECL_FOREIGN = 0x0200
};
typedef U16 DeclFlags;
@@ -813,7 +809,6 @@ typedef enum {
STMT_DECL,
STMT_EXPR,
STMT_RET,
- STMT_NAMESPACE,
STMT_INCLUDE
} StatementKind;
@@ -821,7 +816,7 @@ enum {
RET_HAS_EXPR = 0x01,
};
typedef struct Return {
- U8 flags; /* if this changes, go to package.c */
+ U8 flags;
Expression expr;
} Return;
@@ -834,11 +829,6 @@ typedef union {
struct Statement *stmts; /* after typing */
} Include;
-typedef struct {
- Identifier name; /* NULL = anonymous */
- Block body;
-} Namespace;
-
typedef struct Statement {
Location where;
StatementKind kind;
@@ -848,7 +838,6 @@ typedef struct Statement {
Expression expr;
Return ret;
Include inc;
- Namespace ns;
};
} Statement;
@@ -894,21 +883,10 @@ typedef struct Evaluator {
ForeignFnManager ffmgr;
} Evaluator;
-typedef struct Package {
- char *name;
- const char *filename;
- Identifiers idents;
- Statement *stmts;
- struct {
- char *prefix; /* prefix for C things (not including __) */
- } c;
-} Package;
-
typedef struct Typer {
Allocator *allocr;
Evaluator *evalr;
Identifiers *idents;
- struct Exporter *exptr;
Expression **in_expr_decls; /* an array of expressions whose declarations (e.g. for **x := foo**) we are currently inside */
Declaration **in_decls; /* array of declarations we are currently inside */
Block *block;