Skip to content

Commit

Permalink
Add entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
huynhtrankhanh committed Dec 7, 2023
1 parent 189c74c commit 5724a11
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/cppCodegen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ int main() {
if (binaryOp([&]() { return binaryOp([&]() { return readChar(); }, [&]() { return readChar(); }, [&](auto a, auto b) { return a + b; }); }, [&]() { return uint8_t(uint64_t(3)); }, [&](auto a, auto b) { return a < b; }) && binaryOp([&]() { return toSigned(readChar()); }, [&]() { return toSigned(readChar()); }, [&](auto a, auto b) { return a < b; })) {
}
};
procedure_2(0, 0, 0, 0);
}`)
})
})
15 changes: 15 additions & 0 deletions compiler/cppCodegen.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert } from './assert'
import { consumeNever } from './consumeNever'
import isPure from './isPure'
import { CoqCPAST, ValueType } from './parse'
Expand Down Expand Up @@ -474,6 +475,20 @@ void flushSTDOUT() {
indent +
'std::cin.tie(0)->sync_with_stdio(0);\n' +
mainCode +
(() => {
const mainNumber = procedureNameMap.get('main')
if (mainNumber === undefined) return ''
const definition = procedures.find(({ name }) => name === 'main')
assert(definition !== undefined)
return (
indent +
'procedure_' +
mainNumber +
'(' +
Array(definition.variables.size).fill(0).join(', ') +
');\n'
)
})() +
'}'
)
}
2 changes: 1 addition & 1 deletion compiler/exampleCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ procedure("pointless", { preset: int32 }, () => {
procedure("more", { a: int8, b: int8, c: int8 }, () => {})
procedure("fibonacci", { n: int32, a: int32, b: int32, i: int32 }, () => {
procedure("main", { n: int32, a: int32, b: int32, i: int32 }, () => {
set("n", readChar()); // Reading the term 'n' to which Fibonacci sequence is to be calculated
set("a", 0);
set("b", 1);
Expand Down

0 comments on commit 5724a11

Please sign in to comment.