Skip to content

Commit

Permalink
gen cov
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattmart42 committed May 2, 2024
1 parent 2f1dd53 commit 4973ccd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
26 changes: 17 additions & 9 deletions src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ export default function generate(program) {
const op = { '==': '===', '!=': '!==' }[e.op] ?? e.op
return `(${gen(e.left)} ${op} ${gen(e.right)})`
},
UnaryExpression(e) {
NegationExpression(e) {
const operand = gen(e.operand)
if (e.op === 'some') {
return operand
} else if (e.op === '#') {
return `${operand}.length`
} else if (e.op === 'random') {
return `((a=>a[~~(Math.random()*a.length)])(${operand}))`
}
return `${e.op}(${operand})`
// if (e.op === 'some') {
// return operand
// } else if (e.op === '#') {
// return `${operand}.length`
// } else if (e.op === 'random') {
// return `((a=>a[~~(Math.random()*a.length)])(${operand}))`
// }
return `${e.op}${operand}`
},
SubscriptExpression(e) {
return `${gen(e.array)}[${gen(e.index)}]`
Expand Down Expand Up @@ -177,3 +177,11 @@ export default function generate(program) {
gen(program)
return output.join('\n')
}

//IN CORE NOT IN GENERATOR
//classtype
//functype
//arraytype
//optionaltype
//negation(unary)
//emptyoptional
6 changes: 5 additions & 1 deletion test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const fixtures = [
x = x + 1;
x = x - 1;
auto y = true;
auto z = -2;
`,
expected: dedent`
let x_1 = 21;
x_1 = (x_1 + 1);
x_1 = (x_1 - 1);
let y_2 = true;
let z_3 = -2;
`,
},
{
Expand All @@ -32,6 +34,7 @@ const fixtures = [
if x == 0 { print 1; } else { print 2; }
if x == 0 { print 1; } else if x == 2 { print 3; }
if x == 0 { print 1; } else if x == 2 { print 3; } else { print 4; }
auto y = if (true) yield 2 otherwise 1;
`,
expected: dedent`
let x_1 = 0;
Expand All @@ -57,6 +60,7 @@ const fixtures = [
} else {
console.log(4);
}
let y_2 = (true) ? 2 : 1;
`,
},
{
Expand Down Expand Up @@ -170,7 +174,7 @@ const fixtures = [
}
`,
expected: dedent`
for (let i_1 = 1; i_1 < 50; i_1++) {
for (let i_1 = 1; i_1 <= 50; i_1++) {
console.log(i_1);
}
for (let j_2 of [10,20,30]) {
Expand Down

0 comments on commit 4973ccd

Please sign in to comment.