ProgramMemory refactor - eliminate copies of memory (#5273)
* refactor program memory for encapsulation and remove special treatment of return values Signed-off-by: Nick Cameron <nrc@ncameron.org> * Refactor ProgramMemory to isolate mutation Signed-off-by: Nick Cameron <nrc@ncameron.org> * Refactor ProgramMemory Signed-off-by: Nick Cameron <nrc@ncameron.org> * Generated output Signed-off-by: Nick Cameron <nrc@ncameron.org> * Cache the result of executing modules for their items Signed-off-by: Nick Cameron <nrc@ncameron.org> * Compress envs when popped Signed-off-by: Nick Cameron <nrc@ncameron.org> * Remove the last traces of geometry from the memory module Signed-off-by: Nick Cameron <nrc@ncameron.org> * docs Signed-off-by: Nick Cameron <nrc@ncameron.org> * Fixups Signed-off-by: Nick Cameron <nrc@ncameron.org> * Frontend Signed-off-by: Nick Cameron <nrc@ncameron.org> * Improve Environment GC Signed-off-by: Nick Cameron <nrc@ncameron.org> * Fixup mock execution frontend and interpreter, misc bug fixes Signed-off-by: Nick Cameron <nrc@ncameron.org> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -18,11 +18,11 @@ import {
|
||||
UnaryExpression,
|
||||
BinaryExpression,
|
||||
PathToNode,
|
||||
ProgramMemory,
|
||||
SourceRange,
|
||||
sketchFromKclValue,
|
||||
isPathToNodeNumber,
|
||||
formatNumber,
|
||||
VariableMap,
|
||||
} from './wasm'
|
||||
import {
|
||||
isNodeSafeToReplacePath,
|
||||
@ -1218,7 +1218,7 @@ export function replaceValueAtNodePath({
|
||||
|
||||
export function moveValueIntoNewVariablePath(
|
||||
ast: Node<Program>,
|
||||
programMemory: ProgramMemory,
|
||||
memVars: VariableMap,
|
||||
pathToNode: PathToNode,
|
||||
variableName: string
|
||||
): {
|
||||
@ -1231,11 +1231,7 @@ export function moveValueIntoNewVariablePath(
|
||||
|
||||
if (!isSafe || value.type === 'Identifier') return { modifiedAst: ast }
|
||||
|
||||
const { insertIndex } = findAllPreviousVariablesPath(
|
||||
ast,
|
||||
programMemory,
|
||||
pathToNode
|
||||
)
|
||||
const { insertIndex } = findAllPreviousVariablesPath(ast, memVars, pathToNode)
|
||||
let _node = structuredClone(ast)
|
||||
const boop = replacer(_node, variableName)
|
||||
if (trap(boop)) return { modifiedAst: ast }
|
||||
@ -1251,7 +1247,7 @@ export function moveValueIntoNewVariablePath(
|
||||
|
||||
export function moveValueIntoNewVariable(
|
||||
ast: Node<Program>,
|
||||
programMemory: ProgramMemory,
|
||||
memVars: VariableMap,
|
||||
sourceRange: SourceRange,
|
||||
variableName: string
|
||||
): {
|
||||
@ -1263,11 +1259,7 @@ export function moveValueIntoNewVariable(
|
||||
const { isSafe, value, replacer } = meta
|
||||
if (!isSafe || value.type === 'Identifier') return { modifiedAst: ast }
|
||||
|
||||
const { insertIndex } = findAllPreviousVariables(
|
||||
ast,
|
||||
programMemory,
|
||||
sourceRange
|
||||
)
|
||||
const { insertIndex } = findAllPreviousVariables(ast, memVars, sourceRange)
|
||||
let _node = structuredClone(ast)
|
||||
const replaced = replacer(_node, variableName)
|
||||
if (trap(replaced)) return { modifiedAst: ast }
|
||||
@ -1289,7 +1281,7 @@ export function moveValueIntoNewVariable(
|
||||
export function deleteSegmentFromPipeExpression(
|
||||
dependentRanges: SourceRange[],
|
||||
modifiedAst: Node<Program>,
|
||||
programMemory: ProgramMemory,
|
||||
memVars: VariableMap,
|
||||
code: string,
|
||||
pathToNode: PathToNode
|
||||
): Node<Program> | Error {
|
||||
@ -1321,7 +1313,7 @@ export function deleteSegmentFromPipeExpression(
|
||||
callExp.shallowPath,
|
||||
constraintInfo.argPosition,
|
||||
_modifiedAst,
|
||||
programMemory
|
||||
memVars
|
||||
)
|
||||
if (!transform) return
|
||||
_modifiedAst = transform.modifiedAst
|
||||
@ -1350,7 +1342,7 @@ export function removeSingleConstraintInfo(
|
||||
pathToCallExp: PathToNode,
|
||||
argDetails: SimplifiedArgDetails,
|
||||
ast: Node<Program>,
|
||||
programMemory: ProgramMemory
|
||||
memVars: VariableMap
|
||||
):
|
||||
| {
|
||||
modifiedAst: Node<Program>
|
||||
@ -1367,7 +1359,7 @@ export function removeSingleConstraintInfo(
|
||||
ast,
|
||||
selectionRanges: [pathToCallExp],
|
||||
transformInfos: [transform],
|
||||
programMemory,
|
||||
memVars,
|
||||
referenceSegName: '',
|
||||
})
|
||||
if (err(retval)) return false
|
||||
@ -1377,7 +1369,7 @@ export function removeSingleConstraintInfo(
|
||||
export async function deleteFromSelection(
|
||||
ast: Node<Program>,
|
||||
selection: Selection,
|
||||
programMemory: ProgramMemory,
|
||||
variables: VariableMap,
|
||||
getFaceDetails: (id: string) => Promise<Models['FaceIsPlanar_type']> = () =>
|
||||
({} as any)
|
||||
): Promise<Node<Program> | Error> {
|
||||
@ -1506,7 +1498,7 @@ export async function deleteFromSelection(
|
||||
return
|
||||
}
|
||||
const sketchToPreserve = sketchFromKclValue(
|
||||
programMemory.get(sketchName),
|
||||
variables[sketchName],
|
||||
sketchName
|
||||
)
|
||||
if (err(sketchToPreserve)) return sketchToPreserve
|
||||
|
Reference in New Issue
Block a user