commit cf8cdc2d711c0e44970a2d3a32c6aafa1f1717ee
parent 68787839e62702d0aef68f5ab18dc13afc4cffe2
Author: m21c <ho*******@gmail.com>
Date: Tue, 23 Jun 2026 04:02:39 +0200
fix: record env + record fun tion
Diffstat:
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -2925,13 +2925,15 @@ declaration(Source *source, Type *ty, bool tryreadtype)
Decl *decl = NULL;
Node *result = NULL;
+ Env *env = source->currenv;
+
/*
EnvKind context;
*/
if (tryreadtype) {
decl = finddeclaration(
- source, source->currenv, source->tok.u.key);
+ source, env, source->tok.u.key);
if (decl && decl->kind == DTYPE) {
gettok(source);
@@ -2948,7 +2950,7 @@ declaration(Source *source, Type *ty, bool tryreadtype)
* are processed */
/*
- context = source->currenv->kind;
+ context = env->kind;
*/
redodeclaration:
@@ -2958,7 +2960,7 @@ redodeclaration:
if (getkind(source) == IDENT) {
int key = source->tok.u.key;
SrcLoc loc = source->tok.loc;
- EnvKind envkind = source->currenv->kind;
+ EnvKind envkind = env->kind;
gettok(source);
@@ -2975,7 +2977,7 @@ redodeclaration:
}
}
- decl = finddeclaration(source, source->currenv, key);
+ decl = finddeclaration(source, env, key);
if (decl && decl->kind != DFUNCTION && decl->kind != DPARAM &&
decl->kind != DVAR)
@@ -3040,7 +3042,7 @@ redodeclaration:
}
if (!decl->module)
- decl->module = source->currenv->bundle;
+ decl->module = env->bundle;
/* function declaration */
if (getkind(source) == LPARDELIM) {
@@ -3115,8 +3117,10 @@ redodeclaration:
body = stmtlist(source, source->lastindent,
SFUNCTION, decl, !!functionenv);
- assert(body && body->kind == ASCOPE);
- functionenv = body->u.env;
+ if (env->kind != SSTRUCT && env->kind != SUNION) {
+ assert(body && body->kind == ASCOPE);
+ functionenv = body->u.env;
+ }
/* function init (body defined by assigment) */
} else if (getkind(source) == OASS) {
@@ -3356,10 +3360,9 @@ readrecord(Source *source, bool isunion)
field declarations */
/* @todo check for new-line and only then read body */
- recordnode->rhs = stmtlist(source, indent, envkind, module, false);
- if (recordnode->rhs) {
- module->contentenv = recordnode->rhs->u.env;
- }
+ module->contentenv = pushenv(source, envkind);
+ module->contentenv->envdecl = module;
+ recordnode->rhs = stmtlist(source, indent, envkind, module, true);
record = makerecord(source, module);