Skip to content

Commit 5c4cc35

Browse files
committed
rename csep machine to cset machine
1 parent 10be628 commit 5c4cc35

File tree

9 files changed

+40
-38
lines changed

9 files changed

+40
-38
lines changed

src/createContext.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import { makeWrapper } from './utils/makeWrapper'
3838
import * as operators from './utils/operators'
3939
import { stringify } from './utils/stringify'
4040
import { schemeVisualise } from './alt-langs/scheme/scheme-mapper'
41-
import { csep_eval } from './cse-machine/scheme-macros'
42-
import { Pattern } from './cse-machine/interpreter'
41+
import { cset_eval } from './cse-machine/scheme-macros'
42+
import { Transformers } from './cse-machine/interpreter'
4343

4444
export class LazyBuiltIn {
4545
func: (...arg0: any) => any
@@ -119,7 +119,7 @@ const createEmptyRuntime = () => ({
119119
nodes: [],
120120
control: null,
121121
stash: null,
122-
patterns: new Pattern(),
122+
transformers: new Transformers(),
123123
objectCount: 0,
124124
envSteps: -1,
125125
envStepsTotal: 0,
@@ -455,7 +455,7 @@ export const importBuiltins = (context: Context, externalBuiltIns: CustomBuiltIn
455455
case Chapter.FULL_SCHEME:
456456
// Introduction to eval
457457
// eval metaprocedure
458-
defineBuiltin(context, '$scheme_ZXZhbA$61$$61$(xs)', csep_eval)
458+
defineBuiltin(context, '$scheme_ZXZhbA$61$$61$(xs)', cset_eval)
459459

460460
case Chapter.SCHEME_4:
461461
// Introduction to call/cc

src/cse-machine/__tests__/cse-machine-runtime-context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { parse } from '../../parser/parser'
55
import { runCodeInSource } from '../../runner'
66
import { Chapter, RecursivePartial } from '../../types'
77
import { stripIndent } from '../../utils/formatters'
8-
import { Control, Pattern, Stash, generateCSEMachineStateStream } from '../interpreter'
8+
import { Control, Transformers, Stash, generateCSEMachineStateStream } from '../interpreter'
99

1010
const getContextFrom = async (code: string, steps?: number) => {
1111
const context = mockContext(Chapter.SOURCE_4)
@@ -24,13 +24,13 @@ const evaluateCode = (code: string) => {
2424
context.runtime.isRunning = true
2525
context.runtime.control = new Control(program as es.Program)
2626
context.runtime.stash = new Stash()
27-
context.runtime.patterns = new Pattern()
27+
context.runtime.transformers = new Transformers()
2828

2929
const CSEState = generateCSEMachineStateStream(
3030
context,
3131
context.runtime.control,
3232
context.runtime.stash,
33-
context.runtime.patterns,
33+
context.runtime.transformers,
3434
options.envSteps ?? -1,
3535
options.stepLimit ?? -1,
3636
options.isPrelude

src/cse-machine/__tests__/csep-machine-eval.ts renamed to src/cse-machine/__tests__/cset-machine-eval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Chapter, Variant } from '../../types'
22
import { expectParsedError, expectResult } from '../../utils/testing'
33

4-
// CSEP tests for Scheme
4+
// CSET tests for Scheme
55
const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL }
66

77
test('eval of numbers', () => {

src/cse-machine/__tests__/csep-machine-macros.ts renamed to src/cse-machine/__tests__/cset-machine-macros.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Chapter, Variant } from '../../types'
22
import { expectParsedError, expectResult } from '../../utils/testing'
33

4-
// CSEP tests for Scheme Macros
4+
// CSET tests for Scheme Macros
55
const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL }
66

77
test('definition of a macro', () => {

src/cse-machine/closure.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../cse-machine/utils'
1111
import { Context, Environment, StatementSequence, Value } from '../types'
1212
import * as ast from '../utils/ast/astCreator'
13-
import { Control, Pattern, Stash, generateCSEMachineStateStream } from './interpreter'
13+
import { Control, Transformers, Stash, generateCSEMachineStateStream } from './interpreter'
1414
import { envInstr } from './instrCreator'
1515

1616
const closureToJS = (value: Closure, context: Context) => {
@@ -39,12 +39,12 @@ const closureToJS = (value: Closure, context: Context) => {
3939
// The call expression won't create one as there is only one item in the control.
4040
newContext.runtime.control.push(envInstr(currentEnvironment(context), node), node)
4141
newContext.runtime.stash = new Stash()
42-
newContext.runtime.patterns = context.runtime.patterns
42+
newContext.runtime.transformers = context.runtime.transformers
4343
const gen = generateCSEMachineStateStream(
4444
newContext,
4545
newContext.runtime.control,
4646
newContext.runtime.stash,
47-
newContext.runtime.patterns as Pattern,
47+
newContext.runtime.transformers as Transformers,
4848
-1,
4949
-1
5050
)

src/cse-machine/interpreter.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ export class Stash extends Stack<Value> {
174174
}
175175

176176
/**
177-
* The P component is a dictionary of mappings from syntax names to
177+
* The T component is a dictionary of mappings from syntax names to
178178
* their corresponding syntax rule transformers (patterns).
179179
*/
180-
export class Pattern {
180+
export class Transformers {
181181
private items: Map<string, Transformer[]>
182182
public constructor() {
183183
this.items = new Map<string, Transformer[]>()
@@ -218,12 +218,14 @@ export function evaluate(program: es.Program, context: Context, options: IOption
218218
context.runtime.isRunning = true
219219
context.runtime.control = new Control(program)
220220
context.runtime.stash = new Stash()
221-
context.runtime.patterns = context.runtime.patterns ? context.runtime.patterns : new Pattern()
221+
context.runtime.transformers = context.runtime.transformers
222+
? context.runtime.transformers
223+
: new Transformers()
222224
return runCSEMachine(
223225
context,
224226
context.runtime.control,
225227
context.runtime.stash,
226-
context.runtime.patterns,
228+
context.runtime.transformers,
227229
options.envSteps,
228230
options.stepLimit,
229231
options.isPrelude
@@ -250,7 +252,7 @@ export function resumeEvaluate(context: Context) {
250252
context,
251253
context.runtime.control!,
252254
context.runtime.stash!,
253-
context.runtime.patterns as Pattern,
255+
context.runtime.transformers as Transformers,
254256
-1,
255257
-1
256258
)
@@ -331,7 +333,7 @@ function runCSEMachine(
331333
context: Context,
332334
control: Control,
333335
stash: Stash,
334-
patterns: Pattern,
336+
transformers: Transformers,
335337
envSteps: number,
336338
stepLimit: number,
337339
isPrelude: boolean = false
@@ -340,7 +342,7 @@ function runCSEMachine(
340342
context,
341343
control,
342344
stash,
343-
patterns,
345+
transformers,
344346
envSteps,
345347
stepLimit,
346348
isPrelude
@@ -358,7 +360,7 @@ export function* generateCSEMachineStateStream(
358360
context: Context,
359361
control: Control,
360362
stash: Stash,
361-
patterns: Pattern,
363+
transformers: Transformers,
362364
envSteps: number,
363365
stepLimit: number,
364366
isPrelude: boolean = false
@@ -421,7 +423,7 @@ export function* generateCSEMachineStateStream(
421423
cmdEvaluators[command.instrType](command, context, control, stash, isPrelude)
422424
} else {
423425
// this is a scheme value
424-
schemeEval(command, context, control, stash, patterns, isPrelude)
426+
schemeEval(command, context, control, stash, transformers, isPrelude)
425427
}
426428

427429
// Push undefined into the stack if both control and stash is empty

src/cse-machine/scheme-macros.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { List } from '../stdlib/list'
44
import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base'
55
import { is_number, SchemeNumber } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math'
66
import { Context } from '..'
7-
import { Control, Pattern, Stash } from './interpreter'
7+
import { Control, Transformers, Stash } from './interpreter'
88
import { getVariable, handleRuntimeError } from './utils'
99
import {
1010
Transformer,
@@ -42,10 +42,10 @@ export class Eval extends Function {
4242
}
4343
}
4444

45-
export const csep_eval = Eval.get()
45+
export const cset_eval = Eval.get()
4646

4747
export function isEval(value: any): boolean {
48-
return value === csep_eval
48+
return value === cset_eval
4949
}
5050

5151
// helper function to check if a value is a list.
@@ -84,15 +84,15 @@ export function schemeEval(
8484
context: Context,
8585
control: Control,
8686
stash: Stash,
87-
patterns: Pattern,
87+
transformers: Transformers,
8888
isPrelude: boolean
8989
) {
9090
// scheme CSE machine will only ever encounter
9191
// lists or primitives like symbols, booleans or strings.
9292
// if its a list, we can parse the list and evaluate each item as necessary
9393
// if its a symbol, we can look up the symbol in the environment.
9494
// for either of these operations, if our list matches some pattern in
95-
// the P component, then we can apply the corresponding rule.
95+
// the T component, then we can apply the corresponding rule.
9696

9797
// if its a number, boolean, or string, we can just shift the value
9898
// onto the stash.
@@ -109,14 +109,14 @@ export function schemeEval(
109109
// it should match some symbol "define", "set", "lambda", etc...
110110
// or if it doesn't match any of these, then it is a function call.
111111
if (elem instanceof _Symbol) {
112-
// check if elem matches any defined syntax in the P component.
112+
// check if elem matches any defined syntax in the T component.
113113
// if it does, then apply the corresponding rule.
114-
if (patterns.hasPattern(elem.sym)) {
114+
if (transformers.hasPattern(elem.sym)) {
115115
// get the relevant transformers
116-
const transformers: Transformer[] = patterns.getPattern(elem.sym)
116+
const transformerList: Transformer[] = transformers.getPattern(elem.sym)
117117

118118
// find the first matching transformer
119-
for (const transformer of transformers) {
119+
for (const transformer of transformerList) {
120120
// check if the transformer matches the list
121121
try {
122122
if (match(command, transformer.pattern, transformer.literals)) {
@@ -468,14 +468,14 @@ export function schemeEval(
468468
const rules = syntaxRulesList.slice(2)
469469
// rules are set as a list of patterns and templates.
470470
// we need to convert these into transformers.
471-
const transformers: Transformer[] = rules.map(rule => {
471+
const transformerList: Transformer[] = rules.map(rule => {
472472
const ruleList = flattenList(rule)
473473
const pattern = ruleList[0]
474474
const template = ruleList[1]
475475
return new Transformer(literals, pattern, template)
476476
})
477477
// now we can add the transformers to the patterns component.
478-
patterns.addPattern(syntaxName.sym, transformers)
478+
transformers.addPattern(syntaxName.sym, transformerList)
479479
return
480480
case 'syntax-rules':
481481
// syntax-rules is a special form that is used to define
@@ -503,12 +503,12 @@ export function schemeEval(
503503
control.push(appln as es.CallExpression)
504504
return
505505
} else if (command instanceof _Symbol) {
506-
if (patterns.hasPattern(command.sym)) {
506+
if (transformers.hasPattern(command.sym)) {
507507
// get the relevant transformers
508-
const transformers: Transformer[] = patterns.getPattern(command.sym)
508+
const transformerList: Transformer[] = transformers.getPattern(command.sym)
509509

510510
// find the first matching transformer
511-
for (const transformer of transformers) {
511+
for (const transformer of transformerList) {
512512
// check if the transformer matches the list
513513
try {
514514
if (match(command, transformer.pattern, transformer.literals)) {

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as es from 'estree'
1010

1111
import { EnvTree } from './createContext'
1212
import Heap from './cse-machine/heap'
13-
import { Control, Pattern, Stash } from './cse-machine/interpreter'
13+
import { Control, Stash, Transformers } from './cse-machine/interpreter'
1414
import type { ModuleFunctions } from './modules/moduleTypes'
1515
import { Representation } from './alt-langs/mapper'
1616

@@ -146,7 +146,7 @@ export interface Context<T = any> {
146146

147147
/** Runtime Specific state */
148148
runtime: {
149-
patterns?: Pattern
149+
transformers?: Transformers
150150
break: boolean
151151
debuggerOn: boolean
152152
isRunning: boolean

0 commit comments

Comments
 (0)