-
Notifications
You must be signed in to change notification settings - Fork 108
Stepper
To use the stepper in a REPL, you can run the repl with subst
as its last command line argument:
cd js-slang
yarn build && node dist/repl/repl.js 1 subst
The primary point of entry for the stepper tool is via the getEvaluationSteps-function. This function takes a program an array. This array contains the different program states as the program is being evaluated.
- The method starts off by replacing all predefined constants (such as math_PI) in the program with their corresponding value. This is done via the substPredefinedConstants function.
- The next step is to substitute all predefined functions in the program. This is done with the help of the substPredefinedFns function.
- It then repeatedly reduces the program (which basically means doing repeated one step evaluations) with the help of the reduce function. For every reduction it performs it stores the program state in the return-array. This allows for playback through the evaluation steps.
The function uses an array, mathConstants, that contains all predefined mathematical constants. Each entry of this array is of the form [name, value] - where "name" is the name of the constant (e.g. math_PI) & "value" is the corresponding value (e.g. 3.141592653589793).
The method loops through all elements of mathConstants and replaces all occurrences of the name in the program with the associated value. it does so via the substituteMain method.
This method substitutes all predefined functions in the program. What does substituting these mean?