omega-mcp
aien-dev/omega-mcp
Brought by drakestapleton
GitHub aien-dev/omega-mcp#5 (code only)
Apply it
git checkout -b patch-39d0e97f46959439 07f4246dac7b684c9ae7ac57b8d8879979151ed6 curl -fsSL https://interplane.io/drakestapleton/omega-mcp/patches/39d0e97f46959439.patch | git am
Provenance
github-import 1
aien-dev/omega-mcp
5
d28de887a592517cc3a698c04a8b6c561e17a99f
{"kind":"github-import","owner":"aien-dev","repo":"omega-mcp","number":5,"url":"https://github.com/aien-dev/omega-mcp/pull/5","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:47Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/data/examples/for_guard.om b/data/examples/for_guard.om new file mode 100644 index 0000000..c6e66b0 --- /dev/null +++ b/data/examples/for_guard.om @@ -0,0 +1,12 @@ +note a for with a number count is unguarded; any other count traps 4 after 1000000 passes +fn main to int +s = ulong 0 +for i ulong 2000000 +s = add s 1 +end +k = ulong 1000001 +for j ulong k +s = add s 1 +end +ret int sub s 3000001 +end diff --git a/data/reference.json b/data/reference.json index f23225a..df8c1be 100644 --- a/data/reference.json +++ b/data/reference.json @@ -74,7 +74,7 @@ { "name": "lookup", "title": "Look up an Omega word or topic", - "description": "Look up any Omega keyword (all 177 entries of the compiler's keyword table) or a topic (requires, ensures, invariant, result, om2, exit_status, packed_list, paths, host_words, compile_errors, traps, contracts): form, arity, types, result, example and citations. A query that is not an exact keyword or topic searches names and summaries (at most 20 results).", + "description": "Look up any Omega keyword (all 177 entries of the compiler's keyword table) or a topic (requires, ensures, invariant, result, om2, exit_status, packed_list, paths, host_words, compile_errors, traps, loops, contracts): form, arity, types, result, example and citations. A query that is not an exact keyword or topic searches names and summaries (at most 20 results).", "inputSchema": { "type": "object", "properties": { @@ -788,13 +788,17 @@ "4": { "name": "LOOP_BOUND", "meaning": "loop exceeded its bound", - "cause": "A while ran more than its bound (default 1000000) iterations.", - "fix": "Fix the loop condition or raise bound N (at most 999999).", + "cause": "A while ran more than its bound (default 1000000) iterations, or a for whose count is not a number ran 1000000 passes.", + "fix": "Fix the loop condition, raise a while's bound N (at most 999999), or for more passes use a number count or nest two loops.", "citations": [ { "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:58", "quote": "past N iterations: trap 4" }, + { + "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:60", + "quote": "(any other count: trap 4 after 1000000 passes, as a while with no bound)" + }, { "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:406", "quote": "A trap in program mode ends the program with exit status 100 + the trap code" @@ -4304,7 +4308,8 @@ "quote": "`len A` is A's length as a ulong." } ], - "example": "hello" + "example": "hello", + "notes": "At the pin (omega-mv e5b32567) the count of an empty text (`text e \"\"`) is read from a stale register (omega-mv #775): `len e` returns whatever that register holds (`ret int add 7 len e` exits 14), and get, part and write check against the same stale count, so they can use bytes past the text instead of trapping 3. Fixed in omega-mv #904 (e2662fff): the count is 0. At this pin, avoid empty texts." }, "read": { "table": "kw", @@ -4611,7 +4616,7 @@ "N: integer literal or constant 1..999999" ], "result": "-", - "summary": "Iteration limit of a while loop; exceeding it traps 4.", + "summary": "Iteration limit of a while loop; exceeding it traps 4. A for takes no bound at this pin (error 5).", "citations": [ { "ref": "omega-mv@e5b32567 seed/omc/omc.om:1066-1067", @@ -4637,7 +4642,7 @@ "COUNT: number or value of TYPE" ], "result": "-", - "summary": "Counted loop: NAME = 0 .. COUNT-1.", + "summary": "Counted loop: NAME = 0 .. COUNT-1. A number COUNT runs unguarded; any other COUNT traps 4 after 1000000 passes, as a while with no bound.", "citations": [ { "ref": "omega-mv@e5b32567 seed/omc/omc.om:1069-1070", @@ -4646,9 +4651,14 @@ { "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:59", "quote": "for <name> <type> <count> / end" + }, + { + "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:60", + "quote": "(any other count: trap 4 after 1000000 passes, as a while with no bound)" } ], - "example": "control" + "example": "for_guard", + "notes": "At the pin no bound gives a loop more than 1000000 passes: `for ... bound N` is error 5 (it came with omega-mv #857, 3a163bc5) and a while bound is at most 999999. For more passes use a number count, which is unguarded, or nest two loops." }, "ret": { "table": "kw", @@ -4818,7 +4828,8 @@ "quote": "`text NAME \"bytes\"`: a read-only array of uchar" } ], - "example": "hello" + "example": "hello", + "notes": "At the pin (omega-mv e5b32567) the count of an empty text (`text e \"\"`) is read from a stale register (omega-mv #775): `len e` returns whatever that register holds (`ret int add 7 len e` exits 14), and get, part and write check against the same stale count, so they can use bytes past the text instead of trapping 3. Fixed in omega-mv #904 (e2662fff): the count is 0. At this pin, avoid empty texts." }, "put": { "table": "kw", @@ -5935,15 +5946,39 @@ }, "traps": { "summary": "Run-time traps 1..14 end a program with exit 100 + code.", - "details": "Codes are part of the observable semantics and are never renumbered.", + "details": "Codes are part of the observable semantics and are never renumbered. Loops trap 4: a while past its bound (default 1000000) and a for whose count is not a number after 1000000 passes.", "citations": [ { "ref": "omega-mv@e5b32567 src/compiler/osc_ir.h:165-166", "quote": "Trap codes are part of the observable semantics" + }, + { + "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:58", + "quote": "N 1..999999, default 1000000; past N iterations: trap 4" + }, + { + "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:60", + "quote": "(any other count: trap 4 after 1000000 passes, as a while with no bound)" } ], "example": "t02" }, + "loops": { + "form": "while COND [bound N] / end | for NAME TYPE COUNT [unroll] / end", + "summary": "Every loop except a for with a number count traps 4 (exit 104) past a pass limit.", + "details": "A while runs at most N passes (bound N, 1..999999; default 1000000). A for with a number COUNT is unguarded; any other COUNT traps 4 after 1000000 passes. At this pin a for takes no bound (error 5).", + "citations": [ + { + "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:58", + "quote": "N 1..999999, default 1000000; past N iterations: trap 4" + }, + { + "ref": "omega-mv@e5b32567 docs/one_layer/OMEGESE.md:60", + "quote": "(any other count: trap 4 after 1000000 passes, as a while with no bound)" + } + ], + "example": "for_guard" + }, "contracts": { "summary": "OM-2 contracts: requires, ensures and invariant clauses checked at run time (traps 9 and 10).", "details": "Compiler error 30 covers misplaced contracts, unavailable result and impure predicates.", @@ -5974,6 +6009,10 @@ "mode": "run", "exit": 131 }, + "for_guard": { + "mode": "trap", + "trap": 4 + }, "arrays": { "mode": "run", "exit": 10 diff --git a/evidence/smoke-transcript.jsonl b/evidence/smoke-transcript.jsonl index 8bc8edb..1649f47 100644 --- a/evidence/smoke-transcript.jsonl +++ b/evidence/smoke-transcript.jsonl @@ -2,7 +2,7 @@ {"dir": "server->client", "line": "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"protocolVersion\":\"2025-06-18\",\"capabilities\":{\"tools\":{\"listChanged\":false}},\"serverInfo\":{\"name\":\"omega-mcp\",\"version\":\"0.1.0\"},\"instructions\":\"Compile and run Omega (.om) programs with the pinned seeded compiler omc (omega-mv e5b32567, omc sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f). Tools: compile, run (each call gets a fresh sandbox: no network, no host files, cleared environment, cpu/memory/file-size/process limits and a wall clock), explain_error (compiler error 1..30, an `omc: line N: error K` line, or a trap exit 101..114) and lookup (every keyword of the compiler's keyword table, with citations into omega-mv@e5b32567).\"}}"} {"dir": "client->server", "line": "{\"jsonrpc\": \"2.0\", \"method\": \"notifications/initialized\"}"} {"dir": "client->server", "line": "{\"jsonrpc\": \"2.0\", \"id\": 2, \"method\": \"tools/list\", \"params\": {}}"} -{"dir": "server->client", "line": "{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":{\"tools\":[{\"name\":\"compile\",\"title\":\"Compile Omega source\",\"description\":\"Compile Omega (.om) source with the pinned seeded compiler omc (omega-mv@e5b32567). Returns ok, the binary's size and sha256, or the compile error {line, code, meaning, fix}.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"source\":{\"type\":\"string\",\"description\":\"Omega (.om) source text of one unit\"}},\"required\":[\"source\"],\"additionalProperties\":false}},{\"name\":\"run\",\"title\":\"Compile and run Omega source\",\"description\":\"Compile Omega source and run the program in an isolated sandbox (no network, no host filesystem, empty environment, CPU/memory/file/process limits). Returns the compile result, capped stdout/stderr and the interpreted exit status (normal, trap N with its meaning, or the limit that stopped it).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"source\":{\"type\":\"string\",\"description\":\"Omega (.om) source text of one unit\"},\"stdin\":{\"type\":\"string\",\"description\":\"bytes given to the program on stdin (default empty)\"},\"timeout_ms\":{\"type\":\"integer\",\"minimum\":1,\"maximum\":30000,\"description\":\"wall-clock limit in milliseconds (default 5000)\"}},\"required\":[\"source\"],\"additionalProperties\":false}},{\"name\":\"explain_error\",\"title\":\"Explain an Omega error or trap\",\"description\":\"Explain a compile error code 1..30, an `omc: line N: error K` line, `trap T`, or a program exit status 101..114 (trap). Returns meaning, cause, fix, a minimal example and source citations.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":[\"string\",\"integer\"],\"description\":\"an error code 1..30, an `omc: line N: error K` line, `trap T` (1..14) or an exit status 101..114; a string of 1..200 bytes or a nonnegative integer\"}},\"required\":[\"query\"],\"additionalProperties\":false}},{\"name\":\"lookup\",\"title\":\"Look up an Omega word or topic\",\"description\":\"Look up any Omega keyword (all 177 entries of the compiler's keyword table) or a topic (requires, ensures, invariant, result, om2, exit_status, packed_list, paths, host_words, compile_errors, traps, contracts): form, arity, types, result, example and citations. A query that is not an exact keyword or topic searches names and summaries (at most 20 results).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":64,\"description\":\"exact keyword or topic, or a case-insensitive substring to search for\"}},\"required\":[\"query\"],\"additionalProperties\":false}}]}}"} +{"dir": "server->client", "line": "{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":{\"tools\":[{\"name\":\"compile\",\"title\":\"Compile Omega source\",\"description\":\"Compile Omega (.om) source with the pinned seeded compiler omc (omega-mv@e5b32567). Returns ok, the binary's size and sha256, or the compile error {line, code, meaning, fix}.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"source\":{\"type\":\"string\",\"description\":\"Omega (.om) source text of one unit\"}},\"required\":[\"source\"],\"additionalProperties\":false}},{\"name\":\"run\",\"title\":\"Compile and run Omega source\",\"description\":\"Compile Omega source and run the program in an isolated sandbox (no network, no host filesystem, empty environment, CPU/memory/file/process limits). Returns the compile result, capped stdout/stderr and the interpreted exit status (normal, trap N with its meaning, or the limit that stopped it).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"source\":{\"type\":\"string\",\"description\":\"Omega (.om) source text of one unit\"},\"stdin\":{\"type\":\"string\",\"description\":\"bytes given to the program on stdin (default empty)\"},\"timeout_ms\":{\"type\":\"integer\",\"minimum\":1,\"maximum\":30000,\"description\":\"wall-clock limit in milliseconds (default 5000)\"}},\"required\":[\"source\"],\"additionalProperties\":false}},{\"name\":\"explain_error\",\"title\":\"Explain an Omega error or trap\",\"description\":\"Explain a compile error code 1..30, an `omc: line N: error K` line, `trap T`, or a program exit status 101..114 (trap). Returns meaning, cause, fix, a minimal example and source citations.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":[\"string\",\"integer\"],\"description\":\"an error code 1..30, an `omc: line N: error K` line, `trap T` (1..14) or an exit status 101..114; a string of 1..200 bytes or a nonnegative integer\"}},\"required\":[\"query\"],\"additionalProperties\":false}},{\"name\":\"lookup\",\"title\":\"Look up an Omega word or topic\",\"description\":\"Look up any Omega keyword (all 177 entries of the compiler's keyword table) or a topic (requires, ensures, invariant, result, om2, exit_status, packed_list, paths, host_words, compile_errors, traps, loops, contracts): form, arity, types, result, example and citations. A query that is not an exact keyword or topic searches names and summaries (at most 20 results).\",\"inputSchema\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":64,\"description\":\"exact keyword or topic, or a case-insensitive substring to search for\"}},\"required\":[\"query\"],\"additionalProperties\":false}}]}}"} {"dir": "client->server", "line": "{\"jsonrpc\": \"2.0\", \"id\": 3, \"method\": \"tools/call\", \"params\": {\"name\": \"compile\", \"arguments\": {\"source\": \"text msg \\\"hello\\\\n\\\"\\nfn main to int\\nw = write 1 msg 0 len msg\\nret 0\\nend\\n\"}}}"} {"dir": "server->client", "line": "{\"jsonrpc\":\"2.0\",\"id\":3,\"result\":{\"structuredContent\":{\"ok\":true,\"binary_bytes\":352,\"sha256\":\"24081b70473548ef051eaa3e84f103b54d5b1a548e24d69e5fd53205c6649d98\",\"compiler_sha256\":\"2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f\",\"isolation\":\"bwrap+prlimit: no network, no host files, cleared environment, cpu/as/fsize/nproc limits, server wall clock\"},\"content\":[{\"type\":\"text\",\"text\":\"{\\\"ok\\\":true,\\\"binary_bytes\\\":352,\\\"sha256\\\":\\\"24081b70473548ef051eaa3e84f103b54d5b1a548e24d69e5fd53205c6649d98\\\",\\\"compiler_sha256\\\":\\\"2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f\\\",\\\"isolation\\\":\\\"bwrap+prlimit: no network, no host files, cleared environment, cpu/as/fsize/nproc limits, server wall clock\\\"}\"}],\"isError\":false}}"} {"dir": "client->server", "line": "{\"jsonrpc\": \"2.0\", \"id\": 4, \"method\": \"tools/call\", \"params\": {\"name\": \"run\", \"arguments\": {\"source\": \"text msg \\\"hello\\\\n\\\"\\nfn main to int\\nw = write 1 msg 0 len msg\\nret 0\\nend\\n\"}}}"} @@ -23,4 +23,4 @@ {"dir": "server->client", "line": "{\"jsonrpc\":\"2.0\",\"id\":10,\"error\":{\"code\":-32602,\"message\":\"Invalid params: unknown argument; see the tool's inputSchema in tools/list\"}}"} {"dir": "client->server", "line": "{\"jsonrpc\": \"2.0\", \"id\": 11, \"method\": \"tools/call\", \"params\": {\"name\": \"format_disk\", \"arguments\": {}}}"} {"dir": "server->client", "line": "{\"jsonrpc\":\"2.0\",\"id\":11,\"error\":{\"code\":-32602,\"message\":\"Invalid params: unknown tool; tools/list names compile, run, explain_error and lookup\"}}"} -{"dir": "server stderr", "line": "omega-mcp: ready; isolation bwrap+prlimit; compiler 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f\nreq initialize id=1 -> ok\nreq notifications/initialized no reply\nreq tools/list id=2 -> ok\nreq tools/call id=3 tool=compile compile=0 ms=4 -> ok\nreq tools/call id=4 tool=run compile=0 ms=4 run=1/0 ms=4 -> ok\nreq tools/call id=5 tool=run compile=0 ms=4 run=2/2 ms=4 -> ok\nreq tools/call id=6 tool=compile compile=1 ms=4 -> ok\nreq tools/call id=7 tool=explain_error -> ok\nreq tools/call id=8 tool=lookup -> ok\nreq no/such/method id=9 -> error -32601\nreq -> error -32700\nreq tools/call id=10 tool=lookup -> error -32602\nreq tools/call id=11 -> error -32602\nomega-mcp: end of input; exiting\n"} +{"dir": "server stderr", "line": "omega-mcp: ready; isolation bwrap+prlimit; compiler 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f\nreq initialize id=1 -> ok\nreq notifications/initialized no reply\nreq tools/list id=2 -> ok\nreq tools/call id=3 tool=compile compile=0 ms=6 -> ok\nreq tools/call id=4 tool=run compile=0 ms=5 run=1/0 ms=5 -> ok\nreq tools/call id=5 tool=run compile=0 ms=7 run=2/2 ms=5 -> ok\nreq tools/call id=6 tool=compile compile=1 ms=5 -> ok\nreq tools/call id=7 tool=explain_error -> ok\nreq tools/call id=8 tool=lookup -> ok\nreq no/such/method id=9 -> error -32601\nreq -> error -32700\nreq tools/call id=10 tool=lookup -> error -32602\nreq tools/call id=11 -> error -32602\nomega-mcp: end of input; exiting\n"} diff --git a/tools/gen-reference.py b/tools/gen-reference.py index 7bfa638..d3689e2 100755 --- a/tools/gen-reference.py +++ b/tools/gen-reference.py @@ -247,12 +247,17 @@ word("not", "operator", "not A", 1, ["A: integer type T or bool"], "T", "Bitwise complement of an integer; logical not of a bool.", [c(OMG, "431", "Unsigned add, sub, mul, shl, neg, not wrap modulo 2^width")], "arith") +EMPTY_TEXT_NOTE = ("At the pin (omega-mv e5b32567) the count of an empty text (`text e \"\"`) is read from a stale " + "register (omega-mv #775): `len e` returns whatever that register holds (`ret int add 7 len e` exits " + "14), and get, part and write check against the same stale count, so they can use bytes past " + "the text instead of trapping 3. Fixed in omega-mv #904 (e2662fff): the count is 0. At this pin, " + "avoid empty texts.") D = "data" word("get", D, "get A i | get P field [i]", 2, ["A: array", "i: integer index"], "element type", "Read element i of an array (or a struct/layout field). A constant index outside is error 21; a run-time one traps 3.", [c(OMG, "471", "`get A i` reads element i")], "arrays") word("len", D, "len A", 1, ["A: array or text"], "ulong", "Length of an array as a ulong.", - [c(OMG, "471", "`len A` is A's length as a ulong.")], "hello") + [c(OMG, "471", "`len A` is A's length as a ulong.")], "hello", notes=EMPTY_TEXT_NOTE) word("read", D, "read fd A off n", 4, ["fd: int", "A: writable uchar array", "off: ulong", "n: ulong"], "long", "Read n bytes from fd into A[off..]; bytes read or minus errno. Slice outside A traps 3.", [c(OMG, "478", "`read fd A off n` and `write fd A off n` (fd int, off and n ulong)")], "files") @@ -279,15 +284,20 @@ word("end", S, "end", 0, [], "-", "Closes fn, if/else, while, for, struct and la word("if", S, "if COND / [else] / end", 1, ["COND: bool"], "-", "Conditional block.", [c(OMG, "57", "if <cond> / else / end")], "control") word("else", S, "else", 0, [], "-", "Second arm of an if block.", [c(OMG, "57", "if <cond> / else / end")], "control") +FOR_NOTE = ("At the pin no bound gives a loop more than 1000000 passes: `for ... bound N` is error 5 (it came with " + "omega-mv #857, 3a163bc5) and a while bound is at most 999999. For more passes use a number count, " + "which is unguarded, or nest two loops.") word("while", S, "while COND [bound N] / end", 1, ["COND: bool", "N: 1..999999"], "-", "Loop while COND holds; past N iterations (default 1000000) it traps 4.", [c(OMG, "58", "while <cond> [bound N] / end")], "control") word("bound", S, "while COND bound N", 1, ["N: integer literal or constant 1..999999"], "-", - "Iteration limit of a while loop; exceeding it traps 4.", + "Iteration limit of a while loop; exceeding it traps 4. A for takes no bound at this pin (error 5).", [c(OMG, "58", "N 1..999999, default 1000000; past N iterations: trap 4")], "control") word("for", S, "for NAME TYPE COUNT [unroll] / end", 3, ["NAME: new counter", "TYPE: integer type", "COUNT: number or value of TYPE"], "-", - "Counted loop: NAME = 0 .. COUNT-1.", - [c(OMG, "59", "for <name> <type> <count> / end")], "control") + "Counted loop: NAME = 0 .. COUNT-1. A number COUNT runs unguarded; any other COUNT traps 4 after 1000000 passes, as a while with no bound.", + [c(OMG, "59", "for <name> <type> <count> / end"), + c(OMG, "60", "(any other count: trap 4 after 1000000 passes, as a while with no bound)")], "for_guard", + notes=FOR_NOTE) word("ret", S, "ret [VALUE]", 1, ["VALUE: the function's result type (none for void)"], "-", "Return from the function; ends the path (a later line in the block is error 17).", [c(OMG, "65", "ret [<value>]")], "hello") @@ -307,7 +317,7 @@ word("global", ST, "global NAME T N", 3, ["NAME: up to 8 characters", "T: elemen [c(OMG, "454", "`global NAME T N`: a pool of N elements (1 .. 16777216)")], "arrays") word("text", ST, 'text NAME "bytes"', 2, ["NAME: up to 8 characters", "bytes: escapes \\n \\t \\\\ \\\""], "-", "A read-only uchar array holding the quoted bytes. Program mode only.", - [c(OMG, "457", '`text NAME "bytes"`: a read-only array of uchar')], "hello") + [c(OMG, "457", '`text NAME "bytes"`: a read-only array of uchar')], "hello", notes=EMPTY_TEXT_NOTE) word("put", ST, "put A i v | put P field [i] v", 3, ["A: writable array", "i: integer index", "v: element type"], "-", "Store v at element i. Into a view or text: error 20.", [c(OMG, "66", "put <array> <index> <value>")], "arrays") @@ -440,7 +450,7 @@ for k, (meaning, cause, fix, line, doc) in ERR.items(): TR = {1: ("OVERFLOW", "checked signed arithmetic out of range", "Signed add/sub/mul/neg/div/shl produced a value outside the type.", "Use a wider type, check the range first, or use an unsigned type if wrapping is intended.", (OMG, "433", "Signed add, sub, mul, neg, div and shl trap 1")), 2: ("DIV0", "division by zero", "div or rem with a divisor of 0.", "Check the divisor before dividing.", (OMG, "435", "div and rem trap 2 when the divisor is 0.")), 3: ("BOUNDS", "index or slice out of bounds", "A run-time index is not below the length, or a host/read/write slice is outside its array.", "Check the index against len A, or fix off/n.", (OMG, "473", "traps 3 when it is not below the length")), - 4: ("LOOP_BOUND", "loop exceeded its bound", "A while ran more than its bound (default 1000000) iterations.", "Fix the loop condition or raise bound N (at most 999999).", (OMG, "58", "past N iterations: trap 4")), + 4: ("LOOP_BOUND", "loop exceeded its bound", "A while ran more than its bound (default 1000000) iterations, or a for whose count is not a number ran 1000000 passes.", "Fix the loop condition, raise a while's bound N (at most 999999), or for more passes use a number count or nest two loops.", (OMG, "58", "past N iterations: trap 4")), 5: ("CAST", "checked conversion out of range", "A conversion `T v` got a value outside T.", "Check the range before converting, or convert to a wider type.", (OMG, "439", "A conversion `<type> v` traps 5 when the value is outside the new type.")), 6: ("OOM", "stack pool exhausted", "A call or local array would go below the fixed 8 MiB stack (deep recursion).", "Bound the recursion or use a loop / smaller local arrays.", (OMG, "426-427", "a call or a local array that would go below it traps")), 7: ("SHIFT", "shift or rotate amount out of range", "A shift or rotate amount is outside 0..width-1.", "Check the amount against the width.", (OMG, "437", "A shift amount outside 0 .. width - 1 traps 7")), @@ -456,6 +466,7 @@ for k, (name, meaning, cause, fix, doc) in TR.items(): TRAPS[str(k)] = {"name": name, "meaning": meaning, "cause": cause, "fix": fix, "citations": [c(*doc), c(OMG, "406", "A trap in program mode ends the program with exit status 100 + the trap code")], "example": "contract_fail" if k == 9 else f"t{k:02d}"} +TRAPS["4"]["citations"].insert(1, c(OMG, "60", "(any other count: trap 4 after 1000000 passes, as a while with no bound)")) # ---------------------------------------------------------------- topics TOP = { @@ -490,8 +501,15 @@ TOP = { "details": "Codes 1..24 and 27..30 exist at the pin; 25 and 26 are unused.", "citations": [c(OMC, "292-293", "fn fail code ulong to void")], "example": "e03"}, "traps": {"summary": "Run-time traps 1..14 end a program with exit 100 + code.", - "details": "Codes are part of the observable semantics and are never renumbered.", - "citations": [c(IRH, "165-166", "Trap codes are part of the observable semantics")], "example": "t02"}, + "details": "Codes are part of the observable semantics and are never renumbered. Loops trap 4: a while past its bound (default 1000000) and a for whose count is not a number after 1000000 passes.", + "citations": [c(IRH, "165-166", "Trap codes are part of the observable semantics"), + c(OMG, "58", "N 1..999999, default 1000000; past N iterations: trap 4"), + c(OMG, "60", "(any other count: trap 4 after 1000000 passes, as a while with no bound)")], "example": "t02"}, + "loops": {"form": "while COND [bound N] / end | for NAME TYPE COUNT [unroll] / end", + "summary": "Every loop except a for with a number count traps 4 (exit 104) past a pass limit.", + "details": "A while runs at most N passes (bound N, 1..999999; default 1000000). A for with a number COUNT is unguarded; any other COUNT traps 4 after 1000000 passes. At this pin a for takes no bound (error 5).", + "citations": [c(OMG, "58", "N 1..999999, default 1000000; past N iterations: trap 4"), + c(OMG, "60", "(any other count: trap 4 after 1000000 passes, as a while with no bound)")], "example": "for_guard"}, "contracts": {"summary": "OM-2 contracts: requires, ensures and invariant clauses checked at run time (traps 9 and 10).", "details": "Compiler error 30 covers misplaced contracts, unavailable result and impure predicates.", "citations": [c(OMG, "1177-1178", "Compiler error **30** means misplaced")], "example": "contracts"}, @@ -513,7 +531,7 @@ TOOLS = [ "inputSchema": {"type": "object", "properties": {"query": {"type": ["string", "integer"], "description": "an error code 1..30, an `omc: line N: error K` line, `trap T` (1..14) or an exit status 101..114; a string of 1..200 bytes or a nonnegative integer"}}, "required": ["query"], "additionalProperties": False}}, {"name": "lookup", "title": "Look up an Omega word or topic", - "description": "Look up any Omega keyword (all 177 entries of the compiler's keyword table) or a topic (requires, ensures, invariant, result, om2, exit_status, packed_list, paths, host_words, compile_errors, traps, contracts): form, arity, types, result, example and citations. A query that is not an exact keyword or topic searches names and summaries (at most 20 results).", + "description": "Look up any Omega keyword (all 177 entries of the compiler's keyword table) or a topic (requires, ensures, invariant, result, om2, exit_status, packed_list, paths, host_words, compile_errors, traps, loops, contracts): form, arity, types, result, example and citations. A query that is not an exact keyword or topic searches names and summaries (at most 20 results).", "inputSchema": {"type": "object", "properties": {"query": {"type": "string", "minLength": 1, "maxLength": 64, "description": "exact keyword or topic, or a case-insensitive substring to search for"}}, "required": ["query"], "additionalProperties": False}}, ] diff --git a/tools/ref_examples.py b/tools/ref_examples.py index 294bec9..c32582f 100644 --- a/tools/ref_examples.py +++ b/tools/ref_examples.py @@ -112,6 +112,21 @@ ret int s end ''', mode="run", exit=131) +ex("for_guard", ''' +note a for with a number count is unguarded; any other count traps 4 after 1000000 passes +fn main to int +s = ulong 0 +for i ulong 2000000 +s = add s 1 +end +k = ulong 1000001 +for j ulong k +s = add s 1 +end +ret int sub s 3000001 +end +''', mode="trap", trap=4) + ex("arrays", ''' note a local array (new), a global pool, view and edit parameters, get, put and len global tot ulong 1