summaryrefslogtreecommitdiff
path: root/chapter17/README.md
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-11-11 11:39:32 -0800
committerCliff Click <cliffc@acm.org>2024-11-23 09:03:20 -0800
commitf13a809597991b705db6f185bd356c34eca967be (patch)
treeda1138d131121e5b07ff759b0206c38288fc8c5b /chapter17/README.md
parent688d2230b93b03f2d4505346ef3b89b0f4c46445 (diff)
downloadSimple-f13a809597991b705db6f185bd356c34eca967be.tar.gz
Simple-f13a809597991b705db6f185bd356c34eca967be.zip
Allow pre-inc/dec on variables
Diffstat (limited to 'chapter17/README.md')
-rw-r--r--chapter17/README.md24
1 files changed, 14 insertions, 10 deletions
diff --git a/chapter17/README.md b/chapter17/README.md
index b9733873..fa268293 100644
--- a/chapter17/README.md
+++ b/chapter17/README.md
@@ -1,7 +1,7 @@
# Chapter 17: Syntax Sugar
-## Post-increment
+## Pre/Post-increment
Allow `arg++` and `arg--` with the usual meanings; the value is updated and the
expression is the pre-update value. Greedy match is used so `arg---arg` parses
@@ -9,6 +9,8 @@ as `(arg--)-arg`.
Also allows `s.fld++` and `ary[idx]++`, and their `--` variants.
+Allow pre-increment for identifiers only, for now: `--pc`.
+
## var & val
@@ -19,7 +21,7 @@ value), whose type will be inferred from the initalizing expression.
The inferred value is the `glb` of the peephole type, which means `var` and
`val` will not infer types like `u8` or `f32`, instead inferring `int` and
-`flt` respectively. Struct types will always infer as nullable, so e.g.
+`flt` respectively. Reference types will always infer as nullable, so e.g.
`var s = new S;`
@@ -93,12 +95,10 @@ return p.x;
```cpp
struct Bar { int x; };
-Bar b = new Bar; /* b = null; *//* b.x++; */ // immutable & deep immutable
-Bar !b = new Bar; b = null; /* b.x++; */ // mutable & deep immutable
-Bar b! = new Bar; /* b = null; */ b.x++; // immutable & deep mutable
-Bar !b! = new Bar; b = null; b.x++; // mutable & deep mutable (ignoring NPE)
-val b = new Bar; /* b = null; *//* b.x++; */ // immutable & deep immutable
-var b = new Bar; b = null; b.x++; // mutable & inherits deep mutability from RHS
+Bar b = new Bar; /* b = new Bar; *//* b.x++; */ // immutable & deep immutable
+Bar !b = new Bar; b = new Bar; b.x++; // mutable & deep mutable
+val b = new Bar; /* b = new Bar; *//* b.x++; */ // immutable & deep immutable
+var b = new Bar; b = new Bar; b.x++; // mutable & inherits deep mutability from RHS
```
@@ -114,6 +114,8 @@ Allow C/C++ style `for` loops:
`for( init; test; next ) body`
+Example:
+
```cpp
int sum=0;
for( int i=0; i<arg; i++ )
@@ -128,12 +130,14 @@ Any of `init`, `test` and `next` can be empty.
int sum=0;
for( int i=0; i<arg; i++ )
sum = sum + i;
-return sum;
+return i; // ERROR: Undefined name 'i'
```
-
+pre-dec
+finalize final
+TODO
for-interator
switch