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
3 changes: 1 addition & 2 deletions src/__tests__/block-scoping.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'vitest'
import { Chapter } from '../langs'
import { stripIndent } from '../utils/formatters'
import { expectParsedError, expectFinishedResult } from '../utils/testing'
import { expectFinishedResult, expectParsedError } from '../utils/testing'

// This is bad practice. Don't do this!
test('standalone block statements', () => {
Expand Down Expand Up @@ -145,7 +145,6 @@ test('Error when accessing temporal dead zone', () => {
`).toEqual("Line 3: ReferenceError: Cannot access 'a' before initialization")
}, 30000)

// tslint:disable-next-line:max-line-length
test('In a block, every going-to-be-defined variable in the block cannot be accessed until it has been defined in the block.', () => {
return expectParsedError(stripIndent`
const a = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/draw_data.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { Chapter } from '../langs'
import { expectParsedError, expectFinishedResult } from '../utils/testing'
import { expectFinishedResult, expectParsedError } from '../utils/testing'

test('draw_data returns first argument if more than one argument', () => {
return expectFinishedResult(`draw_data(1, 2);`, Chapter.SOURCE_3).toEqual(1)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/environmentTree.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from 'vitest'
import { createGlobalEnvironment, EnvTree, EnvTreeNode } from '../createContext'
import { pushEnvironment } from '../cse-machine/utils'
import { mockContext, mockEnvironment } from '../utils/testing/mocks'
import { Chapter } from '../langs'
import { mockContext, mockEnvironment } from '../utils/testing/mocks'

test('EnvTree root should be null upon instantiation', () => {
const envTree = new EnvTree()
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { describe, expect, test } from 'vitest'
import type { Position } from 'acorn/dist/acorn'
import type { SourceLocation } from 'estree'
import { describe, expect, test } from 'vitest'

import { findDeclaration, getScope, runInContext } from '../index'
import { Value } from '../types'
import { Chapter } from '../langs'
import { Value } from '../types'
import { stripIndent } from '../utils/formatters'
import {
createTestContext,
expectParsedError,
expectFinishedResult,
expectParsedError,
testSuccess
} from '../utils/testing'
import type { 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
2 changes: 1 addition & 1 deletion src/__tests__/mode.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test, vi } from 'vitest'
import * as ace from 'ace-builds'
import { Mode as DefaultMode } from 'ace-builds/src-noconflict/mode-javascript'
import { expect, test, vi } from 'vitest'

import { HighlightRulesSelector, ModeSelector } from '../editors/ace/modes/source'
import { Chapter, Variant } from '../langs'
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/return-regressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { test } from 'vitest'
import { Chapter } from '../langs'
import { expectParsedError, expectFinishedResult } from '../utils/testing'
import { expectFinishedResult, expectParsedError } from '../utils/testing'

// This is bad practice. Don't do this!
test('Calling unreachable results in error', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/scope-refactoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from 'vitest'

import { default as createContext } from '../createContext'
import { getAllOccurrencesInScope } from '../index'
import { Chapter } from '../langs'
import { looseParse } from '../parser/utils'
import {
getAllIdentifiers,
Expand All @@ -12,7 +13,6 @@ import {
scopeVariables
} from '../scope-refactoring'
import type { BlockFrame } from '../types'
import { Chapter } from '../langs'

class Target {
public name: string
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/sicp/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!*.js
!*.js
2 changes: 1 addition & 1 deletion src/__tests__/stdlib.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { Value } from '../types'
import { Chapter } from '../langs'
import { Value } from '../types'
import { stripIndent } from '../utils/formatters'
import { expectFinishedResult, snapshotFailure } from '../utils/testing'

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/stringify.benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: Convert to actual benchmark
import { test } from 'vitest'
import * as list from '../stdlib/list'
import { Chapter } from '../langs'
import * as list from '../stdlib/list'
import { stripIndent } from '../utils/formatters'
import { stringify } from '../utils/stringify'
import { expectFinishedResult } from '../utils/testing'
Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/stringify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ test('Correctly handles circular structures with multiple entry points', async (
})

// The interpreter runs into a MaximumStackLimitExceeded error on 1000, so reduced it to 100.
// tslint:disable:max-line-length
test('String representation of huge lists are nice', async () => {
const {
result: { value }
Expand Down Expand Up @@ -194,7 +193,6 @@ test('String representation of huge lists are nice', async () => {
[89, [90, [91, [92, [93, [94, [95, [96, [97, [98, [99, [100, null]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
`)
})
// tslint:enable:max-line-length

test('String representation of huge arrays are nice', async () => {
const {
Expand Down Expand Up @@ -432,7 +430,6 @@ test('String representation of undefined is nice', () => {
return expectFinishedResult(`stringify(undefined);`).toEqual('undefined')
})

// tslint:disable:max-line-length
test('String representation with no indent', async () => {
const {
result: { value }
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/tailcall-return.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { stripIndent } from '../utils/formatters'
import { expectParsedError, expectFinishedResult } from '../utils/testing'
import { expectFinishedResult, expectParsedError } from '../utils/testing'

test('Check that stack is at most 10k in size', { timeout: 10000 }, () => {
return expectParsedError(stripIndent`
Expand Down
8 changes: 4 additions & 4 deletions src/alt-langs/__tests__/mapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { mockContext } from "../../utils/testing/mocks";
import { type Finished } from "../../types";
import { expect, test } from 'vitest';
import { Chapter } from "../../langs";
import { type Finished } from "../../types";
import { mockContext } from "../../utils/testing/mocks";
import { mapResult } from "../mapper";

test("given source, mapper should do nothing (no mapping needed)", () => {
Expand Down Expand Up @@ -31,4 +31,4 @@ test("given scheme, mapper should map result to scheme representation", () => {
representation: "#(1 2 3 4 5)",
},
});
})
})
2 changes: 1 addition & 1 deletion src/alt-langs/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,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
6 changes: 3 additions & 3 deletions src/alt-langs/scheme/__tests__/scheme-encode-decode.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, expect, it, test } from 'vitest'
import type { Node } from 'estree'
import { describe, expect, it, test } from 'vitest'

import { UnassignedVariable } from '../../../errors/errors'
import { dummyExpression } from '../../../utils/ast/dummyAstCreator'
import { decodeValue, mapErrorToScheme } from '../scheme-mapper'
import { decode, encode } from '../scm-slang/src'
import { cons, set$45$cdr$33$ } from '../scm-slang/src/stdlib/base'
import { dummyExpression } from '../../../utils/ast/dummyAstCreator'
import { mapErrorToScheme, decodeValue } from '../scheme-mapper'

describe('Scheme encoder and decoder', () => {
describe('encoder and decoder are proper inverses of one another', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/alt-langs/scheme/__tests__/scheme-mapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { schemeVisualise } from "../scheme-mapper"
import { make_number } from "../scm-slang/src/stdlib/core-math"
import { circular$45$list, cons, cons$42$, list } from "../scm-slang/src/stdlib/base"
import { make_number } from "../scm-slang/src/stdlib/core-math"

test("schemeVisualise: should visualise null properly", () => {
expect(schemeVisualise(null).toString()).toEqual("()")
Expand Down
6 changes: 3 additions & 3 deletions src/alt-langs/scheme/scheme-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ArrowFunctionExpression, Identifier, RestElement } from "estree"
import Closure from "../../cse-machine/closure"
import { decode, estreeDecode } from "./scm-slang/src"
import { boolean$63$, car, cdr, circular$45$list$63$, cons, dotted$45$list$63$, last$45$pair, list$45$tail, null$63$, number$63$, pair$63$, proper$45$list$63$, set$45$cdr$33$, vector$63$ } from "./scm-slang/src/stdlib/source-scheme-library"
import { ErrorType, type SourceError } from "../../errors/base"
import { List, Pair } from "../../stdlib/list"
import { Representation } from "../mapper"
import type { Result } from "../../types"
import { Representation } from "../mapper"
import { decode, estreeDecode } from "./scm-slang/src"
import { boolean$63$, car, cdr, circular$45$list$63$, cons, dotted$45$list$63$, last$45$pair, list$45$tail, null$63$, number$63$, pair$63$, proper$45$list$63$, set$45$cdr$33$, vector$63$ } from "./scm-slang/src/stdlib/source-scheme-library"

export function mapResultToScheme(res: Result): Result {
if (res.status === "finished") {
Expand Down
4 changes: 1 addition & 3 deletions src/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import Heap from './cse-machine/heap'
import { Transformers } from './cse-machine/interpreter'
import { cset_apply, cset_eval } from './cse-machine/scheme-macros'
import { Chapter, Variant, type LanguageOptions } from './langs'
import * as list from './stdlib/list'
import { list_to_vector } from './stdlib/list'
import { listPrelude } from './stdlib/list.prelude'
Expand All @@ -25,7 +26,6 @@
import { streamPrelude } from './stdlib/stream.prelude'
import { createTypeEnvironment, tForAll, tVar } from './typeChecker/utils'
import type { Context, CustomBuiltIns, Environment, NativeStorage, Value } from './types'
import { Chapter, Variant, type LanguageOptions } from './langs'
import * as operators from './utils/operators'
import { stringify } from './utils/stringify'

Expand Down Expand Up @@ -366,7 +366,6 @@
defineBuiltin(
context,
'apply_in_underlying_javascript(fun, args)',
// tslint:disable-next-line:ban-types
(fun: Function, args: Value) => fun.apply(fun, list_to_vector(args))
)

Expand All @@ -377,7 +376,7 @@
'call_cc(f)',
context.variant === Variant.EXPLICIT_CONTROL
? call_with_current_continuation
: (f: any) => {

Check warning on line 379 in src/createContext.ts

View workflow job for this annotation

GitHub Actions / build

'f' is defined but never used. Allowed unused args must match /^_/u
throw new Error('call_cc is only available in Explicit-Control variant')
}
)
Expand All @@ -389,7 +388,6 @@
defineBuiltin(context, 'is_NaN(val)', misc.is_NaN)
defineBuiltin(context, 'has_own_property(obj, prop)', misc.has_own_property)
defineBuiltin(context, 'alert(val)', alert)
// tslint:disable-next-line:ban-types
defineBuiltin(context, 'timed(fun)', (f: Function) =>
misc.timed(context, f, context.externalContext, externalBuiltIns.rawDisplay)
)
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/cse-machine-callcc-js.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'vitest'
import { Chapter, Variant } from '../../langs'
import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing'
import { stripIndent } from '../../utils/formatters'
import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing'
// Continuation tests for Source
const optionEC4 = { chapter: Chapter.SOURCE_4, variant: Variant.EXPLICIT_CONTROL }

Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/cse-machine-callcc.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { Chapter, Variant } from '../../langs'
import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing'
import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing'

// Continuation tests for Scheme
const optionECScm = { chapter: Chapter.SCHEME_4, variant: Variant.EXPLICIT_CONTROL }
Expand Down
4 changes: 2 additions & 2 deletions src/cse-machine/__tests__/cse-machine-heap.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from 'vitest'
import { mockClosure, mockContext } from '../../utils/testing/mocks'
import { runCodeInSource } from '../../runner'
import { Chapter } from '../../langs'
import { runCodeInSource } from '../../runner'
import { stripIndent } from '../../utils/formatters'
import { mockClosure, mockContext } from '../../utils/testing/mocks'
import Heap from '../heap'
import type { EnvArray } from '../types'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { test } from 'vitest'
import { Chapter, Variant } from '../../langs'
import { expectParsedError, expectFinishedResult } from '../../utils/testing'
import { expectFinishedResult, expectParsedError } from '../../utils/testing'

const optionEC = { variant: Variant.EXPLICIT_CONTROL }
const optionEC3 = { chapter: Chapter.SOURCE_3, variant: Variant.EXPLICIT_CONTROL }
Expand Down
6 changes: 3 additions & 3 deletions src/cse-machine/__tests__/cse-machine-runtime-context.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type es from 'estree'
import { expect, test } from 'vitest'
import type { IOptions } from '../..'
import { mockContext } from '../../utils/testing/mocks'
import { Chapter } from '../../langs'
import { parse } from '../../parser/parser'
import { runCodeInSource } from '../../runner'
import type { RecursivePartial } from '../../types'
import { Chapter } from '../../langs'
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.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import type { Value } from '../../types'
import { Chapter, Variant } from '../../langs'
import type { Value } from '../../types'
import { stripIndent } from '../../utils/formatters'
import { expectFinishedResult, snapshotFailure } from '../../utils/testing'

Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/cset-machine-apply.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { Chapter, Variant } from '../../langs'
import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing'
import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing'

// apply tests for Scheme
const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL }
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/cset-machine-eval.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { Chapter, Variant } from '../../langs'
import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing'
import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing'

// CSET tests for Scheme
const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL }
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/cset-machine-macros.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'vitest'
import { Chapter, Variant } from '../../langs'
import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing'
import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing'

// CSET tests for Scheme Macros
const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL }
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/__tests__/patterns.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'
import { match } from '../patterns'
import { _Symbol } from '../../alt-langs/scheme/scm-slang/src/stdlib/base'
import { match } from '../patterns'

function makeList(...args: any[]) {
return args.reduceRight((acc, x) => {
Expand Down
2 changes: 1 addition & 1 deletion src/cse-machine/closure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
} from '../cse-machine/utils'
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 Expand Up @@ -52,7 +52,7 @@
-1
)
// Run the new CSE Machine fully to obtain the result in the stash
for (const _ of gen) {

Check warning on line 55 in src/cse-machine/closure.ts

View workflow job for this annotation

GitHub Actions / build

'_' is assigned a value but never used
}
// Also don't forget to update object count in original context
context.runtime.objectCount = newContext.runtime.objectCount
Expand Down
8 changes: 4 additions & 4 deletions src/cse-machine/instrCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
import type es from 'estree'

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

export const resetInstr = (srcNode: Node): Instr => ({
instrType: InstrType.RESET,
Expand Down
Loading