mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 01:01:35 +01:00
Rename PUFFS to WUFFS, part 10 of N
This commit is contained in:
1 parent
8e3b5cce5e
commit
b9fd20bfe4
6 files changed
+141
-141
No files matched your search
+17
-17
@@ -1,12 +1,12 @@
|
||||
# Puffs the Language
|
||||
# Wuffs the Language
|
||||
|
||||
Puffs is an imperative, C-like language and much of it should look familiar to
|
||||
Wuffs is an imperative, C-like language and much of it should look familiar to
|
||||
somebody versed in any one of C, C++, D, Go, Java, JavaScript, Objective-C,
|
||||
Rust, Swift, etc. Accordingly, this section is not an exhaustive specification,
|
||||
merely a rough guide of where Puffs differs.
|
||||
merely a rough guide of where Wuffs differs.
|
||||
|
||||
Like Go, [semi-colons can be omitted](https://golang.org/ref/spec#Semicolons),
|
||||
and `puffsfmt` will remove them. Similarly, the body of an `if` or `while` must
|
||||
and `wuffsfmt` will remove them. Similarly, the body of an `if` or `while` must
|
||||
be enclosed by curly `{}`s. There is no 'dangling else' ambiguity.
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ associative: `(a + b) + c` and `a + (b + c)` are equivalent, and can be written
|
||||
as `a + b + c`.
|
||||
|
||||
The logical operators, `&&` and `||` and `!` in C, are written as `and` and
|
||||
`or` and `not` in Puffs.
|
||||
`or` and `not` in Wuffs.
|
||||
|
||||
TODO: ignore-overflow ops, equivalent to Swift's `&+`.
|
||||
|
||||
@@ -84,7 +84,7 @@ array of unsigned 32-bit integers. `ptr` here means a non-null pointer. Use
|
||||
Integer types can also be refined: `var x u32[10..20]` defines a variable x
|
||||
that is stored as 4 bytes (32 bits) and can be combined arithmetically (e.g.
|
||||
added, compared) with other `u32`s, but whose value must be between 10 and 20
|
||||
inclusive. The syntax is reminiscent of Pascal's subranges, but in Puffs, a
|
||||
inclusive. The syntax is reminiscent of Pascal's subranges, but in Wuffs, a
|
||||
subsequent assignment like `x = 21` or even `x = y + z` is a compile time error
|
||||
unless the right hand side can be proven to be within range.
|
||||
|
||||
@@ -97,7 +97,7 @@ i8[-7..]` means that `y` is between -7 and +127. `var z u32[..]` is equivalent
|
||||
to `var z u32`.
|
||||
|
||||
Refinement bounds must be constant expressions. `var x u32[..2+3]` is valid,
|
||||
but `var x u32; var y u32[..x]` is not. Puffs does not have dependent types.
|
||||
but `var x u32; var y u32[..x]` is not. Wuffs does not have dependent types.
|
||||
Relationships such as `y <= x` are expressible as assertions (see below), but
|
||||
not by the type system.
|
||||
|
||||
@@ -114,7 +114,7 @@ its methods may be coroutines. (See below).
|
||||
Function signatures read from left to right: `func max(x i32, y i32)(z i32)` is
|
||||
a function that takes two `i32`s and returns one `i32`. Two pairs of
|
||||
parentheses are required: a function that in other languages would return
|
||||
`void` in Puffs returns the empty struct `()`, also known as the unit type.
|
||||
`void` in Wuffs returns the empty struct `()`, also known as the unit type.
|
||||
|
||||
When calling a function, each argument must be named. It is `m = max(x:10,
|
||||
y:20)` and not `m = max(10, 20)`.
|
||||
@@ -208,7 +208,7 @@ facts that include both the explicit assertion `x < y` and the implicit
|
||||
assertion `z == 3`, if none of `x`, `y` and `z` alias another (e.g. they are
|
||||
all local variables).
|
||||
|
||||
Puffs has two forms of non-sequential control flow: `if` branches (including
|
||||
Wuffs has two forms of non-sequential control flow: `if` branches (including
|
||||
`if`, `else if`, `else if` chains) and `while` loops.
|
||||
|
||||
For an `if` statement, such as `if b { etc0 } else { etc1 }`, the condition `b`
|
||||
@@ -237,14 +237,14 @@ and assumed after it.
|
||||
|
||||
## Proofs
|
||||
|
||||
Puffs' assertion and bounds checking system is a proof checker, not a full SMT
|
||||
Wuffs' assertion and bounds checking system is a proof checker, not a full SMT
|
||||
solver or automated theorem prover. It verifies explicit annotations instead of
|
||||
the more open-ended task of searching for implicit proof steps. This involves
|
||||
more explicit work by the programmer, but compile times matter, so Puffs is
|
||||
more explicit work by the programmer, but compile times matter, so Wuffs is
|
||||
fast (and dumb) instead of smart (and slow).
|
||||
|
||||
Nonetheless, the Puffs syntax is regular (and unlike C++, does not require a
|
||||
symbol table to parse), so it should be straightforward to transform Puffs code
|
||||
Nonetheless, the Wuffs syntax is regular (and unlike C++, does not require a
|
||||
symbol table to parse), so it should be straightforward to transform Wuffs code
|
||||
to and from file formats used by more sophisticated proof engines.
|
||||
|
||||
Some rules are applied automatically by the proof checker. For example, if `x
|
||||
@@ -253,15 +253,15 @@ type system) or dynamic constraint (an asserted fact), then the checker knows
|
||||
that the expression `x + y` is bounded above by `10 + 5` and therefore will not
|
||||
overflow a `u8` (but would overflow a `u8[..12]`).
|
||||
|
||||
TODO: rigorously specify these automatic rules, when we have written more Puffs
|
||||
TODO: rigorously specify these automatic rules, when we have written more Wuffs
|
||||
code and thus have more experience on what rules are needed to implement
|
||||
multiple, real world image codecs.
|
||||
|
||||
Other rules are built in to the proof checker but are not applied automatically
|
||||
(see "fast... instead of smart" above). Such rules have double-quote enclosed
|
||||
names that look a little like mathematical statements. They are axiomatic, in
|
||||
that these rules are assumed, not proved, by the Puffs toolchain. They are
|
||||
typically at a higher level than e.g. Peano axioms, as Puffs emphasizes
|
||||
that these rules are assumed, not proved, by the Wuffs toolchain. They are
|
||||
typically at a higher level than e.g. Peano axioms, as Wuffs emphasizes
|
||||
practicality over theoretical minimalism. As they are axiomatic, they endeavour
|
||||
to only encode 'obvious' mathematical rules. For example, the rule named `"a <
|
||||
b: a < c; c <= b"` is one expression of transitivity: the assertion `a < b` is
|
||||
@@ -283,7 +283,7 @@ TODO: specify these built-in `via` rules, again after more experience.
|
||||
|
||||
Labeled `break` and `continue` statements enable jumping out of loops that
|
||||
aren't the most deeply nested. The syntax for labels is `while:label` instead
|
||||
of Java's `label:while`, as the former is slightly easier to parse, and Puffs
|
||||
of Java's `label:while`, as the former is slightly easier to parse, and Wuffs
|
||||
does not otherwise use labels for switch cases or goto targets.
|
||||
|
||||
TODO: describe the built in `buf1` and `buf2` types: 1- and 2-dimensional
|
||||
|
||||
Reference in new issue
Block a user