commit 0ad38dae916ab3d590ccb4a79be39c3c05b6146f
parent 681cb49c7bfd03cede4a21b40be3e584e9412166
Author: m21c <ho*******@gmail.com>
Date: Sun, 3 Oct 2021 18:03:14 +0200
fixed implicit var/function forward declaration
Diffstat:
| M | compiler.c | | | 40 | +++++++++++++++------------------------- |
1 file changed, 15 insertions(+), 25 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -1916,27 +1916,21 @@ static Node *
exprlist(Source *source, bool isparam, Type *paramtype);
static Node *
-stmtlist(Source *source, int indent, EnvKind envkind, Decl *envdecl)
+stmtlist(Source *source, int indent, EnvKind envkind,
+ Decl *envdecl, bool reuseenv)
{
Node *head = NULL, *tail = NULL;
int needindent = nextindent(source, indent);
Env *env = NULL;
- /* printf("needident: %d, currindent: %d, lastindent: %d\n", needindent, currindent, lastindent); */
- if (envkind != SFUNCTION || !source->currenv ||
- source->currenv->kind != SPARAMLIST)
- {
- /* NOTE(m21c): if there already is a
- * paramlist-environment and we want a
- * function-environment, we just use
- * paramlist as our function-environment.
- * Else, we push a new environment */
+ if (reuseenv) {
+ source->currenv->kind = envkind;
+ } else {
env = pushenv(source, envkind);
env->envdecl = envdecl;
}
-
for (;;) {
Node *stmt;
@@ -1957,13 +1951,8 @@ stmtlist(Source *source, int indent, EnvKind envkind, Decl *envdecl)
}
}
- /* NOTE(m21c): function: paramlist --> function, see NOTE above */
- if (envkind == SFUNCTION &&
- source->currenv &&
- source->currenv->kind == SPARAMLIST)
- {
+ if (reuseenv) {
assert(env == NULL);
- source->currenv->kind = SFUNCTION;
env = source->currenv;
popenv(source);
@@ -2175,7 +2164,7 @@ redodeclaration:
/* function body */
if (getkind(source) != OASS) {
body = stmtlist(source, source->lastindent,
- SFUNCTION, decl);
+ SFUNCTION, decl, !!functionenv);
/* function init (body defined by assigment) */
} else if (getkind(source) == OASS) {
gettok(source);
@@ -2322,7 +2311,7 @@ readrecord(Source *source, bool isunion)
recordnode->type = module->type;
/* TODO(m21c): check for new-line and only then read body */
- recordnode->rhs = stmtlist(source, indent, envkind, module);
+ recordnode->rhs = stmtlist(source, indent, envkind, module, false);
/* TODO(m21c): validate record body, extract declarations,
* compute size and align, resolve aliases */
@@ -2391,7 +2380,8 @@ readatom(Source *source, int flags)
if (getkind(source) == '\n') {
/* FIXME(m21c): stmtlist should ignore indentation in
* this case! */
- lhs = stmtlist(source, source->lastindent, SSCOPE, NULL);
+ lhs = stmtlist(source, source->lastindent,
+ SSCOPE, NULL, false);
source->lastis = savedis;
} else {
lhs = exprlist(source, false, NULL);
@@ -2537,7 +2527,7 @@ readatom(Source *source, int flags)
lhs = tokennode(source, NULL);
gettok(source);
lhs->kind = ADO;
- lhs->lhs = stmtlist(source, indent, SDO, NULL);
+ lhs->lhs = stmtlist(source, indent, SDO, NULL, false);
break;
@@ -2546,7 +2536,7 @@ readatom(Source *source, int flags)
lhs = tokennode(source, NULL);
gettok(source);
lhs->kind = ALOOP;
- lhs->lhs = stmtlist(source, indent, SLOOP, NULL);
+ lhs->lhs = stmtlist(source, indent, SLOOP, NULL, false);
if (getkind(source) == KUNTIL && source->lastindent >= indent) {
lhs->kind = ALOOPUNTIL;
@@ -2565,7 +2555,7 @@ readatom(Source *source, int flags)
gettok(source);
lhs->kind = AWHILE;
lhs->u.payload = readexpr(source, POR);
- lhs->lhs = stmtlist(source, indent, SWHILE, NULL);
+ lhs->lhs = stmtlist(source, indent, SWHILE, NULL, false);
goto joinelse;
@@ -2580,11 +2570,11 @@ readatom(Source *source, int flags)
if (getkind(source) == 'I' && source->tok.u.key == auxthen)
gettok(source);
- lhs->lhs = stmtlist(source, indent, SIF, NULL);
+ lhs->lhs = stmtlist(source, indent, SIF, NULL, false);
joinelse:
if (getkind(source) == KELSE && source->lastindent >= indent) {
gettok(source);
- lhs->rhs = stmtlist(source, indent, SELSE, NULL);
+ lhs->rhs = stmtlist(source, indent, SELSE, NULL, false);
}
break;