Skip to content

Commit a22af16

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feature-add-cwd-option
2 parents ab0f9ec + 60bfbb6 commit a22af16

File tree

2,743 files changed

+6188
-1742
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,743 files changed

+6188
-1742
lines changed

.github/workflows/build-cppfront.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
runs-on: [ubuntu-latest]
25+
runs-on: [ubuntu-22.04]
2626
compiler: [g++-10, g++-11, g++-12, clang++-12, clang++-14]
2727
cxx-std: ['c++20', 'c++2b']
2828
exclude:
@@ -35,12 +35,21 @@ jobs:
3535
- compiler: clang++-14
3636
cxx-std: 'c++2b'
3737
include:
38-
- runs-on: macos-11
39-
compiler: clang++
40-
cxx-std: 'c++20'
4138
- runs-on: macos-latest
4239
compiler: clang++
4340
cxx-std: 'c++20'
41+
- runs-on: ubuntu-24.04
42+
compiler: clang++-16
43+
cxx-std: 'c++20'
44+
- runs-on: ubuntu-24.04
45+
compiler: clang++-17
46+
cxx-std: 'c++20'
47+
- runs-on: ubuntu-24.04
48+
compiler: clang++-18
49+
cxx-std: 'c++20'
50+
- runs-on: ubuntu-24.04
51+
compiler: g++-14
52+
cxx-std: 'c++2b'
4453
runs-on: ${{ matrix.runs-on }}
4554
env:
4655
CXX: ${{ matrix.compiler }}

.github/workflows/regression-tests.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,70 @@ on:
1111

1212
jobs:
1313
regression-tests:
14-
name: Run on ${{ matrix.os }} using ${{ matrix.compiler }}
14+
name: ${{ matrix.shortosname }} | ${{ matrix.compiler }} | ${{ matrix.cxx_std }} | ${{ matrix.stdlib }} | ${{ matrix.os }}
1515
runs-on: ${{ matrix.os }}
1616
env:
1717
CXX: ${{ matrix.compiler }}
1818

1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [ubuntu-latest]
23-
compiler: [g++-10, g++-13, clang++-15]
22+
os: [ubuntu-24.04]
23+
shortosname: [ubu-24]
24+
compiler: [g++-14, g++-13]
25+
cxx_std: [c++2b]
26+
stdlib: [libstdc++]
2427
include:
2528
- os: ubuntu-20.04
29+
shortosname: ubu-20
30+
compiler: g++-10
31+
cxx_std: c++20
32+
stdlib: libstdc++
33+
- os: ubuntu-24.04
34+
shortosname: ubu-24
35+
compiler: clang++-18
36+
cxx_std: c++20
37+
stdlib: libstdc++
38+
- os: ubuntu-22.04
39+
shortosname: ubu-22
40+
compiler: clang++-15
41+
cxx_std: c++20
42+
stdlib: libstdc++
43+
- os: ubuntu-22.04
44+
shortosname: ubu-22
45+
compiler: clang++-15
46+
cxx_std: c++20
47+
stdlib: libc++-15-dev
48+
- os: ubuntu-20.04
49+
shortosname: ubu-20
2650
compiler: clang++-12
51+
cxx_std: c++20
52+
stdlib: libstdc++
2753
- os: macos-14
54+
shortosname: mac-14
2855
compiler: clang++
56+
cxx_std: c++2b
57+
stdlib: default
2958
- os: macos-13
59+
shortosname: mac-13
3060
compiler: clang++
61+
cxx_std: c++2b
62+
stdlib: default
3163
- os: macos-13
64+
shortosname: mac-13
3265
compiler: clang++-15
33-
- os: windows-latest
66+
cxx_std: c++2b
67+
stdlib: default
68+
- os: windows-2022
69+
shortosname: win-22
70+
compiler: cl.exe
71+
cxx_std: c++latest
72+
stdlib: default
73+
- os: windows-2022
74+
shortosname: win-22
3475
compiler: cl.exe
76+
cxx_std: c++20
77+
stdlib: default
3578
steps:
3679
- name: Checkout repo
3780
uses: actions/checkout@v4
@@ -46,21 +89,21 @@ jobs:
4689
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
4790
run: |
4891
cd regression-tests
49-
bash run-tests.sh -c ${{ matrix.compiler }} -l ${{ matrix.os }}
92+
bash run-tests.sh -c ${{ matrix.compiler }} -s ${{ matrix.cxx_std }} -d ${{ matrix.stdlib }} -l ${{ matrix.os }}
5093
5194
- name: Run regression tests - Windows version
5295
if: matrix.os == 'windows-latest'
5396
run: |
5497
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && ^
5598
git config --local core.autocrlf false && ^
5699
cd regression-tests && ^
57-
bash run-tests.sh -c ${{ matrix.compiler }} -l ${{ matrix.os }}
100+
bash run-tests.sh -c ${{ matrix.compiler }} -s ${{ matrix.cxx_std }} -d ${{ matrix.stdlib }} -l ${{ matrix.os }}
58101
shell: cmd
59102

