Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { Position } from 'acorn/dist/acorn'
import { SourceLocation } from 'estree'

import type { Position } from 'acorn/dist/acorn'
import type { SourceLocation } from 'estree'
import { findDeclaration, getScope, runInContext } from '../index'
import { Chapter, Value } from '../types'
import { Chapter, type Value } from '../types'
import { stripIndent } from '../utils/formatters'
import {
createTestContext,
expectParsedError,
expectFinishedResult,
expectParsedError,
testSuccess
} from '../utils/testing'
import { TestOptions } from '../utils/testing/types'
import {
evalWithBuiltins,
assertFinishedResultValue,
evalWithBuiltins,
processTestOptions
} from '../utils/testing/misc'
import type { TestOptions } from '../utils/testing/types'

const toString = (x: Value) => '' + x

Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/scope-refactoring.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Program } from 'estree'

import type { Program } from 'estree'
import { default as createContext } from '../createContext'
import { getAllOccurrencesInScope } from '../index'
import { looseParse } from '../parser/utils'
Expand All @@ -11,7 +10,7 @@ import {
getScopeHelper,
scopeVariables
} from '../scope-refactoring'
import { BlockFrame, Chapter } from '../types'
import { type BlockFrame, Chapter } from '../types'
/* tslint:disable:max-classes-per-file */

class Target {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/stdlib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chapter, Value } from '../types'
import { Chapter, type Value } from '../types'
import { stripIndent } from '../utils/formatters'
import { expectFinishedResult, snapshotFailure } from '../utils/testing'

Expand Down
5 changes: 2 additions & 3 deletions src/alt-langs/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* If required, maps the final result produced by js-slang to
* the required representation for the language.
*/

import { Context, Result } from ".."
import type { Context, Result } from ".."
import { Chapter } from "../types"
import { mapErrorToScheme, mapResultToScheme } from "./scheme/scheme-mapper"

Expand Down Expand Up @@ -47,4 +46,4 @@ export const isSchemeLanguage = (context: Context) =>
context.chapter === Chapter.SCHEME_2 ||
context.chapter === Chapter.SCHEME_3 ||
context.chapter === Chapter.SCHEME_4 ||
context.chapter === Chapter.FULL_SCHEME
context.chapter === Chapter.FULL_SCHEME
5 changes: 2 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as es from 'estree'

import { AcornOptions } from './parser/types'
import { Chapter, Language, Variant } from './types'
import type { AcornOptions } from './parser/types'
import { Chapter, type Language, Variant } from './types'

export const DEFAULT_ECMA_VERSION = 6
export const ACORN_PARSE_OPTIONS: AcornOptions = { ecmaVersion: DEFAULT_ECMA_VERSION }
Expand Down
5 changes: 2 additions & 3 deletions src/cse-machine/__tests__/cse-machine-errors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* tslint:disable:max-line-length */
import * as _ from 'lodash'

import { Chapter, Variant } from '../../types'
import { stripIndent } from '../../utils/formatters'
import { expectParsedError, expectFinishedResult, testFailure } from '../../utils/testing'
import { TestOptions } from '../../utils/testing/types'
import { expectFinishedResult, expectParsedError, testFailure } from '../../utils/testing'
import type { TestOptions } from '../../utils/testing/types'

jest.spyOn(_, 'memoize').mockImplementation(func => func as any)

Expand Down
8 changes: 4 additions & 4 deletions src/cse-machine/__tests__/cse-machine-runtime-context.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as es from 'estree'
import { IOptions } from '../..'
import { mockContext } from '../../utils/testing/mocks'
import type { IOptions } from '../..'
import { parse } from '../../parser/parser'
import { runCodeInSource } from '../../runner'
import { Chapter, RecursivePartial } from '../../types'
import { Chapter, type RecursivePartial } from '../../types'
import { stripIndent } from '../../utils/formatters'
import { Control, Transformers, Stash, generateCSEMachineStateStream } from '../interpreter'
import { mockContext } from '../../utils/testing/mocks'
import { Control, Stash, Transformers, generateCSEMachineStateStream } from '../interpreter'

const getContextFrom = async (code: string, steps?: number) => {
const context = mockContext(Chapter.SOURCE_4)
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/cse-machine-stdlib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chapter, Value, Variant } from '../../types'
import { Chapter, type Value, Variant } from '../../types'
import { stripIndent } from '../../utils/formatters'
import { expectFinishedResult, snapshotFailure } from '../../utils/testing'

Expand Down
5 changes: 2 additions & 3 deletions src/cse-machine/closure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { generate } from 'astring'
import * as es from 'estree'

