Skip to content

Commit

Permalink
deleted some unneccessary analyzer code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattmart42 committed Apr 26, 2024
1 parent 5a1318a commit 2fcb607
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
14 changes: 0 additions & 14 deletions src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ export default function analyze(match) {
must(e.type?.kind === 'ArrayType', 'Expected an array', at)
}

function mustHaveAnOptionalType(e, at) {
must(e.type?.kind === 'OptionalType', 'Expected an optional', at)
}

function mustHaveAClassType(e, at) {
must(e.type?.kind === 'ClassType', 'Expected a class', at)
}
Expand Down Expand Up @@ -209,10 +205,6 @@ export default function analyze(match) {
return 'string'
case 'BoolType':
return 'boolean'
case 'VoidType':
return 'void'
case 'AnyType':
return 'any'
case 'ClassType':
return type.name
case 'FunctionType':
Expand All @@ -223,8 +215,6 @@ export default function analyze(match) {
return `(${paramTypes})->${returnType}`
case 'ArrayType':
return `[${typeDescription(type.baseType)}]`
case 'OptionalType':
return `${typeDescription(type.baseType)}?`
}
}

Expand All @@ -235,10 +225,6 @@ export default function analyze(match) {
must(assignable(e.type, type), message, at)
}

function mustNotBeReadOnly(e, at) {
must(!e.readOnly, `Cannot assign to constant ${e.name}`, at)
}

function mustHaveDistinctFields(type, at) {
const fieldNames = new Set(type.fields.map((f) => f.name))
must(
Expand Down
20 changes: 10 additions & 10 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ const stringToIntsType = functionType([stringType], arrayType(intType))
const anyToVoidType = functionType([anyType], voidType)

export const standardLibrary = Object.freeze({
print: fun("print", anyToVoidType)
int: intType,
float: floatType,
boolean: boolType,
string: stringType,
void: voidType,
any: anyType,
π: variable('π', true, floatType),
exp: fun('exp', floatToFloatType),
ln: fun('ln', floatToFloatType),
print: fun("print", anyToVoidType),
int: intType,
float: floatType,
boolean: boolType,
string: stringType,
void: voidType,
any: anyType,
π: variable('π', true, floatType),
exp: fun('exp', floatToFloatType),
ln: fun('ln', floatToFloatType),
})

String.prototype.type = stringType
Expand Down
32 changes: 16 additions & 16 deletions test/generator.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// import assert from "node:assert/strict"
// import parse from "../src/parser.js"
// import analyze from "../src/analyzer.js"
// import optimize from "../src/optimizer.js"
// import generate from "../src/generator.js"
import assert from "node:assert/strict"
import parse from "../src/parser.js"
import analyze from "../src/analyzer.js"
import optimize from "../src/optimizer.js"
import generate from "../src/generator.js"

// function dedent(s) {
// return `${s}`.replace(/(?<=\n)\s+/g, "").trim()
// }
function dedent(s) {
return `${s}`.replace(/(?<=\n)\s+/g, "").trim()
}

const fixtures = [
{
Expand Down Expand Up @@ -167,11 +167,11 @@ const fixtures = [
},
]

// describe("The code generator", () => {
// for (const fixture of fixtures) {
// it(`produces expected js output for the ${fixture.name} program`, () => {
// const actual = generate(optimize(analyze(parse(fixture.source))))
// assert.deepEqual(actual, fixture.expected)
// })
// }
// })
describe("The code generator", () => {
for (const fixture of fixtures) {
it(`produces expected js output for the ${fixture.name} program`, () => {
const actual = generate(optimize(analyze(parse(fixture.source))))
assert.deepEqual(actual, fixture.expected)
})
}
})

0 comments on commit 2fcb607

Please sign in to comment.