diff --git a/examples/mistake_literal_op_arg.expect b/examples/mistake_literal_op_arg.expect new file mode 100644 index 0000000..9401caf --- /dev/null +++ b/examples/mistake_literal_op_arg.expect @@ -0,0 +1,2 @@ +compile 11 +stderr omc: line 7: error 11 diff --git a/examples/mistake_literal_op_arg.om b/examples/mistake_literal_op_arg.om new file mode 100644 index 0000000..662b2f3 --- /dev/null +++ b/examples/mistake_literal_op_arg.om @@ -0,0 +1,9 @@ +note mistake_literal_op_arg: an operation whose values are all bare numbers has no type, even as the +note argument of a typed parameter. Fix: type one value, f add ulong 2 1 +fn f q ulong to ulong +ret q +end +fn main to int +r = f add 2 1 +ret int r +end diff --git a/examples/mistake_retype_name.expect b/examples/mistake_retype_name.expect new file mode 100644 index 0000000..c08f954 --- /dev/null +++ b/examples/mistake_retype_name.expect @@ -0,0 +1,2 @@ +compile 7 +stderr omc: line 9: error 7 diff --git a/examples/mistake_retype_name.om b/examples/mistake_retype_name.om new file mode 100644 index 0000000..b350cbb --- /dev/null +++ b/examples/mistake_retype_name.om @@ -0,0 +1,11 @@ +note mistake_retype_name: a name keeps the type of its first assignment; a later value of another +note type is refused. Fix: one name per type, b = g then n = write 1 T 0 1 +text T "a" +fn g to bool +ret true +end +fn main to int +x = g +x = write 1 T 0 1 +ret 0 +end diff --git a/skills/writing-omega/SKILL.md b/skills/writing-omega/SKILL.md index c0a2356..892474b 100644 --- a/skills/writing-omega/SKILL.md +++ b/skills/writing-omega/SKILL.md @@ -125,7 +125,12 @@ Every declaration and statement form at the pin (OMEGESE sections 9 to 12 are th type word: `long x`, `uint b`, `f64 n`. - **A bare number takes its type from context**: the other value of its operation, the parameter it is passed to, the result type at `ret`. With no context it is error 11: write `x = uint 5`, never - `x = 5` for a new name. + `x = 5` for a new name. An operation whose values are all bare numbers has no context even as the + argument of a typed parameter: `f add 2 1` is error 11, `f add ulong 2 1` compiles + (`mistake_literal_op_arg.om`). +- **A name keeps the type of its first assignment.** Reusing one throwaway name for results of + different types (`x = fload ...` a `bool`, then `x = write ...` a `long`) is error 7; use one name + per type (`mistake_retype_name.om`). - Integer literals are decimal with an optional leading `-`. A literal that does not fit its type is error 8. No character literals: write `uchar 65`, not `'A'` (error 3). - Float literals need digits on both sides of the dot: `2.0f64`, `1.0e30f64`, `0.5f32`. The suffix is @@ -367,6 +372,8 @@ Each row is a program in `examples/` with its observed refusal. | `len = ...` | another name | error 16 | `mistake_reserved_name.om` | | `neg = ...` or `text neg "a"` | another name: `neg` is the negation word | error 16 | `mistake_neg_name.om` | | a bare call `f 1` with a result | `v = f 1` | error 7 | `mistake_value_stmt.om` | +| `f add 2 1` (only bare numbers) to a `ulong` parameter | `f add ulong 2 1` | error 11 | `mistake_literal_op_arg.om` | +| `x = g` (`bool`), later `x = write ...` (`long`) | one name per type | error 7 | `mistake_retype_name.om` | | a 7th parameter | a struct or an array | error 9 | `mistake_seven_params.om` | | 2 `view T *` plus 3 scalars (7 slots) | a sized view, a struct, or fewer scalars | error 9 | `mistake_om2_param_slots.om` | | `emit buf` with `buf` a global | name the global inside the function | error 19 | `err19_global_arg.om` |