Skip to content

Commit 1630263

Browse files
committed
Fix remaining errors
1 parent 3ab92ba commit 1630263

File tree

10 files changed

+37
-34
lines changed

10 files changed

+37
-34
lines changed

src/createContext.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
// Variable determining chapter of Source is contained in this file.
22

3+
import { schemeVisualise } from './alt-langs/scheme/scheme-mapper'
34
import * as scheme_libs from './alt-langs/scheme/scm-slang/src/stdlib/source-scheme-library'
4-
import {
5-
scheme1Prelude,
6-
scheme2Prelude,
7-
scheme3Prelude,
8-
scheme4Prelude,
9-
schemeFullPrelude
10-
} from './stdlib/scheme.prelude'
115
import { GLOBAL, JSSLANG_PROPERTIES } from './constants'
126
import { call_with_current_continuation } from './cse-machine/continuations'
137
import Heap from './cse-machine/heap'
8+
import { Transformers } from './cse-machine/interpreter'
9+
import { cset_apply, cset_eval } from './cse-machine/scheme-macros'
1410
import * as list from './stdlib/list'
1511
import { list_to_vector } from './stdlib/list'
1612
import { listPrelude } from './stdlib/list.prelude'
1713
import { localImportPrelude } from './stdlib/localImport.prelude'
1814
import * as misc from './stdlib/misc'
1915
import * as parser from './stdlib/parser'
2016
import * as pylib from './stdlib/pylib'
17+
import {
18+
scheme1Prelude,
19+
scheme2Prelude,
20+
scheme3Prelude,
21+
scheme4Prelude,
22+
schemeFullPrelude
23+
} from './stdlib/scheme.prelude'
2124
import * as stream from './stdlib/stream'
2225
import { streamPrelude } from './stdlib/stream.prelude'
2326
import { createTypeEnvironment, tForAll, tVar } from './typeChecker/utils'
@@ -33,9 +36,6 @@ import {
3336
} from './types'
3437
import * as operators from './utils/operators'
3538
import { stringify } from './utils/stringify'
36-
import { schemeVisualise } from './alt-langs/scheme/scheme-mapper'
37-
import { cset_apply, cset_eval } from './cse-machine/scheme-macros'
38-
import { Transformers } from './cse-machine/interpreter'
3939

