Skip to content

Commit

Permalink
fix: use chunkedFunction to break up initLookups into smaller functio…
Browse files Browse the repository at this point in the history
…ns (#133)

Fixes #132
  • Loading branch information
ToddFincannon authored Oct 14, 2021
1 parent 2fdfb34 commit bad4580
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/CodeGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,37 @@ ${section(Model.dataVars())}
//
function emitInitLookupsCode() {
mode = 'init-lookups'
return `// Internal state
let code = `// Internal state
bool lookups_initialized = false;
void initLookups() {
// Initialize lookups.
bool data_initialized = false;
`
code += chunkedFunctions(
'initLookups',
Model.lookupVars(),
` // Initialize lookups.
if (!lookups_initialized) {
${section(Model.lookupVars())}
${section(Model.dataVars())}
lookups_initialized = true;
`,
` lookups_initialized = true;
}
}
`
)
code += chunkedFunctions(
'initData',
Model.dataVars(),
` // Initialize data.
if (!data_initialized) {
`,
` data_initialized = true;
}
`
)
return code
}

function emitInitConstantsCode() {
mode = 'init-constants'
return `
${chunkedFunctions('initConstants', Model.constVars(), ' // Initialize constants.', ' initLookups();')}
${chunkedFunctions('initConstants', Model.constVars(), ' // Initialize constants.', ' initLookups();\n initData();')}
`
}

Expand Down

0 comments on commit bad4580

Please sign in to comment.