60103
- name: Upload patch
61104
if: ${{ !cancelled() }}
62105
uses: actions/upload-artifact@v4
63106
with:
64-
name: ${{ matrix.os }}-${{ matrix.compiler }}.patch
65-
path: regression-tests/${{ matrix.os }}-${{ matrix.compiler }}.patch
107+
name: ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.cxx_std }}-${{ matrix.stdlib }}.patch
108+
path: regression-tests/${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.cxx_std }}-${{ matrix.stdlib }}.patch
66109
if-no-files-found: ignore

CITATION.cff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cff-version: 1.2.0
2+
message: >-
3+
If you use this software, please cite it using the
4+
metadata from this file.
5+
type: software
6+
title: cppfront
7+
authors:
8+
- given-names: Herb
9+
family-names: Sutter
10+
repository-code: 'https://github.com/hsutter/cppfront'
11+
abstract: A personal experimental C++ Syntax 2 -> Syntax 1 compiler
12+
license: CC-BY-NC-ND-4.0

docs/cpp2/common.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ All lists use `,` commas between list items, and may be enclosed by
6767

6868
For example:
6969

70-
``` cpp title="Lists, using optional trailing commas just because we can" hl_lines="1 4 6 7"
70+
``` cpp title="Lists" hl_lines="1 4 6 7"
7171
print: <T,U> (t: T, u: U) = std::cout << t << u << "\n";
7272

