Skip to content

Commit

Permalink
Try to fix mock execution
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc committed Jan 28, 2025
1 parent ce371dc commit 18fdd1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2471,9 +2471,9 @@ function prepareTruncatedMemoryAndAst(
body: [structuredClone(_ast.body[bodyIndex])],
}

// Grab all the TagDeclarators and TagIdentifiers from memory.
// Ignore anything in memory declared later than the sketch.
let start = _node.node.start
const programMemoryOverride = programMemory.filterVariables(true, (value) => {
const programMemoryOverride = programMemory.filterVariables((value) => {
if (
!('__meta' in value) ||
value.__meta === undefined ||
Expand All @@ -2483,12 +2483,15 @@ function prepareTruncatedMemoryAndAst(
return false
}

if (value.__meta[0].sourceRange[0] >= start) {
if (
value.__meta[0].sourceRange[2] == 0 &&
value.__meta[0].sourceRange[0] >= start
) {
// We only want things before our start point.
return false
}

return value.type === 'TagIdentifier'
return true
})
if (err(programMemoryOverride)) return programMemoryOverride

Expand Down
12 changes: 1 addition & 11 deletions src/lang/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,21 +442,11 @@ export class ProgramMemory {
* Note: Return value of the returned ProgramMemory is always null.
*/
filterVariables(
keepPrelude: boolean,
predicate: (value: KclValue) => boolean
): ProgramMemory | Error {
const environments: Environment[] = []
for (const [i, env] of this.environments.entries()) {
let bindings: Memory
if (i === ROOT_ENVIRONMENT_REF && keepPrelude) {
// Get prelude definitions. Create these first so that they're always
// first in iteration order.
const memoryOrError = programMemoryInit()
if (err(memoryOrError)) return memoryOrError
bindings = memoryOrError.environments[0].bindings
} else {
bindings = emptyEnvironment().bindings
}
let bindings = emptyEnvironment().bindings

for (const [name, value] of Object.entries(env.bindings)) {
if (value === undefined) continue
Expand Down

0 comments on commit 18fdd1c

Please sign in to comment.