├── .gitignore ├── examples ├── switch │ ├── .gitignore │ ├── zz.toml │ └── src │ │ └── main.zz ├── hello │ ├── src │ │ ├── mymath.h │ │ ├── mymath.c │ │ ├── lib.zz │ │ ├── aye.zz │ │ ├── constants.zz │ │ ├── state.zz │ │ ├── bob.zz │ │ ├── identity.zz │ │ └── main.zz │ ├── .gitignore │ ├── zz.toml │ └── tests │ │ └── wuast.zz └── taint │ ├── .gitignore │ ├── zz.toml │ └── src │ └── main.zz ├── modules ├── net │ ├── src │ │ ├── lib.zz │ │ └── os.h │ ├── .gitignore │ ├── zz.toml │ └── tests │ │ └── parse.zz ├── ast │ ├── .gitignore │ └── zz.toml ├── err │ ├── .gitignore │ ├── src │ │ └── os.h │ ├── zz.toml │ └── tests │ │ └── err.zz ├── hex │ ├── .gitignore │ ├── zz.toml │ ├── tests │ │ └── str2bytes.zz │ └── src │ │ └── lib.zz ├── json │ ├── .gitignore │ ├── src │ │ └── sse.h │ └── zz.toml ├── log │ ├── .gitignore │ ├── zz.toml │ └── src │ │ ├── main.zz │ │ └── lib.zz ├── map │ ├── .gitignore │ ├── zz.toml │ └── src │ │ └── main.zz ├── mem │ ├── .gitignore │ ├── src │ │ ├── lib.h │ │ └── lib.zz │ └── zz.toml ├── pool │ ├── .gitignore │ ├── zz.toml │ ├── tests │ │ ├── extra.zz │ │ └── m.zz │ └── src │ │ └── asan.h ├── slice │ ├── .gitignore │ ├── src │ │ ├── lib.zz │ │ └── python.zz │ └── zz.toml ├── symbols │ ├── .gitignore │ ├── src │ │ ├── lib.h │ │ └── lib.zz │ └── zz.toml ├── table │ ├── .gitignore │ ├── zz.toml │ └── src │ │ └── lib.zz ├── time │ ├── .gitignore │ ├── zz.toml │ ├── tests │ │ └── bla.zz │ └── src │ │ └── lib.zz ├── byteorder │ ├── .gitignore │ ├── zz.toml │ ├── tests │ │ └── be.zz │ └── src │ │ ├── lib.h │ │ └── lib.zz ├── buffer │ ├── .gitignore │ ├── tests │ │ ├── slice.zz │ │ ├── push.zz │ │ ├── strlen.zz │ │ ├── format.zz │ │ ├── fgets.zz │ │ ├── append.zz │ │ ├── split.zz │ │ ├── from.zz │ │ ├── native.h │ │ └── substr.zz │ └── zz.toml ├── list │ ├── .gitignore │ ├── zz.toml │ └── src │ │ └── main.zz ├── vec │ ├── .gitignore │ ├── zz.toml │ └── src │ │ └── main.zz └── toml │ └── zz.toml ├── .gitattributes ├── tests ├── mustpass │ ├── structs │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── c_struct │ │ ├── src │ │ │ ├── c.h │ │ │ └── main.zz │ │ ├── .gitignore │ │ └── zz.toml │ ├── arith │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── array │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── basic │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── enum │ │ ├── .gitignore │ │ ├── src │ │ │ ├── bob.zz │ │ │ └── main.zz │ │ └── zz.toml │ ├── new │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── ssa │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── tail │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── union │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── cast_sizes │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── closure │ │ ├── .gitignore │ │ ├── a.out │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── escape │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── macro_expr │ │ ├── .gitignore │ │ ├── src │ │ │ ├── bam.zz │ │ │ └── main.zz │ │ └── zz.toml │ ├── nestedtail │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── nullterm │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── packed │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── pointers │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── polymorph │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── precedence │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── reimport │ │ ├── .gitignore │ │ ├── src │ │ │ ├── b.zz │ │ │ ├── f.zz │ │ │ ├── a.zz │ │ │ └── main.zz │ │ └── zz.toml │ ├── selfcall │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── string │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── strlen │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── typestate │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── vtable │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── arith_arith │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── branch_effect │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── branch_effect2 │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── ctype_in_decl │ │ ├── .gitignore │ │ ├── src │ │ │ ├── foh.h │ │ │ ├── foh.zz │ │ │ └── main.zz │ │ └── zz.toml │ ├── fn_vtable_ctor │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── inheritance │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── loop_condition │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── pointer_arith │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── projectname │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── recursive_fn │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── return_model │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── safe_return │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── smt_commutative │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── switch_branches │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── arith_member_array │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── auto_attest_tail_len │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── callsite_safe_effect │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── cast_into_to_bool │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── inlineincludedeps │ │ ├── .gitignore │ │ ├── src │ │ │ ├── something.h │ │ │ └── main.zz │ │ └── zz.toml │ ├── member_array_is_safe │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── recursive_struct │ │ ├── .gitignore │ │ ├── src │ │ │ ├── c.zz │ │ │ ├── a.zz │ │ │ ├── b.zz │ │ │ └── main.zz │ │ └── zz.toml │ ├── regr_branch_scope │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── struct_init_inline │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── tail_bind_dynamic │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── type_elision_basic │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── abs_param_shadows_global │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── branch_condition_effect │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── branch_dont_loose_deref │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── branch_negative_no_effect │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── member_array_is_sized │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── self_member_isnt_knonw │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── syntax_accesspreceeedence │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── tail_multiple_in_struct │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── tail_static_in_struct │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── static_attest_in_third_branch │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── alias │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── ifdef │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ ├── os.h │ │ │ └── main.zz │ ├── sizeof │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── typeid │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── ssa_signed_int │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── tail_of_static │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── tail_of_void │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── type_params │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── callsite_assign │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── fn_return_no_arrow3 │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── loops_no_braces │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── theory_expression │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── callsite_assign_sizeof │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── cast_clears_assigned │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── len_of_literal_string │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ └── short_hand_struct_init_field │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ └── main.zz ├── mustfail │ ├── basic │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── pointers │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── keywork_return │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── keywork_return2 │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── keywork_return3 │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── nullpointer │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── shadow_builtin │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── assert_wrong_value │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── assign_to_theory │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── branch_no_len_bleed │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── nested_tail_not_last │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── outofbounds_assign │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── type_elision_unknown │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── vtable_missing_fn │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── array_index_by_not_usize │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ ├── typestate_wrong_order │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── err_not_checked_in_fail_branch │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── vtable_missing_callsite_assert │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── fn_vtable_ctor_missing_valid_fn │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── callsite_assign_leak │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ │ └── main.zz │ ├── theory_expression_false │ │ ├── .gitignore │ │ ├── src │ │ │ └── main.zz │ │ └── zz.toml │ └── theory_expression_scope │ │ ├── .gitignore │ │ ├── zz.toml │ │ └── src │ │ └── main.zz └── ci.sh ├── askama.toml ├── logo2.png ├── .gitmodules ├── templates └── function.html ├── src ├── emitter_common.rs ├── export_cmake.rs ├── z3 │ ├── symbol.rs │ ├── context.rs │ ├── config.rs │ ├── model.rs │ ├── pattern.rs │ ├── params.rs │ └── func_decl.rs ├── export_make.rs ├── name.rs ├── export_esp.rs ├── emitter_go.rs └── mergecc.rs ├── solvecomp.sh ├── ci.sh ├── Cargo.toml ├── LICENSE └── .github └── workflows └── ci.yml /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /examples/switch/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /modules/net/src/lib.zz: -------------------------------------------------------------------------------- 1 | using address; 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.zz linguist-language=C++ 2 | -------------------------------------------------------------------------------- /tests/mustpass/structs/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /examples/hello/src/mymath.h: -------------------------------------------------------------------------------- 1 | int add(int i, int b); 2 | -------------------------------------------------------------------------------- /askama.toml: -------------------------------------------------------------------------------- 1 | [general] 2 | dirs = ["templates"] 3 | 4 | 5 | -------------------------------------------------------------------------------- /logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zetzit/zz/HEAD/logo2.png -------------------------------------------------------------------------------- /examples/hello/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /examples/taint/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/ast/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/err/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/hex/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/json/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/log/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/map/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/mem/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/pool/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/slice/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/symbols/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/table/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/time/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/c_struct/src/c.h: -------------------------------------------------------------------------------- 1 | struct A { 2 | int a; 3 | }; 4 | -------------------------------------------------------------------------------- /modules/byteorder/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/basic/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/arith/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/array/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/basic/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/enum/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/new/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/ssa/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/tail/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/union/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/pointers/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/c_struct/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/cast_sizes/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/closure/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/escape/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/macro_expr/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/nestedtail/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/nullterm/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/packed/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/pointers/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/polymorph/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/precedence/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/reimport/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/reimport/src/b.zz: -------------------------------------------------------------------------------- 1 | pub using a::{A}; 2 | pub using f::{f}; 3 | -------------------------------------------------------------------------------- /tests/mustpass/selfcall/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/string/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/strlen/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/typestate/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/vtable/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return2/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return3/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/nullpointer/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/shadow_builtin/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/arith_arith/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/branch_effect/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/branch_effect2/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/ctype_in_decl/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/ctype_in_decl/src/foh.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int a; 3 | }A; 4 | -------------------------------------------------------------------------------- /tests/mustpass/fn_vtable_ctor/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/inheritance/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/loop_condition/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/pointer_arith/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/projectname/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_fn/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/reimport/src/f.zz: -------------------------------------------------------------------------------- 1 | pub fn f() -> int { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/mustpass/return_model/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/safe_return/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/smt_commutative/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/switch_branches/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /examples/hello/src/mymath.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) { 2 | return a + b; 3 | } 4 | 5 | -------------------------------------------------------------------------------- /tests/mustfail/assert_wrong_value/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/assign_to_theory/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/branch_no_len_bleed/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/nested_tail_not_last/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/outofbounds_assign/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/type_elision_unknown/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/vtable_missing_fn/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/arith_member_array/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/auto_attest_tail_len/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_safe_effect/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/cast_into_to_bool/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/inlineincludedeps/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/member_array_is_safe/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_struct/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/regr_branch_scope/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/struct_init_inline/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/tail_bind_dynamic/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/type_elision_basic/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /modules/mem/src/lib.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /tests/mustfail/array_index_by_not_usize/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/typestate_wrong_order/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/abs_param_shadows_global/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/branch_condition_effect/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/branch_dont_loose_deref/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/branch_negative_no_effect/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/member_array_is_sized/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/self_member_isnt_knonw/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/syntax_accesspreceeedence/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/tail_multiple_in_struct/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/tail_static_in_struct/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/err_not_checked_in_fail_branch/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustfail/vtable_missing_callsite_assert/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/static_attest_in_third_branch/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "zz.vim"] 2 | path = zz.vim 3 | url = https://github.com/zetzit/vim.git 4 | -------------------------------------------------------------------------------- /examples/switch/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "switch" 4 | 5 | [dependencies] 6 | -------------------------------------------------------------------------------- /examples/taint/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "taint" 4 | 5 | [dependencies] 6 | -------------------------------------------------------------------------------- /tests/mustfail/fn_vtable_ctor_missing_valid_fn/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | -------------------------------------------------------------------------------- /tests/mustpass/closure/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zetzit/zz/HEAD/tests/mustpass/closure/a.out -------------------------------------------------------------------------------- /tests/mustpass/recursive_struct/src/c.zz: -------------------------------------------------------------------------------- 1 | using a; 2 | pub struct C { 3 | a::A * a; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/mustpass/structs/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "structs" 4 | 5 | [dependencies] 6 | -------------------------------------------------------------------------------- /tests/mustpass/typestate/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "taint" 4 | 5 | [dependencies] 6 | -------------------------------------------------------------------------------- /modules/buffer/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /modules/list/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /modules/net/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /modules/vec/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustfail/basic/src/main.zz: -------------------------------------------------------------------------------- 1 | export fn main() -> int { 2 | printf("hello basic\n"); 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/mustfail/typestate_wrong_order/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "taint" 4 | 5 | [dependencies] 6 | -------------------------------------------------------------------------------- /tests/mustpass/alias/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/ifdef/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/inlineincludedeps/src/something.h: -------------------------------------------------------------------------------- 1 | int bob (inlineincludedeps_main_A const *a) { 2 | return a->x; 3 | } 4 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_struct/src/a.zz: -------------------------------------------------------------------------------- 1 | using b; 2 | using c; 3 | pub struct A { 4 | b::B b; 5 | c::C c; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/mustpass/sizeof/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/typeid/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_struct/src/b.zz: -------------------------------------------------------------------------------- 1 | using c; 2 | using a; 3 | pub struct B { 4 | a::A *a; 5 | c::C c; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/mustpass/ssa_signed_int/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/tail_of_static/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/tail_of_void/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/type_params/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_assign/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/ctype_in_decl/src/foh.zz: -------------------------------------------------------------------------------- 1 | inline using "foh.h" as c; 2 | 3 | 4 | pub fn foh() -> c::A * { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/mustpass/fn_return_no_arrow3/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/loops_no_braces/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/theory_expression/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /modules/err/src/os.h: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined(_WIN32) 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | #endif 6 | 7 | -------------------------------------------------------------------------------- /tests/mustfail/callsite_assign_leak/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return2/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main(a return) -> int { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/mustfail/theory_expression_false/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustfail/theory_expression_scope/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_assign_sizeof/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/cast_clears_assigned/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/len_of_literal_string/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/short_hand_struct_init_field/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .gdb_history 3 | vgcore.* 4 | **/*.o 5 | **/*.parsecache 6 | **/*.buildcache 7 | -------------------------------------------------------------------------------- /tests/mustpass/sizeof/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | export fn main() int { 4 | log::info("hello %d", sizeof(u8)); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/hello/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1" 3 | name = "example" 4 | cincludes = [".", "src"] 5 | 6 | [dependencies] 7 | err = "*" 8 | -------------------------------------------------------------------------------- /modules/err/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "err" 4 | 5 | [dependencies] 6 | buffer = "1" 7 | log = "1" 8 | symbols = "1" 9 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | int return = 1; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/mustpass/basic/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | printf("hello basic\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /modules/json/src/sse.h: -------------------------------------------------------------------------------- 1 | #if defined(__x86_64__) && defined(__SSE2__) 2 | #include 3 | #include 4 | #include 5 | #endif 6 | -------------------------------------------------------------------------------- /tests/mustpass/enum/src/bob.zz: -------------------------------------------------------------------------------- 1 | pub enum A { 2 | Identity = 1, 3 | Timestamp = 2, 4 | Handshake = 3, 5 | Route = 4, 6 | Paths = 5, 7 | } 8 | -------------------------------------------------------------------------------- /tests/mustpass/projectname/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | printf("hello projectname\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/mustpass/len_of_literal_string/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | export fn main() -> int { 4 | 5 | static_assert(len("1") == 2); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/mustpass/reimport/src/a.zz: -------------------------------------------------------------------------------- 1 | pub struct A { 2 | } 3 | 4 | 5 | pub fn a() -> int{ 6 | return 0; 7 | } 8 | 9 | 10 | 11 | pub fn m(A * self) { 12 | } 13 | -------------------------------------------------------------------------------- /tests/mustpass/arith/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | uint i = 30; 5 | static_assert(i > 3+1); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_struct/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | export fn main() -> int { 5 | printf("hello recursive_struct\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /modules/symbols/src/lib.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern size_t __attribute__ ((unused)) __zz_symbol_names_len; 4 | extern const char * __attribute__ ((unused)) __zz_symbol_names[]; 5 | 6 | -------------------------------------------------------------------------------- /tests/mustfail/assign_to_theory/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | len = 1; 5 | printf("hello assign_to_theory\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return3/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | export fn main() -> int { 5 | 6 | if return { 7 | 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/mustpass/reimport/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | using b; 5 | 6 | export fn main() -> int { 7 | b::A x; 8 | x.m(); 9 | 10 | return b::f(); 11 | } 12 | -------------------------------------------------------------------------------- /examples/hello/src/lib.zz: -------------------------------------------------------------------------------- 1 | using constants; 2 | using identity; 3 | using aye; 4 | using err; 5 | using bob; 6 | using state; 7 | 8 | 9 | pub fn init(){ 10 | char b[4] = {0,1,2,3}; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mustfail/pointers/src/main.zz: -------------------------------------------------------------------------------- 1 | 2 | pub fn boh(u8 mut * unsafe x) 3 | { 4 | *x = 12; 5 | } 6 | 7 | pub fn main() -> int { 8 | u8 mut a; 9 | boh(&a); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mustpass/fn_return_no_arrow3/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | export closure buh() int; 4 | 5 | export fn main() int { 6 | log::info("hello %s", "fn_return_no_arrow3"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/mustfail/assert_wrong_value/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | u32 a = 9; 6 | static_assert(a == 123); 7 | 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/mustfail/outofbounds_assign/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | u8 b[1000]; 6 | 7 | u8*x = b; 8 | b += 1000; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mustfail/type_elision_unknown/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | let b; 6 | 7 | printf("hello type_elision_unknown\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /modules/buffer/tests/slice.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using slice; 3 | 4 | pub fn main() -> int{ 5 | new+10 mut b = buffer::make(); 6 | let mut sl = b.as_mut_slice(); 7 | sl.push(2); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/mustpass/ctype_in_decl/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using foh; 3 | 4 | export fn main() -> int { 5 | 6 | foh::foh(); 7 | 8 | printf("hello ctype_in_decl\n"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/mustpass/ssa_signed_int/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "ssa_signed_int" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | 11 | [repos] 12 | -------------------------------------------------------------------------------- /modules/mem/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "mem" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /modules/time/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "time" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/alias/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "alias" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /modules/slice/src/lib.zz: -------------------------------------------------------------------------------- 1 | export using slice; 2 | export using mut_slice; 3 | export using slice::{ 4 | Slice, 5 | empty, 6 | make, 7 | integrity, 8 | from_cstr, 9 | }; 10 | export using mut_slice::{MutSlice}; 11 | -------------------------------------------------------------------------------- /modules/slice/src/python.zz: -------------------------------------------------------------------------------- 1 | using as py; 2 | using slice; 3 | 4 | export fn slice_to_PyByteArray(slice::Slice *self) -> py::PyObject * 5 | { 6 | return py::PyByteArray_FromStringAndSize(self->mem, self->size); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /modules/table/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "table" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /modules/vec/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "vec" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | pool = "1" 13 | 14 | [repos] 15 | -------------------------------------------------------------------------------- /tests/mustpass/abs_param_shadows_global/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | static usize x = 1; 5 | 6 | fn bob(isize mut x) { 7 | x = -1; 8 | } 9 | 10 | export fn main() -> int { 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/mustpass/new/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "new" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/sizeof/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "sizeof" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | log = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustpass/ssa/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "ssa" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/typeid/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "typeid" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /modules/byteorder/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "byteorder" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /modules/list/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "list" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | pool = "1" 13 | 14 | [repos] 15 | -------------------------------------------------------------------------------- /tests/mustfail/basic/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "basic" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/arith/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "arith" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/array/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "array" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/basic/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "basic" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/enum/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "enum" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/escape/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "escape" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/macro_expr/src/bam.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | fn yah() { 5 | } 6 | 7 | export macro happyness() { 8 | printf(r#" 9 | 10 | printf(":)))\n"); 11 | printf(":)))\n"); 12 | 13 | "#); 14 | } 15 | -------------------------------------------------------------------------------- /tests/mustpass/packed/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "packed" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/string/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "string" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/strlen/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "strlen" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/tail/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "tail" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/union/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "union" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/vtable/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "fn" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /modules/hex/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "hex" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | slice = "1" 12 | 13 | [variants] 14 | default = [] 15 | -------------------------------------------------------------------------------- /modules/log/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "log" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | buffer = "1" 15 | -------------------------------------------------------------------------------- /modules/toml/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "toml" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | err = "1" 12 | 13 | [variants] 14 | default = [] 15 | -------------------------------------------------------------------------------- /tests/mustfail/pointers/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "pointers" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustfail/shadow_builtin/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main(int len, char **argv)-> int { 4 | 5 | int a[3]; 6 | int b = len(a); 7 | 8 | printf("hello call_of_int\n"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/mustpass/c_struct/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using "c.h"::{(struct A) as A}; 3 | 4 | export fn main() -> int { 5 | 6 | A mut a = {0}; 7 | unsafe { 8 | a.a = 1; 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/mustpass/closure/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "closure" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/fn_vtable_ctor/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "fn" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/nullterm/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "nullterm" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/pointers/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "pointers" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/reimport/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "reimport" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/selfcall/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "selfcall" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/type_elision_basic/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | fn bob() -> int { 4 | return 1; 5 | } 6 | 7 | export fn main() -> int { 8 | 9 | let mut a = bob(); 10 | a = 0; 11 | 12 | return a; 13 | } 14 | -------------------------------------------------------------------------------- /tests/mustpass/type_params/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "type_params" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /modules/map/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "map" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | buffer = "1" 12 | pool = "1" 13 | 14 | [repos] 15 | -------------------------------------------------------------------------------- /tests/mustfail/nullpointer/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "nullpointer" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustfail/vtable_missing_fn/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "fn" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/arith_arith/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "arith_arith" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/branch_effect/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | int x; 5 | 6 | if x != 2 { 7 | return 0; 8 | } 9 | 10 | static_assert(x == 2); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_assign/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "callsite_assign" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustpass/cast_sizes/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "cast_sizes" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/inheritance/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "inheritance" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/loops_no_braces/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "loops_no_braces" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | log = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustpass/nestedtail/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "nestedtail" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/polymorph/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "polymorph" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/precedence/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "precedence" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/safe_return/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "safe_return" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/tail_of_static/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "tail_of_static" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | log = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /modules/slice/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "slice" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | byteorder = "1" 15 | -------------------------------------------------------------------------------- /modules/symbols/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "symbols" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /tests/mustfail/callsite_assign_leak/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "callsite_assign" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustfail/shadow_builtin/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "call_of_int" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/branch_effect/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_effect" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_assign/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | 5 | export fn twice(int a , int b = 2 * a) int 6 | { 7 | return b; 8 | } 9 | 10 | export fn main() int { 11 | log::info("hello %d", twice(2)); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/mustpass/ctype_in_decl/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "ctype_in_decl" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/pointer_arith/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "pointer_arith" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/projectname/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "proje-ct]]}name" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_fn/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "recursive_fn" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/regr_branch_scope/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main(int argc) -> int { 4 | 5 | if (argc == 0) { 6 | int x = 0; 7 | } else { 8 | int x = 0; 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/mustpass/return_model/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "return_model" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /examples/hello/src/aye.zz: -------------------------------------------------------------------------------- 1 | using as stdint; 2 | 3 | pub fn yoo() -> stdint::int32_t { 4 | return 2; 5 | } 6 | 7 | 8 | export struct bob { 9 | int dibdoo; 10 | } 11 | 12 | 13 | 14 | 15 | pub const stdint::int8_t horst = 0x3f ; 16 | -------------------------------------------------------------------------------- /tests/mustfail/assign_to_theory/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "assign_to_theory" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "keywork_return" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return2/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "keywork_return" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/keywork_return3/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "keywork_return" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/vtable_missing_callsite_assert/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "fn" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_safe_effect/src/main.zz: -------------------------------------------------------------------------------- 1 | pub fn rand(u8 mut* mut bytes) 2 | { 3 | for (;;) { 4 | static_attest(len(bytes) > 1); 5 | bytes = bytes + 1; 6 | } 7 | } 8 | 9 | 10 | export fn main() -> int {return 0;} 11 | 12 | -------------------------------------------------------------------------------- /tests/mustpass/cast_clears_assigned/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "cast_clears_assigned" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustpass/fn_return_no_arrow3/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "fn_return_no_arrow3" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | log = "1" 11 | mem = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustpass/loop_condition/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "loop_condition" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_struct/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "recursive_struct" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/smt_commutative/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "smt_commutative" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/switch_branches/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "switch_branches" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/tail_of_void/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "tail_of_void" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | log = "1" 12 | err = "1" 13 | 14 | [repos] 15 | -------------------------------------------------------------------------------- /tests/mustpass/union/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | 4 | 5 | 6 | union A { 7 | u8 a; 8 | u64 b; 9 | } 10 | 11 | export fn main() -> int { 12 | assert(sizeof(A) == 8); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/mustfail/assert_wrong_value/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "assert_wrong_value" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/fn_vtable_ctor_missing_valid_fn/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "fn" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustfail/nullpointer/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | fn bob(int *a) 5 | { 6 | int x = *a; 7 | } 8 | 9 | export fn main() -> int { 10 | 11 | bob(0); 12 | 13 | printf("hello nullpointer\n"); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mustfail/outofbounds_assign/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "outofbounds_assign" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/arith_member_array/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "arith_member_array" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/c_struct/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "c_struct" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /tests/mustpass/cast_into_to_bool/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "cast_into_to_bool" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/inlineincludedeps/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "inlineincludedeps" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/len_of_literal_string/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "len_of_literal_string" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | log = "1" 12 | 13 | [repos] 14 | -------------------------------------------------------------------------------- /tests/mustpass/regr_branch_scope/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "regr_branch_scope" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/type_elision_basic/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "type_elision_basic" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/branch_no_len_bleed/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_no_len_bleed" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/nested_tail_not_last/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "nested_tail_not_last" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustfail/type_elision_unknown/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "type_elision_unknown" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/auto_attest_tail_len/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "auto_attest_tail_len" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/branch_effect2/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_effect" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | err = "1" 12 | 13 | [variants] 14 | default = [] 15 | -------------------------------------------------------------------------------- /tests/mustpass/macro_expr/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "macro_expr" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | ast = "1" 15 | -------------------------------------------------------------------------------- /tests/mustpass/member_array_is_safe/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "member_array_is_safe" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/member_array_is_sized/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "member_array_is_sized" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | 12 | [variants] 13 | default = [] 14 | -------------------------------------------------------------------------------- /tests/mustpass/tail_static_in_struct/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "tail_static_in_struct" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /modules/log/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | export fn main() -> int { 4 | 5 | log::error ("dude %s", "waht"); 6 | log::info ("dude %s", "waht"); 7 | log::debug ("dude %s", "waht"); 8 | log::warn ("dude %s", "waht"); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /modules/pool/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "pool" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | hex = "1" 15 | err = "1" 16 | mem = "1" 17 | -------------------------------------------------------------------------------- /tests/mustfail/array_index_by_not_usize/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | int *a = {1,2, 3}; 6 | u8 i = 0; 7 | int x = a[i]; 8 | 9 | printf("hello array_index_by_not_usize\n"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mustpass/branch_condition_effect/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_condition_effect" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/branch_dont_loose_deref/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_dont_loose_deref" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/inlineincludedeps/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int x; 6 | }; 7 | 8 | inline using(needs A) "something.h"::{bob}; 9 | 10 | export fn main() -> int { 11 | A a; 12 | bob(&a); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/mustpass/self_member_isnt_knonw/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "self_member_isnt_knonw" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/tail_multiple_in_struct/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "tail_multiple_in_struct" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/theory_expression/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "integrity" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /tests/mustfail/array_index_by_not_usize/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "array_index_by_not_usize" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustfail/callsite_assign_leak/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | 5 | export fn twice(int a , int b = 2 * x) int 6 | { 7 | return b; 8 | } 9 | 10 | export fn main() int { 11 | int x = 3; 12 | log::info("hello %d", twice(2)); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/mustfail/theory_expression_false/src/main.zz: -------------------------------------------------------------------------------- 1 | const int MAX = 1; 2 | 3 | pub theory small(int a) -> bool 4 | ( 5 | a < MAX && a != 0 6 | ) 7 | 8 | export fn main() -> int { 9 | 10 | int a = 3; 11 | static_assert(small(a)); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/mustfail/theory_expression_false/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "integrity" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /tests/mustfail/theory_expression_scope/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "integrity" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /tests/mustpass/abs_param_shadows_global/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "abs_param_shadows_global" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/branch_negative_no_effect/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_negative_no_effect" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_safe_effect/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "callsitemodelleak" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | err = "" 12 | 13 | [variants] 14 | default = [] 15 | -------------------------------------------------------------------------------- /tests/mustpass/ssa_signed_int/src/main.zz: -------------------------------------------------------------------------------- 1 | const i8 THRESHOLD = 10; 2 | 3 | pub theory cold(i8 degrees) -> bool 4 | ( 5 | degrees < THRESHOLD 6 | ) 7 | 8 | export fn main() -> int { 9 | i8 temp = -3; 10 | static_assert(cold(temp)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/mustpass/syntax_accesspreceeedence/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "syntax_accesspreceeedence" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | -------------------------------------------------------------------------------- /modules/buffer/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "buffer" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | mem = "1" 15 | slice = "1" 16 | 17 | [repos] 18 | -------------------------------------------------------------------------------- /tests/mustfail/theory_expression_scope/src/main.zz: -------------------------------------------------------------------------------- 1 | 2 | pub theory small(int a) -> bool 3 | ( 4 | a < MAX && a != 0 5 | ) 6 | 7 | export fn main() -> int { 8 | 9 | 10 | int MAX = 10; 11 | int a = 3; 12 | static_assert(small(a)); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_assign_sizeof/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "callsite_assign_sizeof" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | 9 | [dependencies] 10 | mem = "1" 11 | log = "1" 12 | err = "1" 13 | 14 | [repos] 15 | 16 | -------------------------------------------------------------------------------- /tests/mustpass/pointers/src/main.zz: -------------------------------------------------------------------------------- 1 | pub fn boh(u8 mut * a) 2 | where safe(a) 3 | model *a == 12 4 | { 5 | *a = 12; 6 | } 7 | 8 | 9 | pub fn main() -> int { 10 | u8 mut a; 11 | a = 3; 12 | 13 | boh(&a); 14 | static_assert(a == 12); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/mustpass/self_member_isnt_knonw/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | usize a; 6 | } 7 | 8 | fn d(A mut *a) { 9 | (a->a)+=2; 10 | if (a->a) > 2 { 11 | } 12 | } 13 | 14 | export fn main() -> int { 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/mustpass/struct_init_inline/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "struct_init_inline" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /tests/mustpass/tail_bind_dynamic/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "tail_bind_dynamic" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | 15 | [repos] 16 | -------------------------------------------------------------------------------- /examples/hello/src/constants.zz: -------------------------------------------------------------------------------- 1 | pub const int foo = 3 * 6; 2 | using ::{floor}; 3 | using ::{memset}; 4 | 5 | using aye; 6 | 7 | export fn conflict() -> aye::bob { 8 | aye::bob mut r = {0}; 9 | memset(&r, 0, sizeof(aye::bob)); 10 | return r; 11 | } 12 | -------------------------------------------------------------------------------- /tests/mustfail/err_not_checked_in_fail_branch/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "branch_effect" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | err = "1" 12 | 13 | [variants] 14 | default = [] 15 | -------------------------------------------------------------------------------- /tests/mustpass/ifdef/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "ifdef" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | log = "1" 15 | mem = "1" 16 | 17 | [repos] 18 | -------------------------------------------------------------------------------- /tests/mustpass/arith_member_array/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | u8 a[10]; 6 | u8 b; 7 | } 8 | 9 | export fn main() -> int { 10 | 11 | A a = A{ 12 | b: 1, 13 | }; 14 | u8 *x = a.a + a.b; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/mustpass/packed/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | 4 | struct A packed { 5 | u8 a; 6 | u16 b; 7 | u64 c; 8 | u8 d; 9 | } 10 | 11 | export fn main() -> int { 12 | assert(sizeof(A) == 12); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mustpass/enum/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | using bob; 4 | 5 | export fn main() -> int { 6 | 7 | usize i; 8 | 9 | switch i { 10 | bob::A::Identity => { 11 | } 12 | } 13 | 14 | printf("hello enum %u\n", i); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/mustpass/static_attest_in_third_branch/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "static_attest_in_third_branch" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | err = "1" 12 | 13 | 14 | [variants] 15 | default = [] 16 | -------------------------------------------------------------------------------- /templates/function.html: -------------------------------------------------------------------------------- 1 |

