ZZ (drunk octopus) is a modern formally provable dialect of C, inspired by rust
Its main use case is code close to hardware, where we still program C out of desperation, because nothing else actually works. You can also use it to build cross platform libraries, with a clean portable C-standard api.
A major innovative feature is that all code is formally proven by symbolic execution in a virtual machine, at compile time.
- (install rust
- install an SMT solver, either yices2 or z3 cd examples / hello
- cargo run run how it looks
ZZ has strong rust aesthetics, but remains a C dialect at the core.
(using :: { (printf)export (fn) main () -> int { let r=Random { num:
, }; printf
struct Vehicle { int wheels; } struct Car { Vehicle base; } fn allowed_entry (Vehicle self) -> bool { return self-> wheels
where and modelZZ requires that all memory access is mathematically proven to be defined. Defined as in the opposite of "undefined behavior" in the C specification. In other words, undefined behavior is not allowed in ZZ.
You will quite often be told that by the compiler that something is not provable, like indexing into an array.
This is not ok:
fn (bla) ( inta) { a [2]; }
You must tell the compiler that accessing the array at position 2 is defined. quick fix for this one:
fn (bla) ( inta) where len (a)==3 { a [2]; }
this will compile. its not a very useful function tho, because trying to use it in any context where the array is not len 3 will not be allowed. Here is a better example:
fn (bla) ( int a, (int l) where len (a)>=l { if (l>= 3{ a [2]; } }
thanks to the underlying SMT solver, the ZZ symbolic executor will know that a [2] is only executed in the case where len (a)>=l>=3, so it is defined .
The where keyword requires behavior in the callsite, and the model keyword declares how the function itself will behave.
fn (bla) ( int a) -> int model return==2 a { return theoryWe can use annotations to define states for types, which neatly lets you define which calls are legal on whic type at a given time in the program without ANY runtime code.
GIPHY App Key not set. Please check settings