Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattmart42 committed Apr 26, 2024
1 parent 47a4d0e commit 3c9cfaa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export function constructorCall(callee, args) {
// const stringToIntsType = functionType([stringType], arrayType(intType))
// const anyToVoidType = functionType([anyType], voidType)

const anyToVoidType = functionType([anyType], voidType)

export const standardLibrary = Object.freeze({
print: fun("print", anyToVoidType)
// int: intType,
// float: floatType,
// boolean: boolType,
Expand Down
4 changes: 4 additions & 0 deletions src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default function generate(program) {
// with newlines and return the result.
const output = []

const standardFunctions = new Map([
[standardLibrary.print, x => `console.log(${x})`]
])

// Variable and function names in JS will be suffixed with _1, _2, _3,
// etc. This is because "switch", for example, is a legal name in Carlos,
// but not in JS. So, the Carlos variable "switch" must become something
Expand Down
10 changes: 2 additions & 8 deletions test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const fixtures = [
`,
expected: dedent`
let x_1 = 21;
x_1++;
x_1--;
x_1 = x_1 + 1;
x_1 = x_1 - 1;
let y_2 = true;
`,
},
Expand Down Expand Up @@ -155,9 +155,6 @@ const fixtures = [
for j in [10, 20, 30] {
print j;
}
for k in 1..10 {
return;
}
`,
expected: dedent`
for (let i_1 = 1; i_1 < 50; i_1++) {
Expand All @@ -166,9 +163,6 @@ const fixtures = [
for (let j_2 of [10,20,30]) {
console.log(j_2);
}
for (let k_4 = 1; k_4 <= 10; k_4++) {
return;
}
`,
},
]
Expand Down

0 comments on commit 3c9cfaa

Please sign in to comment.