Skip to content

Intermediate Representation Specification

mtrberzi edited this page Oct 22, 2014 · 5 revisions

This specification describes the implementation of the intermediate representation in the Manifold core library manifold-core version 0.4.

Abstract Syntax

Basic Objects

A Schematic is an object that contains all information about the intermediate representation of a Manifold design.

A Value is a quantity or object represented within a Schematic.

A String is a Value. The value represented by a String is a sequence of zero or more bytes.

An Int is a Value. The value represented by an Int is an integer.

A Real is a Value. The value represented by a Real is any finite floating-point number.

A TypeValue is a kind of Value that signifies the type of another value. Every TypeValue has at most one supertype, which is also a TypeValue.

TypeTypeValue is a TypeValue.

A TypeAttribute is an object consisting of a String, the attribute name, and a TypeValue, the attribute value.

Schematic Types

A PortTypeValue is a TypeValue. Every PortTypeValue has zero or more TypeAttributes.

A NodeTypeValue is a TypeValue. Every NodeTypeValue has zero or more TypeAttributes and zero or more PortTypes.

A ConnectionTypeValue is a TypeValue. Every ConnectionTypeValue has zero or more TypeAttributes.

A ConstraintTypeValue is a TypeValue. Every ConstraintTypeValue has zero or more TypeAttributes.

A foo Definition is a pair consisting of a String, the defined name, and a foo, the defined type. Any TypeValue object can be substituted for foo.

Every Schematic has zero or more PortTypeValue Definitions, NodeTypeValue Definitions, ConnectionTypeValue Definitions, and ConstraintTypeValue Definitions.

Schematic Objects

An Attribute is a pair consisting of a String, the attribute name, and a Value, the attribute value.

A PortValue is a Value. Every PortValue has zero or more Attributes and a NodeValue which is its parent.

A NodeValue is a Value. Every NodeValue has zero or more Attributes and zero or more pairs consisting of a String, the port name, and a PortValue, the port value.

A ConnectionValue is a Value. Every ConnectionValue has zero or more Attributes. Every ConnectionValue has a PortValue called "from" and a PortValue called "to".

A ConstraintValue is a Value. Every ConstraintValue has zero or more Attributes.

A foo Instance is a pair consisting of a String, the instance name, and a foo, the instance. Any Value that is not a TypeValue can be substituted for foo.

Every Schematic has zero or more NodeValue Instances, ConnectionValue Instances, and ConstraintValue Instances.

Concrete Syntax

A Manifold Schematic is serialized and deserialized to and from JSON.

Basic Objects

A String is equivalent to a JSON string.

An Int is equivalent to a JSON int.

A Real is equivalent to a JSON number.

A Bool is either of the JSON atoms true or false.

A Schematic is a JSON object with the following structure:

{
"name": <string>,
"userDefinedTypes": {[UserDefinedTypeValue] definitions},
"portTypes": {[PortTypeValue definitions]},
"nodeTypes": {[NodeTypeValue definitions]},
"connectionTypes": {[ConnectionTypeValue definitions]},
"constraintTypes": {[ConstraintTypeValue definitions]},
"nodes": {[NodeValue instances]},
"connections": {[ConnectionValue instances]},
"constraints": {[ConstraintValue instances]}
}

where the attributes of each abstract object are name-value pairs whose structure is defined in the following sections.

Type Definitions

A TypeAttribute is a key-value pair of the form "attributeName": "typename", where "attributeName" is the name of the attribute to be defined and "typename" is the name of a type definition.

A TypeAttribute set is a JSON object whose attributes (of which there may be zero or more) are all TypeAttributes. No two attributes in the same TypeAttribute set may have the same attribute name.

A PortTypeValue definition is a JSON object:

"portTypeName": {
  "attributes": [TypeAttribute set]
}

A NodeTypeValue definition is a JSON object:

"nodeTypeName": {
  "attributes": [TypeAttribute set],
  "ports": [PortTypeAttribute set]
}

with the further restriction that each type named in the "ports" type attribute set must be the name of a previously-defined PortTypeValue.

A ConnectionTypeValue definition is a JSON object:

"connectionTypeName": {
  "attributes": [TypeAttribute set]
}

A ConstraintTypeValue definition is a JSON object:

"ConstraintTypeName": {
  "attributes": [TypeAttribute set]
}

Object Instances

An Attribute is a key-value pair of the form "attributeName": attributeValue where attributeValue can be any JSON object.

An Attribute set is a JSON object whose attributes (of which there may be zero or more) are all Attributes. No two attributes in the same Attribute set may have the same attribute name.

A NodeValue instance is a JSON object:

"Node instance name": {
  "type": "NodeTypeValue typename",
  "attributes": [Attribute set],
  "portAttrs": {
    "port name": [Attribute set],
    ...
  }
}

A ConnectionValue instance is a JSON object:

"Connection instance name": {
  "type": "ConnectionTypeValue typename",
  "attributes": [Attribute set],
  "from": [Port descriptor],
  "to": [Port descriptor]
}

where a Port descriptor is a string of the form "Node instance name:Port instance name".

A ConstraintValue instance is a JSON object:

"Constraint instance name": {
  "type": "ConstraintTypeValue typename",
  "attributes": [Attribute set]
}

Semantics

The supertype of a TypeValue is TypeTypeValue if not specified. TypeTypeValue does not have a supertype.

Every TypeValue has all the TypeAttributes of its supertype, if any, and if it is a NodeTypeValue, all the PortAttributes of its supertype, if any.

Every instance of a given NodeTypeValue must define an attribute set for all ports that are members of that type, even if a given port has zero attributes.