7373
main: () = {
@@ -223,7 +223,6 @@ Unary suffix operators must not be preceded by whitespace. When `*`, `&`, and `~
223223
|---|---|---|
224224
| `#!cpp *` | `#!cpp pobj* * 42` | `#!cpp (*pobj)*42` |
225225
| `#!cpp &` | `#!cpp obj& & mask` <p> (note: allowed in unsafe code only) | `#!cpp &obj & mask` |
226-
| `#!cpp ~` | `#!cpp ~val ~ bitcomplement` | `#!cpp val~ ~ bitcomplement` |
227226

228227
For more details, see [Design note: Postfix unary operators vs binary operators](https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-unary-operators-vs-binary-operators).
229228

docs/cpp2/contracts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ For example:
3232
``` cpp title="Precondition and postcondition examples" hl_lines="2 3"
3333
insert_at: (container, where: int, val: int)
3434
pre<bounds_safety>( 0 <= where <= container.ssize(), "position (where)$ is outside 'container'" )
35-
post ( container.ssize() == container.ssize()$ + 1 )
35+
post ( container.ssize() == container.ssize()$ + 1 )
3636
= {
3737
_ = container.insert( container.begin()+where, val );
3838
}

docs/cpp2/declarations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ main: () = {
254254
// Assertion that the size is the square of 4
255255
static_assert( ints.size() == 16 );
256256

257-
// And if can be used at run time, with run time values
257+
// And it can be used at run time, with run time values
258258
std::cout << "the square of 4 is (square(4))$\n";
259259
}
260260
// Prints:

docs/cpp2/expressions.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ For example:
4949

5050

5151

52-
## <a id="wildcard"></a> `_` — the "don't care" wildcard, including explicit discard
52+
## <a id="wildcard"></a> <a id="discard"></a> `_` — the "don't care" wildcard, including explicit discard
5353

5454
`_` is pronounced **"don't care"** and allowed as a wildcard in most contexts. For example:
5555

@@ -173,13 +173,11 @@ Here are some `as` casts with their Cpp1 equivalents. In this table, uppercase n
173173

174174
## <a id="inspect"></a> `inspect` — pattern matching
175175

176-
An `inspect expr -> Type` expression allows pattern matching using `is`.
176+
An `inspect expr -> Type = { /* alternatives */ }` expression allows pattern matching using `is`.
177177

178178
- `expr` is evaluated once.
179179

180-
- Each alternative spelled `is C` is evaluated in order as if called with `expr is C`.
181-
182-
- If an alternative evaluates to `#!cpp true`, then its `#!cpp = alternative;` body is used as the value of the entire `inspect` expression, and the meaning is the same as if the entire `inspect` expression had been written as just `#!cpp :Type = alternative;` — i.e., an unnamed object expression (aka 'temporary object') of type `Type` initialized with `alternative`.
180+
- Each alternative is spelled `is C = statement;` and are evaluated in order. Each `is C` is evaluated as if called with `expr is C`, and if it evaluates to `#!cpp true`, then its `#!cpp = alternative;` body is used as the value of the entire `inspect` expression, and the meaning is the same as if the entire `inspect` expression had been written as just `#!cpp :Type = alternative;` — i.e., an unnamed object expression (aka 'temporary object') of type `Type` initialized with `alternative`.
183181

184182
- A catchall `is _` is required.
185183

@@ -277,7 +275,7 @@ For example:
277275

278276
``` cpp title="Capture in contract postconditions" hl_lines="2"
279277
push_back: (coll, value)
280-
[[post: coll.ssize() == coll.ssize()$ + 1]]
278+
post(coll.ssize() == coll.ssize()$ + 1)
281279
// Paste the value of `coll.ssize()`
282280
= {
283281
// ...

docs/cpp2/functions.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,39 @@ func: (
2727
}
2828
```
2929

30-
There are six ways to pass parameters that cover all use cases:
30+
There are six ways to pass parameters that cover all use cases, that can be written before the parameter name:
3131

3232
| Parameter ***kind*** | "Pass me an `x` I can ______" | Accepts arguments that are | Special semantics | ***kind*** `x: X` Compiles to Cpp1 as |
3333
|---|---|---|---|---|
3434
| `in` (default) | read from | anything | always `#!cpp const`<p>automatically passes by value if cheaply copyable | `X const x` or `X const& x` |
3535
| `copy` | take a copy of | anything | acts like a normal local variable initialized with the argument | `X x` |
3636
| `inout` | read from and write to | lvalues | | `X& x` |
37-
| `out` | write to (including construct) | lvalues, including uninitialized lvalues | must `=` assign/construct before other uses | `cpp2::out<X>` |
38-
| `move` | move from | rvalues | automatically moves from every definite last use | `X&&` |
37+
| `out` | write to (including construct) | lvalues (including uninitialized) | must `=` assign/construct before other uses | `cpp2::impl::out<X>` |
38+
| `move` | move from (consume the value of) | rvalues | automatically moves from every definite last use | `X&&` |
3939
| `forward` | forward | anything | automatically forwards from every definite last use | `T&&` constrained to type `X` |
4040

41-
4241
> Note: All parameters and other objects in Cpp2 are `#!cpp const` by default, except for local variables. For details, see [Design note: `#!cpp const` objects by default](https://github.com/hsutter/cppfront/wiki/Design-note%3A-const-objects-by-default).
4342
43+
For example:
44+
45+
``` cpp title="Declaring parameter kinds" hl_lines="2 3 10"
46+
append_x_to_y: (
47+
x : i32, // an i32 I can read from (i.e., const)
48+
inout y : std::string // a string I can read from and write to
49+
)
50+
= {
51+
y = y + to_string(x); // read x, read and write y
52+
}
53+
54+
wrap_f: (
55+
forward x // a generic value of deduced type I can forward
56+
) // (omitting x's type means the same as ': _')
57+
= {
58+
global_counter += x; // ok to read x
59+
f(x); // last use: automatically does 'std::forward<T>(x)'
60+
}
61+
```
62+
4463

4564
## <a id="return-values"></a> Return values
4665

@@ -188,7 +207,7 @@ else {
188207

189208
**`#!cpp do`** and **`#!cpp while`** are like always in C++, except that `(` `)` parentheses around the condition are not required. Instead, `{` `}` braces around the loop body *are* required.
190209

191-
**`#!cpp for range do (e)`** ***statement*** says "for each element in `range`, call it `e` and perform the statement." The loop parameter `(e)` is an ordinary parameter that can be passed isoing any [parameter passing style](#parameters); as always, the default is `in`, which is read-only and expresses a read-only loop. The statement is not required to be enclosed in braces.
210+
**`#!cpp for range do (e)`** ***statement*** says "for each element in `range`, call it `e` and perform the statement." The loop parameter `(e)` is an ordinary parameter that can be passed using any [parameter passing style](#parameters); as always, the default is `in`, which is read-only and expresses a read-only loop. The statement is not required to be enclosed in braces.
192211

193212
Every loop can have a `next` clause, that is performed at the end of each loop body execution. This makes it easy to have a counter for any loop, including a range `#!cpp for` loop.
194213

@@ -247,6 +266,22 @@ if i % 2 == 1 // if i is odd
247266
// counter: 1, word: [Betty]
248267
```
249268

269+
Here is the equivalent of the Cpp1 code `for ( int i = 0; i < 10; ++i ){ std::cout << i; }`:
270+
271+
``` cpp title="Equivalent of Cpp1 'for ( int i = 0; i < 10; ++i ){ std::cout << i; }'"
272+
(copy i := 0)
273+
while i < 10
274+
next i++ {
275+
std::cout << i;
276+
}
277+
```
278+
279+
Line by line:
280+
281+
- `(copy i := 0)`: Any statement can have [statement-local parameters](declarations.md#from-functions-to-local-scopes-and-back-again), and this is declaring `i` as an `int` that's local to the loop. Parameters by default are `const`, and for not-cheap-to-copy types they bind to the original value; so because we want to modify `i` we say `copy` to explicitly declare this is the loop's own mutable scratch variable.
282+
- `while i < 10`: The termination condition.
283+
- `next i++`: The end-of-loop-iteration statement. Note `++` is always postfix in Cpp2.
284+
250285

251286
### Loop names, `#!cpp break`, and `#!cpp continue`
252287

docs/cpp2/types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ For example:
8181
abstract_base: type
8282
= {
8383
// A pure virtual function: virtual + no body
84-
print: (virtual this, msg: std::string);
84+
print: (virtual this, msg: std::string) = { /*...*/ }
8585

8686
// ...
8787
}
@@ -92,7 +92,7 @@ derived: type
9292
this: abstract_base;
9393

9494
// Explicit override
95-
print: (override this, msg: std::string);
95+
print: (override this, msg: std::string) = { /*...*/ }
9696

9797
// ...
9898
}
@@ -199,7 +199,7 @@ mytype: type
199199
name: std::string;
200200
social_handle: std::string = "(unknown)";
201201

202-
// conversion from string
202+
// conversion from string (construction + assignment)
203203
operator=: (out this, who: std::string) = {
204204
name = who;
205205
// if social_handle is not mentioned, defaults to:

0 commit comments

Comments
 (0)