This document specifies the JSON format used for ObjectIR module serialization, which is consumed by the ObjectIR runtime (OJRuntime) and produced by various ObjectIR compilers including the Fortran compiler.
ObjectIR modules are serialized as JSON objects containing metadata, type definitions, and executable instructions. This format enables:
- Execution: Runtime loading and execution of compiled modules
- Inspection: Analysis and debugging of module contents
- Interoperability: Exchange of modules between different ObjectIR implementations
- Persistence: Storage and retrieval of compiled code
{
"Name": "string",
"Version": "string",
"Metadata": {
"additionalProperties": "string"
},
"Types": [
// Array of type definitions
],
"Functions": [
// Array of global function definitions (optional)
]
}- Name (string): Module name identifier
- Version (string): Module version in semantic versioning format (e.g., "1.0.0")
- Metadata (object): Optional key-value metadata pairs
- Types (array): Array of type definitions (classes, interfaces, structs, enums)
- Functions (array): Array of global function definitions (may be empty)
{
"Kind": "Class" | "Interface" | "Struct" | "Enum",
"Name": "string",
"Namespace": "string",
"Access": "Public" | "Private" | "Protected" | "Internal",
"IsAbstract": boolean,
"IsSealed": boolean,
"BaseType": "string" | null,
"Interfaces": ["string"],
"BaseInterfaces": ["string"],
"GenericParameters": ["string"],
"Fields": [
// Field definitions
],
"Methods": [
// Method definitions
],
"Properties": [
// Property definitions
]
}- Class: Reference type with fields and methods
- Interface: Contract defining method signatures
- Struct: Value type with fields
- Enum: Enumeration of named constants
BaseTypespecifies the base class (null for interfaces and object)Interfaceslists implemented interfacesBaseInterfaceslists base interfaces (for interfaces only)
{
"Name": "string",
"Type": "string",
"Access": "Public" | "Private" | "Protected" | "Internal",
"IsStatic": boolean,
"IsReadOnly": boolean
}{
"Name": "string",
"ReturnType": "string",
"Parameters": [
{
"Name": "string",
"Type": "string"
}
],
"LocalVariables": [
{
"Name": "string",
"Type": "string"
}
],
"InstructionCount": number,
"Instructions": [
// Instruction objects
]
}Global functions are similar to static methods but defined at the module level rather than within a type.
{
"Name": "string",
"Type": "string",
"Access": "Public" | "Private" | "Protected" | "Internal",
"IsStatic": boolean,
"HasGetter": boolean,
"HasSetter": boolean
}{
"Name": "string",
"ReturnType": "string",
"Access": "Public" | "Private" | "Protected" | "Internal",
"IsStatic": boolean,
"IsVirtual": boolean,
"IsOverride": boolean,
"IsAbstract": boolean,
"IsConstructor": boolean,
"Parameters": [
{
"Name": "string",
"Type": "string"
}
],
"LocalVariables": [
{
"Name": "string",
"Type": "string"
}
],
"InstructionCount": number,
"Instructions": [
// Instruction objects
]
}Instructions are represented as objects with an opCode and optional operand:
{
"opCode": "string",
"operand": object | null
}{
"opCode": "ldarg",
"operand": {
"argumentName": "string"
}
}{
"opCode": "ldloc",
"operand": {
"localName": "string"
}
}{
"opCode": "ldc",
"operand": {
"value": "string",
"type": "string"
}
}{
"opCode": "ldfld",
"operand": {
"field": {
"declaringType": "string",
"name": "string",
"type": "string"
}
}
}{
"opCode": "ldsfld",
"operand": {
"field": {
"declaringType": "string",
"name": "string",
"type": "string"
}
}
}{
"opCode": "ldnull"
}{
"opCode": "starg",
"operand": {
"argumentName": "string"
}
}{
"opCode": "stloc",
"operand": {
"localName": "string"
}
}{
"opCode": "stfld",
"operand": {
"field": {
"declaringType": "string",
"name": "string",
"type": "string"
}
}
}{
"opCode": "stsfld",
"operand": {
"field": {
"declaringType": "string",
"name": "string",
"type": "string"
}
}
}{
"opCode": "add"
}{
"opCode": "sub"
}{
"opCode": "mul"
}{
"opCode": "div"
}{
"opCode": "rem"
}{
"opCode": "ceq"
}{
"opCode": "cne"
}{
"opCode": "cgt"
}{
"opCode": "cge"
}{
"opCode": "clt"
}{
"opCode": "cle"
}{
"opCode": "call",
"operand": {
"method": {
"declaringType": "string",
"name": "string",
"returnType": "string",
"parameterTypes": ["string"]
}
}
}{
"opCode": "callvirt",
"operand": {
"method": {
"declaringType": "string",
"name": "string",
"returnType": "string",
"parameterTypes": ["string"]
}
}
}{
"opCode": "newobj",
"operand": {
"type": "string"
}
}{
"opCode": "newarr",
"operand": {
"elementType": "string"
}
}{
"opCode": "cast",
"operand": {
"targetType": "string"
}
}{
"opCode": "dup"
}{
"opCode": "pop"
}{
"opCode": "neg"
}{
"opCode": "not"
}{
"opCode": "ldelem"
}{
"opCode": "stelem"
}{
"opCode": "ret"
}{
"opCode": "if",
"operand": {
"thenBlock": [
// Instruction array
],
"elseBlock": [
// Instruction array (optional)
]
}
}{
"opCode": "while",
"operand": {
"condition": "string", // Simplified for spec
"body": [
// Instruction array
]
}
}{
"opCode": "try",
"operand": {
"tryBlock": [
// Instruction array
],
"catchClauses": [
{
"exceptionType": "string" | null,
"body": [
// Instruction array
]
}
],
"finallyBlock": [
// Instruction array (optional)
]
}
}{
"opCode": "throw"
}void- No valuebool- Boolean valuechar- Unicode characterint8- 8-bit signed integerint16- 16-bit signed integerint32- 32-bit signed integerint64- 64-bit signed integeruint8- 8-bit unsigned integeruint16- 16-bit unsigned integeruint32- 32-bit unsigned integeruint64- 64-bit unsigned integerfloat32- 32-bit floating pointfloat64- 64-bit floating point
System.string- String typeSystem.object- Base object type- Arrays:
TypeName[](e.g.,System.string[]) - User-defined types:
Namespace.TypeName
{
"Name": "HelloWorld",
"Version": "1.0.0",
"Metadata": {},
"Types": [
{
"Kind": "Class",
"Name": "Program",
"Namespace": "HelloWorld",
"Access": "Public",
"IsAbstract": false,
"IsSealed": false,
"Interfaces": [],
"GenericParameters": [],
"Fields": [],
"Methods": [
{
"Name": "Main",
"ReturnType": "void",
"Access": "Public",
"IsStatic": true,
"IsVirtual": false,
"IsOverride": false,
"IsAbstract": false,
"IsConstructor": false,
"Parameters": [],
"LocalVariables": [],
"InstructionCount": 1,
"Instructions": [
{
"opCode": "ret"
}
]
}
],
"Properties": []
}
]
}{
"Name": "Calculator",
"Version": "1.0.0",
"Metadata": {},
"Types": [
{
"Kind": "Class",
"Name": "Calculator",
"Namespace": "Calculator",
"Access": "Public",
"IsAbstract": false,
"IsSealed": false,
"Interfaces": [],
"GenericParameters": [],
"Fields": [],
"Methods": [
{
"Name": "Add",
"ReturnType": "int32",
"Access": "Public",
"IsStatic": true,
"IsVirtual": false,
"IsOverride": false,
"IsAbstract": false,
"IsConstructor": false,
"Parameters": [
{
"Name": "a",
"Type": "int32"
},
{
"Name": "b",
"Type": "int32"
}
],
"LocalVariables": [
{
"Name": "result",
"Type": "int32"
}
],
"InstructionCount": 4,
"Instructions": [
{
"opCode": "ldarg",
"operand": {
"argumentName": "a"
}
},
{
"opCode": "ldarg",
"operand": {
"argumentName": "b"
}
},
{
"opCode": "add"
},
{
"opCode": "ret"
}
]
}
],
"Properties": []
}
]
}The ObjectIR runtime (OJRuntime) loads and executes modules in this JSON format. The runtime:
- Parses the JSON structure
- Validates the schema compliance
- Loads types and methods into memory
- Executes instructions in method bodies
- Manages the evaluation stack and local variables
Invalid JSON or unsupported constructs will cause runtime errors. Ensure all referenced types and methods are properly defined or available in the runtime environment.
- All string values are case-sensitive
- Type names should be fully qualified (e.g.,
System.stringnotstring) - Array types are denoted with
[]suffix - Generic types use angle brackets:
List<int32> - Null values are represented as JSON
null - Boolean values are lowercase
true/false - Numeric values in constants are stored as strings to preserve precision
JSON modules should be validated against this schema before execution. The runtime will reject malformed modules with appropriate error messages.
- v1.0.0: Initial specification covering basic types, methods, and instructions
- Future versions may add support for additional instruction types, type constructs, and metadata fields d:\ObjectIR\docs\OBJECTIR_JSON_SPEC.md