shithub: lpa

Download patch

ref: 5a13bf8802eea9663d555a24c90dc0e8c346d97d
parent: da6308e5df8ed9cdf8d8f6cad73eef10f31ac4b0
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Mon Jul 22 16:36:28 EDT 2024

Only list symbols which have a value

--- a/eval.c
+++ b/eval.c
@@ -202,7 +202,7 @@
 static void
 pushlocal(CallStack *c, Symtab *s, uvlong id)
 {
-	CallFrame f = c->frames[s->count-1];
+	CallFrame f = c->frames[c->count-1];
 
 	f.locals->count++;
 	f.locals->list = allocextra(f.locals, sizeof(Local) * f.locals->count);
--- a/fns.h
+++ b/fns.h
@@ -45,7 +45,7 @@
 void symset(Symtab *, uvlong, void *);
 Symbol *symptr(Symtab *, uvlong);
 
-Enumeration *enumsymbols(Symtab *);
+Enumeration *enumsymbols(Symtab *, int);
 
 /* systemcmd.c */
 void systemcmd(Session *, char *, int);
--- a/fs.c
+++ b/fs.c
@@ -373,7 +373,7 @@
 			*qid = m->qsession;
 		else{
 			int found = 0;
-			e = enumsymbols(m->symtab);
+			e = enumsymbols(m->symtab, 1);
 			for(uvlong i = 0; i < e->count && !found; i++){
 				Symbol *symb = e->items[i];
 				if(strcmp(name, symb->name) == 0){
@@ -510,7 +510,7 @@
 		dirread9p(r, modulesgen, e);
 		break;
 	case Qmodule:
-		e = enumsymbols(aux->module->symtab);
+		e = enumsymbols(aux->module->symtab, 0);
 		dirread9p(r, symbolsgen, e);
 		break;
 	case Qnew:
--- a/symtab.c
+++ b/symtab.c
@@ -82,12 +82,26 @@
 }
 
 Enumeration *
-enumsymbols(Symtab *symtab)
+enumsymbols(Symtab *symtab, int all)
 {
 	rlock(&symtab->lock);
-	Enumeration *e = allocenum(symtab->count);
-	for(uvlong i = 0; i < symtab->count; i++)
-		e->items[i] = symtab->symbols[i];
+	uvlong count;
+	if(all)
+		count = symtab->count;
+	else{
+		count = 0;
+		for(uvlong i = 0; i < symtab->count; i++)
+			count += symtab->symbols[i]->value != nil;
+	}
+
+	Enumeration *e = allocenum(count);
+	uvlong j = 0;
+	for(uvlong i = 0; i < symtab->count; i++){
+		if(all || symtab->symbols[i]->value){
+			e->items[j] = symtab->symbols[i];
+			j++;
+		}
+	}
 	runlock(&symtab->lock);
 	return e;
 }
\ No newline at end of file