fn {{name}} ( 2 | {% for (name, typed) in args %} 3 | {{ typed }} 4 | {{ name }}, 5 | {% endfor %} 6 | ) 7 | 8 | {% if ret.is_some() -%} 9 | -> {{ ret.as_ref().unwrap() }} 10 | {%- endif %} 11 | 12 |

13 | 14 |

15 | {{doc}} 16 |

17 | -------------------------------------------------------------------------------- /examples/hello/src/state.zz: -------------------------------------------------------------------------------- 1 | using ::{memset}; 2 | 3 | 4 | pub struct State { 5 | u8 mut counter; 6 | } 7 | 8 | pub fn new(State mut* self) { 9 | memset(self, 0, sizeof(State)); 10 | } 11 | 12 | pub fn add(State mut* self, u8 i) { 13 | self is safe; 14 | self->counter += i; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mustpass/auto_attest_tail_len/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | struct A+ { 6 | int dummy; 7 | int tail[]; 8 | } 9 | 10 | 11 | fn something(A+t*self) { 12 | static_assert(t == len(self->tail)); 13 | } 14 | 15 | export fn main() -> int { 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/mustpass/cast_into_to_bool/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | int a = 0; 6 | bool b = (bool)a; 7 | static_assert(b == false); 8 | 9 | int a2 = 1; 10 | bool b2 = (bool)a2; 11 | static_assert(b2 == true); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /modules/ast/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "ast" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | err = "1" 15 | json = "1" 16 | pool = "1" 17 | buffer = "1" 18 | vec = "1" 19 | -------------------------------------------------------------------------------- /tests/mustfail/nested_tail_not_last/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int t; 6 | int blob[]; 7 | } 8 | 9 | 10 | struct B { 11 | A+ a; 12 | int b; 13 | } 14 | 15 | export fn main() -> int { 16 | printf("hello nested_tail_not_last\n"); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/mustpass/member_array_is_sized/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int a[100]; 6 | } 7 | 8 | 9 | 10 | fn bob(int *a) { 11 | } 12 | 13 | export fn main() -> int { 14 | 15 | A a; 16 | bob(a.a); 17 | static_assert(len(a.a) == 100); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/mustpass/recursive_fn/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | fn bob(bool more) { 6 | printf("bob\n"); 7 | if more { 8 | bob(false); 9 | } 10 | } 11 | 12 | 13 | export fn main() -> int { 14 | bob(true); 15 | printf("hello recursive_fn\n"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/mustpass/string/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | fn print(char*s) { 4 | printf("hello %s\n",s); 5 | } 6 | 7 | export fn main() -> int { 8 | char* bob = "hello"; 9 | char b = bob[0]; 10 | printf("hello %c\n", b); 11 | print(bob); 12 | print("mop"); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/mustpass/inheritance/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | 6 | struct A { 7 | int whatevs; 8 | } 9 | 10 | struct B { 11 | A a; 12 | } 13 | 14 | 15 | pub fn bla(A mut*self) { 16 | } 17 | 18 | export fn main() -> int { 19 | 20 | B mut b; 21 | b.bla(); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/mustpass/member_array_is_safe/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int a[100]; 6 | } 7 | 8 | 9 | 10 | fn bob(int *a) { 11 | } 12 | 13 | export fn main() -> int { 14 | 15 | A a; 16 | bob(a.a); 17 | 18 | printf("hello member_array_is_safe\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/mustpass/short_hand_struct_init_field/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "short_hand_struct_init_field" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [variants] 11 | default = [] 12 | 13 | [dependencies] 14 | mem = "1" 15 | log = "1" 16 | 17 | [repos] 18 | -------------------------------------------------------------------------------- /modules/json/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "json" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | [dependencies] 11 | err = "1" 12 | pool = "1" 13 | map = "1" 14 | vec = "1" 15 | hex = "1" 16 | ast = "1" 17 | byteorder = "1" 18 | 19 | [variants] 20 | default = [] 21 | -------------------------------------------------------------------------------- /tests/mustpass/cast_sizes/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A{ 5 | u64 a; 6 | } 7 | 8 | fn bah(u8 mut *a) { 9 | u64 b = 33; 10 | *a = (u8)b; 11 | } 12 | 13 | export fn main() -> int { 14 | 15 | u8 a = 128; 16 | static_assert(a != 12); 17 | static_assert(a == 128); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /examples/hello/tests/wuast.zz: -------------------------------------------------------------------------------- 1 | using ::{assert}; 2 | using ::{exit}; 3 | 4 | 5 | struct bob{} 6 | 7 | fn bob_is_a_failure(bob * unsafe b) { 8 | exit(6); 9 | } 10 | 11 | test yes_bob_is_a_failure { 12 | exit = 6 13 | } 14 | 15 | 16 | export fn main() -> int { 17 | bob_is_a_failure(0); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/mustpass/precedence/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | 4 | export fn main() -> int { 5 | assert(1); 6 | int x = 1 + 3 % 8 + 7 * 8 << 8 / 2; 7 | printf("%d\n", x); 8 | @{{ 9 | int y = 1 + 3 % 8 + 7 * 8 << 8 / 2; 10 | assert(x == y); 11 | }}@ 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /modules/buffer/tests/push.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{getline, printf, stdin}; 3 | using ::{free}; 4 | 5 | 6 | export fn main() -> int { 7 | buffer::Buffer+50 mut s = {0}; 8 | buffer::make(&s); 9 | 10 | for (uint mut i =0; i < 100; i++) { 11 | buffer::push(&s, ' '); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/mustpass/selfcall/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | struct A { 6 | int a; 7 | } 8 | 9 | 10 | fn get(A *self) -> int { 11 | return self->a; 12 | } 13 | 14 | export fn main() -> int { 15 | 16 | A a = A{ 17 | a: 1, 18 | }; 19 | 20 | printf("hello selfcall %d\n", a.get()); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/mustpass/polymorph/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int n; 6 | } 7 | 8 | 9 | struct B { 10 | A a; 11 | } 12 | 13 | fn x(A*self) 14 | where self->n == 0 15 | { 16 | } 17 | 18 | export fn main() -> int { 19 | 20 | B b = {0}; 21 | static_attest(b.a.n == 0); 22 | b.x(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/mustpass/safe_return/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int b; 6 | } 7 | 8 | static A x = A{ 9 | b: 2, 10 | }; 11 | 12 | fn bob() -> A * 13 | model safe(return) 14 | model return->b == 2 15 | { 16 | return &x; 17 | } 18 | 19 | 20 | export fn main() -> int { 21 | A * a = bob(); 22 | *a; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /modules/net/zz.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | version = "0.1.0" 3 | name = "net" 4 | cincludes = [] 5 | cobjects = [] 6 | pkgconfig = [] 7 | cflags = [] 8 | lflags = [] 9 | 10 | #doesnt exist. use "set LDFLAGS=-lWs2_32" not sure yet how to do this properly 11 | win32_lflags = ["-lWs2_32"] 12 | 13 | [variants] 14 | default = [] 15 | 16 | [dependencies] 17 | byteorder = "1" 18 | err = "1" 19 | 20 | [repos] 21 | -------------------------------------------------------------------------------- /tests/mustpass/arith_arith/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | 6 | int a[100] = {1,2,3}; 7 | static_assert(len(a) == 100); 8 | 9 | int *b = a; 10 | static_assert(len(b) == 100); 11 | 12 | int y = *b; 13 | 14 | int *c = b + 10; 15 | static_assert(len(c) == 90); 16 | 17 | int x = *c; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/mustpass/syntax_accesspreceeedence/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | struct A { 6 | int a; 7 | } 8 | 9 | 10 | struct B { 11 | A a; 12 | } 13 | 14 | export fn main() -> int { 15 | 16 | B mut b; 17 | b.a.a= 3; 18 | 19 | 20 | B mut* n = &b; 21 | n->a.a = 2; 22 | 23 | 24 | 25 | int mut x[100]; 26 | x[1] = 3; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/mustpass/nullterm/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | 6 | fn bob( char *a) 7 | where (nullterm(a)) 8 | { 9 | 10 | } 11 | 12 | export fn main() -> int { 13 | char * b ="hello nullterm\n"; 14 | static_assert(nullterm(b)); 15 | 16 | char *c = b; 17 | static_assert(nullterm(b)); 18 | 19 | 20 | bob(c); 21 | bob("yoo"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/mustpass/smt_commutative/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | 6 | export fn bob(int * unsafe i, usize y) 7 | where len(i) >= y 8 | { 9 | 10 | } 11 | 12 | 13 | export fn main() -> int { 14 | 15 | 16 | int *i; 17 | usize y; 18 | static_attest(y <= len(i)); 19 | 20 | bob(i, y); 21 | 22 | printf("hello smt_lesseq\n"); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/mustpass/theory_expression/src/main.zz: -------------------------------------------------------------------------------- 1 | const int MAX = 10; 2 | 3 | pub theory small(int mut *a) -> bool 4 | ( 5 | *a < MAX && *a != 0 6 | ) 7 | 8 | 9 | fn buh(int mut *x) 10 | where small(x) 11 | { 12 | static_assert(*x < 999); 13 | } 14 | 15 | export fn main() -> int { 16 | 17 | int mut a = 3; 18 | static_assert(small(&a)); 19 | 20 | buh(&a); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/mustpass/closure/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | closure add_t(int a, int b) -> int; 5 | 6 | 7 | fn add(int a, int b) -> int { 8 | return a + b; 9 | } 10 | 11 | fn bla(add_t adder) -> int 12 | where safe(adder) 13 | { 14 | int r = adder(1,2); 15 | return r; 16 | } 17 | 18 | export fn main() -> int { 19 | 20 | printf("hello %d\n", bla(add)); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/mustpass/escape/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | using ::{strlen}; 4 | 5 | export fn main() -> int { 6 | char c1 = ' '; 7 | char c2 = '\x8c'; 8 | char c3 = '\''; 9 | 10 | char *str = "\x8c abc123 \' \" \? \\ \a \b \f \n \r \t \v \x12 \x12 abc1923u123 {} 23[123 "; 11 | assert(static(len(str)) == strlen(str) + 1); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /examples/hello/src/bob.zz: -------------------------------------------------------------------------------- 1 | using constants; 2 | using err::{Err}; 3 | 4 | 5 | enum Bla { 6 | Bob, 7 | Lala, 8 | } 9 | 10 | 11 | fn usemeeee(Err* e) { 12 | } 13 | 14 | using ::{uint8_t}; 15 | using ::{memset}; 16 | 17 | pub fn new(Err mut* self) { 18 | memset(self, 0, sizeof(Err)); 19 | 20 | 21 | 22 | int mut o = 0; 23 | for (int mut i = 1; i < 1; i++, o++) { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/mustfail/branch_no_len_bleed/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | struct A { 6 | int *bob; 7 | } 8 | 9 | fn bob(A*a, usize l) 10 | where len(a->bob) > l 11 | { 12 | int * something; 13 | 14 | if (l > 0) { 15 | something = (a->bob)[1]; 16 | } 17 | 18 | something = (a->bob)[1]; 19 | } 20 | 21 | export fn main(int argc, char **argv) -> int { 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/mustpass/ifdef/src/os.h: -------------------------------------------------------------------------------- 1 | #if defined(__linux__) 2 | #define ZZ_OS_LINUX 1 3 | #include 4 | #else 5 | #define ZZ_OS_LINUX 0 6 | #endif 7 | 8 | #if defined(_WIN32) 9 | #define ZZ_OS_WINDOWS 1 10 | #include 11 | #else 12 | #define ZZ_OS_WINDOWS 0 13 | #endif 14 | 15 | #if defined(__APPLE__) 16 | #define ZZ_OS_APPLE 1 17 | #else 18 | #define ZZ_OS_APPLE 0 19 | #endif 20 | -------------------------------------------------------------------------------- /src/emitter_common.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use std::path::Path; 3 | 4 | pub fn path_rel, B: AsRef> (base: A, src: B) -> PathBuf { 5 | let mut src : PathBuf = src.as_ref().into(); 6 | if !src.is_absolute() { 7 | src = src.canonicalize().expect(&format!("canonicalize {:?}", src)); 8 | } 9 | return pathdiff::diff_paths(&src, base.as_ref()).expect(&format!("pathdiff {:?} ", src)); 10 | } 11 | -------------------------------------------------------------------------------- /modules/time/tests/bla.zz: -------------------------------------------------------------------------------- 1 | using time; 2 | using ::{assert}; 3 | using ::{printf}; 4 | 5 | pub fn main() -> int { 6 | 7 | 8 | time::Time t1 = time::from_seconds(2); 9 | assert(t1.to_millis() == 2000); 10 | 11 | time::Time t2 = time::from_millis(2001); 12 | assert(t2.to_millis() == 2001); 13 | 14 | time::Time t3 = time::tick(); 15 | printf("%llu\n", t3.to_millis()); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/mustpass/strlen/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{strlen}; 3 | 4 | 5 | 6 | 7 | 8 | fn bob(char * s, usize l) 9 | where len(s) >= l 10 | { 11 | 1; 12 | } 13 | 14 | export fn main() -> int { 15 | 16 | 17 | char * s = "asdaksmdaklsmdaklsmdklad"; 18 | usize l = (usize)strlen(s); 19 | static_attest(len(s) == l); 20 | bob(s, l); 21 | 22 | printf("hello strlen\n"); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/mustpass/short_hand_struct_init_field/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | struct Object { 4 | char *string; 5 | int number; 6 | bool boolean; 7 | void *data; 8 | } 9 | 10 | export fn main() -> int { 11 | char *string = "hello"; 12 | int number = 123; 13 | bool boolean = true; 14 | let object = Object { string, number, boolean, data: "hello" }; 15 | log::info("hello %s\n", "short_hand_struct_init_field"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/mustpass/struct_init_inline/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | 6 | struct A{ 7 | int x; 8 | int y; 9 | } 10 | 11 | 12 | 13 | export fn take(A a) { 14 | printf("%d\n", a.y); 15 | } 16 | 17 | export fn main() -> int { 18 | 19 | let a = A { 20 | x: 1, 21 | y: 2, 22 | }; 23 | 24 | take(a); 25 | take(A{ 26 | x: 1, 27 | y: 2, 28 | }); 29 | 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/mustpass/tail_of_static/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | using buffer; 3 | 4 | struct A { 5 | int a; 6 | int b[]; 7 | } 8 | 9 | 10 | 11 | fn a() { 12 | static_attest(buffer::integrity(&stringbuf)); 13 | stringbuf.push(1); 14 | } 15 | 16 | 17 | 18 | static buffer::Buffer+1000 mut stringbuf = {0}; 19 | 20 | export fn main() int { 21 | stringbuf.make(); 22 | 23 | 24 | log::info("hello %s", "tail_of_static"); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/mustpass/pointer_arith/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | int a[] = {1,2,3,4}; 6 | static_assert(safe(a)); 7 | static_assert(len(a) == 4); 8 | 9 | int *b = a; 10 | static_assert(safe(b)); 11 | static_assert(len(b) == 4); 12 | 13 | int *c = a + 1; 14 | static_assert(safe(c)); 15 | static_assert(len(c) == 3); 16 | printf("%zu\n", static(len(c))); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /modules/buffer/tests/strlen.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{printf, stdin}; 3 | using ::{free}; 4 | inline using "native.h"::{getline}; 5 | 6 | 7 | test { 8 | stdin = "hello world" 9 | stdout = "11\n" 10 | } 11 | 12 | test { 13 | stdin = "" 14 | stdout = "0\n" 15 | } 16 | 17 | export fn main() -> int { 18 | new+50 s = buffer::make(); 19 | s.fgets(stdin); 20 | printf("%u\n", buffer::strlen(s.cstr())); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/mustfail/vtable_missing_fn/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | closure add_t(int a, int b) -> int; 5 | 6 | 7 | fn add(int a, int b) -> int { 8 | return a + b; 9 | } 10 | 11 | struct Math { 12 | add_t mut adder; 13 | } 14 | 15 | fn bla(Math *m) -> int 16 | where safe(m->adder) 17 | { 18 | return m->adder(1,2); 19 | } 20 | 21 | export fn main() -> int { 22 | Math mut m; 23 | 24 | printf("hello %d\n", bla(&m)); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tests/mustpass/ifdef/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | inline using "os.h" as os; 3 | 4 | export fn main() -> int if #(os::ZZ_OS_WINDOWS) { 5 | log::info("hello windows %d\n", os::GetVersion()); 6 | return 0; 7 | } else if #(os::ZZ_OS_APPLE) { 8 | log::info("hello apple \n"); 9 | return 0; 10 | } else if #(os::ZZ_OS_LINUX) { 11 | log::info("hello linux %ld\n", os::gethostid()); 12 | return 0; 13 | } else { 14 | log::info("hello unknown OS\n"); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/mustpass/vtable/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | closure add_t(int a, int b) -> int; 5 | 6 | 7 | fn add(int a, int b) -> int { 8 | return a + b; 9 | } 10 | 11 | struct Math { 12 | add_t mut adder; 13 | } 14 | 15 | fn bla(Math *m) -> int 16 | where safe(m->adder) 17 | { 18 | return m->adder(1,2); 19 | } 20 | 21 | export fn main() -> int { 22 | Math mut m; 23 | m.adder = add; 24 | 25 | printf("hello %d\n", bla(&m)); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /modules/buffer/tests/format.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{getline, printf, stdin}; 3 | using ::{free}; 4 | 5 | 6 | 7 | test blah { 8 | stdout = "hello2366\n" 9 | } 10 | 11 | export fn main() -> int { 12 | buffer::Buffer+10 mut s; 13 | buffer::make(&s); 14 | 15 | buffer::append_cstr(&s, "hello"); 16 | buffer::format(&s, "%d%d%d%d", 2, 3, 66,9); 17 | buffer::format(&s, "%s", "12345678901234567890"); 18 | 19 | printf("%s\n", s.mem); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tests/mustfail/vtable_missing_callsite_assert/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | closure add_t(int a, int b) -> int; 5 | 6 | 7 | fn add(int a, int b) -> int { 8 | return a + b; 9 | } 10 | 11 | struct Math { 12 | add_t mut adder; 13 | } 14 | 15 | fn bla(Math *m) -> int 16 | where safe(m) 17 | { 18 | return m->adder(1,2); 19 | } 20 | 21 | export fn main() -> int { 22 | Math mut m; 23 | m.adder = add; 24 | 25 | printf("hello %d\n", bla(&m)); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /examples/switch/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | enum A { 5 | g, 6 | f, 7 | } 8 | 9 | enum B { 10 | wop, 11 | dop = 10, 12 | mop, 13 | } 14 | 15 | 16 | export fn main() -> int { 17 | printf("hello switch\n"); 18 | 19 | A a = A::g; 20 | 21 | switch a { 22 | A::f => { 23 | printf("no\n"); 24 | return 1; 25 | } 26 | default => { 27 | printf("yes\n"); 28 | return 0; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/mustpass/return_model/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | int a; 6 | } 7 | 8 | fn dab() -> A 9 | model return.a == 2 10 | { 11 | return A{ 12 | a: 2 13 | }; 14 | } 15 | 16 | fn bob() -> int 17 | model return == 2 18 | { 19 | return 2; 20 | } 21 | 22 | export fn main() -> int { 23 | 24 | int b = bob(); 25 | static_assert(b == 2); 26 | 27 | 28 | A a = dab(); 29 | static_assert(a.a == 2); 30 | 31 | printf("hello return_model\n"); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/mustpass/tail_multiple_in_struct/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{assert}; 2 | 3 | struct B+ { 4 | int bla; 5 | u8 mem[]; 6 | } 7 | 8 | 9 | struct A+ { 10 | B+1 x; 11 | B+ y; 12 | } 13 | 14 | export fn assert_correct_tailx(B+bt *b) { 15 | assert(bt == 1); 16 | } 17 | 18 | export fn assert_correct_taily(B+bt *b) { 19 | assert(bt == 100); 20 | } 21 | 22 | export fn main() -> int { 23 | 24 | A+100 a; 25 | 26 | assert_correct_tailx(&a.x); 27 | assert_correct_taily(&a.y); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /solvecomp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | echo "z3 , yices2, fn" 3 | for i in *.smt2 4 | do 5 | 6 | 7 | TIME_Z3=$( 8 | (time z3 $i >/dev/null) 2>&1 | rev | cut -d ' ' -f 2 | rev | tr -d '.' 9 | ) 10 | TIME_YI=$( 11 | (time yices_smt2 --incremental $i >/dev/null) 2>&1 | rev | cut -d ' ' -f 2 | rev | tr -d '.' 12 | ) 13 | 14 | if [ $TIME_Z3 -gt $TIME_YI ] 15 | then 16 | echo -e "\e[31m$TIME_Z3\e[39m , \e[32m$TIME_YI\e[39m , $i" 17 | else 18 | echo -e "\e[32m$TIME_Z3\e[39m , \e[31m$TIME_YI\e[39m , $i" 19 | fi 20 | done 21 | -------------------------------------------------------------------------------- /tests/mustpass/switch_branches/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | export fn main() -> int { 4 | 5 | 6 | int i = 0; 7 | int mut x = 3; 8 | 9 | switch i { 10 | 0 => { 11 | x = 16; 12 | } 13 | 1 => { 14 | x = 32; 15 | } 16 | } 17 | 18 | static_assert(x == 16); 19 | 20 | 21 | 22 | 23 | switch i { 24 | 0 => { 25 | x = 32; 26 | return 0; 27 | } 28 | } 29 | 30 | 31 | static_assert(x == 16); 32 | 33 | 34 | return 1; 35 | } 36 | -------------------------------------------------------------------------------- /modules/err/tests/err.zz: -------------------------------------------------------------------------------- 1 | using err; 2 | 3 | 4 | symbol BadThings; 5 | 6 | fn bad(err::Err+et mut *e) 7 | where err::checked(*e) 8 | { 9 | err::fail(e, BadThings , "no you cannot %s", "do this"); 10 | } 11 | 12 | fn maybe(err::Err+et mut *e) 13 | where err::checked(*e) 14 | { 15 | bad(e); 16 | if err::check(e) { 17 | return; 18 | } 19 | } 20 | 21 | pub fn main() -> int { 22 | new+500 e = err::make(); 23 | 24 | maybe(&e); 25 | if err::check(&e) { 26 | return 0; 27 | } 28 | bad(&e); 29 | 30 | return 999; 31 | } 32 | -------------------------------------------------------------------------------- /tests/mustpass/callsite_assign_sizeof/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | using err; 3 | 4 | fn dump(void * obj, usize expect, usize actual = sizeof(*obj)) 5 | { 6 | log::info("dumping object of size %d", actual); 7 | err::assert(expect == actual); 8 | } 9 | 10 | struct A { 11 | u64 dummy; 12 | u64 b[]; 13 | } 14 | 15 | export fn main() int { 16 | 17 | u8 a; 18 | dump(&a, 1); 19 | 20 | A+1000 b; 21 | dump(&b, 8008); 22 | 23 | 24 | dump(&b, 1000, 1000); 25 | 26 | log::info("hello %s", "callsite_assign_sizeof"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /tests/mustpass/static_attest_in_third_branch/src/main.zz: -------------------------------------------------------------------------------- 1 | theory bob(int a) -> bool; 2 | 3 | fn doh(int *a) 4 | where bob(*a) 5 | { 6 | 7 | } 8 | 9 | fn from_str(bool whatever, int * i) 10 | where bob(*i) 11 | { 12 | if whatever { 13 | } else { 14 | } 15 | 16 | if (whatever) { 17 | doh(i); 18 | return; 19 | } 20 | 21 | static_attest(bob(*i)); 22 | 23 | bool somethingelse; 24 | 25 | if (somethingelse) { 26 | doh(i); 27 | } 28 | 29 | } 30 | 31 | 32 | export fn main() -> int { 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /tests/mustpass/ssa/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | fn foo(uint b) -> uint 4 | { 5 | return b + 3; 6 | } 7 | 8 | export fn main(int argc, char ** argv) -> int { 9 | 10 | uint mut x = 1; 11 | static_assert(x == 1); 12 | uint mut b = x++; 13 | static_assert(b == 1); 14 | static_assert(x == 2); 15 | 16 | 17 | for (int mut i = 0; i < 10; i++) { 18 | static_assert(i < 10); 19 | } 20 | 21 | static_assert(b == 1); 22 | 23 | 24 | 25 | 26 | 27 | uint y = foo(b); 28 | printf("%u\n", y); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/mustpass/branch_condition_effect/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | theory checked(int a) -> bool; 6 | 7 | fn check(int *thing) -> bool 8 | model checked(*thing) 9 | { 10 | static_attest(checked(*thing)); 11 | 12 | return false; 13 | } 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | export fn bob(int *a) -> int { 28 | 29 | 30 | if check(a) { 31 | return 2; 32 | } 33 | 34 | static_assert(checked(*a)); 35 | 36 | return 0; 37 | } 38 | 39 | 40 | export fn main() -> int { 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /modules/buffer/tests/fgets.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{printf, stdin}; 3 | 4 | 5 | test test1 { 6 | stdin = "bob" 7 | stdout == "bob" 8 | } 9 | 10 | 11 | test test2 { 12 | stdin = "dudeldii\nasdasd" 13 | stdout == "dudeldii\n" 14 | } 15 | 16 | test limiter { 17 | stdin = "12345678901234567890" 18 | stdout == "123456789" 19 | } 20 | 21 | pub fn main() -> int { 22 | buffer::Buffer+10 mut s = {0}; 23 | buffer::make(&s); 24 | if !buffer::fgets(&s, stdin) { 25 | return 2; 26 | } 27 | printf("%.*s", (int)s.at, s.mem); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/mustpass/loops_no_braces/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | 5 | fn never_happens() { 6 | while true { 7 | } 8 | for ;; {} 9 | } 10 | 11 | export fn main() -> int { 12 | 13 | for (int mut i = 1; i < 2; i++) { 14 | log::info("hello %s\n", "loops_no_braces"); 15 | log::info("hello %s\n", "loops_no_braces"); 16 | } 17 | for int mut i = 1; i < 2; i++ { 18 | log::info("hello %s\n", "loops_no_braces"); 19 | log::info("hello %s\n", "loops_no_braces"); 20 | } 21 | 22 | while unsafe(false) { 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | THIS=$PWD 6 | cargo build --release 7 | 8 | cd $THIS/tests 9 | ./ci.sh 10 | 11 | for i in $THIS/examples/* 12 | do 13 | echo "=================" 14 | cd $i 15 | ../../target/release/zz --smt-timeout=200000 clean 16 | ../../target/release/zz --smt-timeout=200000 run 17 | ../../target/release/zz --smt-timeout=200000 test 18 | done 19 | 20 | for i in $THIS/modules/* 21 | do 22 | cd $i 23 | ../../target/release/zz --smt-timeout=200000 clean 24 | ../../target/release/zz --smt-timeout=200000 test 25 | done 26 | 27 | echo 28 | echo all passed 29 | -------------------------------------------------------------------------------- /modules/symbols/src/lib.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | inline using "lib.h"::{ 3 | __zz_symbol_names_len, 4 | __zz_symbol_names, 5 | }; 6 | 7 | export fn nameof(usize s) -> char* 8 | where symbol(s) 9 | { 10 | static_attest(s < len(__zz_symbol_names)); 11 | return __zz_symbol_names[s]; 12 | } 13 | 14 | export fn nameof_checked(usize s) -> char* 15 | { 16 | static_attest((usize)__zz_symbol_names_len == len(__zz_symbol_names)); 17 | if s <= 0 || s >= (usize)__zz_symbol_names_len { 18 | return 0; 19 | } 20 | static_attest(symbol(s)); 21 | return nameof(s); 22 | } 23 | -------------------------------------------------------------------------------- /modules/pool/tests/extra.zz: -------------------------------------------------------------------------------- 1 | using pool; 2 | using err; 3 | 4 | 5 | export fn main() int { 6 | new+1000 big = pool::make(10); 7 | new+100 small = pool::make(80); 8 | 9 | err::assert(small.alloc() != 0); 10 | err::assert(small.alloc() == 0); 11 | 12 | small.extra = &big; 13 | 14 | err::assert(small.alloc() != 0); 15 | err::assert(small.alloc() != 0); 16 | err::assert(small.alloc() != 0); 17 | err::assert(small.alloc() != 0); 18 | 19 | 20 | for usize mut i = 0; i < 100; i++ { 21 | small.free(small.alloc()); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/mustpass/tail_static_in_struct/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A+ { 5 | int bla; 6 | int mem[]; 7 | }; 8 | 9 | 10 | fn foh(A+at * self) { 11 | static_assert(len(self->mem) == at); 12 | } 13 | 14 | struct B { 15 | A+100 a1; 16 | A+200 a2; 17 | }; 18 | 19 | 20 | fn bob(B*self) { 21 | self->a1.foh(); 22 | self->a2.foh(); 23 | static_assert(len(self->a1.mem) == 100); 24 | static_assert(len(self->a2.mem) == 200); 25 | } 26 | 27 | export fn main() -> int { 28 | B b; 29 | 30 | b.a1.foh(); 31 | b.a2.foh(); 32 | 33 | b.bob(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/mustpass/cast_clears_assigned/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | struct A{ 5 | int dummy; 6 | }; 7 | 8 | 9 | 10 | export fn blah(void *x ) { 11 | static_attest(typeof(*x) == typeof(void)); 12 | static_assert(typeof(*x) == typeof(void)); 13 | 14 | A mut *a = (A mut *)x; 15 | static_attest(safe(a)); 16 | a->dummy = 3; 17 | 18 | static_assert(typeof(*a) == typeof(A)); 19 | 20 | // TODO once asserted, that's kinda it 21 | //static_assert(typeof(*x) == typeof(void)); 22 | 23 | } 24 | 25 | export fn main() int { 26 | 27 | log::info("hello %s", "cast_clears_assigned"); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tests/mustpass/tail_bind_dynamic/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | 4 | 5 | 6 | 7 | struct A+ { 8 | u8 blah; 9 | u8 mem[]; 10 | } 11 | 12 | 13 | 14 | export fn gimmetail(A+t*a) -> usize 15 | { 16 | return t; 17 | } 18 | 19 | 20 | export fn use_as_A(u8*mem, usize l) -> usize 21 | where len(mem) >= l 22 | { 23 | A+l * a = (A*)mem; 24 | 25 | 26 | return a->gimmetail(); 27 | } 28 | 29 | export fn main() -> int { 30 | 31 | u8 mem[100]; 32 | usize tail = use_as_A(mem, static(len(mem))); 33 | 34 | assert(tail == static(len(mem))); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /tests/mustpass/nestedtail/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{memset}; 3 | 4 | 5 | 6 | struct A+ { 7 | u8 nothing; 8 | u8 a[]; 9 | } 10 | 11 | 12 | struct B+ { 13 | A+ a; 14 | } 15 | 16 | 17 | 18 | fn gimme_a(A+tail *self) -> u8 19 | where tail > 99 20 | { 21 | return (self->a)[99]; 22 | } 23 | 24 | fn gimme_b(B+tail *self) -> u8 25 | where tail > 99 26 | { 27 | return gimme_a(&(self->a)); 28 | } 29 | 30 | export fn main() -> int { 31 | B+100 mut b; 32 | memset(&b, 12, sizeof(b)); 33 | 34 | printf("hello nestedtail %zu %u\n", sizeof(b), gimme_b(&b)); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /tests/mustpass/fn_vtable_ctor/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | // abstract 5 | closure AdderFn(int a, int b) -> int; 6 | struct Math { 7 | AdderFn add; 8 | } 9 | 10 | // impl 11 | fn add_impl(int a, int b) -> int { 12 | return a+b; 13 | } 14 | 15 | fn nu(Math mut new * self, AdderFn add) 16 | where safe(self) 17 | where safe(add) 18 | model safe(self->add) 19 | { 20 | self->add = add; 21 | } 22 | 23 | export fn main() -> int { 24 | Math mm = Math { 25 | add: add_impl, 26 | }; 27 | int x = mm.add(1,8); 28 | 29 | new m = nu(add_impl); 30 | 31 | int x2 = m.add(1,8); 32 | printf("hello %u\n", x2); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /modules/net/src/os.h: -------------------------------------------------------------------------------- 1 | #if defined (_WIN32) 2 | #define WIN32_LEAN_AND_MEAN 1 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #endif 9 | 10 | #if defined(__unix__) || defined(__APPLE__) || defined(__linux__) 11 | #include 12 | #include 13 | #include 14 | #endif 15 | 16 | #if defined(ESP_PLATFORM) 17 | #include 18 | #include 19 | #include 20 | #include "lwip/err.h" 21 | #include "lwip/sockets.h" 22 | #include "lwip/sys.h" 23 | #include 24 | #endif 25 | 26 | typedef struct sockaddr_in sockaddr_in4_t; 27 | typedef struct sockaddr_in6 sockaddr_in6_t; 28 | -------------------------------------------------------------------------------- /tests/ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | THIS=$PWD 5 | cargo build --release 6 | 7 | 8 | 9 | for i in $THIS/mustpass/* 10 | do 11 | cd $i 12 | ../../../target/release/zz clean; 13 | if ../../../target/release/zz run; then 14 | echo "$i" passed 15 | else 16 | echo "$i" failed 17 | exit 1 18 | fi 19 | done 20 | 21 | 22 | for i in $THIS/mustfail/* 23 | do 24 | cd $i 25 | ../../../target/release/zz clean; 26 | if ../../../target/release/zz check; then 27 | echo "$i" passed, but it should not 28 | exit 1 29 | else 30 | echo "$i" "failed to build, as it's supposed to" 31 | fi 32 | done 33 | 34 | 35 | 36 | echo 37 | echo all passed 38 | -------------------------------------------------------------------------------- /tests/mustfail/fn_vtable_ctor_missing_valid_fn/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | // abstract 5 | closure AdderFn(int a, int b) -> int; 6 | struct Math { 7 | AdderFn add; 8 | } 9 | 10 | // impl 11 | fn add_impl(int a, int b) -> int { 12 | return a+b; 13 | } 14 | 15 | fn new(Math mut *self, AdderFn add) 16 | where safe(self) 17 | //where safe(add) 18 | model safe(self->add) 19 | { 20 | self->add = add; 21 | } 22 | 23 | export fn main() -> int { 24 | Math mm = Math { 25 | .add = add_impl, 26 | }; 27 | int x = mm.add(1,8); 28 | 29 | Math mut m; 30 | new(&m, add_impl); 31 | 32 | int x2 = m.add(1,8); 33 | printf("hello %u\n", x2); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /tests/mustpass/array/src/main.zz: -------------------------------------------------------------------------------- 1 | pub fn memcpy(u8 mut *dst, u8 * src, usize l) 2 | where l > 0 3 | where len(dst) >= l 4 | where len(src) >= l 5 | { 6 | for (usize mut i = 0; i < l; i++) { 7 | dst[i] = src[i]; 8 | } 9 | } 10 | 11 | const usize SIZE = 3; 12 | 13 | pub fn fixed(u8 mut* boh) 14 | where len(boh) == SIZE 15 | { 16 | boh[2] = 3; 17 | } 18 | 19 | pub fn main() -> int { 20 | u8 mut src[23] = {0}; 21 | u8 mut f[SIZE] = {0}; 22 | 23 | static_assert(len(f) == SIZE); 24 | static_assert(len(src) == 23); 25 | 26 | memcpy(f, src, SIZE); 27 | 28 | src[1] = 3; 29 | 30 | u8 mut dst[20] = {0}; 31 | memcpy(dst, src, static(len(dst))); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/hello/src/identity.zz: -------------------------------------------------------------------------------- 1 | using "mymath.h" as math; 2 | using ::{printf} ; 3 | 4 | using constants::{foo}; 5 | using err::{Err}; 6 | using constants::{conflict as constant_conflict}; 7 | 8 | using main; 9 | 10 | static u32 wuast = 9; 11 | static u32 mut counter = 1; 12 | 13 | 14 | pub fn some_helper(Err mut* err, u32 mut* bob) -> u32 { 15 | counter+=1; 16 | printf("lol\n"); 17 | if (bob > 0 ) { 18 | (*bob) = as(math::add(horst(), foo)); 19 | printf("bob %d\n", (*bob)); 20 | } 21 | return 41; 22 | } 23 | 24 | fn horst() -> u32 { 25 | constant_conflict(); 26 | printf("wee? %f\n", main::gimme_wee(0)); 27 | return 0; 28 | } 29 | 30 | const int conflict = 1; 31 | 32 | 33 | const char* lol = "bob"; 34 | -------------------------------------------------------------------------------- /tests/mustpass/alias/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | 5 | struct A { 6 | int dummy; 7 | }; 8 | 9 | theory booze(void _) bool; 10 | 11 | export type B = A[booze = true]; 12 | 13 | 14 | export struct X { 15 | B b; 16 | } 17 | 18 | export fn main() int { 19 | 20 | B mut b; 21 | b.dummy = 3; 22 | 23 | static_assert(booze(b)); 24 | bleep(&b); 25 | static_assert(booze(b)); 26 | 27 | 28 | 29 | 30 | X mut x = {0}; 31 | x.b.dummy = 3; 32 | static_assert(booze(x.b)); 33 | 34 | 35 | 36 | 37 | return 0; 38 | } 39 | 40 | export fn mop(B *b) int 41 | where b->dummy == 3 42 | { 43 | return bleep(b); 44 | } 45 | 46 | export fn bleep(B *b) int 47 | where b->dummy == 3 48 | { 49 | return b->dummy; 50 | } 51 | -------------------------------------------------------------------------------- /tests/mustpass/branch_effect2/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using err; 3 | 4 | 5 | 6 | symbol Bad; 7 | 8 | 9 | fn boh (err::Err+et mut*e) 10 | where err::checked(*e) 11 | { 12 | err::fail(e, Bad, "buh"); 13 | } 14 | 15 | export fn main() -> int { 16 | 17 | err::Err+1000 mut e; 18 | err::make(&e); 19 | boh(&e); 20 | 21 | // must not compile 22 | //static_assert(err::checked(e)); 23 | 24 | if err::check(&e) { 25 | int x = 0; 26 | // must not compile 27 | // static_assert(err::checked(e)); 28 | return 0; 29 | } 30 | static_assert(err::checked(e)); 31 | boh(&e); 32 | 33 | 34 | int x; 35 | if x != 2 { 36 | return 0; 37 | } 38 | 39 | static_assert(x == 2); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /modules/list/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | using list; 3 | using pool; 4 | 5 | export fn main() int { 6 | 7 | new+1000 p = pool::make(8); 8 | new+0 l = list::make_with_pool(&p); 9 | 10 | l.push("hello"); 11 | l.push_b("bob"); 12 | 13 | for let mut i = l.iter(); i.next(); { 14 | log::info(">%.*s<", i.val.size, i.val.mem); 15 | } 16 | 17 | l.pop(); 18 | 19 | for let mut i = l.iter(); i.next(); { 20 | log::info(">%.*s<", i.val.size, i.val.mem); 21 | } 22 | 23 | l.pop(); 24 | 25 | for let mut i = l.iter(); i.next(); { 26 | log::info(">%.*s<", i.val.size, i.val.mem); 27 | } 28 | 29 | l.pop(); 30 | 31 | for let mut i = l.iter(); i.next(); { 32 | log::info(">%.*s<", i.val.size, i.val.mem); 33 | } 34 | 35 | l.push("bob"); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /modules/mem/src/lib.zz: -------------------------------------------------------------------------------- 1 | inline using "lib.h" as libc; 2 | 3 | pub fn copy(void * src, void mut *dst, usize n) 4 | where len(dst) >= n 5 | where len(src) >= n 6 | { 7 | libc::memcpy(dst, src, n); 8 | } 9 | 10 | pub fn move(void * src, void mut *dst, usize n) 11 | where len(dst) >= n 12 | where len(src) >= n 13 | { 14 | libc::memmove(dst, src, n); 15 | } 16 | 17 | pub fn set(void mut * dst, u8 c, usize n) 18 | where len(dst) >= n 19 | { 20 | libc::memset(dst, c, n); 21 | } 22 | 23 | pub fn eq(void * a, void * b, usize n) -> bool 24 | where len(a) >= n 25 | where len(b) >= n 26 | { 27 | return libc::memcmp(a,b, n) == 0; 28 | } 29 | 30 | pub fn zero(void mut * dst, usize vt = sizeof(*dst)) 31 | model *dst == 0 32 | { 33 | libc::memset(dst, 0, vt); 34 | static_attest(*dst == 0); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zz" 3 | version = "0.1.1" 4 | authors = ["Arvid E. Picciani "] 5 | edition = '2018' 6 | license = "MIT/Apache-2.0" 7 | description = "the zz language" 8 | repository = "https://github.com/aep/zz" 9 | readme = "README.md" 10 | 11 | 12 | [[bin]] 13 | name = "zz" 14 | path = "src/main.rs" 15 | 16 | 17 | [lib] 18 | name = "zz" 19 | path = "src/lib.rs" 20 | 21 | [dependencies] 22 | pest = "2.1" 23 | pest_derive = "2.1" 24 | serde = { version = "1.0", features = ["derive"] } 25 | serde_json = "1.0" 26 | toml = "0.5" 27 | metrohash = "1.0.6" 28 | clap = "2" 29 | log = "0.4" 30 | env_logger = "0.6" 31 | pbr = "1.0.1" 32 | rayon = "1.1.0" 33 | tempdir = "0.3" 34 | which = "3.1.0" 35 | askama = "0.9" 36 | getrandom = "0.1.14" 37 | lazy_static = "1.4.0" 38 | rmp-serde = "0.14.3" 39 | sha2 = "0.8" 40 | url = "2.1.1" 41 | rsmt2 = "0.14.1" 42 | pathdiff = "0.2" 43 | -------------------------------------------------------------------------------- /tests/mustpass/new/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A 5 | { 6 | int f; 7 | } 8 | 9 | struct B+ 10 | { 11 | A a; 12 | int b[]; 13 | } 14 | 15 | fn borrow(A mut*self) -> A mut* 16 | where self->f == 3 17 | model self->f == 3 18 | model safe(return) 19 | { 20 | return self; 21 | } 22 | 23 | 24 | export fn null(A mut new * self) 25 | { 26 | self->f = 3; 27 | } 28 | 29 | export fn none(B+t mut new * self) 30 | { 31 | null(&self->a); 32 | } 33 | 34 | export fn get(A mut *self) -> int 35 | { 36 | return self->f; 37 | } 38 | 39 | export fn convert(B+t mut * self, A mut new *that) 40 | { 41 | } 42 | 43 | 44 | export fn main() -> int { 45 | 46 | new a = null(); 47 | a.get(); 48 | a.get(); 49 | printf("hello %d\n", a.f); 50 | 51 | 52 | new+100 b = none(); 53 | new x = convert(&b); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/export_cmake.rs: -------------------------------------------------------------------------------- 1 | use super::make::Make; 2 | use std::fs; 3 | use std::io::Write; 4 | 5 | pub fn export(make: Make) { 6 | let pdir_ = format!("target/cmake/{}/", make.artifact.name); 7 | let pdir = std::path::Path::new(&pdir_); 8 | std::fs::create_dir_all(&pdir).unwrap(); 9 | 10 | let p = pdir.join("CMakeLists.txt"); 11 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 12 | 13 | write!( 14 | f, 15 | r#" 16 | include_directories("${{CMAKE_CURRENT_LIST_DIR}}/../../{}/") 17 | set({}_SOURCES 18 | "#, 19 | make.stage, make.artifact.name 20 | ) 21 | .unwrap(); 22 | 23 | for step in &make.steps { 24 | write!( 25 | f, 26 | " ${{CMAKE_CURRENT_LIST_DIR}}/../../../{}\n", 27 | step.source.to_string_lossy() 28 | ) 29 | .unwrap(); 30 | } 31 | 32 | write!(f, ")\n").unwrap(); 33 | } 34 | -------------------------------------------------------------------------------- /tests/mustfail/err_not_checked_in_fail_branch/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using err; 3 | 4 | 5 | 6 | fn boh (err::Err+et mut*e) 7 | where err::checked(*e) 8 | { 9 | err::fail(e, 12, "buh"); 10 | } 11 | 12 | export fn main() -> int { 13 | 14 | err::Err+1000 mut e; 15 | err::make(&e); 16 | boh(&e); 17 | 18 | // must not compile 19 | //static_assert(err::checked(e)); 20 | 21 | if err::check(&e) { 22 | int x = 0; 23 | // must not compile 24 | // must not pass e to another function here, 25 | // because the function obviously expects the passed in err to be clean 26 | static_assert(err::checked(e)); 27 | return 0; 28 | } 29 | static_assert(err::checked(e)); 30 | boh(&e); 31 | 32 | 33 | int x; 34 | if x != 2 { 35 | return 0; 36 | } 37 | 38 | static_assert(x == 2); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tests/mustpass/type_params/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | export struct A { 5 | 6 | } 7 | 8 | export theory bob(A self) int; 9 | export theory mop(A self) int; 10 | 11 | 12 | export fn make (A mut new *self) 13 | where bob(*self) > 0 14 | 15 | { 16 | } 17 | 18 | 19 | export fn fop(A mut*self) 20 | where bob(*self) > 1 21 | { 22 | dop(self); 23 | } 24 | 25 | 26 | 27 | export fn dop(A mut*self) 28 | where bob(*self) > 1 29 | { 30 | } 31 | 32 | 33 | export struct B { 34 | A[bob(self) == 3] a; 35 | } 36 | 37 | 38 | 39 | export fn main() int { 40 | 41 | B[mop(self.a) == 3] mut b; 42 | 43 | log::info("hello %d %d", 44 | static(mop(b.a)), 45 | static(bob(b.a)) 46 | ); 47 | 48 | b.a.fop(); 49 | 50 | 51 | 52 | new[bob = 12] a = make(); 53 | static_assert(bob(a) == 12); 54 | a.fop(); 55 | static_assert(bob(a) == 12); 56 | 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /examples/taint/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | pub theory isopen(Socket*s) -> bool; 4 | 5 | struct Socket { 6 | int mut fd; 7 | } 8 | 9 | fn open(Socket mut* self) 10 | model isopen(*self) 11 | { 12 | static_attest(isopen(*self) == true); 13 | static_assert(isopen(*self) == true); 14 | self->fd = 2; 15 | } 16 | 17 | fn read(Socket mut* self) 18 | where isopen(*self) 19 | model isopen(*self) 20 | { 21 | int bla = self->fd; 22 | } 23 | 24 | fn close(Socket mut* self) 25 | where isopen(*self) 26 | model !isopen(*self) 27 | { 28 | //convince the symbolic executor that we did something, so we can have new constraints 29 | *self = Socket{fd: 0}; 30 | static_attest(isopen(*self) == false); 31 | } 32 | 33 | export fn main() -> int { 34 | 35 | Socket mut sock = {0}; 36 | open(&sock); 37 | read(&sock); 38 | close(&sock); 39 | 40 | printf("hello taint\n"); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /tests/mustpass/branch_negative_no_effect/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | theory checked(int a) -> bool; 6 | 7 | fn check(int * thing) -> bool 8 | model checked(*thing) 9 | { 10 | static_attest(checked(*thing)); 11 | 12 | return false; 13 | } 14 | 15 | fn uncheck(int mut *thing) 16 | where checked(*thing) 17 | { 18 | } 19 | 20 | 21 | 22 | 23 | 24 | enum Enum { 25 | Bob, 26 | Peter, 27 | } 28 | 29 | 30 | 31 | 32 | 33 | export fn bob(Enum x, int mut* a) -> int { 34 | 35 | 36 | if check(a) { 37 | return 2; 38 | } 39 | uncheck(a); 40 | 41 | if check(a) { 42 | return 2; 43 | } 44 | 45 | 46 | switch x { 47 | Enum::Bob => { 48 | uncheck(a); 49 | } 50 | Enum::Peter => { 51 | uncheck(a); 52 | } 53 | } 54 | 55 | 56 | return 0; 57 | } 58 | 59 | 60 | export fn main() -> int { 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /modules/byteorder/tests/be.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | using byteorder; 4 | 5 | pub fn main() -> int { 6 | assert(byteorder::from_be16(byteorder::to_be16(123)) == 123); 7 | assert(byteorder::from_be16(byteorder::to_be16(123)) == byteorder::to_be16(byteorder::from_be16(123))); 8 | 9 | assert(byteorder::to_le16(8) != byteorder::to_be16(8)); 10 | 11 | assert(byteorder::from_be32(byteorder::to_be32(123123123)) == 123123123); 12 | assert(byteorder::from_be32(byteorder::to_be32(123)) == byteorder::to_be32(byteorder::from_be32(123))); 13 | assert(byteorder::to_le32(123) != byteorder::to_be32(123)); 14 | 15 | assert(byteorder::from_be64(byteorder::to_be64(123123123123123123)) == 123123123123123123); 16 | assert(byteorder::from_be64(byteorder::to_be64(123)) == byteorder::to_be64(byteorder::from_be64(123))); 17 | assert(byteorder::to_le64(123) != byteorder::to_be64(123)); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/mustpass/typestate/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | pub theory isopen(Socket*s) -> bool; 4 | 5 | struct Socket { 6 | int mut fd; 7 | } 8 | 9 | fn open(Socket mut* self) 10 | model isopen(*self) 11 | { 12 | static_attest(isopen(*self) == true); 13 | static_assert(isopen(*self) == true); 14 | self->fd = 2; 15 | } 16 | 17 | fn read(Socket mut* self) 18 | where isopen(*self) 19 | model isopen(*self) 20 | { 21 | int bla = self->fd; 22 | } 23 | 24 | fn close(Socket mut* self) 25 | where isopen(*self) 26 | model !isopen(*self) 27 | { 28 | //convince the symbolic executor that we did something, so we can have new constraints 29 | *self = Socket{fd : 0}; 30 | static_attest(isopen(*self) == false); 31 | } 32 | 33 | export fn main() -> int { 34 | 35 | Socket mut sock = {0}; 36 | open(&sock); 37 | read(&sock); 38 | close(&sock); 39 | 40 | printf("hello taint\n"); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /src/z3/symbol.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CString; 2 | use z3_sys::*; 3 | use crate::z3::Context; 4 | use crate::z3::Symbol; 5 | 6 | impl Symbol { 7 | pub fn as_z3_symbol(&self, ctx: &Context) -> Z3_symbol { 8 | match self { 9 | Symbol::Int(i) => unsafe { Z3_mk_int_symbol(ctx.z3_ctx, *i as ::std::os::raw::c_int) }, 10 | Symbol::String(s) => { 11 | let ss = CString::new(s.clone()).unwrap(); 12 | let p = ss.as_ptr(); 13 | unsafe { Z3_mk_string_symbol(ctx.z3_ctx, p) } 14 | } 15 | } 16 | } 17 | } 18 | 19 | impl From for Symbol { 20 | fn from(val: u32) -> Self { 21 | Symbol::Int(val) 22 | } 23 | } 24 | 25 | impl From for Symbol { 26 | fn from(val: String) -> Self { 27 | Symbol::String(val) 28 | } 29 | } 30 | 31 | impl From<&str> for Symbol { 32 | fn from(val: &str) -> Self { 33 | Symbol::String(val.to_owned()) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/mustfail/typestate_wrong_order/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | pub theory isopen(Socket*s) -> bool; 4 | 5 | struct Socket { 6 | int mut fd; 7 | } 8 | 9 | fn open(Socket mut* self) 10 | model isopen(*self) 11 | { 12 | static_attest(isopen(*self) == true); 13 | static_assert(isopen(*self) == true); 14 | self->fd = 2; 15 | } 16 | 17 | fn read(Socket mut* self) 18 | where isopen(*self) 19 | model isopen(*self) 20 | { 21 | int bla = self->fd; 22 | } 23 | 24 | fn close(Socket mut* self) 25 | where isopen(*self) 26 | model !isopen(*self) 27 | { 28 | //convince the symbolic executor that we did something, so we can have new constraints 29 | *self = Socket{.fd = 0}; 30 | static_attest(isopen(*self) == false); 31 | } 32 | 33 | export fn main() -> int { 34 | 35 | Socket mut sock = {0}; 36 | open(&sock); 37 | close(&sock); 38 | read(&sock); 39 | 40 | printf("hello taint\n"); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /src/z3/context.rs: -------------------------------------------------------------------------------- 1 | use z3_sys::*; 2 | use crate::z3::Config; 3 | use crate::z3::Context; 4 | use crate::z3::Z3_MUTEX; 5 | 6 | impl Context { 7 | pub fn new(cfg: &Config) -> Context { 8 | Context { 9 | z3_ctx: unsafe { 10 | let guard = Z3_MUTEX.lock().unwrap(); 11 | let p = Z3_mk_context_rc(cfg.z3_cfg); 12 | debug!("new context {:p}", p); 13 | p 14 | }, 15 | } 16 | } 17 | 18 | /// Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions. 19 | /// 20 | /// This method can be invoked from a thread different from the one executing the 21 | /// interruptible procedure. 22 | pub fn interrupt(&self) { 23 | unsafe { 24 | Z3_interrupt(self.z3_ctx); 25 | } 26 | } 27 | } 28 | 29 | impl Drop for Context { 30 | fn drop(&mut self) { 31 | unsafe { Z3_del_context(self.z3_ctx) }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/mustpass/tail_of_void/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | using slice; 3 | using err; 4 | 5 | fn dump(void+vt * obj, usize expect) { 6 | log::info("dumping object of size %d", vt); 7 | 8 | err::assert(expect == vt); 9 | } 10 | 11 | struct A { 12 | u16 x; 13 | u16 y; 14 | }; 15 | 16 | 17 | struct X+ { 18 | u32 forp; 19 | u32 dummy; 20 | u32 x[]; 21 | }; 22 | 23 | fn ftail(X+xt * obj) { 24 | dump(obj, 108); 25 | } 26 | 27 | 28 | fn wrap(void+vt mut *val, usize expect) { 29 | dump(val, expect); 30 | } 31 | 32 | export fn main() -> int { 33 | 34 | A a; 35 | 36 | dump(&a, 4); 37 | dump(&A{x:1}, 4); 38 | 39 | A *b = &a; 40 | dump(b, 4); 41 | 42 | 43 | dump("literal string", 15); 44 | 45 | u8 mem[19]; 46 | dump(mem, 19); 47 | 48 | X+100 mut x; 49 | ftail(&x); 50 | dump(&x, 108); 51 | 52 | dump(slice::slice::Slice{mem: (u8*)"abc", size: 3}, 3); 53 | 54 | 55 | wrap(&x, 108); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /modules/buffer/tests/append.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{printf, stdin}; 3 | using ::{free}; 4 | inline using "native.h"::{getline}; 5 | 6 | 7 | test append{ 8 | stdin = "hello\n world\n" 9 | stdout = "hello\n world\n" 10 | } 11 | 12 | test overflow{ 13 | stdin = "lorum ipsdulbla bla something something hello hello" 14 | stdout = "lorum ipsdulbla bla something something hello hel" 15 | } 16 | 17 | export fn main() -> int { 18 | buffer::Buffer+50 mut s = {0}; 19 | buffer::make(&s); 20 | 21 | for (;;) { 22 | char mut * mut line = 0; 23 | usize mut l = 0; 24 | int nread = as(getline(&line, &l, stdin)); 25 | if nread < 1 { 26 | free(line); 27 | break; 28 | } 29 | static_attest(safe(line)); 30 | static_attest(nullterm(line)); 31 | buffer::append_cstr(&s, line); 32 | free(line); 33 | } 34 | 35 | printf("%.*s", s.at, s.mem); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /modules/pool/tests/m.zz: -------------------------------------------------------------------------------- 1 | using pool; 2 | using ::{printf}; 3 | using ::{assert}; 4 | 5 | fn main() -> int { 6 | for (usize mut i= 0; i < 1000; i++) { 7 | m2(); 8 | } 9 | return 0; 10 | } 11 | 12 | fn m2(){ 13 | pool::Pool+10000 mut p; 14 | p.make(64); 15 | 16 | void mut * mut a = 0; 17 | for (usize mut i = 0;;i++) { 18 | void mut *b = p.malloc(1 + (30 * (i%3))); 19 | if b == 0 { 20 | printf("memory full after %zu rounds\n", i); 21 | break; 22 | } 23 | unsafe { 24 | *(char mut*)b = 1; 25 | } 26 | if i % 3 == 0 { 27 | p.free(b); 28 | } else { 29 | a = b; 30 | } 31 | 32 | } 33 | 34 | printf("%p\n", a); 35 | static_attest(pool::member(a, &p)); 36 | p.free(a); 37 | 38 | void mut *b = p.malloc(180); 39 | assert(b == 0); 40 | 41 | void mut *c = p.malloc(1); 42 | printf("last: %p\n", c); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/mustpass/structs/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | struct A { 5 | uint a; 6 | } 7 | 8 | 9 | struct V { 10 | A a; 11 | } 12 | 13 | 14 | 15 | 16 | fn peter(V *v) 17 | { 18 | if (v->a).a > 0 && (v->a).a < 2 { 19 | static_assert((v->a).a == 1); 20 | printf("yep\n"); 21 | } 22 | } 23 | 24 | 25 | export fn bob(A mut * a) 26 | { 27 | a->a = 1; 28 | static_assert(a->a == 1); 29 | } 30 | 31 | export fn main() -> int { 32 | 33 | 34 | A mut a = {0}; 35 | a.a = 3; 36 | 37 | A mut * b = &a; 38 | static_assert(safe(&a)); 39 | static_assert(safe(b)); 40 | static_assert(&a == b); 41 | 42 | b->a = 8; 43 | 44 | static_assert(b->a == 8); 45 | static_assert(a.a == 8); 46 | 47 | bob(b); 48 | 49 | // must fail 50 | //static_assert(a.a == 8); 51 | 52 | 53 | 54 | V mut v; 55 | (v.a).a = 1; 56 | 57 | peter(&v); 58 | 59 | 60 | printf("hello structs %d\n", a.a); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /modules/buffer/tests/split.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{printf, stdin}; 3 | 4 | 5 | test test1 { 6 | stdin = "a:b:cccasdasd:asd:asd" 7 | stdout == ">a<\n>b<\n>cccasdasd<\n>asd<\n>asd<\n" 8 | } 9 | 10 | test test2 { 11 | stdin = ":b:cccasdasd:asd:asd" 12 | stdout == "><\n>b<\n>cccasdasd<\n>asd<\n>asd<\n" 13 | } 14 | 15 | test test3 { 16 | stdin = "" 17 | stdout == "" 18 | } 19 | 20 | test test4 { 21 | stdin = ":a" 22 | stdout == "><\n>a<\n" 23 | } 24 | 25 | test test5 { 26 | stdin = ":" 27 | stdout == "><\n" 28 | } 29 | 30 | 31 | export fn main() -> int { 32 | 33 | buffer::Buffer+100 mut a; 34 | buffer::make(&a); 35 | buffer::fgets(&a, stdin); 36 | 37 | 38 | usize mut iterator = 0; 39 | buffer::Buffer+100 mut part; 40 | buffer::make(&part); 41 | while (buffer::split(&a, ':', &iterator, &part)) { 42 | printf(">%.*s<\n", (int)part.at, part.mem); 43 | buffer::clear(&part); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /tests/mustpass/typeid/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | 3 | 4 | 5 | export theory bob() type; 6 | 7 | struct A { 8 | } 9 | 10 | struct B { 11 | } 12 | 13 | 14 | export fn callme(void* whatever) 15 | where typeof(*whatever) == bob() 16 | { 17 | } 18 | 19 | export fn main() int { 20 | 21 | static_assert(typeof(A) == typeof(A)); 22 | 23 | A a1; 24 | A a2; 25 | 26 | static_assert(typeof(a1) == typeof(a2)); 27 | 28 | 29 | static_attest(bob() == typeof(a1)); 30 | 31 | static_assert(typeof(a1) == bob()); 32 | static_assert(typeof(a2) == bob()); 33 | 34 | B b1; 35 | 36 | static_assert(typeof(b1) != bob()); 37 | 38 | 39 | callme(&a1); 40 | 41 | 42 | 43 | void * a; 44 | static_assert(!constrained(typeof(*a))); 45 | static_attest(typeof(*a) == bob()); 46 | static_assert(constrained(typeof(*a))); 47 | 48 | static_assert(typeof(u8) == typeof(u8)); 49 | static_assert(typeof(u8) != typeof(i8)); 50 | 51 | log::info("hello %s", "typeof"); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Arvid E. Picciani 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /modules/buffer/tests/from.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{printf, stdin}; 3 | using ::{free}; 4 | inline using "native.h"::{getline}; 5 | 6 | 7 | test from{ 8 | stdin = "hello world\n" 9 | stdout = "hello world\nhello world\nhello world\n" 10 | } 11 | 12 | export fn main() -> int { 13 | char mut * mut line = 0; 14 | usize mut l = 0; 15 | int nread = as(getline(&line, &l, stdin)); 16 | if nread < 1 { 17 | free(line); 18 | } else { 19 | static_attest(safe(line)); 20 | static_attest(nullterm(line)); 21 | static_attest(len(line) == (usize) nread); 22 | new+50 mut s = buffer::from_bytes((u8 *)line, (usize)nread); 23 | new+50 mut copy = buffer::from_slice(s.as_slice()); 24 | new+50 mut cstr_copy = buffer::from_cstr(copy.cstr()); 25 | free(line); 26 | printf("%.*s", s.slen(), s.mem); 27 | printf("%.*s", copy.slen(), copy.mem); 28 | printf("%.*s", cstr_copy.slen(), cstr_copy.mem); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /examples/hello/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using identity::{some_helper}; 3 | using aye; 4 | using err; 5 | 6 | thread_local u8 mut wee = 1; 7 | atomic u32 mut bargh = 932; 8 | 9 | struct Bob { 10 | char a; 11 | char b; 12 | }; 13 | static u32 mut bob = 932; 14 | static Bob mut stbob = Bob{ 15 | a: 2, 16 | }; 17 | 18 | pub fn gimme_wee(aye::bob * unsafe lol) -> u8 { 19 | bob += (u32)lol; 20 | return wee; 21 | } 22 | 23 | export fn main() -> int { 24 | err::Err mut e = {0}; 25 | u32 bob; 26 | 27 | wee += 0.1; 28 | 29 | flsomething(); 30 | 31 | if some_helper(&e, &bob) == 41 { 32 | return 0; 33 | } else { 34 | return 1; 35 | } 36 | } 37 | 38 | 39 | fn boop() { 40 | } 41 | 42 | 43 | export fn flsomething() { 44 | 45 | printf("static struct initialization Bob should be 2,0: %d,%d\n", stbob.a, stbob.b); 46 | 47 | //fl::MAKE(b, 8, 1000); 48 | //for (int mut i = 0; i < 10; i+=1) { 49 | // fl::alloc(b); 50 | //} 51 | } 52 | 53 | 54 | using ::{bool, false}; 55 | static bool horst = false; 56 | -------------------------------------------------------------------------------- /tests/mustpass/branch_dont_loose_deref/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{memcpy, memset}; 3 | 4 | 5 | export const usize MAX_BROKERS = 16; 6 | export struct Broker packed { 7 | u8 protocol; 8 | } 9 | export struct Store { 10 | Broker broker[MAX_BROKERS]; 11 | } 12 | 13 | 14 | pub fn parse_query(Store mut*store, usize answers) -> bool 15 | { 16 | usize mut storepos = 0; 17 | 18 | bool mut it; 19 | while it { 20 | // the bug was that we did a deref here 21 | ((store->broker)[storepos]).protocol = 2; 22 | } 23 | // and the symbol for the deref is lost here in smt but not in symbolic, 24 | // because in smt, the declarations are removed on pop 25 | // but in symbolic, symbols are a global counter exactly so we can carry over deref 26 | 27 | if ((store->broker)[storepos]).protocol >0 { 28 | storepos += 1; 29 | } else { 30 | static_attest(storepos < len(store->broker)); 31 | memset(&(store->broker)[storepos], 0, sizeof(Broker)); 32 | } 33 | 34 | 35 | return true; 36 | } 37 | 38 | 39 | export fn main(int argc, char **argv) -> int 40 | where (usize)argc <= len(argv) 41 | { 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /modules/hex/tests/str2bytes.zz: -------------------------------------------------------------------------------- 1 | using ::{memcmp, strlen}; 2 | using ::{printf, fgetc, putchar, fgets, stdin, FILE}; 3 | using hex; 4 | using ::{malloc, realloc, free}; 5 | 6 | 7 | 8 | test { 9 | stdin = "" 10 | stdout = "" 11 | } 12 | 13 | test { 14 | stdin = "76" 15 | stdout = {0x76} 16 | } 17 | 18 | test { 19 | stdin = "7612" 20 | stdout = {0x76, 0x12} 21 | } 22 | 23 | test { 24 | stdin = "EeEafF8e" 25 | stdout = {0xee, 0xea, 0xff, 0x8e} 26 | } 27 | 28 | fn t(char *str) { 29 | u8 mut out[1024]; 30 | out[0] = 0; 31 | 32 | usize slen = as(strlen(str)); 33 | static_attest(len(str) == slen); 34 | usize count = hex::str2bin(str, slen, out, 1024); 35 | 36 | static_attest(count < len(out)); 37 | 38 | for (usize mut i = 0; i < count; i++) { 39 | putchar(out[i]); 40 | } 41 | } 42 | 43 | pub fn main() -> int { 44 | for (;;) { 45 | char mut line[128]; 46 | usize mut l = 0; 47 | 48 | char *rr = (char*)fgets(line, sizeof(line), stdin); 49 | if rr == 0 { 50 | break; 51 | } 52 | static_attest(safe(line)); 53 | static_attest(nullterm(line)); 54 | t(line); 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /modules/byteorder/src/lib.h: -------------------------------------------------------------------------------- 1 | #if !defined(BYTE_ORDER) 2 | #if defined(__BYTE_ORDER__) 3 | #define BYTE_ORDER __BYTE_ORDER__ 4 | #elif defined(__BYTE_ORDER) 5 | #define BYTE_ORDER __BYTE_ORDER 6 | #else 7 | #error cannot find a definition of BYTE_ORDER 8 | #endif 9 | #endif 10 | 11 | #if !defined(LITTLE_ENDIAN) 12 | #if defined(__LITTLE_ENDIAN) 13 | #define LITTLE_ENDIAN __LITTLE_ENDIAN 14 | #elif defined(__ORDER_LITTLE_ENDIAN__) 15 | #define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ 16 | #else 17 | #error cannot find a definition of LITTLE_ENDIAN 18 | #endif 19 | #endif 20 | 21 | #if !defined(BIG_ENDIAN) 22 | #if defined(__BIG_ENDIAN) 23 | #define BIG_ENDIAN __BIG_ENDIAN 24 | #elif defined(__ORDER_BIG_ENDIAN__) 25 | #define BIG_ENDIAN __ORDER_BIG_ENDIAN__ 26 | #else 27 | #error cannot find a definition of BIG_ENDIAN 28 | #endif 29 | #endif 30 | 31 | #if BYTE_ORDER == LITTLE_ENDIAN 32 | #if BYTE_ORDER == BIG_ENDIAN 33 | #error "compiler claims byte order is both little and big endian" 34 | #endif 35 | #else 36 | #if BYTE_ORDER == BIG_ENDIAN 37 | 38 | #else 39 | #error "compiler claims byte order is neither little nor big endian" 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /tests/mustpass/tail/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | struct Bob+ { 6 | int a; 7 | int b[]; 8 | } 9 | 10 | 11 | // old style generated arg 12 | fn whutup(Bob+t * bob) 13 | where t > 10 14 | { 15 | printf("hello bob and a %zu integers\n", t); 16 | int x = (bob->b)[t-1]; 17 | printf(" the %zu'th integer is %d\n", t-1, x); 18 | } 19 | 20 | // as callsite assign of len 21 | fn broccoli(Bob * bob, usize t = static(len(bob->b))) 22 | where t > 10 23 | { 24 | printf("hello bob and a %zu integers\n", t); 25 | int x = (bob->b)[t-1]; 26 | printf(" the %zu'th integer is %d\n", t-1, x); 27 | } 28 | 29 | // as callsite assign of tailof 30 | fn yahl(Bob * bob, usize t = static(tailof(*bob))) 31 | where t > 10 32 | { 33 | // this would be needed if we did not do type_params_into_ssa earlier 34 | //static_attest(t == len(bob->b)); 35 | 36 | printf("hello bob and a %zu integers\n", t); 37 | int x = (bob->b)[t-1]; 38 | printf(" the %zu'th integer is %d\n", t-1, x); 39 | } 40 | 41 | export fn main() -> int { 42 | 43 | Bob+100 mut b = {0}; 44 | static_assert(tailof(b) == 100); 45 | 46 | (b.b)[99] = 99; 47 | static_assert(tailof(b) == 100); 48 | 49 | 50 | 51 | whutup(&b); 52 | broccoli(&b); 53 | static_assert(tailof(b) == 100); 54 | yahl(&b); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /modules/vec/src/main.zz: -------------------------------------------------------------------------------- 1 | using log; 2 | using vec; 3 | using pool; 4 | using err; 5 | 6 | 7 | export struct A { 8 | int d; 9 | } 10 | 11 | export struct B { 12 | int d; 13 | } 14 | 15 | export fn main() int { 16 | 17 | 18 | new+1000 p = pool::make(8); 19 | 20 | 21 | new+0 l = vec::make_with_pool(&p); 22 | 23 | 24 | 25 | err::assert(l.push("hello")); 26 | err::assert(l.put("bob")); 27 | 28 | 29 | 30 | 31 | int ar[2] = {0}; 32 | err::assert(l.push(ar)); 33 | 34 | u8 o = 12; 35 | l.push(&o); 36 | 37 | err::assert(l.count == 4); 38 | 39 | let mut v = l.items[0]; 40 | log::info(">%.*s<", v.size, v.mem); 41 | v = l.items[1]; 42 | log::info(">%.*s<", v.size, v.mem); 43 | 44 | 45 | 46 | new[vec::item = A, +0] l2 = vec::make_with_pool(&p); 47 | 48 | 49 | A a; 50 | l2.push(&a); 51 | A a2 = A{d:99}; 52 | l2.push(&a2); 53 | 54 | err::assert(l2.count == 2); 55 | A * a3 = (A*)l2.get(1); 56 | err::assert(a3->d == 99); 57 | 58 | 59 | // must not compile 60 | //B b; 61 | //l2.push(&b); 62 | 63 | 64 | new[vec::item = u64, +1000] l3 = vec::make(); 65 | u64 val = 9; 66 | l3.push(&val); 67 | err::assert(l3.count == 1); 68 | static_assert(typeof(*l3.get(0)) == typeof(u64)); 69 | u64 val_back = *((u64*)l3.get(0)); 70 | err::assert(val_back == val); 71 | 72 | 73 | 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /src/export_make.rs: -------------------------------------------------------------------------------- 1 | use super::make::Make; 2 | use std::fs; 3 | use std::io::Write; 4 | use super::emitter_common; 5 | 6 | pub fn export(make: Make) { 7 | let td = super::project::target_dir(); 8 | let pdir_ = td.join("make").join(&make.artifact.name); 9 | let pdir = std::path::Path::new(&pdir_); 10 | std::fs::create_dir_all(&pdir).unwrap(); 11 | 12 | let p = pdir.join("Makefile.include"); 13 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 14 | 15 | 16 | 17 | 18 | 19 | write!( 20 | f, 21 | r#" 22 | 23 | {an}_TARGET_DIR := $(dir $(lastword $(MAKEFILE_LIST))) 24 | 25 | {an}_SOURCES=\ 26 | "#, 27 | an=make.artifact.name 28 | ) 29 | .unwrap(); 30 | 31 | for step in &make.steps { 32 | write!( 33 | f, 34 | " ${{{an}_TARGET_DIR}}/{ss}\\\n", 35 | an = make.artifact.name, 36 | ss = emitter_common::path_rel(&pdir, &step.source).to_string_lossy().to_string(), 37 | ) 38 | .unwrap(); 39 | } 40 | 41 | write!(f, "\n").unwrap(); 42 | 43 | 44 | write!(f, "{an}_CINCLUDES += ${{{an}_TARGET_DIR}} \\\n", an = make.artifact.name).unwrap(); 45 | for ss in &make.cincludes{ 46 | write!(f, " ${{{an}_TARGET_DIR}}/{ss}\\\n", an = make.artifact.name, 47 | ss = emitter_common::path_rel(&pdir, ss).to_string_lossy().to_string(), 48 | ).unwrap(); 49 | } 50 | write!(f, "\n").unwrap(); 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /modules/buffer/tests/native.h: -------------------------------------------------------------------------------- 1 | #if defined(__linux__) || defined(__APPLE__) 2 | #include 3 | #endif 4 | 5 | #if defined(_WIN64) || defined(_WIN32) 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // if typedef doesn't exist (msvc, blah) 12 | typedef intptr_t ssize_t; 13 | 14 | ssize_t getline(char **lineptr, size_t *n, FILE *stream) { 15 | size_t pos; 16 | int c; 17 | 18 | if (lineptr == NULL || stream == NULL || n == NULL) { 19 | errno = EINVAL; 20 | return -1; 21 | } 22 | 23 | c = getc(stream); 24 | if (c == EOF) { 25 | return -1; 26 | } 27 | 28 | if (*lineptr == NULL) { 29 | *lineptr = malloc(128); 30 | if (*lineptr == NULL) { 31 | return -1; 32 | } 33 | *n = 128; 34 | } 35 | 36 | pos = 0; 37 | while(c != EOF) { 38 | if (pos + 1 >= *n) { 39 | size_t new_size = *n + (*n >> 2); 40 | if (new_size < 128) { 41 | new_size = 128; 42 | } 43 | char *new_ptr = realloc(*lineptr, new_size); 44 | if (new_ptr == NULL) { 45 | return -1; 46 | } 47 | *n = new_size; 48 | *lineptr = new_ptr; 49 | } 50 | 51 | ((unsigned char *)(*lineptr))[pos ++] = c; 52 | if (c == '\n') { 53 | break; 54 | } 55 | c = getc(stream); 56 | } 57 | 58 | (*lineptr)[pos] = '\0'; 59 | return pos; 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/name.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | use std::hash::{Hash, Hasher}; 3 | 4 | #[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Serialize, Deserialize)] 5 | pub struct Name(pub Vec); 6 | 7 | impl Name { 8 | pub fn push(&mut self, v: String) { 9 | for v in v.split("::") { 10 | self.0.push(v.to_string()); 11 | } 12 | } 13 | 14 | pub fn pop(&mut self) -> Option { 15 | self.0.pop() 16 | } 17 | 18 | pub fn len(&self) -> usize { 19 | self.0.len() 20 | } 21 | 22 | pub fn is_absolute(&self) -> bool { 23 | if let Some(s) = self.0.get(0) { 24 | return s.is_empty(); 25 | } else { 26 | false 27 | } 28 | } 29 | 30 | pub fn human_name(&self) -> String { 31 | if self.is_absolute() { 32 | (self.0)[1..].join("::") 33 | } else { 34 | self.0.join("::") 35 | } 36 | } 37 | } 38 | 39 | impl Hash for Name { 40 | fn hash(&self, state: &mut H) { 41 | self.0.hash(state); 42 | } 43 | } 44 | 45 | impl std::fmt::Display for Name { 46 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 47 | write!(f, "{}", self.0.join("::")) 48 | } 49 | } 50 | 51 | impl From<&str> for Name { 52 | fn from(s: &str) -> Self { 53 | Name(s.split("::").map(|s| s.to_string()).collect()) 54 | } 55 | } 56 | 57 | impl From<&String> for Name { 58 | fn from(s: &String) -> Self { 59 | Name(s.split("::").map(|s| s.to_string()).collect()) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /modules/table/src/lib.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{assert}; 3 | 4 | struct Slot { 5 | bool used; 6 | usize key; 7 | void mut* value; 8 | } 9 | 10 | export struct Table+ { 11 | u8 dummy; 12 | Slot slots[]; 13 | } 14 | 15 | export fn insert(Table+tt mut* self, usize key, void mut* unsafe value) -> bool { 16 | for (usize mut i=0; i < tt; i++) { 17 | usize index = (key + i * i) % tt; 18 | static_attest(index < tt); 19 | if !self->slots[index].used { 20 | self->slots[index] = Slot { 21 | used: true, 22 | key: key, 23 | value: value, 24 | }; 25 | return true; 26 | } 27 | } 28 | return false; 29 | } 30 | 31 | export fn get(Table+tt mut* self, usize key) -> void mut* 32 | { 33 | for (usize mut i=0; i < tt; i++) { 34 | usize index = (key + i * i) % tt; 35 | static_attest(index < tt); 36 | 37 | if self->slots[index].used && (self->slots[index].key == key) { 38 | return self->slots[index].value; 39 | } 40 | } 41 | return 0; 42 | } 43 | 44 | export fn remove(Table+tt mut* self, usize key) -> void mut* 45 | { 46 | for (usize mut i=0; i < tt; i++) { 47 | usize index = (key + i * i) % tt; 48 | static_attest(index < tt); 49 | 50 | if self->slots[index].used && (self->slots[index].key == key) { 51 | void mut*v = self->slots[index].value; 52 | self->slots[index].used = false; 53 | return v; 54 | } 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /src/export_esp.rs: -------------------------------------------------------------------------------- 1 | use super::make::Make; 2 | use std::fs; 3 | use std::io::Write; 4 | 5 | pub fn export(make: Make) { 6 | let pdir_ = format!("target/esp32/{}/", make.artifact.name); 7 | let pdir = std::path::Path::new(&pdir_); 8 | std::fs::create_dir_all(&pdir).unwrap(); 9 | 10 | let p = pdir.join("CMakeLists.txt"); 11 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 12 | 13 | write!(f, "idf_component_register(SRCS \n").unwrap(); 14 | for step in &make.steps { 15 | if step.source.is_absolute() { 16 | write!(f, " {}\n", step.source.to_string_lossy()).unwrap(); 17 | } else { 18 | write!( 19 | f, 20 | " ${{CMAKE_CURRENT_LIST_DIR}}/../../../{}\n", 21 | step.source.to_string_lossy() 22 | ) 23 | .unwrap(); 24 | } 25 | } 26 | write!(f, "INCLUDE_DIRS ${{CMAKE_CURRENT_LIST_DIR}}/../../include/\n").unwrap(); 27 | 28 | if make.artifact.requires.len() > 0 { 29 | write!(f, " REQUIRES ").unwrap(); 30 | } 31 | for r in &make.artifact.requires { 32 | write!(f, " {} \n", r).unwrap(); 33 | } 34 | 35 | write!(f, ")\n").unwrap(); 36 | 37 | write!(f, " target_compile_options(${{COMPONENT_LIB}} PRIVATE \n").unwrap(); 38 | write!( 39 | f, 40 | " 41 | -fdiagnostics-color=always 42 | -Wno-error=duplicate-decl-specifier 43 | -Wno-unused-function 44 | -Wno-attributes 45 | " 46 | ) 47 | .unwrap(); 48 | for cflag in &make.cflags { 49 | write!(f, "{}\n", cflag).unwrap(); 50 | } 51 | write!(f, ")\n").unwrap(); 52 | } 53 | -------------------------------------------------------------------------------- /modules/pool/src/asan.h: -------------------------------------------------------------------------------- 1 | // Marks memory region [addr, addr+size) as unaddressable. 2 | // This memory must be previously allocated by the user program. Accessing 3 | // addresses in this region from instrumented code is forbidden until 4 | // this region is unpoisoned. This function is not guaranteed to poison 5 | // the whole region - it may poison only subregion of [addr, addr+size) due 6 | // to ASan alignment restrictions. 7 | // Method is NOT thread-safe in the sense that no two threads can 8 | // (un)poison memory in the same memory region simultaneously. 9 | void __asan_poison_memory_region(void const volatile *addr, size_t size); 10 | // Marks memory region [addr, addr+size) as addressable. 11 | // This memory must be previously allocated by the user program. Accessing 12 | // addresses in this region is allowed until this region is poisoned again. 13 | // This function may unpoison a superregion of [addr, addr+size) due to 14 | // ASan alignment restrictions. 15 | // Method is NOT thread-safe in the sense that no two threads can 16 | // (un)poison memory in the same memory region simultaneously. 17 | void __asan_unpoison_memory_region(void const volatile *addr, size_t size); 18 | 19 | // User code should use macros instead of functions. 20 | #if defined(__SANITIZE_ADDRESS__) 21 | #define ASAN_POISON_MEMORY_REGION(addr, size) \ 22 | __asan_poison_memory_region((addr), (size)) 23 | #define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ 24 | __asan_unpoison_memory_region((addr), (size)) 25 | #else 26 | #define ASAN_POISON_MEMORY_REGION(addr, size) \ 27 | ((void)(addr), (void)(size)) 28 | #define ASAN_UNPOISON_MEMORY_REGION(addr, size) \ 29 | ((void)(addr), (void)(size)) 30 | #endif 31 | -------------------------------------------------------------------------------- /tests/mustpass/loop_condition/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | 3 | 4 | 5 | inline fn alias(void * alias a) {} 6 | 7 | export fn main() -> int { 8 | 9 | 10 | usize no_changes_in_loop = 1; 11 | 12 | usize mut changes_in_loop1 = 1; 13 | usize mut changes_in_loop2 = 1; 14 | usize mut changes_in_loop3 = 1; 15 | usize mut changes_in_loop4 = 1; 16 | 17 | for (usize mut i = 0; i < 3; i++) { 18 | static_assert( i < 3 ); 19 | 20 | // this would not compile if ssa incorrectly believes i has a known value 21 | if i == 0 { 22 | } 23 | 24 | changes_in_loop1++; 25 | if changes_in_loop1 > 2 { 26 | } 27 | 28 | changes_in_loop2 += 1; 29 | if changes_in_loop2 > 2 { 30 | } 31 | 32 | 33 | static_assert(no_changes_in_loop == 1); 34 | 35 | int mut declared_in_loop = 3; 36 | static_assert(declared_in_loop == 3); 37 | 38 | if i == 0 { 39 | } 40 | 41 | 42 | int uninitialized; 43 | 44 | if uninitialized == 2 { 45 | continue; 46 | } 47 | static_assert(uninitialized != 2); 48 | 49 | 50 | // this is a workaround until symbolic understands loop passes 51 | // we just tell it the value is unknown because there's an alias 52 | alias(&changes_in_loop3); 53 | 54 | // change in previous iteration 55 | if changes_in_loop3 == 1 { 56 | changes_in_loop4 = 2; 57 | } 58 | changes_in_loop3 = 8; 59 | } 60 | 61 | 62 | if changes_in_loop1 == 2 { 63 | } 64 | if changes_in_loop2 == 2 { 65 | } 66 | if changes_in_loop3 == 2 { 67 | } 68 | if changes_in_loop4 == 2 { 69 | } 70 | 71 | printf("hello loop_condition\n"); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /modules/byteorder/src/lib.zz: -------------------------------------------------------------------------------- 1 | inline using "lib.h"::{BYTE_ORDER, BIG_ENDIAN, LITTLE_ENDIAN}; 2 | 3 | // host to big endian 4 | 5 | pub inline fn to_be16(u16 x) -> u16 if #(BYTE_ORDER == LITTLE_ENDIAN) { 6 | return swap16(x); 7 | } else if #(BYTE_ORDER == BIG_ENDIAN) { 8 | return x; 9 | }; 10 | 11 | pub inline fn from_be16(u16 x) -> u16 { 12 | return to_be16(x); 13 | } 14 | 15 | pub inline fn to_be32(u32 x) -> u32 if #(BYTE_ORDER == LITTLE_ENDIAN) { 16 | return swap32(x); 17 | } else if #(BYTE_ORDER == BIG_ENDIAN) { 18 | return x; 19 | } 20 | 21 | pub inline fn from_be32(u32 x) -> u32 { 22 | return to_be32(x); 23 | } 24 | 25 | 26 | pub inline fn to_be64(u64 x) -> u64 if #(BYTE_ORDER == LITTLE_ENDIAN) { 27 | return swap64(x); 28 | } else if #(BYTE_ORDER == BIG_ENDIAN) { 29 | return x; 30 | } 31 | 32 | pub inline fn from_be64(u64 x) -> u64 { 33 | return to_be64(x); 34 | } 35 | 36 | 37 | // host to little endian 38 | 39 | pub inline fn to_le16(u16 x) -> u16 if #(BYTE_ORDER == BIG_ENDIAN) { 40 | return swap16(x); 41 | } else if #(BYTE_ORDER == LITTLE_ENDIAN) { 42 | return x; 43 | } 44 | 45 | pub inline fn from_le16(u16 x) -> u16 { 46 | return to_le16(x); 47 | } 48 | 49 | pub inline fn to_le32(u32 x) -> u32 if #(BYTE_ORDER == BIG_ENDIAN) { 50 | return swap32(x); 51 | } else if #(BYTE_ORDER == LITTLE_ENDIAN) { 52 | return x; 53 | } 54 | 55 | pub inline fn from_le32(u32 x) -> u32 { 56 | return to_le32(x); 57 | } 58 | 59 | 60 | pub inline fn to_le64(u64 x) -> u64 if #(BYTE_ORDER == BIG_ENDIAN) { 61 | return swap64(x); 62 | } else if #(BYTE_ORDER == LITTLE_ENDIAN) { 63 | return x; 64 | } 65 | 66 | pub inline fn from_le64(u64 x) -> u64 { 67 | return to_le64(x); 68 | } 69 | 70 | 71 | 72 | // swap impl 73 | 74 | 75 | pub inline fn swap16(u16 x) -> u16 76 | { 77 | return x<<8 | x>>8; 78 | } 79 | 80 | pub inline fn swap32(u32 x) -> u32 81 | { 82 | return x>>24 | ( (x >> 8) & 0xff00) | ((x<<8) & 0xff0000) | x<<24; 83 | } 84 | 85 | pub inline fn swap64(u64 x) -> u64 86 | { 87 | return ((u64)swap32(x) + ((u64)0)) << 32 | (u64)swap32(x>>32); 88 | } 89 | -------------------------------------------------------------------------------- /modules/time/src/lib.zz: -------------------------------------------------------------------------------- 1 | using ::{UINT64_MAX}; 2 | 3 | /* remember 4 | 5 | 1s = 1000 milliseconds/ms 6 | 1s = 1000 000 microseconds/us 7 | 1s = 1000 000 000 nanoseconds/ns 8 | 9 | 1ms = 1000000 ns 10 | 11 | */ 12 | 13 | export struct Time { 14 | u64 secs; 15 | u64 nano; 16 | bool finite; 17 | } 18 | 19 | export fn infinite() -> Time { 20 | return Time { 21 | finite: false, 22 | }; 23 | } 24 | 25 | export fn from_seconds(u64 secs) -> Time { 26 | return Time { 27 | secs: secs, 28 | finite: true, 29 | }; 30 | } 31 | 32 | export fn to_seconds(Time *self) -> u64 { 33 | return self->secs; 34 | } 35 | 36 | export fn to_millis(Time *self) -> u64 37 | @prover("yices2") 38 | { 39 | if self->secs > (u64)UINT64_MAX/1000 { 40 | return (u64)UINT64_MAX; 41 | } 42 | u64 mut r = self->secs * 1000; 43 | if r + (self->nano / 1000000) < r { 44 | return (u64)UINT64_MAX; 45 | } 46 | r += self->nano / 1000000; 47 | return r; 48 | } 49 | 50 | export fn from_millis(u64 millis) -> Time { 51 | return Time { 52 | secs: (millis / 1000), 53 | nano: ((millis % 1000) * 1000000), 54 | finite: true, 55 | }; 56 | } 57 | 58 | 59 | export fn more_than(Time *self, Time *other) -> bool { 60 | 61 | if !self->finite { 62 | if !other->finite { 63 | return false; 64 | } else { 65 | return true; 66 | } 67 | } 68 | 69 | if self->secs == other->secs { 70 | if self->nano > other->nano { 71 | return true; 72 | } 73 | return false; 74 | } else if self->secs > other->secs { 75 | return true; 76 | } 77 | return false; 78 | } 79 | 80 | inline using "native.h"::{ os_time_tick, os_time_real} 81 | 82 | /// monotonic system clock 83 | export fn tick() -> Time { 84 | Time mut tr = {0}; 85 | tr.finite = os_time_tick(&tr.secs, &tr.nano) == 0; 86 | return tr; 87 | } 88 | 89 | 90 | /// real world time 91 | export fn real() -> Time { 92 | Time mut tr = {0}; 93 | tr.finite = os_time_real(&tr.secs, &tr.nano) == 0; 94 | return tr; 95 | } 96 | -------------------------------------------------------------------------------- /modules/buffer/tests/substr.zz: -------------------------------------------------------------------------------- 1 | using buffer; 2 | using ::{printf, stdin}; 3 | using ::{free, atoi}; 4 | inline using "native.h"::{getline}; 5 | 6 | 7 | test t1{ 8 | stdin = "abc\nhello\n1\n1" 9 | stdout = "abce" 10 | } 11 | 12 | test t2{ 13 | stdin = "123\nhello\n1\n1000" 14 | stdout = "123ello" 15 | } 16 | 17 | test t3{ 18 | stdin = "\nhello\n1000\n1" 19 | stdout = "" 20 | } 21 | 22 | test t4{ 23 | stdin = "12345678901234567890\nxxxxxxxxxxxxxxxxxxxx\n1\n10" 24 | stdout = "1234567890123456789" 25 | } 26 | 27 | test t5{ 28 | stdin = "123456789012345678\nxxxxxxxxxxxxxxxxxxxx\n1\n10" 29 | stdout = "123456789012345678x" 30 | } 31 | 32 | test t6{ 33 | stdin = "123\nxxxxxxxxxxxxxxxxxxxx\n1\n10000" 34 | stdout = "123xxxxxxxxxxxxxxxx" 35 | } 36 | 37 | test t7{ 38 | stdin = "123\nxxxxxxxxxxxxxxxxxxxx\n1\n0" 39 | stdout = "123xxxxxxxxxxxxxxxx" 40 | } 41 | 42 | 43 | export fn main() -> int { 44 | buffer::Buffer+20 mut sub; 45 | buffer::make(&sub); 46 | 47 | char mut * mut line = 0; 48 | usize mut l = 0; 49 | int mut nread = as(getline(&line, &l, stdin)); 50 | if nread < 1 { return 1; } 51 | static_attest(safe(line)); 52 | static_attest(len(line) >= (usize)nread); 53 | buffer::append_bytes(&sub, (u8*)line, (usize)nread -1); 54 | 55 | 56 | buffer::Buffer+20 mut s; 57 | buffer::make(&s); 58 | 59 | nread = as(getline(&line, &l, stdin)); 60 | if nread < 1 { return 1; } 61 | static_attest(safe(line)); 62 | static_attest(len(line) >= (usize)nread); 63 | buffer::append_bytes(&s, (u8*)line, (usize)nread -1); 64 | 65 | 66 | nread = as(getline(&line, &l, stdin)); 67 | if nread < 1 { return 1; } 68 | int start = as(atoi(line)); 69 | if start < 0 { 70 | return 2; 71 | } 72 | 73 | 74 | nread = as(getline(&line, &l, stdin)); 75 | if nread < 1 { return 1; } 76 | int size = as(atoi(line)); 77 | if size < 0 { 78 | return 2; 79 | } 80 | 81 | free(line); 82 | 83 | 84 | buffer::substr(&s, (usize)start, (usize)size, &sub); 85 | 86 | 87 | printf("%.*s", sub.at, sub.mem); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /modules/log/src/lib.zz: -------------------------------------------------------------------------------- 1 | using ::{va_list, va_start, va_end}; 2 | using buffer; 3 | 4 | inline using "os.h"::{ 5 | os_zz_log_error, 6 | os_zz_log_warn, 7 | os_zz_log_info, 8 | os_zz_log_debug, 9 | getenv, 10 | } 11 | 12 | 13 | enum LogLevel { 14 | Invalid = 99999, 15 | None = 0, 16 | Error = 1, 17 | Warn = 2, 18 | Info = 3, 19 | Debug = 4, 20 | } 21 | 22 | 23 | static LogLevel mut s_log_level = LogLevel::Invalid; 24 | 25 | fn log_level() -> LogLevel { 26 | if s_log_level == LogLevel::Invalid { 27 | s_log_level = LogLevel::Info; 28 | 29 | char * e = getenv("ZZLOG"); 30 | if e != 0 { 31 | static_attest(safe(e)); 32 | static_attest(nullterm(e)); 33 | if buffer::cstr_eq(e, "info") { 34 | s_log_level = LogLevel::Info; 35 | } else if buffer::cstr_eq(e, "info") { 36 | s_log_level = LogLevel::Info; 37 | } else if buffer::cstr_eq(e, "err") { 38 | s_log_level = LogLevel::Error; 39 | } else if buffer::cstr_eq(e, "error") { 40 | s_log_level = LogLevel::Error; 41 | } else if buffer::cstr_eq(e, "debug") { 42 | s_log_level = LogLevel::Debug; 43 | } else if buffer::cstr_eq(e, "none") { 44 | s_log_level = LogLevel::None; 45 | } 46 | } 47 | } 48 | return s_log_level; 49 | } 50 | 51 | 52 | export fn error(char * callsite_source module, char *fmt, ...) 53 | { 54 | if log_level() < LogLevel::Error { 55 | return; 56 | } 57 | os_zz_log_error(module, fmt); 58 | } 59 | 60 | export fn warn(char * callsite_source module, char *fmt, ...) 61 | { 62 | if log_level() < LogLevel::Warn { 63 | return; 64 | } 65 | os_zz_log_warn(module, fmt); 66 | } 67 | 68 | export fn info(char * callsite_source module, char *fmt, ...) 69 | { 70 | if log_level() < LogLevel::Info { 71 | return; 72 | } 73 | os_zz_log_info(module, fmt); 74 | } 75 | 76 | export fn debug(char * callsite_source module, char *fmt, ...) 77 | { 78 | if log_level() < LogLevel::Debug { 79 | return; 80 | } 81 | os_zz_log_debug(module, fmt); 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/z3/config.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CString; 2 | use z3_sys::*; 3 | use crate::z3::Config; 4 | use crate::z3::Z3_MUTEX; 5 | 6 | impl Config { 7 | pub fn new() -> Config { 8 | Config { 9 | kvs: Vec::new(), 10 | z3_cfg: unsafe { 11 | let guard = Z3_MUTEX.lock().unwrap(); 12 | let p = Z3_mk_config(); 13 | debug!("new config {:p}", p); 14 | p 15 | }, 16 | } 17 | } 18 | pub fn set_param_value(&mut self, k: &str, v: &str) { 19 | let ks = CString::new(k).unwrap(); 20 | let vs = CString::new(v).unwrap(); 21 | self.kvs.push((ks, vs)); 22 | let guard = Z3_MUTEX.lock().unwrap(); 23 | unsafe { 24 | Z3_set_param_value( 25 | self.z3_cfg, 26 | self.kvs.last().unwrap().0.as_ptr(), 27 | self.kvs.last().unwrap().1.as_ptr(), 28 | ) 29 | }; 30 | } 31 | 32 | pub fn set_global_param_value(k: &str, v: &str) { 33 | let ks = CString::new(k).unwrap(); 34 | let vs = CString::new(v).unwrap(); 35 | let guard = Z3_MUTEX.lock().unwrap(); 36 | unsafe { 37 | Z3_global_param_set( 38 | ks.as_ptr(), 39 | vs.as_ptr(), 40 | ) 41 | }; 42 | } 43 | 44 | pub fn set_bool_param_value(&mut self, k: &str, v: bool) { 45 | self.set_param_value(k, if v { "true" } else { "false" }); 46 | } 47 | 48 | // Helpers for common parameters 49 | pub fn set_proof_generation(&mut self, b: bool) { 50 | self.set_bool_param_value("proof", b); 51 | } 52 | 53 | pub fn set_model_generation(&mut self, b: bool) { 54 | self.set_bool_param_value("model", b); 55 | } 56 | 57 | pub fn set_debug_ref_count(&mut self, b: bool) { 58 | self.set_bool_param_value("debug_ref_count", b); 59 | } 60 | 61 | pub fn set_timeout_msec(&mut self, ms: u64) { 62 | self.set_param_value("timeout", &format!("{}", ms)); 63 | } 64 | } 65 | 66 | impl Default for Config { 67 | fn default() -> Self { 68 | Self::new() 69 | } 70 | } 71 | 72 | impl Drop for Config { 73 | fn drop(&mut self) { 74 | let guard = Z3_MUTEX.lock().unwrap(); 75 | unsafe { Z3_del_config(self.z3_cfg) }; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /modules/hex/src/lib.zz: -------------------------------------------------------------------------------- 1 | using ::{memset}; 2 | using ::{printf, fprintf, FILE}; 3 | using slice; 4 | 5 | static u8 map[] = { 6 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 01234567 7 | 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 89:;<=>? 8 | 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, // @ABCDEFG 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // HIJKLMNO 10 | }; 11 | 12 | export fn str2bin(char *in, usize inlen, u8 mut * mut out, usize outlen = static(len(out))) -> usize 13 | where len(in) >= inlen 14 | where len(out) >= outlen 15 | model return <= inlen 16 | model return <= len(out) 17 | { 18 | usize mut pos; 19 | u8 mut idx0; 20 | u8 mut idx1; 21 | *in is safe; 22 | 23 | memset(out, 0, outlen); 24 | for (pos = 0; ((pos < (outlen*2)) && ((pos + 1) < inlen)); pos += 2) { 25 | 26 | usize p0 = pos+0; 27 | usize p1 = pos+1; 28 | p0 is bound; 29 | p1 is bound; 30 | 31 | unsafe { 32 | idx0 = (((u8)in[p0]) & 0x1f) ^ 0x10; 33 | idx1 = (((u8)in[p1]) & 0x1f) ^ 0x10; 34 | 35 | out[pos/2] = map[idx0] << 4 | map[idx1]; 36 | } 37 | } 38 | return pos/2; 39 | } 40 | 41 | 42 | export fn print(u8 *data, usize l = static(len(data))) 43 | where len(data) >= l 44 | { 45 | for (usize mut i = 0; i < l; i++) { 46 | printf("%02x", data[i]); 47 | } 48 | } 49 | 50 | 51 | export fn dump_slice(slice::Slice s) 52 | where slice::slice::integrity(&s) 53 | { 54 | for (usize mut i = 0; i < s.size; i++) { 55 | printf("%02x ", s.mem[i]); 56 | if i % 16 == 15 { 57 | printf("\n"); 58 | } 59 | } 60 | printf("\n"); 61 | } 62 | 63 | export fn dump(u8 * unsafe data, usize l = static(len(data))) 64 | where len(data) >= l 65 | { 66 | for (usize mut i = 0; i < l; i++) { 67 | printf("%02x ", data[i]); 68 | if i % 16 == 15 { 69 | printf("\n"); 70 | } 71 | } 72 | printf("\n"); 73 | } 74 | 75 | export fn fdump(FILE mut *f, u8 * unsafe data, usize l = static(len(data))) 76 | where len(data) >= l 77 | { 78 | for (usize mut i = 0; i < l; i++) { 79 | fprintf(f, "%02x ", data[i]); 80 | if i % 16 == 15 { 81 | printf("\n"); 82 | } 83 | } 84 | fprintf(f, "\n"); 85 | } 86 | -------------------------------------------------------------------------------- /src/z3/model.rs: -------------------------------------------------------------------------------- 1 | use crate::z3::ast::Ast; 2 | use std::ffi::CStr; 3 | use std::fmt; 4 | use z3_sys::*; 5 | use crate::z3::Model; 6 | use crate::z3::Optimize; 7 | use crate::z3::Solver; 8 | use crate::z3::Z3_MUTEX; 9 | 10 | impl<'ctx> Model<'ctx> { 11 | pub fn of_solver(slv: &Solver<'ctx>) -> Model<'ctx> { 12 | Model { 13 | ctx: slv.ctx, 14 | z3_mdl: unsafe { 15 | let guard = Z3_MUTEX.lock().unwrap(); 16 | let m = Z3_solver_get_model(slv.ctx.z3_ctx, slv.z3_slv); 17 | Z3_model_inc_ref(slv.ctx.z3_ctx, m); 18 | m 19 | }, 20 | } 21 | } 22 | 23 | pub fn of_optimize(opt: &Optimize<'ctx>) -> Model<'ctx> { 24 | Model { 25 | ctx: opt.ctx, 26 | z3_mdl: unsafe { 27 | let guard = Z3_MUTEX.lock().unwrap(); 28 | let m = Z3_optimize_get_model(opt.ctx.z3_ctx, opt.z3_opt); 29 | Z3_model_inc_ref(opt.ctx.z3_ctx, m); 30 | m 31 | }, 32 | } 33 | } 34 | 35 | pub fn eval(&self, ast: &T, model_completion: bool) -> Option 36 | where 37 | T: Ast<'ctx>, 38 | { 39 | let mut tmp: Z3_ast = ast.get_z3_ast(); 40 | let res = { 41 | let guard = Z3_MUTEX.lock().unwrap(); 42 | unsafe { 43 | Z3_model_eval( 44 | self.ctx.z3_ctx, 45 | self.z3_mdl, 46 | ast.get_z3_ast(), 47 | model_completion, 48 | &mut tmp, 49 | ) 50 | } 51 | }; 52 | if res { 53 | Some(T::new(self.ctx, tmp)) 54 | } else { 55 | None 56 | } 57 | } 58 | } 59 | 60 | impl<'ctx> fmt::Display for Model<'ctx> { 61 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 62 | let p = unsafe { Z3_model_to_string(self.ctx.z3_ctx, self.z3_mdl) }; 63 | if p.is_null() { 64 | return Result::Err(fmt::Error); 65 | } 66 | match unsafe { CStr::from_ptr(p) }.to_str() { 67 | Ok(s) => write!(f, "{}", s), 68 | Err(_) => Result::Err(fmt::Error), 69 | } 70 | } 71 | } 72 | 73 | impl<'ctx> Drop for Model<'ctx> { 74 | fn drop(&mut self) { 75 | let guard = Z3_MUTEX.lock().unwrap(); 76 | unsafe { Z3_model_dec_ref(self.ctx.z3_ctx, self.z3_mdl) }; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ${{ matrix.os }} 16 | strategy: 17 | matrix: 18 | os: [macos-latest, windows-latest, ubuntu-18.04] 19 | 20 | defaults: 21 | run: 22 | shell: bash 23 | 24 | steps: 25 | - uses: actions/checkout@v2 26 | 27 | - name: Prepare Artifact 28 | run: | 29 | 7z a artifact.zip modules/ 30 | 31 | - name: macos 32 | if: matrix.os == 'macos-latest' 33 | run: | 34 | brew install SRI-CSL/sri-csl/yices2 35 | ./ci.sh 36 | 37 | - name: ubuntu 38 | if: matrix.os == 'ubuntu-18.04' 39 | run: | 40 | sudo add-apt-repository ppa:sri-csl/formal-methods 41 | sudo apt-get update 42 | sudo apt-get install yices2 43 | ./ci.sh 44 | 45 | - name: windows 46 | if: matrix.os == 'windows-latest' 47 | run: | 48 | curl -fsSL "https://yices.csl.sri.com/releases/2.6.2/yices-2.6.2-x86_64-pc-mingw32-static-gmp.zip" -o "yices2.zip" 49 | 7z e "yices2.zip" -o/c/z3_downloaded -r -y 50 | rm -rf /c/z3_downloaded/z3 ## this is an empty directory 51 | export "PATH=/c/z3_downloaded:/c/msys64/mingw64/bin/:$PATH" 52 | clang --version 53 | export "ZZ_ASAN=false" 54 | ./ci.sh 55 | 56 | - name: Upload Release Asset 57 | if: github.ref == 'refs/heads/master' 58 | env: 59 | FILE: ./.zip 60 | AWS_REGION: 'eu-west-1' 61 | S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} 62 | AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} 63 | AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 64 | GITHUB_OS: ${{matrix.os}} 65 | run: | 66 | mkdir -p ~/.aws 67 | echo "[default]" > ~/.aws/credentials 68 | echo "aws_access_key_id = ${AWS_ACCESS_KEY_ID}" >> ~/.aws/credentials 69 | echo "aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}" >> ~/.aws/credentials 70 | 71 | 7z a artifact.zip target/release/zz* 72 | export BNAME="zz-${GITHUB_RUN_NUMBER}-${GITHUB_SHA}-$(echo $GITHUB_OS | cut -d '-' -f 1).zip" 73 | aws s3 cp artifact.zip s3://${S3_BUCKET}/${BNAME} --region ${AWS_REGION} --acl public-read 74 | export BNAME="zz-master-$(echo $GITHUB_OS | cut -d '-' -f 1).zip" 75 | aws s3 cp artifact.zip s3://${S3_BUCKET}/${BNAME} --region ${AWS_REGION} --acl public-read 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/emitter_go.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused)] 2 | 3 | use super::ast; 4 | use super::flatten; 5 | use super::make; 6 | use super::emitter_common; 7 | use super::name::Name; 8 | use super::parser::{self, emit_error}; 9 | use super::project::Project; 10 | use std::collections::HashSet; 11 | use std::fs; 12 | use std::io::Write; 13 | use std::path::PathBuf; 14 | 15 | pub struct Emitter { 16 | p: String, 17 | project_name: String, 18 | f: fs::File, 19 | module: flatten::Module, 20 | } 21 | 22 | pub fn make_module(make: &super::make::Make) { 23 | let td = super::project::target_dir(); 24 | 25 | let pdir_ = td.join("go").join(&make.artifact.name); 26 | let pdir = std::path::Path::new(&pdir_); 27 | std::fs::create_dir_all(&pdir).unwrap(); 28 | 29 | let p = pdir.join(format!("{}.c", make.artifact.name)); 30 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 31 | 32 | for step in &make.steps { 33 | let s = step.source.parent().unwrap(); 34 | if s.file_name().unwrap() == "zz" || s.file_name().unwrap() == "gen"{ 35 | let c = fs::read_to_string(&step.source).unwrap(); 36 | f.write(c.as_bytes()); 37 | } else { 38 | let ie = emitter_common::path_rel(&pdir, &step.source); 39 | 40 | let f = "c_".to_string() + &ie.to_string_lossy().replace("/", "_").replace("..", "_"); 41 | let p = pdir.join(f); 42 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 43 | write!(f, "#include {:?}", ie); 44 | } 45 | } 46 | 47 | 48 | 49 | let p = pdir.join("go.mod"); 50 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 51 | write!(f, "module {}\n", make.artifact.name).unwrap(); 52 | write!(f, "go 1.14\n").unwrap(); 53 | 54 | 55 | 56 | let p = pdir.join(format!("{}.h", make.artifact.name)); 57 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 58 | for step in &make.steps { 59 | let mut b = step.source.file_stem().unwrap().to_string_lossy(); 60 | let p = format!("target/include/zz/{}.h", b); 61 | let p = std::path::Path::new(&p); 62 | if p.exists() { 63 | let c = fs::read_to_string(&p).unwrap(); 64 | f.write(c.as_bytes()); 65 | } 66 | } 67 | 68 | 69 | 70 | let p = pdir.join(format!("{}.go", make.artifact.name)); 71 | let mut f = fs::File::create(&p).expect(&format!("cannot create {:?}", p)); 72 | write!(f, "package {}\n\n/*\n", make.artifact.name).unwrap(); 73 | write!(f, "#include \"{}.h\"\n", make.artifact.name).unwrap(); 74 | write!(f, "\n*/\nimport \"C\"\n").unwrap(); 75 | } 76 | -------------------------------------------------------------------------------- /src/z3/pattern.rs: -------------------------------------------------------------------------------- 1 | use crate::z3::ast::Ast; 2 | use crate::z3::ast::Dynamic; 3 | use std::convert::TryInto; 4 | use std::ffi::CStr; 5 | use std::fmt; 6 | use z3_sys::*; 7 | use crate::z3::Context; 8 | use crate::z3::Pattern; 9 | use crate::z3::Z3_MUTEX; 10 | 11 | impl<'ctx> Pattern<'ctx> { 12 | /// Create a pattern for quantifier instantiation. 13 | /// 14 | /// Z3 uses pattern matching to instantiate quantifiers. If a 15 | /// pattern is not provided for a quantifier, then Z3 will 16 | /// automatically compute a set of patterns for it. However, for 17 | /// optimal performance, the user should provide the patterns. 18 | /// 19 | /// Patterns comprise a list of terms. The list should be 20 | /// non-empty. If the list comprises of more than one term, it is 21 | /// a called a multi-pattern. 22 | /// 23 | /// In general, one can pass in a list of (multi-)patterns in the 24 | /// quantifier constructor. 25 | /// 26 | /// # See also: 27 | /// 28 | /// - `ast::forall_const()` 29 | /// - `ast::exists_const()` 30 | pub fn new(ctx: &'ctx Context, terms: &[&Dynamic]) -> Pattern<'ctx> { 31 | assert!(!terms.is_empty()); 32 | assert!(terms.iter().all(|t| t.get_ctx().z3_ctx == ctx.z3_ctx)); 33 | 34 | let terms: Vec<_> = terms.iter().map(|t| t.get_z3_ast()).collect(); 35 | 36 | Pattern { 37 | ctx, 38 | z3_pattern: unsafe { 39 | let guard = Z3_MUTEX.lock().unwrap(); 40 | let p = Z3_mk_pattern( 41 | ctx.z3_ctx, 42 | terms.len().try_into().unwrap(), 43 | terms.as_ptr() as *const Z3_ast, 44 | ); 45 | Z3_inc_ref(ctx.z3_ctx, p as Z3_ast); 46 | p 47 | }, 48 | } 49 | } 50 | } 51 | 52 | impl<'ctx> fmt::Debug for Pattern<'ctx> { 53 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 54 | let p = unsafe { Z3_pattern_to_string(self.ctx.z3_ctx, self.z3_pattern) }; 55 | if p.is_null() { 56 | return Result::Err(fmt::Error); 57 | } 58 | match unsafe { CStr::from_ptr(p) }.to_str() { 59 | Ok(s) => write!(f, "{}", s), 60 | Err(_) => Result::Err(fmt::Error), 61 | } 62 | } 63 | } 64 | 65 | impl<'ctx> fmt::Display for Pattern<'ctx> { 66 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 67 | ::fmt(self, f) 68 | } 69 | } 70 | 71 | impl<'ctx> Drop for Pattern<'ctx> { 72 | fn drop(&mut self) { 73 | unsafe { 74 | Z3_dec_ref(self.ctx.z3_ctx, self.z3_pattern as Z3_ast); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /modules/net/tests/parse.zz: -------------------------------------------------------------------------------- 1 | using ::{printf, stdin}; 2 | using net::address; 3 | using buffer; 4 | using err; 5 | 6 | 7 | test { 8 | stdin = "127.0.0.1:8083" 9 | stdout == "127.0.0.1:8083" 10 | } 11 | 12 | test { 13 | stdin = "127.0.0.1" 14 | stdout == "127.0.0.1:0" 15 | } 16 | 17 | test { 18 | stdin = "255.255.255.255:65535" 19 | stdout == "255.255.255.255:65535" 20 | } 21 | 22 | test { 23 | stdin = "255.255.255.255:65535123123" 24 | exit = 3 25 | } 26 | 27 | test t5 { 28 | stdin = "355.255.255.255:12" 29 | exit = 3 30 | } 31 | 32 | test { 33 | stdin = "1.1.1.1.1" 34 | exit = 3 35 | } 36 | 37 | test { 38 | stdin = "1.1.1" 39 | exit = 3 40 | } 41 | 42 | test { 43 | stdin = "" 44 | exit = 3 45 | } 46 | 47 | test { 48 | stdin = "1.1.1.1::22" 49 | exit = 3 50 | } 51 | 52 | test { 53 | stdin = "bob1.1.1.1:22" 54 | exit = 3 55 | } 56 | 57 | test { 58 | stdin = "192.168.11.1" 59 | stdout = "192.168.11.1:0" 60 | } 61 | 62 | test { 63 | stdin = "[2001:4860:4860::8888]:9000" 64 | stdout = "[2001:4860:4860::8888]:9000" 65 | } 66 | 67 | 68 | test { 69 | stdin = "[2001:4860:4860:0:0:0:0:8888]:9000" 70 | stdout = "[2001:4860:4860::8888]:9000" 71 | } 72 | 73 | test { 74 | stdin = "[::]:9000" 75 | stdout = "[::]:9000" 76 | } 77 | 78 | test { 79 | stdin = "[10f::]:9000" 80 | stdout = "[10f::]:9000" 81 | } 82 | 83 | test { 84 | stdin = "[::10f]:9000" 85 | stdout = "[::10f]:9000" 86 | } 87 | 88 | test { 89 | stdin = "[::4860:4860:0:0:0:0:8888]:9000" 90 | stdout = "[0:4860:4860::8888]:9000" 91 | } 92 | 93 | test { 94 | stdin = "[::10f::]:9000" 95 | exit = 3 96 | } 97 | 98 | test maxv6 { 99 | stdin = "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535" 100 | stdout = "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535" 101 | } 102 | 103 | test { 104 | stdin = "[ffff:ffff:effff:ffff:ffff:ffff:ffff:ffff]:65535" 105 | exit = 3 106 | } 107 | 108 | test { 109 | stdin = "::10f" 110 | stdout = "::10f" 111 | } 112 | 113 | test { 114 | stdin = "::" 115 | stdout = "::" 116 | } 117 | 118 | test { 119 | stdin = "100::100" 120 | stdout = "100::100" 121 | } 122 | export fn main() -> int { 123 | new+100 sin = buffer::make(); 124 | buffer::fgets(&sin, stdin); 125 | 126 | new sa = address::from_buffer(&sin); 127 | if !sa.valid() { 128 | return 3; 129 | } 130 | 131 | new+100 sout = buffer::make(); 132 | sa.to_buffer(&sout); 133 | 134 | printf("%.*s", (int)sout.at, sout.mem); 135 | 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /src/z3/params.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CStr; 2 | use std::fmt; 3 | use z3_sys::*; 4 | use crate::z3::Context; 5 | use crate::z3::Params; 6 | use crate::z3::Symbol; 7 | use crate::z3::Z3_MUTEX; 8 | 9 | impl<'ctx> Params<'ctx> { 10 | pub fn new(ctx: &'ctx Context) -> Params<'ctx> { 11 | Params { 12 | ctx, 13 | z3_params: unsafe { 14 | let guard = Z3_MUTEX.lock().unwrap(); 15 | let p = Z3_mk_params(ctx.z3_ctx); 16 | Z3_params_inc_ref(ctx.z3_ctx, p); 17 | p 18 | }, 19 | } 20 | } 21 | 22 | pub fn set_symbol, V: Into>(&mut self, k: K, v: V) { 23 | let guard = Z3_MUTEX.lock().unwrap(); 24 | unsafe { 25 | Z3_params_set_symbol( 26 | self.ctx.z3_ctx, 27 | self.z3_params, 28 | k.into().as_z3_symbol(self.ctx), 29 | v.into().as_z3_symbol(self.ctx), 30 | ) 31 | }; 32 | } 33 | 34 | pub fn set_bool>(&mut self, k: K, v: bool) { 35 | let guard = Z3_MUTEX.lock().unwrap(); 36 | unsafe { 37 | Z3_params_set_bool( 38 | self.ctx.z3_ctx, 39 | self.z3_params, 40 | k.into().as_z3_symbol(self.ctx), 41 | v, 42 | ) 43 | }; 44 | } 45 | 46 | pub fn set_f64>(&mut self, k: K, v: f64) { 47 | let guard = Z3_MUTEX.lock().unwrap(); 48 | unsafe { 49 | Z3_params_set_double( 50 | self.ctx.z3_ctx, 51 | self.z3_params, 52 | k.into().as_z3_symbol(self.ctx), 53 | v, 54 | ) 55 | }; 56 | } 57 | 58 | pub fn set_u32>(&mut self, k: K, v: u32) { 59 | let guard = Z3_MUTEX.lock().unwrap(); 60 | unsafe { 61 | Z3_params_set_uint( 62 | self.ctx.z3_ctx, 63 | self.z3_params, 64 | k.into().as_z3_symbol(self.ctx), 65 | v, 66 | ) 67 | }; 68 | } 69 | } 70 | 71 | impl<'ctx> fmt::Display for Params<'ctx> { 72 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 73 | let p = unsafe { Z3_params_to_string(self.ctx.z3_ctx, self.z3_params) }; 74 | if p.is_null() { 75 | return Result::Err(fmt::Error); 76 | } 77 | match unsafe { CStr::from_ptr(p) }.to_str() { 78 | Ok(s) => write!(f, "{}", s), 79 | Err(_) => Result::Err(fmt::Error), 80 | } 81 | } 82 | } 83 | 84 | impl<'ctx> Drop for Params<'ctx> { 85 | fn drop(&mut self) { 86 | let guard = Z3_MUTEX.lock().unwrap(); 87 | unsafe { Z3_params_dec_ref(self.ctx.z3_ctx, self.z3_params) }; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/mustpass/macro_expr/src/main.zz: -------------------------------------------------------------------------------- 1 | using ::{printf}; 2 | using ::{atoi}; 3 | using err; 4 | using ast; 5 | using slice; 6 | using bam; 7 | 8 | /// creates literal string with arg0 repeated arg1 times 9 | export macro repeat() { 10 | new+1000 a = ast::from_macro(); 11 | 12 | err::assert(a.args.count == 2); 13 | 14 | let arg0 = (ast::Expression*)(a.args.items[0].mem); 15 | let arg1 = (ast::Expression*)(a.args.items[1].mem); 16 | err::assert_safe(arg0); 17 | err::assert_safe(arg1); 18 | 19 | err::assert2(arg0->t == ast::ExpressionType::LiteralString, "expected arg0: string"); 20 | err::assert2(arg1->t == ast::ExpressionType::Literal, "expected arg1: number"); 21 | static_attest(slice::slice::integrity(&arg1->v.literal)); 22 | let num = arg1->v.literal.atoi(10); 23 | 24 | printf("\""); 25 | for (i64 mut i = 0; i < num; i++) { 26 | printf("%.*s", arg0->v.literal.size, arg0->v.literal.mem); 27 | } 28 | printf("\""); 29 | } 30 | 31 | 32 | /// tests if call in statement context will correctly expand to multiple statements 33 | /// 34 | /// TODO: statementm macros are still weird, because the first pass will yield nothing 35 | /// resulting in var declarations not being available in the first pass 36 | /// the workaround for users is to have macros in separate modules. 37 | 38 | export macro make_int() { 39 | printf("int mut a = 0;\n"); 40 | printf("return a;\n"); 41 | } 42 | 43 | export macro increment() { 44 | new+1000 a = ast::from_macro(); 45 | err::assert(a.args.count == 1); 46 | let arg0 = (ast::Expression*)(a.args.items[0].mem); 47 | err::assert_safe(arg0); 48 | 49 | if arg0->t == ast::ExpressionType::Name { 50 | printf("%.*s = %.*s + 1;\n", 51 | arg0->v.literal.size, arg0->v.literal.mem, 52 | arg0->v.literal.size, arg0->v.literal.mem); 53 | } 54 | } 55 | 56 | export macro add() { 57 | new+2000 a = ast::from_macro(); 58 | err::assert(a.args.count == 3); 59 | 60 | let arg0 = (ast::Expression*)(a.args.items[0].mem); 61 | let arg1 = (ast::Expression*)(a.args.items[1].mem); 62 | let arg2 = (ast::Expression*)(a.args.items[2].mem); 63 | err::assert_safe(arg0); 64 | err::assert_safe(arg1); 65 | err::assert_safe(arg2); 66 | 67 | if arg0->t == ast::ExpressionType::Name { 68 | printf("%.*s = %.*s + %.*s;\n", 69 | arg0->v.literal.size, arg0->v.literal.mem, 70 | arg1->v.literal.size, arg1->v.literal.mem, 71 | arg2->v.literal.size, arg2->v.literal.mem); 72 | } 73 | } 74 | 75 | export fn main() -> int { 76 | 77 | @bam::happyness(); 78 | 79 | int mut foo = 0; 80 | @increment(foo); 81 | if 1 != foo { 82 | return 1; 83 | } 84 | @add(foo, 1, 2); 85 | if 3 != foo { 86 | return 1; 87 | } 88 | 89 | printf("hello %s\n", @repeat("world ", 32)); 90 | @make_int("a", 1); 91 | } 92 | -------------------------------------------------------------------------------- /src/mergecc.rs: -------------------------------------------------------------------------------- 1 | use std::path::Path; 2 | use std::path::PathBuf; 3 | use std::fs; 4 | use std::io::{self, BufRead, Write}; 5 | use std::collections::HashMap; 6 | 7 | 8 | #[derive(Default)] 9 | struct M { 10 | outbase: PathBuf, 11 | includes: Vec, 12 | visited: HashMap, 13 | } 14 | 15 | pub fn mergecc(includes: &Vec, outbase: &Path, inp: &Path) -> PathBuf { 16 | 17 | let mut m = M { 18 | includes: includes.clone(), 19 | outbase: outbase.into(), 20 | ..Default::default() 21 | }; 22 | 23 | m.copy(inp.into()) 24 | } 25 | 26 | 27 | impl M { 28 | 29 | fn copy(&mut self, inp: PathBuf) -> PathBuf 30 | { 31 | if let Some(x) = self.visited.get(&inp) { 32 | return x.clone(); 33 | } 34 | 35 | let oext = inp.extension().map(|v| v.to_str().unwrap()).unwrap_or(""); 36 | 37 | let merged = inp.to_string_lossy() 38 | .replace(|c: char| !c.is_alphanumeric(), "_"); 39 | let merged = self.outbase.join(merged + "." + oext); 40 | 41 | self.visited.insert(inp.clone(), merged.clone()); 42 | 43 | if let Ok(target) = std::fs::metadata(&merged) { 44 | if let Ok(source) = std::fs::metadata(&inp) { 45 | let itarget = target.modified().expect(&format!("cannot stat {:?}", target)); 46 | let isource = source.modified().expect(&format!("cannot stat {:?}", source)); 47 | if itarget > isource { 48 | return merged; 49 | } 50 | } 51 | } 52 | 53 | let mut w = fs::File::create(&merged).expect(&format!("cannot create {:?}", merged)); 54 | 55 | let iff = fs::File::open(&inp).expect(&format!("cannot open {:?}", inp)); 56 | 57 | 'outer: for line in io::BufReader::new(iff).lines() { 58 | let line = line.unwrap(); 59 | 60 | if line.starts_with("#include ") { 61 | let l : Vec<&str> = line.split(" ").collect(); 62 | if l.len() > 1 { 63 | let mut l = l[1].trim().to_string(); 64 | if l.starts_with("\"") && l.ends_with("\"") { 65 | l.remove(0); 66 | l.remove(l.len() - 1); 67 | 68 | if let Some(p) = inp.parent() { 69 | let l = p.join(&l); 70 | if l.exists() { 71 | let nu = self.copy(l); 72 | let nu = nu.file_name().unwrap(); 73 | w.write(format!("#include {:?}\n", nu).as_bytes()).unwrap(); 74 | continue 'outer; 75 | } 76 | } 77 | for include in &self.includes { 78 | let l = Path::new(include).join(&l); 79 | if l.exists() { 80 | let nu = self.copy(l); 81 | let nu = nu.file_name().unwrap(); 82 | w.write(format!("#include {:?}\n", nu).as_bytes()).unwrap(); 83 | continue 'outer; 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | w.write(line.as_bytes()).unwrap(); 91 | w.write(b"\n").unwrap(); 92 | } 93 | 94 | return merged; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /modules/map/src/main.zz: -------------------------------------------------------------------------------- 1 | using map; 2 | using err; 3 | using log; 4 | using pool; 5 | using slice; 6 | using buffer; 7 | 8 | 9 | struct A+ { 10 | buffer::Buffer+ mut b; 11 | } 12 | 13 | 14 | pub fn main() -> int { 15 | 16 | 17 | new[map::key = char, map::val = char, +1000] smap = map::make(); 18 | 19 | smap.insert_oo("bob", "uncle"); 20 | err::assert(smap.count() == 1); 21 | 22 | log::info("%s", smap.get("bob")); 23 | 24 | 25 | 26 | 27 | 28 | new[map::key = char, +1000] amap = map::make(); 29 | 30 | A+1000 mut a = {0}; 31 | a.b.make(); 32 | a.b.append_cstr("blargh"); 33 | a.b.append_cstr(" borp"); 34 | 35 | // too large to own 36 | err::assert(!amap.insert_oo("bob", &a)); 37 | // ok to borrow 38 | err::assert(amap.insert_ob("bob", &a)); 39 | 40 | err::assert(amap.count() == 1); 41 | 42 | err::assert(amap.insert_ob("beep", &a)); 43 | err::assert(amap.insert_ob("boop", &a)); 44 | 45 | err::assert(amap.count() == 3); 46 | 47 | let gimmeback = (A*)amap.get("bob"); 48 | err::assert_safe(gimmeback); 49 | static_attest(buffer::integrity(&gimmeback->b)); 50 | log::info("%s", gimmeback->b.cstr()); 51 | 52 | let free_bytes = amap.p.free_bytes(); 53 | let mut free_bytes_after_clear = free_bytes; 54 | 55 | for let mut keys = amap.keys(); keys.next(); { 56 | let mut keysize = pool::align(keys.key.size); 57 | let mut nodesize = pool::align(unsafe(sizeof(map::Node))); 58 | 59 | free_bytes_after_clear += keysize + nodesize; 60 | } 61 | 62 | amap.clear(); 63 | 64 | err::assert(amap.count() == 0); 65 | err::assert(free_bytes_after_clear == amap.p.free_bytes()); 66 | 67 | 68 | 69 | 70 | /* 71 | 72 | err::assert(t.insert_oo(bob.mem, uncle.mem)); 73 | err::assert(t.count() == 1); 74 | err::assert(t.insert_oo(bob.mem, uncle.mem)); 75 | err::assert(t.insert_oo(doop.mem, text.mem)); 76 | err::assert(t.count() == 2); 77 | 78 | let vv = (char*)t.borrow(doop.mem); 79 | log::info("%s", vv); 80 | 81 | err::assert(t.count() == 2); 82 | err::assert(t.remove(doop.mem)); 83 | err::assert(!t.remove(doop.mem)); 84 | err::assert(t.count() == 1); 85 | 86 | err::assert(t.insert_oo(bob.mem, uncle.mem)); 87 | err::assert(t.insert_oo(bob.mem, uncle.mem)); 88 | err::assert(t.insert_bb(bob.mem, uncle.mem)); 89 | err::assert(t.count() == 1); 90 | 91 | let vv2 = (char*)t.borrow(bob.mem); 92 | log::info("%s", vv2); 93 | 94 | 95 | // too large to own 96 | err::assert(!t.insert_oo(bob.mem, &a)); 97 | // ok to borrow 98 | err::assert(t.insert_ob(bob.mem, &a)); 99 | 100 | err::assert(t.count() == 1); 101 | 102 | 103 | err::assert(t.insert_oo(bob.mem, uncle.mem)); 104 | err::assert(t.insert_oo(CS("bob").mem, CS("unclina").mem); 105 | err::assert(t.insert_oo(CS("derp"), "ughlinor")); 106 | err::assert(t.insert_oo("foo", "baz bar biggest borp")); 107 | err::assert(t.remove("boba")); 108 | err::assert(t.count() == 3); 109 | 110 | for(let mut it = t.keys(); map::next(&it);) { 111 | let vv2 = (char*)t.borrow(it.k.mem); 112 | log::info(" - %s = %s", (char*)it.k.mem, vv2); 113 | } 114 | 115 | 116 | */ 117 | 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /src/z3/func_decl.rs: -------------------------------------------------------------------------------- 1 | use crate::z3::ast; 2 | use ast::Ast; 3 | use std::convert::TryInto; 4 | use std::ffi::CStr; 5 | use std::fmt; 6 | use z3_sys::*; 7 | use crate::z3::{Context, FuncDecl, Sort, Symbol, Z3_MUTEX}; 8 | 9 | impl<'ctx> FuncDecl<'ctx> { 10 | pub fn new>( 11 | ctx: &'ctx Context, 12 | name: S, 13 | domain: &[&Sort<'ctx>], 14 | range: &Sort<'ctx>, 15 | ) -> Self { 16 | assert!(domain.iter().all(|s| s.ctx.z3_ctx == ctx.z3_ctx)); 17 | assert_eq!(ctx.z3_ctx, range.ctx.z3_ctx); 18 | 19 | let domain: Vec<_> = domain.iter().map(|s| s.z3_sort).collect(); 20 | 21 | unsafe { 22 | Self::from_raw( 23 | ctx, 24 | Z3_mk_func_decl( 25 | ctx.z3_ctx, 26 | name.into().as_z3_symbol(ctx), 27 | domain.len().try_into().unwrap(), 28 | domain.as_ptr(), 29 | range.z3_sort, 30 | ), 31 | ) 32 | } 33 | } 34 | 35 | pub unsafe fn from_raw(ctx: &'ctx Context, z3_func_decl: Z3_func_decl) -> Self { 36 | let guard = Z3_MUTEX.lock().unwrap(); 37 | 38 | Z3_inc_ref(ctx.z3_ctx, Z3_func_decl_to_ast(ctx.z3_ctx, z3_func_decl)); 39 | 40 | Self { ctx, z3_func_decl } 41 | } 42 | 43 | /// Return the number of arguments of a function declaration. 44 | /// 45 | /// If the function declaration is a constant, then the arity is `0`. 46 | /// 47 | /// ``` 48 | /// # use z3::{Config, Context, FuncDecl, Solver, Sort, Symbol}; 49 | /// # let cfg = Config::new(); 50 | /// # let ctx = Context::new(&cfg); 51 | /// let f = FuncDecl::new( 52 | /// &ctx, 53 | /// "f", 54 | /// &[&Sort::int(&ctx), &Sort::real(&ctx)], 55 | /// &Sort::int(&ctx)); 56 | /// assert_eq!(f.arity(), 2); 57 | /// ``` 58 | pub fn arity(&self) -> usize { 59 | unsafe { Z3_get_arity(self.ctx.z3_ctx, self.z3_func_decl) as usize } 60 | } 61 | 62 | /// Create a constant (if `args` has length 0) or function application (otherwise). 63 | /// 64 | /// Note that `args` should have the types corresponding to the `domain` of the `FuncDecl`. 65 | pub fn apply(&self, args: &[&ast::Dynamic<'ctx>]) -> ast::Dynamic<'ctx> { 66 | assert!(args.iter().all(|s| s.get_ctx().z3_ctx == self.ctx.z3_ctx)); 67 | 68 | let args: Vec<_> = args.iter().map(|a| a.get_z3_ast()).collect(); 69 | 70 | ast::Dynamic::new(self.ctx, unsafe { 71 | let guard = Z3_MUTEX.lock().unwrap(); 72 | Z3_mk_app( 73 | self.ctx.z3_ctx, 74 | self.z3_func_decl, 75 | args.len().try_into().unwrap(), 76 | args.as_ptr(), 77 | ) 78 | }) 79 | } 80 | } 81 | 82 | impl<'ctx> fmt::Display for FuncDecl<'ctx> { 83 | fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { 84 | let p = unsafe { Z3_func_decl_to_string(self.ctx.z3_ctx, self.z3_func_decl) }; 85 | if p.is_null() { 86 | return Result::Err(fmt::Error); 87 | } 88 | match unsafe { CStr::from_ptr(p) }.to_str() { 89 | Ok(s) => write!(f, "{}", s), 90 | Err(_) => Result::Err(fmt::Error), 91 | } 92 | } 93 | } 94 | 95 | impl<'ctx> Drop for FuncDecl<'ctx> { 96 | fn drop(&mut self) { 97 | unsafe { 98 | Z3_dec_ref( 99 | self.ctx.z3_ctx, 100 | Z3_func_decl_to_ast(self.ctx.z3_ctx, self.z3_func_decl), 101 | ); 102 | } 103 | } 104 | } 105 | --------------------------------------------------------------------------------