Skip to content

Commit

Permalink
Exclude defined variables
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienTainon committed Aug 28, 2024
1 parent 4273791 commit f055abc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions frontend/stepper/python/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import log from 'loglevel';
*/
const SKULPT_ANALYSIS_DEBUG = 1;

export const convertSkulptStateToAnalysisSnapshot = function (suspensions: readonly any[], lastAnalysis: AnalysisSnapshot, newStepNum: number): AnalysisSnapshot {
export const convertSkulptStateToAnalysisSnapshot = function (suspensions: readonly any[], lastAnalysis: AnalysisSnapshot, newStepNum: number, excludedVariableNames: string[]): AnalysisSnapshot {
// @ts-ignore
if (SKULPT_ANALYSIS_DEBUG === 2) {
log.getLogger('python_runner').debug('[¥¥¥¥¥¥¥] Building analysis');
Expand Down Expand Up @@ -57,7 +57,7 @@ export const convertSkulptStateToAnalysisSnapshot = function (suspensions: reado

log.getLogger('python_runner').debug('suspension loaded', suspension.$loaded_references);

const scope = analyseSkulptScope(suspension);
const scope = analyseSkulptScope(suspension, excludedVariableNames);
stackFrame.scopes.push(scope);
stackFrame.name = scope.name;
stackFrames.push(stackFrame);
Expand Down Expand Up @@ -95,7 +95,7 @@ const isProgramSuspension = function(suspension): boolean {
/**
* Transforms the skulpt scope (one suspension) to something readable with the variables content.
*/
export const analyseSkulptScope = function(suspension: any): AnalysisScope {
export const analyseSkulptScope = function(suspension: any, excludedVariableNames: string[]): AnalysisScope {
// @ts-ignore
if (SKULPT_ANALYSIS_DEBUG === 2) {
log.getLogger('python_runner').debug('////// Analyse scope...');
Expand All @@ -118,7 +118,7 @@ export const analyseSkulptScope = function(suspension: any): AnalysisScope {
suspVariables = suspension.$loc;
}

const variableNames = sortArgumentsFirst(filterInternalVariables(Object.keys(suspVariables)), suspension._argnames);
const variableNames = sortArgumentsFirst(filterInternalVariables(Object.keys(suspVariables), excludedVariableNames), suspension._argnames);
const loadedReferences = suspension.$loaded_references ? suspension.$loaded_references : {};

for (let variableName of variableNames) {
Expand Down Expand Up @@ -188,9 +188,12 @@ const variablesBeginWithIgnore = [
*
* @returns {Array}
*/
const filterInternalVariables = (variableNames: string[]): string[] => {
const filterInternalVariables = (variableNames: string[], excludedVariableNames: string[]): string[] => {
return variableNames.filter((name) => {
let ignore = false;
if (-1 !== excludedVariableNames.indexOf(name)) {
return false;
}

for (let variableBeginWithIgnore of variablesBeginWithIgnore) {
if (name.indexOf(variableBeginWithIgnore) === 0) {
return false;
Expand Down
5 changes: 4 additions & 1 deletion frontend/stepper/python/python_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default class PythonRunner extends AbstractRunner {
private _stepInProgress = false;
private stepMode = false;
private _editorMarker = null;
private definedConstants = [];
private availableModules = [];
private availableBlocks = [] as Block[];
public _isFinished = false;
Expand Down Expand Up @@ -280,9 +281,11 @@ mod.${className} = Sk.misceval.buildClass(mod, newClass${className}, "${classNam
modContents += PythonRunner._skulptifyClassInstance(classInstance, className);
}

this.definedConstants = [];
for (let block of blocks.filter(block => block.type === BlockType.Constant)) {
const {name, value} = block;
modContents += PythonRunner._skulptifyConst(name, value);
this.definedConstants.push(name);
}

modContents += "\nreturn mod;\n};";
Expand Down Expand Up @@ -775,7 +778,7 @@ mod.${className} = Sk.misceval.buildClass(mod, newClass${className}, "${classNam
stepperState.isFinished = true;
} else {
log.getLogger('stepper').debug('INCREASE STEP NUM TO ', stepperState.analysis.stepNum + 1);
stepperState.analysis = convertSkulptStateToAnalysisSnapshot(stepperState.suspensions, stepperState.lastAnalysis, stepperState.analysis.stepNum + 1);
stepperState.analysis = convertSkulptStateToAnalysisSnapshot(stepperState.suspensions, stepperState.lastAnalysis, stepperState.analysis.stepNum + 1, this.definedConstants);
stepperState.directives = {
ordered: parseDirectives(stepperState.analysis),
functionCallStackMap: null,
Expand Down

0 comments on commit f055abc

Please sign in to comment.