Skip to content

Commit 5e6be8d

Browse files
(feature) Add support for thunked ifs.
1 parent 18d3b54 commit 5e6be8d

File tree

14 files changed

+82
-24
lines changed

14 files changed

+82
-24
lines changed

.vscode/launch.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
},
2323
{
2424
"name": "Debug",
25-
"type": "node2",
25+
"type": "node",
2626
"request": "launch",
27+
"protocol": "inspector",
2728
"program": "${workspaceRoot}/.vscode/debug.js",
2829
"cwd": "${workspaceRoot}",
29-
"args": ["print.json", "-l", "languages/c", "-l", "languages/c-like"],
30+
"args": ["if.json", "-l", "languages/c-edge-debugger", "-l", "languages/c", "-l", "languages/c-like"],
3031
"env": {
3132
"NODE_ENV": "development"
3233
},

languages/c-edge-debugger/templates/activation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ module.exports = {
22
EdgeDebugger: {
33
activation: (context) => {
44
// only handle edges
5-
if (Graph.Edge.isValid(context.data)) {
5+
if (context.template === 'Compound.defineEdges') {
66
// does not yet work with edge selection
7-
return !context.options.selectEdge
7+
return true
8+
// return typeof (context.data.type) === 'string'
9+
// return !context.options || !context.options.selectEdge
810
}
11+
return true
912
}
1013
}
1114
}

languages/c-edge-debugger/templates/compound.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ module.exports = {
22
Compound: {
33
defineEdges: (node) => {
44
const edges = Graph.edges(node)
5-
return edges.map((e) => ` debug_shared_ptr<${t('Edge.type')(e)}> ${t('Edge.name')(e)};`).join('\n')
5+
return edges.map((e) => {
6+
if (typeof (e.type) === 'string') {
7+
return ` debug_shared_ptr<${t('Edge.type')(e)}> ${t('Edge.name')(e)};`
8+
} else return ` std::shared_ptr<${t('Edge.type')(e)}> ${t('Edge.name')(e)};`
9+
}).join('\n')
610
}
711
}
812
}

languages/c-edge-debugger/templates/main.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = {
2-
prefix: (graph) => {
3-
const structs = Graph.components(graph).filter(Types.isType).filter(Types.isConstructor)
4-
return `${t('base')()}
5-
2+
defineTypes: (graph) => {
3+
// const structs = Graph.components(graph).filter(Types.isType).filter(Types.isConstructor)
4+
return `
65
template <typename T>
76
class debug_shared_ptr : public std::shared_ptr<T> {
87
public:
@@ -11,12 +10,14 @@ public:
1110
debug_shared_ptr(const std::shared_ptr<T>& other);
1211
};
1312
13+
${t('base')()}
14+
15+
` },
1416

15-
${['String', 'IO'].map(t('defineSpecialization')).join('\n')}
16-
${structs.map(Types.structureData).map((s) => s.name).map(t('defineSpecialization')).join('\n')}
17-
`},
17+
// ${structs.map(Types.structureData).map((s) => s.name).map(t('defineSpecialization')).join('\n')}
18+
// ${['String', 'IO'].map(t('defineSpecialization')).join('\n')}
1819

19-
defineSpecialization: (typeName) => `
20+
defineSpecialization: (typeName) => `
2021
template <>
2122
debug_shared_ptr<${typeName}>::debug_shared_ptr(const std::shared_ptr<${typeName}>& other) : std::shared_ptr<${typeName}>(other) {
2223
std::cout << "Copy: " << ${t('Types.toStringName')(typeName)}(*other) << std::endl;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
Types: {
3+
definition: (typeName) => {
4+
return `${t('base')(typeName)}
5+
6+
${t('defineSpecialization')(typeName)}
7+
8+
`
9+
}
10+
}
11+
}

languages/c-like/templates/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
${t('prefix')(graph)}
99
1010
// atomics
11-
${uniqBy(componentName, atomics).map(t('Process.definition')).join('\n')}
11+
${uniqBy(t('Component.name'), atomics).map(t('Process.definition')).join('\n')}
1212
1313
// compounds...
1414
${compounds.map(t('Compound.definition')).join('\n')}

languages/c/atomics/basic.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@ module.exports = {
77
numToStr: (node) => `
88
${variable('outStr')} = std::shared_ptr<String>(new String(${t('Types.toStringName')('Number')}(*${variable('inNumber')})));
99
`,
10+
11+
ifThunk: (node) => `
12+
if (${variable('condition')}->value) {
13+
(*${variable('inTrue')})(${variable('choice')});
14+
} else {
15+
(*${variable('inFalse')})(${variable('choice')});
16+
}
17+
`
1018
}

languages/c/atomics/math.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ module.exports = {
22
'math/add': (node) => `
33
${variable('sum')} = std::shared_ptr<Number>(new Number(${variable('summand1')}->value + ${variable('summand2')}->value));
44
`,
5+
6+
'math/less': (node) => `
7+
${variable('isLess')} = std::shared_ptr<Bool>(new Bool(${variable('lesser')}->value < ${variable('bigger')}->value));
8+
`
59
}

languages/c/templates/component.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
Component: {
3+
name: (node) => {
4+
if (node.componentId === 'functional/lambda') {
5+
return t('base')(node) + sanitize(Node.id(Graph.Lambda.implementation(node)))
6+
} else {
7+
return t('base')(node)
8+
}
9+
}
10+
}
11+
}

languages/c/templates/compound.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ${t('Compound.assignInputs')(node)}
2727
assignInputs: (node) => {
2828
const inputPorts = Node.inputPorts(node).map((port) =>
2929
({port, edges: Graph.outIncidents(port, graph)}))
30-
return `${inputPorts.map((p) => p.edges.map((e) => ' ' + t('Compound.edgeAssign')(e)(`input_${p.port.port}`))).join('\n')}`
30+
return `${inputPorts.map((p) => p.edges.map((e) => ' ' + t('Compound.edgeAssign')(e)(`input_${sanitize(p.port.port)}`))).join('\n')}`
3131
},
3232

3333
edgeAssign: (edge) => (variable) => `${t('Edge.name')(edge)} = ${variable};`,
@@ -47,7 +47,7 @@ ${t('Compound.postfix')(node)}`
4747
const outputArguments = Node.outputPorts(node).map(t('Port.variable'))
4848
const functionArguments = inputArguments.concat(outputArguments).join(', ')
4949

50-
const functionCall = `P_${componentName(node)}(${functionArguments});`
50+
const functionCall = `P_${t('Component.name')(node)}(${functionArguments});`
5151

5252
const edgeAssignments = Graph.outIncidents(node, graph).map((edge) =>
5353
` ${t('Edge.name')(edge)} = ${t('Port.variable')(edge.from)};`).join('\n')
@@ -61,7 +61,7 @@ ${edgeAssignments}
6161

6262
postfix: (node) => {
6363
return Node.outputPorts(node).map((p) =>
64-
` output_${p.port} = ${t('Edge.name')(Graph.inIncident(p, graph))};`).join('\n')
64+
` output_${sanitize(p.port)} = ${t('Edge.name')(Graph.inIncident(p, graph))};`).join('\n')
6565
},
6666
},
6767
}

0 commit comments

Comments
 (0)