Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { CodeGenCtx } from "./CodeGenCtx";
- import { NodesSystem } from "./systems/NodesSystem";
- export function generateCode(params: {
- nodesSystem: NodesSystem,
- }): string {
- let nodesSystem = params.nodesSystem;
- let entityIdOutputAtomsMap = new Map<
- string,
- {
- outputAtoms: Map<string,string>,
- }[]
- >();
- let codeGenCtx = new CodeGenCtx();
- let stack1 = [ ...nodesSystem.nodes(), ];
- let stack2: typeof stack1 = [];
- while (true) {
- let at = stack1.pop();
- if (at == undefined) {
- let tmp = stack1;
- stack1 = stack2;
- stack2 = tmp;
- at = stack2.pop();
- if (at == undefined) {
- break;
- }
- }
- let hasStaleChildren = false;
- for (let source of at.node.inputPins?.() ?? []) {
- let source2 = source.source()?.target;
- if (source2 == undefined) {
- continue;
- }
- if (!entityIdOutputAtomsMap.has(source2)) {
- let node = nodesSystem.lookupNodeById(source2);
- if (node != undefined) {
- stack1.push(node);
- hasStaleChildren = true;
- }
- }
- }
- if (hasStaleChildren) {
- stack2.push(at);
- } else {
- // TODO
- let sourceEntityPinInputMap = new Map<string,Map<string,string[]>>();
- for (let source of at.node.inputPins?.() ?? []) {
- let source2 = source.source();
- if (source2 != undefined) {
- let sourceEntity = source2.target;
- let pinInputMap: Map<string,string[]>;
- if (sourceEntityPinInputMap.has(sourceEntity)) {
- pinInputMap = sourceEntityPinInputMap.get(sourceEntity)!;
- } else {
- pinInputMap = new Map<string,string[]>();
- sourceEntityPinInputMap.set(sourceEntity, pinInputMap);
- }
- let outputAtoms = entityIdOutputAtomsMap.get(source2.target) ?? [];
- pinInputMap.set(
- source.name,
- outputAtoms.flatMap((outputAtoms2) => {
- let x = outputAtoms2.outputAtoms.get(source2.pin);
- if (x == undefined) {
- return [];
- }
- return [x];
- })
- );
- }
- }
- }
- }
- return codeGenCtx.code;
- }
Advertisement
Add Comment
Please, Sign In to add comment