Skip to content

Commit

Permalink
fix weird programMemory Map issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Irev-Dev committed Aug 16, 2024
1 parent bc82575 commit 6c387bd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/lang/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ export const parse = (code: string | Error): Program | Error => {

export type PathToNode = [string | number, string][]

interface Memory {
[key: string]: KclValue
}
type Memory = Map<string, KclValue>

type EnvironmentRef = number

Expand All @@ -153,7 +151,7 @@ interface Environment {
}

function emptyEnvironment(): Environment {
return { bindings: {}, parent: null }
return { bindings: new Map(), parent: null }
}

interface RawProgramMemory {
Expand All @@ -168,7 +166,7 @@ interface RawProgramMemory {
* in the future.
*/
export class ProgramMemory {
private environments: Environment[]
environments: Environment[]
private currentEnv: EnvironmentRef
private return: KclValue | null

Expand Down Expand Up @@ -219,9 +217,9 @@ export class ProgramMemory {
let envRef = this.currentEnv
while (true) {
const env = this.environments[envRef]
if (env.bindings.hasOwnProperty(name)) {
return env.bindings[name]
}
const val = env.bindings.get(name)
if (val) return val

if (!env.parent) {
break
}
Expand All @@ -235,7 +233,7 @@ export class ProgramMemory {
return new Error('No environment to set memory in')
}
const env = this.environments[this.currentEnv]
env.bindings[name] = value
env.bindings.set(name, value)
return null
}

Expand Down Expand Up @@ -268,7 +266,7 @@ export class ProgramMemory {
continue
}
// Deep copy.
bindings[name] = structuredClone(value)
bindings.set(name, structuredClone(value))
}
environments.push({ bindings, parent: env.parent })
}
Expand Down

0 comments on commit 6c387bd

Please sign in to comment.