ArnaudBuchholz / psbots

A project about a PostScript based programming language for robots
MIT License
0 stars 0 forks source link

Operators description #2

Open ArnaudBuchholz opened 1 month ago

ArnaudBuchholz commented 1 month ago
[{
  "operator": "add",
  "description": "adds two integers",
  "labels": ["math", "number"],
  "signature": {
    "input": ["integer", "integer"],
    "output": ["integer"],
    "exceptions.comment": "TypeCheck and StackUnderflow are implicit",
    "exceptions": [],
  },
  "samples": [{
    "description": "Simple use case"
    "in": "1 2 add",
    "out": "3"
  }]
}, {
  "operator": "aload",
  "description": "dumps the content of the array on the operand stack",
  "labels": ["array", "load"],
  "signature": {
    "input": ["array"],
    "output": ["...any"],
    "exceptions": []
  },
  "samples": [{
    "description": "all the elements of an array",
    "in": "[1 2 3] aload",
    "out": "1 2 3"
  }, {
    "description": "all the elements of a block",
    "in": "{1 2 3} aload",
    "out": "1 2 3"
  }, {
    "description": "all the elements of a block (with calls)",
    "in": "{1 2 add} aload",
    "out.description": "How to distinguish things that must be evaluated from things that should not",
    "out": "1 2 add"
  }]
}, {
  "operator": "where",
  "description": "detect if the name is defined in the dictionary stack and, if found, returns the corresponding dictionary and true",
  "labels": ["dictionary stack"],
  "signature": {
    "input": ["string"],
    "output": {
      "name is found": ["dictionary", "boolean:true"]
      "name is unknown": ["boolean:false"]
    },
    "exceptions": [],
    "samples": []
  }
}]
ArnaudBuchholz commented 1 month ago

This will help generating :

ArnaudBuchholz commented 1 month ago
ArnaudBuchholz commented 1 month ago
{
    "type": "object",
    "properties": {
        "operator": {
            "type": "string"
        },
        "description": {
            "type": "string"
        },
        "labels": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "signature": {
            "type": "object",
            "properties": {
                "input": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "output": {
                    "oneOf": [
                        {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        },
                        {
                            "type": "object",
                            "properties": {}
                        }
                    ]
                }
            }
        }
    },
    "title": "schema"
}