* 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>
95 lines
2.6 KiB
TypeScript
95 lines
2.6 KiB
TypeScript
import { toolTips } from 'lang/langHelpers'
|
|
import { Selection, Selections } from 'lib/selections'
|
|
import { PathToNode, Program, Expr, topLevelRange } from '../../lang/wasm'
|
|
import { getNodeFromPath } from '../../lang/queryAst'
|
|
import {
|
|
PathToNodeMap,
|
|
getRemoveConstraintsTransforms,
|
|
transformAstSketchLines,
|
|
} from '../../lang/std/sketchcombos'
|
|
import { TransformInfo } from 'lang/std/stdTypes'
|
|
import { kclManager } from 'lib/singletons'
|
|
import { err } from 'lib/trap'
|
|
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
|
import { codeRefFromRange } from 'lang/std/artifactGraph'
|
|
|
|
export function removeConstrainingValuesInfo({
|
|
selectionRanges,
|
|
pathToNodes,
|
|
}: {
|
|
selectionRanges: Selections
|
|
pathToNodes?: Array<PathToNode>
|
|
}):
|
|
| {
|
|
transforms: TransformInfo[]
|
|
enabled: boolean
|
|
updatedSelectionRanges: Selections
|
|
}
|
|
| Error {
|
|
const _nodes = selectionRanges.graphSelections.map(({ codeRef }) => {
|
|
const tmp = getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode)
|
|
if (err(tmp)) return tmp
|
|
return tmp.node
|
|
})
|
|
const _err1 = _nodes.find(err)
|
|
if (err(_err1)) return _err1
|
|
const nodes = _nodes as Expr[]
|
|
|
|
const updatedSelectionRanges = pathToNodes
|
|
? {
|
|
otherSelections: [],
|
|
graphSelections: nodes.map(
|
|
(node): Selection => ({
|
|
codeRef: codeRefFromRange(
|
|
topLevelRange(node.start, node.end),
|
|
kclManager.ast
|
|
),
|
|
})
|
|
),
|
|
}
|
|
: selectionRanges
|
|
const isAllTooltips = nodes.every(
|
|
(node) =>
|
|
(node?.type === 'CallExpression' || node?.type === 'CallExpressionKw') &&
|
|
toolTips.includes(node.callee.name as any)
|
|
)
|
|
|
|
const transforms = getRemoveConstraintsTransforms(
|
|
updatedSelectionRanges,
|
|
kclManager.ast,
|
|
'removeConstrainingValues'
|
|
)
|
|
if (err(transforms)) return transforms
|
|
|
|
const enabled = isAllTooltips && transforms.every(Boolean)
|
|
return { enabled, transforms, updatedSelectionRanges }
|
|
}
|
|
|
|
export function applyRemoveConstrainingValues({
|
|
selectionRanges,
|
|
pathToNodes,
|
|
}: {
|
|
selectionRanges: Selections
|
|
pathToNodes?: Array<PathToNode>
|
|
}):
|
|
| {
|
|
modifiedAst: Node<Program>
|
|
pathToNodeMap: PathToNodeMap
|
|
}
|
|
| Error {
|
|
const constraint = removeConstrainingValuesInfo({
|
|
selectionRanges,
|
|
pathToNodes,
|
|
})
|
|
if (err(constraint)) return constraint
|
|
const { transforms, updatedSelectionRanges } = constraint
|
|
|
|
return transformAstSketchLines({
|
|
ast: kclManager.ast,
|
|
selectionRanges: updatedSelectionRanges,
|
|
transformInfos: transforms,
|
|
memVars: kclManager.variables,
|
|
referenceSegName: '',
|
|
})
|
|
}
|