import {
currentEnvironment,
currentTransformers,
Expand All @@ -9,10 +8,10 @@ import {
isStatementSequence,
uniqueId
} from '../cse-machine/utils'
import { Context, Environment, StatementSequence, Value } from '../types'
import type { Context, Environment, StatementSequence, Value } from '../types'
import * as ast from '../utils/ast/astCreator'
import { Control, Transformers, Stash, generateCSEMachineStateStream } from './interpreter'
import { envInstr } from './instrCreator'
import { Control, Stash, Transformers, generateCSEMachineStateStream } from './interpreter'

const closureToJS = (value: Closure, context: Context) => {
function DummyClass(this: Closure) {
Expand Down
3 changes: 1 addition & 2 deletions src/cse-machine/continuations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as es from 'estree'

import { Context, Environment } from '../types'
import type { Context, Environment } from '../types'
import { Control, Stash, Transformers } from './interpreter'
import { uniqueId } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/heap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HeapObject } from './types'
import type { HeapObject } from './types'

/**
* The heap stores all objects in each environment.
Expand Down
25 changes: 12 additions & 13 deletions src/cse-machine/instrCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
*/

import * as es from 'estree'

import { Environment, Node } from '../types'
import type { Environment, Node } from '../types'
import { Transformers } from './interpreter'
import {
AppInstr,
ArrLitInstr,
AssmtInstr,
BinOpInstr,
BranchInstr,
EnvInstr,
ForInstr,
Instr,
type AppInstr,
type ArrLitInstr,
type AssmtInstr,
type BinOpInstr,
type BranchInstr,
type EnvInstr,
type ForInstr,
type Instr,
InstrType,
UnOpInstr,
WhileInstr
type UnOpInstr,
type WhileInstr
} from './types'
import { Transformers } from './interpreter'

export const resetInstr = (srcNode: Node): Instr => ({
instrType: InstrType.RESET,
Expand Down
36 changes: 18 additions & 18 deletions src/cse-machine/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,46 @@
import * as es from 'estree'
import { isArray } from 'lodash'

import { IOptions } from '..'
import type { IOptions } from '..'
import { isSchemeLanguage } from '../alt-langs/mapper'
import { UNKNOWN_LOCATION } from '../constants'
import * as errors from '../errors/errors'
import { RuntimeSourceError } from '../errors/runtimeSourceError'
import { checkEditorBreakpoints } from '../stdlib/inspector'
import { Context, ContiguousArrayElements, Result, Value, type StatementSequence } from '../types'
import type { Context, ContiguousArrayElements, Result, StatementSequence, Value } from '../types'
import * as ast from '../utils/ast/astCreator'
import { filterImportDeclarations } from '../utils/ast/helpers'
import { evaluateBinaryExpression, evaluateUnaryExpression } from '../utils/operators'
import * as rttc from '../utils/rttc'
import * as seq from '../utils/statementSeqTransform'
import { checkProgramForUndefinedVariables } from '../validator/validator'
import { isSchemeLanguage } from '../alt-langs/mapper'
import Closure from './closure'
import {
Continuation,
isCallWithCurrentContinuation,
makeDummyContCallExpression
} from './continuations'
import * as instr from './instrCreator'
import { flattenList, isList } from './macro-utils'
import { Transformer } from './patterns'
import { isApply, isEval, schemeEval } from './scheme-macros'
import { Stack } from './stack'
import {
AppInstr,
ArrLitInstr,
AssmtInstr,
BinOpInstr,
BranchInstr,
type AppInstr,
type ArrLitInstr,
type AssmtInstr,
type BinOpInstr,
type BranchInstr,
CSEBreak,
ControlItem,
type ControlItem,
CseError,
EnvInstr,
ForInstr,
Instr,
type EnvInstr,
type ForInstr,
type Instr,
InstrType,
UnOpInstr,
WhileInstr,
SpreadInstr
type SpreadInstr,
type UnOpInstr,
type WhileInstr
} from './types'
import {
checkNumberOfArguments,
Expand Down Expand Up @@ -81,9 +84,6 @@ import {
setVariable,
valueProducing
} from './utils'
import { isApply, isEval, schemeEval } from './scheme-macros'
import { Transformer } from './patterns'
import { flattenList, isList } from './macro-utils'

type CmdEvaluator = (
command: ControlItem,
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/macro-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { List, Pair } from '../stdlib/list'
import type { List, Pair } from '../stdlib/list'

/**
* Low-level check for a list.
Expand Down
6 changes: 3 additions & 3 deletions src/cse-machine/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
// it consists of a set of literals used as additional syntax,
// a pattern (for a list to match against)
// and a final template (for the list to be transformed into).
import { List, Pair } from '../stdlib/list'
import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base'
import { atomic_equals, is_number } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math'
import type { List, Pair } from '../stdlib/list'
import {
arrayToImproperList,
arrayToList,
flattenList,
improperListLength,
isImproperList,
isPair,
isList
isList,
isPair
} from './macro-utils'

// a single pattern stored within the patterns component
Expand Down
20 changes: 10 additions & 10 deletions src/cse-machine/scheme-macros.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import * as es from 'estree'
import * as errors from '../errors/errors'
import { List } from '../stdlib/list'
import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base'
import { is_number, SchemeNumber } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math'
import { Context } from '..'
import type { Context } from '..'
import { encode } from '../alt-langs/scheme/scm-slang/src'
import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base'
import { is_number, type SchemeNumber } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math'
import * as errors from '../errors/errors'
import type { List } from '../stdlib/list'
import { popInstr } from './instrCreator'
import { Control, Stash } from './interpreter'
import { currentTransformers, getVariable, handleRuntimeError } from './utils'
import { Transformer, macro_transform, match } from './patterns'
import {
arrayToImproperList,
arrayToList,
flattenImproperList,
isImproperList,
flattenList,
isImproperList,
isList
} from './macro-utils'
import { ControlItem } from './types'
import { popInstr } from './instrCreator'
import { Transformer, macro_transform, match } from './patterns'
import type { ControlItem } from './types'
import { currentTransformers, getVariable, handleRuntimeError } from './utils'

// this needs to be better but for now it's fine
export type SchemeControlItems = List | _Symbol | SchemeNumber | boolean | string
Expand Down
5 changes: 2 additions & 3 deletions src/cse-machine/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as es from 'estree'

import { Environment, Node } from '../types'
import type { Environment, Node } from '../types'
import Closure from './closure'
import { SchemeControlItems } from './scheme-macros'
import { Transformers } from './interpreter'
import type { SchemeControlItems } from './scheme-macros'

export enum InstrType {
RESET = 'Reset',
Expand Down
27 changes: 13 additions & 14 deletions src/cse-machine/utils.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import * as es from 'estree'
import { isArray, isFunction } from 'lodash'

import { Context } from '..'
import type { Context } from '..'
import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base'
import { is_number } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math'
import * as errors from '../errors/errors'
import { RuntimeSourceError } from '../errors/runtimeSourceError'
import { Chapter, type Environment, type Node, type StatementSequence, type Value } from '../types'
import * as ast from '../utils/ast/astCreator'
import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base'
import { is_number } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math'
import Closure from './closure'
import { Continuation, isCallWithCurrentContinuation } from './continuations'
import Heap from './heap'
import * as instr from './instrCreator'
import { Control, Transformers } from './interpreter'
import { isApply, isEval } from './scheme-macros'
import {
AppInstr,
EnvArray,
ControlItem,
Instr,
InstrType,
BranchInstr,
WhileInstr,
ForInstr
type AppInstr,
type BranchInstr,
type ControlItem,
type EnvArray,
type ForInstr,
type Instr,
type WhileInstr
} from './types'
import Closure from './closure'
import { Continuation, isCallWithCurrentContinuation } from './continuations'
import { isApply, isEval } from './scheme-macros'

/**
* Typeguard for commands to check if they are scheme values.
Expand Down
3 changes: 1 addition & 2 deletions src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
/* tslint:disable:max-line-length */
import { baseGenerator, generate } from 'astring'
import * as es from 'estree'

import { UNKNOWN_LOCATION } from '../constants'
import { ErrorSeverity, ErrorType, Node, SourceError, Value } from '../types'
import { ErrorSeverity, ErrorType, type Node, type SourceError, type Value } from '../types'
import { stringify } from '../utils/stringify'
import { RuntimeSourceError } from './runtimeSourceError'

Expand Down
3 changes: 1 addition & 2 deletions src/errors/runtimeSourceError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as es from 'estree'

import { UNKNOWN_LOCATION } from '../constants'
import { ErrorSeverity, ErrorType, Node, SourceError } from '../types'
import { ErrorSeverity, ErrorType, type Node, type SourceError } from '../types'

export class RuntimeSourceError implements SourceError {
public type = ErrorType.RUNTIME
Expand Down
2 changes: 1 addition & 1 deletion src/errors/timeoutErrors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* tslint:disable:max-classes-per-file */
import { JSSLANG_PROPERTIES } from '../constants'
import { ErrorSeverity, ErrorType, Node } from '../types'
import { ErrorSeverity, ErrorType, type Node } from '../types'
import { stripIndent } from '../utils/formatters'
import { stringify } from '../utils/stringify'
import { RuntimeSourceError } from './runtimeSourceError'
Expand Down
Loading