@hlang-tech /红外
hlang中间表示。 IGraph 是hlang程序的JSON形式。 planGraph 验证图形并将其降低为执行计划。解释器和编译器都从这个计划开始,所以它们应用相同的规则。
安装
npm install @hlang-tech/ir
相同的构建发布为 @hlang-org/ir。没有运行时依赖项。ESM和CommonJS的构建带有类型声明。
IGraph
import type { IGraph } from '@hlang-tech/ir';
const graph: IGraph = {
nodeList: [
{ nodeId: 'a', code: 'numbers', name: 'Numbers', type: 'R', bizData: { params: { count: 3 } } },
{ nodeId: 'b', code: 'log', name: 'Log', type: 'W' },
],
connections: [
{ Output: { nodeId: 'a', portConf: { id: 'out' } }, Input: { nodeId: 'b', portConf: { id: 'in' } } },
],
};
type为节点类型:'R'(读),'T'(变换),或'W'(可写)。code选择节点实现。后端将其映射到类或模块。bizData传递给节点构造函数为config;参数在bizData.params.- 在某种意义上,
Output上行输出端口和Input是下行输入端口。丢失的端口号默认为Output和Input。传统拼写portConfig.id也是读的。
planGraph
import { planGraph, GraphError } from '@hlang-tech/ir';
const plan = planGraph(graph);
// {
// nodes: [{ nodeId: 'a', code: 'numbers', kind: 'R', config: { params: { count: 3 } } }, ...],
// connections: [{ source: { nodeId: 'a', portId: 'out' }, target: { nodeId: 'b', portId: 'in' } }],
// roots: ['a'],
// }
平面图保持图形顺序。 config 是一份 bizData 与 params 默认 {}.
planGraph 抛出一个 GraphError 用下列代码之一:
code | 导致 |
|---|---|
duplicate-node-id | 两个节点共用一个 nodeId. |
invalid-node-kind | 一个节点 type 不是 R, T,或者 W. |
unknown-node | 连接引用不在中的节点 nodeList. |
invalid-connection | 可写节点是源,可读节点是目标,或 @node/error 是一个目标。 |
no-readable-root | 图没有可读节点可运行。 |
转换到转换循环是有效的。
出口
- 类型:
IGraph,INodeInfo,IConnection,IConnectionEndpoint,IBizData,IPortInfo,IPackageInfo,ParamBag,ParamValue,IParamObject,NodeKind,ExecutionPlan,PlannedNode,PlannedConnection,PlannedEndpoint,GraphErrorCode. - 价值观:
planGraph,GraphError,ERROR_PORT_NAME('@node/error')。
来源和文件: github.com/hlang-tech/hlang.
许可证
麻省理工学院