Skip to content

Commit 787dc8a

Browse files
committed
fix a stack overflow with circular module references
1 parent 0751dfd commit 787dc8a

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

site/primitives.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@
257257
"class": "StdIO",
258258
"description": "Read a line from stdin"
259259
},
260+
"&seek": {
261+
"args": 2,
262+
"outputs": 0,
263+
"class": "Stream",
264+
"description": "Moves to a absolute position in the file under the stream."
265+
},
260266
"&sl": {
261267
"args": 1,
262268
"outputs": 0,
@@ -335,12 +341,6 @@
335341
"class": "Stream",
336342
"description": "Write an array to a stream"
337343
},
338-
"&sb": {
339-
"args": 2,
340-
"outputs": 0,
341-
"class": "Stream",
342-
"description": "Goes to the position in a stream"
343-
},
344344
"above": {
345345
"glyph": "",
346346
"outputs": 1,
@@ -1483,4 +1483,4 @@
14831483
"class": "Encoding",
14841484
"description": "Encode an array into XLSX bytes"
14851485
}
1486-
}
1486+
}

src/compile/binding.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ impl Compiler {
7272
_ => None,
7373
}) {
7474
if let Ok(Some((path_locals, local))) = self.ref_local(r) {
75-
let is_noadic_function = match &self.asm.bindings[local.index].kind {
76-
BindingKind::Func(f) if f.sig.args() == 0 => true,
77-
_ => false,
75+
let allow_alias = match &self.asm.bindings[local.index].kind {
76+
BindingKind::Func(f) if f.sig.args() == 0 => false,
77+
BindingKind::Scope(_) => false,
78+
_ => true,
7879
};
79-
if !is_noadic_function {
80+
if allow_alias {
8081
self.validate_local(&r.name.value, local, &r.name.span);
8182
(self.code_meta.global_references)
8283
.insert(binding.name.span.clone(), local.index);
@@ -303,13 +304,13 @@ impl Compiler {
303304
let in_function = self
304305
.scopes()
305306
.any(|sc| matches!(sc.kind, ScopeKind::Function));
307+
let no_code_words = binding.words.iter().all(|w| !w.value.is_code());
306308
self.current_bindings.push(CurrentBinding {
307309
name: name.clone(),
308310
signature: binding.signature.as_ref().map(|s| s.value),
309311
recurses: 0,
310312
global_index: local.index,
311313
});
312-
let no_code_words = binding.words.iter().all(|w| !w.value.is_code());
313314

314315
// Compile the words
315316
let (_, mut node) = self.in_scope(ScopeKind::Binding, |comp| {
@@ -514,6 +515,7 @@ impl Compiler {
514515
}
515516
ModuleKind::Test => (ScopeKind::Test, None),
516517
};
518+
// Compile items
517519
let (module, ()) = self.in_scope(scope_kind, |comp| {
518520
comp.items(m.items, ItemCompMode::TopLevel)?;
519521
comp.end_enum()?;

src/compile/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl AsMut<Assembly> for Compiler {
192192
}
193193
}
194194

195-
#[derive(Clone)]
195+
#[derive(Debug, Clone)]
196196
struct CurrentBinding {
197197
name: Ident,
198198
signature: Option<Signature>,

tests/data_defs.ua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,9 @@ M! ← F^0
111111

112112
~F {A ← 0|B ← 0|C ← 0|D ← 0} ∘
113113
⍤⤙≍ {2 3 4 1} F D:1 ⊓A:C: 2 B:3 4
114+
115+
┌─╴A
116+
Call ← +1
117+
B ← A
118+
└─╴
119+
⍤⤙≍ 6 A~B 5

tests_special/error.ua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,8 @@ M~G
172172
└─╴
173173
M 5
174174

175-
F ← |0.1000 ⍢(F F F|1)
175+
F ← |0.1000 ⍢(F F F|1)
176+
177+
┌─╴A
178+
B ← A
179+
└─╴

0 commit comments

Comments
 (0)