← All procedures

program.compile

Compile a program to a JavaScript function that makes the same calls in the same order

MCPCLI
Package
@procedures/compiler · README
Path
["program","compile"]
CLI
mark program compile --program <any>
MCP tool
program.compile on the dev-tools server
As data
{"$proc":["program","compile"],"input":{}}
Tags
compiler, raw-input

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/compiler/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["program","compile"], { program: "<program>" });
console.log(JSON.stringify(result));

From the command line

$ mark program compile --program <any>

As data, in a program

{ "$proc": ["program", "compile"], "input": { "program": "<program>" } }

Input

FieldTypeRequiredDefaultDescription
programanyyesThe program: a call ({ $proc, input }). The procedure reads it as data: nothing in it starts.
capabilityobjectnoThe capability of the run. Absent: the capability of the caller.
mode"exec" | "body"noexec (the default): the program runs as client.exec runs it. body: as the body of a defined procedure, with input in scope.
foldbooleannoTrue: compute the pure core calls with literal inputs now
language"js" | "ts"noThe language of the code: js (the default) or ts

Output

FieldTypeRequiredDefaultDescription
okbooleanyesTrue when no diagnostic is an error: then the host can start the program
effectsobjectyesThe effects that a run can have (the upper bound)
mustEffectsobjectyesThe effects of each run in which no call fails (the lower bound)
diagnosticsobject[]yesThe problems, in the order of the program
registryHashstringyesThe hash of the manifest that the check used
codestringyesThe ES module: its default export is async (ctx, input) => output
sourceMapobject[]yesThe lines of the code that start a part of the program
foldedstring[]yesThe pointers of the calls that the fold pass computed
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "program": {
        "description": "The program: a call ({ $proc, input }). The procedure reads it as data: nothing in it starts."
      },
      "capability": {
        "type": "object",
        "properties": {
          "clearance": {
            "description": "The clearance of the run"
          },
          "effects": {
            "description": "The effects that the calls can have. Absent: all effects.",
            "type": "object",
            "properties": {
              "reads": {
                "description": "The resources that a call can read: names, or \"any\"",
                "anyOf": [
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  {
                    "type": "string",
                    "const": "any"
                  }
                ]
              },
              "writes": {
                "description": "The resources that a call can change: names, or \"any\". An empty list: no change.",
                "anyOf": [
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  {
                    "type": "string",
                    "const": "any"
                  }
                ]
              },
              "destructive": {
                "description": "False: a call cannot start a destructive procedure",
                "type": "boolean"
              }
            }
          },
          "deadline": {
            "description": "The deadline (the static check does not use it)",
            "type": "number"
          }
        },
        "description": "The capability of the run. Absent: the capability of the caller."
      },
      "mode": {
        "description": "exec (the default): the program runs as client.exec runs it. body: as the body of a defined procedure, with input in scope.",
        "type": "string",
        "enum": [
          "exec",
          "body"
        ]
      },
      "fold": {
        "description": "True: compute the pure core calls with literal inputs now",
        "type": "boolean"
      },
      "language": {
        "description": "The language of the code: js (the default) or ts",
        "type": "string",
        "enum": [
          "js",
          "ts"
        ]
      }
    },
    "required": [
      "program"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "ok": {
        "type": "boolean",
        "description": "True when no diagnostic is an error: then the host can start the program"
      },
      "effects": {
        "type": "object",
        "properties": {
          "reads": {
            "description": "The resources that a run can read. Absent: not known.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "writes": {
            "description": "The resources that a run can change. Absent: not known.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "destructive": {
            "description": "True: a call can delete or overwrite data",
            "type": "boolean"
          },
          "idempotent": {
            "description": "True: each call that changes data is idempotent",
            "type": "boolean"
          }
        },
        "additionalProperties": false,
        "description": "The effects that a run can have (the upper bound)"
      },
      "mustEffects": {
        "type": "object",
        "properties": {
          "reads": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The resources that each run reads"
          },
          "writes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The resources that each run changes"
          }
        },
        "required": [
          "reads",
          "writes"
        ],
        "additionalProperties": false,
        "description": "The effects of each run in which no call fails (the lower bound)"
      },
      "diagnostics": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "severity": {
              "type": "string",
              "enum": [
                "error",
                "warning",
                "info"
              ],
              "description": "An error stops the program"
            },
            "code": {
              "type": "string",
              "description": "The code of the problem, for example unknown-name"
            },
            "message": {
              "type": "string",
              "description": "The text of the problem"
            },
            "pointer": {
              "type": "string",
              "description": "The JSON pointer of the part of the program"
            }
          },
          "required": [
            "severity",
            "code",
            "message",
            "pointer"
          ],
          "additionalProperties": false
        },
        "description": "The problems, in the order of the program"
      },
      "registryHash": {
        "type": "string",
        "description": "The hash of the manifest that the check used"
      },
      "code": {
        "type": "string",
        "description": "The ES module: its default export is async (ctx, input) => output"
      },
      "sourceMap": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "line": {
              "type": "number",
              "description": "The line of the code, from 1"
            },
            "pointer": {
              "type": "string",
              "description": "The JSON pointer of the part of the program"
            }
          },
          "required": [
            "line",
            "pointer"
          ],
          "additionalProperties": false
        },
        "description": "The lines of the code that start a part of the program"
      },
      "folded": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "The pointers of the calls that the fold pass computed"
      }
    },
    "required": [
      "ok",
      "effects",
      "mustEffects",
      "diagnostics",
      "registryHash",
      "code",
      "sourceMap",
      "folded"
    ],
    "additionalProperties": false
  }
}