Skip to content

Commit

Permalink
Repaired borrowed bindings from other sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jul 30, 2024
1 parent b46347c commit 3d0d56a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
We'll note all notable changes in this file, including bug fixes, enhancements, and all closed issues.
Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http://semver.org/) format.

## 0.10.8 2024-08-03

### Fixed

- Repaired borrowed bindings from other sources.

## 0.10.7 2024-07-27

### Added
Expand Down
7 changes: 7 additions & 0 deletions src/nodes/Borrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ Time()
[`0`],
'0',
],
[
`↓ sup1.a
a
`,
[`↑ a: 0`],
'0',
],
])('Expect %s to be %s', (code, supplements, value) => {
expect(evaluateCode(code, supplements)?.toString()).toBe(value);
});
5 changes: 4 additions & 1 deletion src/nodes/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ export default class Program extends Expression {
const [source, definition] = borrow.getShare(context) ?? [];
if (source === undefined) {
if (definition !== undefined) definitions.push(definition);
} else
} else {
definitions.push(
definition === undefined ? source : definition,
);
definitions.push(source);
}
}
// Return all of the imported definitions and any sources that are part of a named import
return definitions;
}

Expand Down
12 changes: 7 additions & 5 deletions src/runtime/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export default class Evaluator {
/** This represents a stack of node evaluations. The first element of the stack is the currently evaluating node. */
readonly evaluations: Evaluation[] = [];

/** The last evaluation to be removed from the stack */
#lastEvaluation: Evaluation | undefined;
/** The last evaluation to be removed from the stack not triggered by source, used to get shared bindings from a source's block. */
#lastSourceEvaluation: Evaluation | undefined;

/** The callback to notify if the evaluation's value changes. */
readonly observers: EvaluationObserver[] = [];
Expand Down Expand Up @@ -444,7 +444,7 @@ export default class Evaluator {
}

getLastEvaluation() {
return this.#lastEvaluation;
return this.#lastSourceEvaluation;
}

getCurrentClosure() {
Expand Down Expand Up @@ -688,7 +688,7 @@ export default class Evaluator {

// Reset the evluation stack.
this.evaluations.length = 0;
this.#lastEvaluation = undefined;
this.#lastSourceEvaluation = undefined;

// Didn't recently step to node.
this.#steppedToNode = false;
Expand Down Expand Up @@ -1638,7 +1638,9 @@ export default class Evaluator {
throw Error(
"Shouldn't be possible to end an evaluation on an empty evaluation stack.",
);
this.#lastEvaluation = evaluation;
// We want to remember the block and it's bindings for borrowing, since the source's evaluation doesn't have any bindings.
if (!(evaluation.getDefinition() instanceof Source))
this.#lastSourceEvaluation = evaluation;
const def = evaluation.getDefinition();
if (def instanceof Source) {
// If not in the past, save the source value.
Expand Down

0 comments on commit 3d0d56a

Please sign in to comment.