4040
export class EnvTree {
4141
private _root: EnvTreeNode | null = null
@@ -262,7 +262,7 @@ export const importExternalSymbols = (context: Context, externalSymbols: string[
262262
ensureGlobalEnvironmentExist(context)
263263

264264
externalSymbols.forEach(symbol => {
265-
defineSymbol(context, symbol, GLOBAL[symbol])
265+
defineSymbol(context, symbol, GLOBAL[symbol as keyof typeof GLOBAL])
266266
})
267267
}
268268

@@ -324,7 +324,7 @@ export const importBuiltins = (context: Context, externalBuiltIns: CustomBuiltIn
324324
// Short param names for stringified version of math functions
325325
const parameterNames = [...'abcdefghijklmnopqrstuvwxyz']
326326
for (const name of mathLibraryNames) {
327-
const value = Math[name]
327+
const value = Math[name as keyof typeof Math]
328328
if (typeof value === 'function') {
329329
let paramString: string
330330
let minArgsNeeded = undefined

src/infiniteLoops/instrument.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import type es from 'estree'
44
import { transformImportDeclarations } from '../transpiler/transpiler'
55
import type { Node } from '../types'
66
import * as create from '../utils/ast/astCreator'
7-
import { recursive, simple, WalkerCallback } from '../utils/walkers'
87
import { getIdsFromDeclaration } from '../utils/ast/helpers'
8+
import { objectValues } from '../utils/misc'
9+
import { recursive, simple, WalkerCallback } from '../utils/walkers'
910
// transforms AST of program
1011

1112
const globalIds = {
@@ -40,8 +41,8 @@ enum FunctionNames {
4041
* E.g. "function f(f)..." -> "function f_0(f_1)..."
4142
* @param predefined A table of [key: string, value:string], where variables named 'key' will be renamed to 'value'
4243
*/
43-
function unshadowVariables(program: Node, predefined = {}) {
44-
for (const name of Object.values(globalIds)) {
44+
function unshadowVariables(program: Node, predefined: { [key: string]: string } = {}) {
45+
for (const name of objectValues(globalIds)) {
4546
predefined[name] = name
4647
}
4748
const seenIds = new Set()
@@ -607,7 +608,7 @@ function instrument(
607608
builtins: Iterable<string>
608609
): string {
609610
const { builtinsId, functionsId, stateId } = globalIds
610-
const predefined = {}
611+
const predefined: Record<string, string> = {}
611612
predefined[builtinsId] = builtinsId
612613
predefined[functionsId] = functionsId
613614
predefined[stateId] = stateId
@@ -640,7 +641,7 @@ function instrument(
640641
}
641642

642643
export {
643-
instrument,
644644
FunctionNames as InfiniteLoopRuntimeFunctions,
645-
globalIds as InfiniteLoopRuntimeObjectNames
645+
globalIds as InfiniteLoopRuntimeObjectNames,
646+
instrument
646647
}

src/infiniteLoops/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function prepareBuiltins(oldBuiltins: Map<string, any>) {
251251
const nonDetFunctions = ['get_time', 'math_random']
252252
const newBuiltins = new Map<string, any>()
253253
for (const [name, fun] of oldBuiltins) {
254-
const specialCase = builtinSpecialCases[name]
254+
const specialCase = builtinSpecialCases[name as keyof typeof builtinSpecialCases]
255255
if (specialCase !== undefined) {
256256
newBuiltins.set(name, specialCase)
257257
} else {

src/infiniteLoops/state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ export class State {
138138
}
139139
const transitions = this.mixedStack[this.stackPointer].transitions
140140
for (let i = 0; i < transitions.length; i++) {
141-
const transition = transitions[i]
141+
// TODO: Something seems to be very wrong with the type definitions here
142+
// Shall we just remove the infinite loop detector as per #1516?
143+
const transition: any = transitions[i]
142144
if (transition[0] === name) {
143145
transition[1] = concrete
144146
transition[2] = id
@@ -234,6 +236,6 @@ export class State {
234236
* @returns the name of the last function in the stack.
235237
*/
236238
public getLastFunctionName() {
237-
return this.functionStack[this.functionStack.length - 1][0]
239+
return (this.functionStack[this.functionStack.length - 1] as any)[0]
238240
}
239241
}

src/repl/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Option } from '@commander-js/extra-typings'
2-
2+
import { parseError, type Context } from '..'
33
import { pyLanguages, scmLanguages, sourceLanguages } from '../constants'
4-
import { Chapter, type Language, Variant, type Result, type LanguageOptions } from '../types'
5-
import { stringify } from '../utils/stringify'
64
import Closure from '../cse-machine/closure'
7-
import { parseError, type Context } from '..'
5+
import { Chapter, Variant, type Language, type LanguageOptions, type Result } from '../types'
86
import { objectKeys } from '../utils/misc'
7+
import { stringify } from '../utils/stringify'
98

109
export function chapterParser(str: string): Chapter {
1110
let foundChapter: string | undefined
@@ -23,7 +22,7 @@ export function chapterParser(str: string): Chapter {
2322
}
2423

2524
if (foundChapter in Chapter) {
26-
return Chapter[foundChapter]
25+
return Chapter[foundChapter as keyof typeof Chapter]
2726
}
2827
throw new Error(`Invalid chapter value: ${str}`)
2928
}

src/stdlib/pylib.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function __py_adder(x: Value, y: Value) {
2828
return x + Number(y)
2929
}
3030
if (__is_numeric(x) && __is_numeric(y)) {
31-
return x + y
31+
// TODO: Shouldn't this be `Number(x) + Number(y)`?
32+
return (x as any) + (y as any)
3233
}
3334
throw new Error(`Invalid types for addition operation: ${typeof x}, ${typeof y}`)
3435
}

src/stepper/lib.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as es from 'estree'
22

3+
import { BuiltInFunctionError } from '../errors/errors'
34
import * as misc from '../stdlib/misc'
45
import { Context, substituterNodes } from '../types'
56
import * as ast from '../utils/ast/astCreator'
6-
import { BuiltInFunctionError } from '../errors/errors'
77
import { nodeToValue, nodeToValueWithContext, valueToExpression } from './converter'
88
import { codify } from './stepper'
99
import { isBuiltinFunction, isNumber } from './util'
@@ -98,7 +98,7 @@ export function parse_int(str: substituterNodes, radix: substituterNodes): es.Ex
9898
// }
9999
// evaluateMath(mathFn: string, ...args: substituterNodes): substituterNodes
100100
export function evaluateMath(mathFn: string, ...args: substituterNodes[]): es.Expression {
101-
const fn = Math[mathFn.split('_')[1]]
101+
const fn = Math[mathFn.split('_')[1] as keyof typeof Math] as Function
102102
if (!fn) {
103103
throw new BuiltInFunctionError(`Math function ${mathFn} not found.`)
104104
} else if (args.some(arg => !isNumber(arg))) {

src/transpiler/transpiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ function transformSomeExpressionsToCheckIfBoolean(program: es.Program, globalIds
260260
const { line, column } = (node.loc ?? UNKNOWN_LOCATION).start
261261
const source = node.loc?.source ?? null
262262
const test = node.type === 'LogicalExpression' ? 'left' : 'test'
263-
node[test] = create.callExpression(globalIds.boolOrErr, [
264-
node[test],
263+
;(node as any)[test] = create.callExpression(globalIds.boolOrErr, [
264+
(node as any)[test],
265265
create.literal(line),
266266
create.literal(column),
267267
create.literal(source)

src/utils/stringify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ function niceTypeToString(type: Type, nameMap = { _next: 0 }): string {
4949
}
5050
if (!(type.name in nameMap)) {
5151
// type name is not in map, so add it
52-
nameMap[type.name] = 'T' + nameMap._next++
52+
;(nameMap as any)[type.name] = 'T' + nameMap._next++
5353
}
54-
return nameMap[type.name]
54+
return (nameMap as any)[type.name]
5555
case 'list':
5656
return `List<${curriedTypeToString(type.elementType)}>`
5757
case 'array':

src/vm/svml-assembler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function serialiseFunction(f: SVMFunction): ImFunction {
9393
case OpCodes.NEWC:
9494
holes.push({
9595
offset: b.cursor,
96-
referent: ['function', instr[1]![0]]
96+
referent: ['function', (instr[1]! as any)[0]]
9797
})
9898
b.putU(32, 0)
9999
break

0 commit comments

Comments
 (0)