summaryrefslogtreecommitdiffstats
path: root/llparse-frontend/src/node/invoke.ts
blob: ba6ef53941d1065dff01f51c28ce5769b78c7301 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Code } from '../code';
import { IUniqueName } from '../utils';
import { IWrap } from '../wrap';
import { Node } from './base';
import { Slot } from './slot';

interface IInvokeEdge {
  readonly code: number;
  node: IWrap<Node>;
}

export interface IReadonlyInvokeEdge {
  readonly code: number;
  readonly node: IWrap<Node>;
}

export class Invoke extends Node {
  private readonly privEdges: IInvokeEdge[] = [];

  constructor(id: IUniqueName, public readonly code: IWrap<Code>) {
    super(id);
  }

  public addEdge(code: number, node: IWrap<Node>): void {
    this.privEdges.push({ code, node });
  }

  public get edges(): ReadonlyArray<IReadonlyInvokeEdge> {
    return this.privEdges;
  }

  protected *buildSlots() {
    for (const edge of this.privEdges) {
      yield new Slot(edge.node, (value) => edge.node = value);
    }

    yield* super.buildSlots();
  }
}