├── .gitattributes ├── .github ├── README_logo.png └── workflows │ └── remoteBuild.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── HOW_TO_COMPILE.md ├── LICENSE ├── README.md ├── docs ├── collections.md ├── datatypes.md └── pointers.md ├── infrastructure ├── import │ └── std │ │ └── _.adept └── to_windows │ ├── crt2.o │ ├── crtbegin.o │ ├── crtend.o │ ├── from_aarch64_macos │ ├── llvm-windres │ └── x86_64-w64-mingw32-ld │ ├── from_x86_64_linux │ ├── llvm-windres │ └── x86_64-w64-mingw32-ld │ ├── from_x86_64_windows │ ├── ld.exe │ └── llvm-windres.exe │ ├── libadvapi32.a │ ├── libgcc.a │ ├── libgcc_eh.a │ ├── libkernel32.a │ ├── libmingw32.a │ ├── libmingwex.a │ ├── libmsvcrt.a │ ├── libpthread.a │ ├── libshell32.a │ └── libuser32.a ├── rustfmt.toml ├── src ├── adept │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── components │ ├── build_asg │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── collect_polymorphs.rs │ │ │ ├── conform │ │ │ ├── from_anonymous_enum.rs │ │ │ ├── from_c_integer.rs │ │ │ ├── from_float.rs │ │ │ ├── from_float_literal.rs │ │ │ ├── from_integer.rs │ │ │ ├── from_integer_literal.rs │ │ │ ├── from_pointer.rs │ │ │ ├── from_size_integer.rs │ │ │ ├── mod.rs │ │ │ ├── mode.rs │ │ │ └── to_default.rs │ │ │ ├── core_struct_info.rs │ │ │ ├── ctx.rs │ │ │ ├── destination.rs │ │ │ ├── error.rs │ │ │ ├── expr │ │ │ ├── array_access.rs │ │ │ ├── basic_binary_operation.rs │ │ │ ├── call │ │ │ │ ├── cast.rs │ │ │ │ ├── infer_impl.rs │ │ │ │ ├── mod.rs │ │ │ │ └── specified_impl.rs │ │ │ ├── conditional.rs │ │ │ ├── declare_assign.rs │ │ │ ├── member_expr.rs │ │ │ ├── mod.rs │ │ │ ├── short_circuiting_binary_operation.rs │ │ │ ├── static_member.rs │ │ │ ├── struct_literal.rs │ │ │ ├── unary_operation.rs │ │ │ └── variable.rs │ │ │ ├── expr_alias.rs │ │ │ ├── func_body.rs │ │ │ ├── func_haystack.rs │ │ │ ├── func_head.rs │ │ │ ├── global_variable.rs │ │ │ ├── impl_head │ │ │ ├── for_alls.rs │ │ │ └── mod.rs │ │ │ ├── initialized.rs │ │ │ ├── job.rs │ │ │ ├── lib.rs │ │ │ ├── polymorph │ │ │ ├── matcher.rs │ │ │ ├── mod.rs │ │ │ └── type_args_to_poly_value.rs │ │ │ ├── stmt.rs │ │ │ ├── type_ctx │ │ │ ├── find.rs │ │ │ ├── find_error.rs │ │ │ ├── mod.rs │ │ │ └── resolve_type.rs │ │ │ ├── type_definition │ │ │ ├── mod.rs │ │ │ ├── prepare.rs │ │ │ └── resolve.rs │ │ │ ├── unalias.rs │ │ │ ├── unify_types │ │ │ ├── compute.rs │ │ │ ├── integer_literals.rs │ │ │ └── mod.rs │ │ │ └── variable_haystack.rs │ ├── build_ast │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── annotation.rs │ │ │ ├── error.rs │ │ │ ├── input.rs │ │ │ ├── lib.rs │ │ │ ├── make_error.rs │ │ │ ├── parse_annotation.rs │ │ │ ├── parse_block.rs │ │ │ ├── parse_enum.rs │ │ │ ├── parse_expr │ │ │ ├── mod.rs │ │ │ ├── post │ │ │ │ ├── array_access.rs │ │ │ │ ├── is_match.rs │ │ │ │ ├── member.rs │ │ │ │ └── mod.rs │ │ │ └── primary │ │ │ │ ├── call.rs │ │ │ │ ├── declare_assign.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── operator.rs │ │ │ │ ├── static_member.rs │ │ │ │ └── struct_literal.rs │ │ │ ├── parse_func.rs │ │ │ ├── parse_func_params.rs │ │ │ ├── parse_global.rs │ │ │ ├── parse_helper_expr.rs │ │ │ ├── parse_impl.rs │ │ │ ├── parse_namespace.rs │ │ │ ├── parse_stmt │ │ │ ├── mod.rs │ │ │ ├── parse_assignment.rs │ │ │ ├── parse_declaration.rs │ │ │ └── parse_return.rs │ │ │ ├── parse_structure.rs │ │ │ ├── parse_top_level.rs │ │ │ ├── parse_trait.rs │ │ │ ├── parse_type.rs │ │ │ ├── parse_type_alias.rs │ │ │ ├── parse_type_params.rs │ │ │ └── parse_util.rs │ ├── build_c_ast │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── parse │ │ │ ├── error.rs │ │ │ ├── expr.rs │ │ │ ├── input.rs │ │ │ ├── mod.rs │ │ │ └── speculate.rs │ │ │ └── translate │ │ │ ├── eval.rs │ │ │ ├── expr │ │ │ ├── caster.rs │ │ │ ├── compound_literal.rs │ │ │ ├── integer.rs │ │ │ ├── mod.rs │ │ │ └── string.rs │ │ │ ├── function.rs │ │ │ ├── mod.rs │ │ │ ├── parameters.rs │ │ │ └── types │ │ │ ├── composite.rs │ │ │ ├── decorate.rs │ │ │ ├── enumeration.rs │ │ │ ├── get_type_base.rs │ │ │ └── mod.rs │ ├── build_c_token │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lexer.rs │ │ │ ├── lib.rs │ │ │ └── number.rs │ ├── build_executable │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── build_ir │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── cast.rs │ │ │ ├── datatype.rs │ │ │ ├── error.rs │ │ │ ├── expr │ │ │ ├── call.rs │ │ │ ├── mod.rs │ │ │ └── short_circuit.rs │ │ │ ├── func_builder.rs │ │ │ ├── funcs.rs │ │ │ ├── function.rs │ │ │ ├── global.rs │ │ │ ├── globals.rs │ │ │ ├── lib.rs │ │ │ ├── stmts.rs │ │ │ ├── structs.rs │ │ │ └── structure.rs │ ├── build_llvm_ir │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── abi │ │ │ ├── abi_function.rs │ │ │ ├── abi_type │ │ │ │ ├── direct.rs │ │ │ │ ├── extend.rs │ │ │ │ ├── indirect.rs │ │ │ │ ├── kinds.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── offset_align.rs │ │ │ │ └── show_llvm_type.rs │ │ │ ├── arch │ │ │ │ ├── aarch64.rs │ │ │ │ ├── mod.rs │ │ │ │ └── x86_64 │ │ │ │ │ ├── avx_level.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── reg_count.rs │ │ │ │ │ ├── sysv │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── reg_class.rs │ │ │ │ │ └── reg_class_pair.rs │ │ │ │ │ └── win64 │ │ │ │ │ └── mod.rs │ │ │ ├── cxx │ │ │ │ ├── itanium.rs │ │ │ │ └── mod.rs │ │ │ ├── empty.rs │ │ │ ├── homo_aggregate.rs │ │ │ └── mod.rs │ │ │ ├── address.rs │ │ │ ├── backend_type.rs │ │ │ ├── builder │ │ │ ├── gep.rs │ │ │ ├── gep_in_bounds.rs │ │ │ ├── gep_struct.rs │ │ │ ├── int_cast.rs │ │ │ ├── int_to_ptr.rs │ │ │ ├── load.rs │ │ │ ├── memcpy.rs │ │ │ ├── mod.rs │ │ │ ├── phi_relocation.rs │ │ │ ├── ptr_to_int.rs │ │ │ └── store.rs │ │ │ ├── ctx.rs │ │ │ ├── functions │ │ │ ├── attribute.rs │ │ │ ├── block.rs │ │ │ ├── body.rs │ │ │ ├── epilogue │ │ │ │ └── mod.rs │ │ │ ├── function_type.rs │ │ │ ├── head.rs │ │ │ ├── helpers.rs │ │ │ ├── mod.rs │ │ │ ├── param_values │ │ │ │ ├── coerce_and_expand.rs │ │ │ │ ├── direct.rs │ │ │ │ ├── expand.rs │ │ │ │ ├── ignore.rs │ │ │ │ ├── inalloca.rs │ │ │ │ ├── indirect.rs │ │ │ │ ├── mod.rs │ │ │ │ └── value.rs │ │ │ ├── params_mapping.rs │ │ │ ├── prologue │ │ │ │ └── mod.rs │ │ │ └── return_location.rs │ │ │ ├── globals.rs │ │ │ ├── intrinsics.rs │ │ │ ├── lib.rs │ │ │ ├── llvm_type_ref_ext.rs │ │ │ ├── llvm_value_ref_ext.rs │ │ │ ├── module.rs │ │ │ ├── null_terminated_string.rs │ │ │ ├── raw_address.rs │ │ │ ├── structure.rs │ │ │ ├── target_data.rs │ │ │ ├── target_machine.rs │ │ │ ├── target_triple.rs │ │ │ ├── value_catalog.rs │ │ │ └── values.rs │ ├── build_pp_ast │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── error.rs │ │ │ ├── expand │ │ │ ├── control_line.rs │ │ │ ├── depleted.rs │ │ │ ├── embed.rs │ │ │ ├── environment.rs │ │ │ ├── expr.rs │ │ │ ├── include.rs │ │ │ ├── mod.rs │ │ │ └── region.rs │ │ │ ├── lexer │ │ │ ├── lex_line.rs │ │ │ ├── line.rs │ │ │ ├── mod.rs │ │ │ └── state.rs │ │ │ ├── lib.rs │ │ │ ├── line_splice.rs │ │ │ ├── parser │ │ │ ├── error.rs │ │ │ └── mod.rs │ │ │ └── stdc.rs │ ├── build_token │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── compound_identifier_state.rs │ │ │ ├── hex_number_state.rs │ │ │ ├── identifier_state.rs │ │ │ ├── lib.rs │ │ │ ├── number_state.rs │ │ │ ├── polymorph_state.rs │ │ │ ├── state.rs │ │ │ └── string_state.rs │ ├── build_workspace │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── compile │ │ │ ├── c_code.rs │ │ │ ├── mod.rs │ │ │ ├── module.rs │ │ │ └── normal.rs │ │ │ ├── explore.rs │ │ │ ├── explore_within.rs │ │ │ ├── export_and_link.rs │ │ │ ├── file.rs │ │ │ ├── interpreter_env.rs │ │ │ ├── lex_and_parse.rs │ │ │ ├── lib.rs │ │ │ ├── module_file.rs │ │ │ ├── normal_file.rs │ │ │ ├── pragma_section │ │ │ ├── mod.rs │ │ │ ├── parse.rs │ │ │ └── run.rs │ │ │ ├── queue.rs │ │ │ └── stats.rs │ ├── cli │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── build │ │ │ ├── invoke.rs │ │ │ ├── mod.rs │ │ │ ├── parse.rs │ │ │ └── supported_targets.rs │ │ │ ├── help │ │ │ ├── invoke.rs │ │ │ ├── mod.rs │ │ │ └── parse.rs │ │ │ ├── lib.rs │ │ │ └── new │ │ │ ├── invoke.rs │ │ │ ├── mod.rs │ │ │ └── parse.rs │ ├── interpret │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── error.rs │ │ │ ├── ip.rs │ │ │ ├── lib.rs │ │ │ ├── memory │ │ │ ├── mod.rs │ │ │ ├── read.rs │ │ │ └── write.rs │ │ │ ├── ops │ │ │ └── mod.rs │ │ │ ├── registers.rs │ │ │ ├── size_of.rs │ │ │ ├── syscall_handler.rs │ │ │ └── value.rs │ └── job │ │ ├── Cargo.toml │ │ └── src │ │ ├── allocator.rs │ │ ├── artifact.rs │ │ ├── continuation.rs │ │ ├── execution │ │ ├── build_asg.rs │ │ ├── diverge.rs │ │ ├── estimate_decl_scope.rs │ │ ├── estimate_type_heads.rs │ │ ├── find_type.rs │ │ ├── find_type_in_decl_set.rs │ │ ├── find_type_in_estimated.rs │ │ ├── get_func_body.rs │ │ ├── get_func_head.rs │ │ ├── get_type_body.rs │ │ ├── get_type_head.rs │ │ ├── mod.rs │ │ ├── print.rs │ │ ├── resolve_type.rs │ │ └── resolve_type_arg.rs │ │ ├── execution_ctx.rs │ │ ├── executor.rs │ │ ├── lib.rs │ │ ├── main_executor.rs │ │ ├── pending.rs │ │ ├── repr │ │ ├── decl.rs │ │ ├── decl_scope.rs │ │ ├── decl_scope_origin.rs │ │ ├── decl_scope_ref.rs │ │ ├── decl_set.rs │ │ ├── enum_body.rs │ │ ├── func_body.rs │ │ ├── func_head.rs │ │ ├── mod.rs │ │ ├── params.rs │ │ ├── struct_body.rs │ │ ├── trait_body.rs │ │ ├── ty.rs │ │ ├── type_alias_body.rs │ │ └── type_head.rs │ │ ├── suspend_condition.rs │ │ ├── task.rs │ │ ├── task_state.rs │ │ ├── top_n.rs │ │ ├── truth.rs │ │ ├── typed_cfg │ │ ├── mod.rs │ │ └── value.rs │ │ ├── unify │ │ └── mod.rs │ │ ├── unwrap_from.rs │ │ ├── waiting_count.rs │ │ └── worker.rs ├── representations │ ├── asg │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── block.rs │ │ │ ├── datatype │ │ │ ├── kind │ │ │ │ ├── anonymous_enum.rs │ │ │ │ ├── fixed_array.rs │ │ │ │ ├── func_ptr.rs │ │ │ │ └── mod.rs │ │ │ └── mod.rs │ │ │ ├── destination │ │ │ ├── kind.rs │ │ │ └── mod.rs │ │ │ ├── enumeration.rs │ │ │ ├── error.rs │ │ │ ├── expr │ │ │ ├── array_access.rs │ │ │ ├── binary │ │ │ │ ├── basic.rs │ │ │ │ ├── mod.rs │ │ │ │ └── short_circuit.rs │ │ │ ├── call.rs │ │ │ ├── cast.rs │ │ │ ├── cast_from.rs │ │ │ ├── conditional.rs │ │ │ ├── decl_assign.rs │ │ │ ├── enum_member.rs │ │ │ ├── global_variable.rs │ │ │ ├── kind.rs │ │ │ ├── member.rs │ │ │ ├── mod.rs │ │ │ ├── poly_call.rs │ │ │ ├── struct_literal.rs │ │ │ ├── typed.rs │ │ │ ├── unary │ │ │ │ └── mod.rs │ │ │ ├── variable.rs │ │ │ └── while_loop.rs │ │ │ ├── func.rs │ │ │ ├── generic_trait_ref.rs │ │ │ ├── global.rs │ │ │ ├── helper_expr.rs │ │ │ ├── human_name.rs │ │ │ ├── impl_params.rs │ │ │ ├── implementation.rs │ │ │ ├── lib.rs │ │ │ ├── name.rs │ │ │ ├── poly_catalog.rs │ │ │ ├── poly_recipe.rs │ │ │ ├── poly_resolver.rs │ │ │ ├── poly_value.rs │ │ │ ├── stmt │ │ │ ├── assignment.rs │ │ │ ├── declaration.rs │ │ │ └── mod.rs │ │ │ ├── structure.rs │ │ │ ├── trait_constraint.rs │ │ │ ├── type_alias.rs │ │ │ ├── type_decl.rs │ │ │ └── variable_storage.rs │ ├── ast │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── block.rs │ │ │ ├── cfg │ │ │ ├── builder.rs │ │ │ ├── cursor.rs │ │ │ ├── flatten.rs │ │ │ ├── graphviz.rs │ │ │ ├── label.rs │ │ │ ├── mod.rs │ │ │ └── node.rs │ │ │ ├── conforming.rs │ │ │ ├── datatype │ │ │ ├── fixed_array.rs │ │ │ ├── func_ptr.rs │ │ │ ├── generics.rs │ │ │ ├── kind │ │ │ │ ├── common.rs │ │ │ │ ├── display.rs │ │ │ │ └── mod.rs │ │ │ ├── mod.rs │ │ │ ├── nameless_enumeration.rs │ │ │ ├── nameless_structure.rs │ │ │ └── nameless_union.rs │ │ │ ├── enumeration.rs │ │ │ ├── expr │ │ │ ├── array_access.rs │ │ │ ├── binary │ │ │ │ ├── mod.rs │ │ │ │ ├── regular.rs │ │ │ │ └── short_circuiting.rs │ │ │ ├── call.rs │ │ │ ├── conditional.rs │ │ │ ├── constant.rs │ │ │ ├── declare_assign.rs │ │ │ ├── integer.rs │ │ │ ├── interpreter_syscall.rs │ │ │ ├── kind.rs │ │ │ ├── mod.rs │ │ │ ├── static_member.rs │ │ │ ├── struct_literal.rs │ │ │ ├── unary │ │ │ │ ├── math.rs │ │ │ │ └── mod.rs │ │ │ └── while_loop.rs │ │ │ ├── expr_alias.rs │ │ │ ├── file.rs │ │ │ ├── func │ │ │ ├── mod.rs │ │ │ └── params.rs │ │ │ ├── given.rs │ │ │ ├── global_variable.rs │ │ │ ├── implementation.rs │ │ │ ├── lib.rs │ │ │ ├── namespace.rs │ │ │ ├── stmt │ │ │ ├── assignment.rs │ │ │ ├── declaration.rs │ │ │ ├── kind.rs │ │ │ └── mod.rs │ │ │ ├── structs.rs │ │ │ ├── traits.rs │ │ │ ├── type_alias.rs │ │ │ └── type_params.rs │ ├── ast_workspace │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── all_symbols.rs │ │ │ ├── ast_file.rs │ │ │ ├── configure_job.rs │ │ │ ├── lib.rs │ │ │ ├── module.rs │ │ │ ├── name_scope.rs │ │ │ ├── namespace.rs │ │ │ └── type_decl_ref.rs │ ├── ast_workspace_settings │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── attributes │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── exposure.rs │ │ │ ├── lib.rs │ │ │ ├── privacy.rs │ │ │ └── tag.rs │ ├── c_ast │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── expr.rs │ │ │ └── lib.rs │ ├── c_token │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── fs_tree │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── fs_node_id.rs │ │ │ └── lib.rs │ ├── interpreter_api │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── ir │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── field.rs │ │ │ ├── instr.rs │ │ │ ├── lib.rs │ │ │ └── value.rs │ ├── pp_ast │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ ├── pp_token │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── encoding.rs │ │ │ ├── lib.rs │ │ │ └── punctuator.rs │ ├── primitives │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── c_integer.rs │ │ │ ├── float_or_integer.rs │ │ │ ├── float_or_sign.rs │ │ │ ├── float_or_sign_lax.rs │ │ │ ├── float_size.rs │ │ │ ├── integer_bits.rs │ │ │ ├── integer_rigidity.rs │ │ │ ├── integer_sign.rs │ │ │ ├── lib.rs │ │ │ ├── numeric_mode.rs │ │ │ └── sign_or_indeterminate.rs │ ├── source_files │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── file.rs │ │ │ ├── key.rs │ │ │ ├── lib.rs │ │ │ └── source.rs │ └── token │ │ ├── Cargo.toml │ │ └── src │ │ ├── lib.rs │ │ └── name.rs └── support │ ├── append_only_vec │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── arena │ ├── Cargo.toml │ └── src │ │ ├── arena.rs │ │ ├── id.rs │ │ ├── idx.rs │ │ ├── idx_span.rs │ │ ├── impl_id.rs │ │ ├── iter.rs │ │ ├── lib.rs │ │ ├── lock_free_arena.rs │ │ ├── map.rs │ │ ├── map_idx.rs │ │ ├── map_idx_span.rs │ │ ├── new_id.rs │ │ ├── simple_type_name.rs │ │ └── values.rs │ ├── backend │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── compiler │ ├── Cargo.toml │ └── src │ │ ├── compiler.rs │ │ ├── lib.rs │ │ └── options.rs │ ├── compiler_version │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── data_units │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── diagnostics │ ├── Cargo.toml │ └── src │ │ ├── error.rs │ │ ├── lib.rs │ │ ├── show.rs │ │ ├── unerror.rs │ │ └── warning.rs │ ├── infinite_iterator │ ├── Cargo.toml │ └── src │ │ ├── end.rs │ │ ├── infinite.rs │ │ ├── iter.rs │ │ ├── lib.rs │ │ ├── peekable.rs │ │ ├── peeker.rs │ │ └── tools.rs │ ├── line_column │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── look_ahead │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── optional_string │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── repeating_last │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ ├── std_ext │ ├── Cargo.toml │ └── src │ │ ├── hash_map_ext.rs │ │ ├── index_map_ext.rs │ │ └── lib.rs │ ├── target │ ├── Cargo.toml │ └── src │ │ ├── arch.rs │ │ ├── display.rs │ │ ├── lib.rs │ │ └── os.rs │ ├── target_layout │ ├── Cargo.toml │ └── src │ │ ├── alignment_requirement.rs │ │ ├── lib.rs │ │ ├── record_layout │ │ ├── itanium.rs │ │ ├── mod.rs │ │ └── record_info.rs │ │ ├── type_layout.rs │ │ └── type_layout_cache.rs │ └── text │ ├── Cargo.toml │ └── src │ ├── character.rs │ ├── character_infinite_iterator.rs │ ├── character_peeker.rs │ ├── eatable.rs │ └── lib.rs └── tests ├── c ├── 0001 │ ├── _.adept │ └── main.c └── 0002 │ ├── _.adept │ └── main.c ├── error ├── cannot_use_private_func │ ├── _.adept │ └── sayMessage.adept ├── cannot_use_private_type │ ├── _.adept │ └── test.adept ├── duplicate_type_names │ └── main.adept ├── generics_trait_unsatisfied │ └── main.adept ├── impl_dual_use_polymorph │ └── main.adept ├── impl_inconsistent │ └── main.adept ├── impl_inconsistent_for_all │ └── main.adept ├── impl_inconsistent_for_all_return_type │ └── main.adept ├── impl_missing_func │ └── main.adept ├── impl_unknown_func │ └── main.adept ├── impl_wrong_func_return_type │ └── main.adept ├── impl_wrong_sub │ └── main.adept ├── mismatching_yielded_types │ └── main.adept ├── pragma_adept_first │ └── _.adept ├── struct_missing_polymorph │ └── main.adept ├── undefined_impl │ └── main.adept ├── unsuitable_type_for_literal │ └── main.adept ├── using_on_main │ └── main.adept ├── using_trait_on_impl_func │ └── main.adept └── using_trait_on_trait_func │ └── main.adept ├── framework.py ├── run.py └── success ├── and_or └── main.adept ├── annotation_groups └── main.adept ├── array_access └── main.adept ├── auto_defer_ptr └── main.adept ├── bitwise_operators └── main.adept ├── break └── main.adept ├── c_global_variable ├── _.adept └── special_value.c ├── c_global_variable_extern_thread_local ├── _.adept └── errno.h ├── c_math ├── _.adept └── result.h ├── c_printf └── main.adept ├── cast_trait └── main.adept ├── casts └── main.adept ├── character_literals └── main.adept ├── compare_ints └── main.adept ├── continue └── main.adept ├── defines └── main.adept ├── dereference └── main.adept ├── enums └── main.adept ├── float_literal └── main.adept ├── function_parameters └── main.adept ├── function_simple └── main.adept ├── generics └── main.adept ├── generics_shorthand └── main.adept ├── generics_struct_simple └── main.adept ├── generics_type_alias └── main.adept ├── global_variables └── main.adept ├── global_variables_exposed ├── _.adept └── special_variable.adept ├── hello_world └── main.adept ├── if └── main.adept ├── if_elif_else └── main.adept ├── if_eval └── main.adept ├── if_neglect_result └── main.adept ├── impl_generic_simple └── main.adept ├── impl_generic_simple2 └── main.adept ├── impl_generic_simple3 └── main.adept ├── impl_sub_renames └── main.adept ├── implicits_explicit └── main.adept ├── implicits_for_all └── main.adept ├── implicits_multi_funcs └── main.adept ├── integer_and_float_literals_combining └── main.adept ├── integer_hex_literals └── main.adept ├── integer_literal_conforming └── main.adept ├── integer_signed_overflow └── main.adept ├── integer_typed └── main.adept ├── integer_unsigned_overflow └── main.adept ├── integer_value_conforming └── main.adept ├── math_floats └── main.adept ├── math_simple └── main.adept ├── member └── main.adept ├── modules_simple ├── _.adept ├── greet.adept ├── main.adept └── printf.adept ├── multiline_comments └── main.adept ├── nested_expressions └── main.adept ├── null └── main.adept ├── object_mutation └── main.adept ├── op_then_assign └── main.adept ├── pointers └── main.adept ├── preprocessor_toggle ├── _.adept └── header.h ├── private_func ├── _.adept └── sayMessage.adept ├── private_type ├── _.adept └── test.adept ├── return └── main.adept ├── return_message └── main.adept ├── return_skipping └── main.adept ├── signed_unsigned_promotion └── main.adept ├── size_integers └── main.adept ├── sizeof └── main.adept ├── sizeof_value └── main.adept ├── structure_definitions └── main.adept ├── structure_literals └── main.adept ├── structure_literals_abbr └── main.adept ├── type_aliases └── main.adept ├── ufcs └── main.adept ├── unary_operators └── main.adept ├── variables └── main.adept ├── variables_override └── main.adept ├── variables_typed └── main.adept ├── while └── main.adept └── zeroed └── main.adept /.gitattributes: -------------------------------------------------------------------------------- 1 | tests/** linguist-vendored 2 | -------------------------------------------------------------------------------- /.github/README_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/.github/README_logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .DS_Store 3 | a.o 4 | a.out 5 | bin/ 6 | obj/ 7 | __pycache__ 8 | -------------------------------------------------------------------------------- /docs/collections.md: -------------------------------------------------------------------------------- 1 | 2 | # collections 3 | 4 | ### Common: 5 | - `String` 6 | - `List<$T>` 7 | - `Tuple<$A, $B, $C, ...>` 8 | - `LinkedList<$T>` 9 | - `HashMap<$K, $V>` 10 | - `HashSet<$T>` 11 | - `OrdMap<$K, $V>` 12 | - `OrdSet<$T>` 13 | - `Deque<$T>` 14 | - `MinHeap<$T>` 15 | - `MaxHeap<$T>` 16 | - `SlotMap<$T>` 17 | 18 | -------------------------------------------------------------------------------- /infrastructure/import/std/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[public] 5 | trait Cast<$From, $To> { 6 | func cast(from $From) $To 7 | } 8 | 9 | #[public] 10 | #[using $cast Cast<$From, $To>] 11 | func cast<$To>(from $From) $To { 12 | return $cast::cast(from) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /infrastructure/to_windows/crt2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/crt2.o -------------------------------------------------------------------------------- /infrastructure/to_windows/crtbegin.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/crtbegin.o -------------------------------------------------------------------------------- /infrastructure/to_windows/crtend.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/crtend.o -------------------------------------------------------------------------------- /infrastructure/to_windows/from_aarch64_macos/llvm-windres: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/from_aarch64_macos/llvm-windres -------------------------------------------------------------------------------- /infrastructure/to_windows/from_aarch64_macos/x86_64-w64-mingw32-ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/from_aarch64_macos/x86_64-w64-mingw32-ld -------------------------------------------------------------------------------- /infrastructure/to_windows/from_x86_64_linux/llvm-windres: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/from_x86_64_linux/llvm-windres -------------------------------------------------------------------------------- /infrastructure/to_windows/from_x86_64_linux/x86_64-w64-mingw32-ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/from_x86_64_linux/x86_64-w64-mingw32-ld -------------------------------------------------------------------------------- /infrastructure/to_windows/from_x86_64_windows/ld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/from_x86_64_windows/ld.exe -------------------------------------------------------------------------------- /infrastructure/to_windows/from_x86_64_windows/llvm-windres.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/from_x86_64_windows/llvm-windres.exe -------------------------------------------------------------------------------- /infrastructure/to_windows/libadvapi32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libadvapi32.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libgcc.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libgcc_eh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libgcc_eh.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libkernel32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libkernel32.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libmingw32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libmingw32.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libmingwex.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libmingwex.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libmsvcrt.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libmsvcrt.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libpthread.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libpthread.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libshell32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libshell32.a -------------------------------------------------------------------------------- /infrastructure/to_windows/libuser32.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaacShelton/Adept3x/7a56b50328625c854d0d2d15cbd5bf652ac3ac39/infrastructure/to_windows/libuser32.a -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | imports_granularity = "Crate" 2 | group_imports = "One" 3 | 4 | -------------------------------------------------------------------------------- /src/adept/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "adept" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | cli = { version = "0.1.0", path = "../components/cli" } 8 | -------------------------------------------------------------------------------- /src/adept/src/main.rs: -------------------------------------------------------------------------------- 1 | use cli; 2 | use std::process::ExitCode; 3 | 4 | fn main() -> ExitCode { 5 | match cli::Command::parse().and_then(cli::Invoke::invoke) { 6 | Ok(()) => ExitCode::SUCCESS, 7 | Err(()) => ExitCode::FAILURE, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/components/build_asg/src/conform/from_float_literal.rs: -------------------------------------------------------------------------------- 1 | use super::{Objective, ObjectiveResult}; 2 | use asg::{Expr, ExprKind, Type, TypeKind, TypedExpr}; 3 | use ordered_float::NotNan; 4 | use source_files::Source; 5 | 6 | pub fn from_float_literal( 7 | from: Option>, 8 | to_type: &Type, 9 | source: Source, 10 | ) -> ObjectiveResult { 11 | match &to_type.kind { 12 | TypeKind::Floating(to_size) => O::success(|| { 13 | TypedExpr::new( 14 | TypeKind::Floating(*to_size).at(to_type.source), 15 | Expr::new(ExprKind::FloatingLiteral(*to_size, from), source), 16 | ) 17 | }), 18 | _ => O::fail(), 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/components/build_asg/src/conform/mode.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, Default)] 2 | pub enum ConformMode { 3 | #[default] 4 | Normal, 5 | ParameterPassing, 6 | Explicit, 7 | } 8 | 9 | impl ConformMode { 10 | pub fn allow_pointer_into_void_pointer(&self) -> bool { 11 | match self { 12 | Self::Normal => false, 13 | Self::ParameterPassing => true, 14 | Self::Explicit => true, 15 | } 16 | } 17 | 18 | pub fn allow_lossy_integer(&self) -> bool { 19 | matches!(self, Self::Explicit) 20 | } 21 | 22 | pub fn allow_lossless_integer(&self) -> bool { 23 | matches!(self, Self::Normal | Self::Explicit) 24 | } 25 | 26 | pub fn allow_lossless_float(&self) -> bool { 27 | matches!(self, Self::Normal | Self::Explicit) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/components/build_asg/src/expr_alias.rs: -------------------------------------------------------------------------------- 1 | use super::{ctx::ResolveCtx, error::ResolveError}; 2 | use asg::HelperExprDecl; 3 | use ast_workspace::AstWorkspace; 4 | 5 | pub fn resolve_expr_aliases( 6 | ctx: &mut ResolveCtx, 7 | ast_workspace: &AstWorkspace, 8 | ) -> Result<(), ResolveError> { 9 | for (physical_file_id, file) in ast_workspace.files.iter() { 10 | let module_folder_id = ast_workspace.get_owning_module_or_self(physical_file_id); 11 | 12 | for helper_expr in ast_workspace.view(file).expr_aliases { 13 | let helper_exprs = ctx 14 | .helper_exprs_in_modules 15 | .entry(module_folder_id) 16 | .or_default(); 17 | 18 | helper_exprs.insert( 19 | helper_expr.name.clone(), 20 | HelperExprDecl { 21 | value: helper_expr.value.clone(), 22 | privacy: helper_expr.privacy, 23 | }, 24 | ); 25 | } 26 | } 27 | 28 | Ok(()) 29 | } 30 | -------------------------------------------------------------------------------- /src/components/build_asg/src/initialized.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug)] 2 | pub enum Initialized { 3 | Require, 4 | AllowUninitialized, 5 | } 6 | -------------------------------------------------------------------------------- /src/components/build_asg/src/job.rs: -------------------------------------------------------------------------------- 1 | use arena::Idx; 2 | use asg::{EnumRef, StructRef, TraitRef, TypeAliasRef}; 3 | use ast_workspace::{FuncId, ImplId}; 4 | use fs_tree::FsNodeId; 5 | 6 | #[derive(Clone, Debug)] 7 | pub enum FuncJob { 8 | Regular(FsNodeId, Idx, asg::FuncRef), 9 | Impling(FsNodeId, Idx, usize, asg::FuncRef), 10 | } 11 | 12 | #[derive(Clone, Debug)] 13 | pub struct TypeJob { 14 | pub physical_file_id: FsNodeId, 15 | pub type_aliases: Vec, 16 | pub traits: Vec, 17 | pub structs: Vec, 18 | pub enums: Vec, 19 | } 20 | -------------------------------------------------------------------------------- /src/components/build_asg/src/polymorph/type_args_to_poly_value.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | error::ResolveError, 3 | expr::{ResolveExprCtx, ResolveExprMode, resolve_expr}, 4 | initialized::Initialized, 5 | type_ctx::ResolveTypeOptions, 6 | }; 7 | use asg::PolyValue; 8 | use ast::TypeArg; 9 | 10 | pub fn resolve_type_args_to_poly_args( 11 | ctx: &mut ResolveExprCtx, 12 | generics: &[TypeArg], 13 | ) -> Result, ResolveError> { 14 | generics 15 | .iter() 16 | .map(|type_arg| match type_arg { 17 | TypeArg::Type(ty) => ctx 18 | .type_ctx() 19 | .resolve(ty, ResolveTypeOptions::Unalias) 20 | .map(PolyValue::Type), 21 | TypeArg::Expr(expr) => resolve_expr( 22 | ctx, 23 | expr, 24 | None, 25 | Initialized::Require, 26 | ResolveExprMode::RequireValue, 27 | ) 28 | .map(PolyValue::Expr), 29 | }) 30 | .collect() 31 | } 32 | -------------------------------------------------------------------------------- /src/components/build_asg/src/type_definition/mod.rs: -------------------------------------------------------------------------------- 1 | mod prepare; 2 | mod resolve; 3 | 4 | use super::{ctx::ResolveCtx, error::ResolveError}; 5 | use asg::Asg; 6 | use ast_workspace::AstWorkspace; 7 | use prepare::prepare_type_jobs; 8 | use resolve::resolve_type_jobs; 9 | 10 | pub fn resolve_type_definitions( 11 | ctx: &mut ResolveCtx, 12 | asg: &mut Asg, 13 | ast_workspace: &AstWorkspace, 14 | ) -> Result<(), ResolveError> { 15 | prepare_type_jobs(ctx, asg, ast_workspace) 16 | .and_then(|type_jobs| resolve_type_jobs(ctx, asg, ast_workspace, type_jobs.as_slice())) 17 | } 18 | -------------------------------------------------------------------------------- /src/components/build_asg/src/unify_types/integer_literals.rs: -------------------------------------------------------------------------------- 1 | use asg::{Type, TypeKind}; 2 | use data_units::BitUnits; 3 | use primitives::IntegerSign; 4 | 5 | pub fn integer_literals_all_fit<'a>( 6 | preferred_type: Option<&Type>, 7 | mut types: impl Iterator, 8 | ) -> bool { 9 | let Some(Type { 10 | kind: TypeKind::Integer(preferred_bits, preferred_sign), 11 | .. 12 | }) = preferred_type 13 | else { 14 | return false; 15 | }; 16 | 17 | types.all(|ty| match &ty.kind { 18 | TypeKind::IntegerLiteral(value) => { 19 | let literal_sign = IntegerSign::from(value); 20 | 21 | let literal_bits = BitUnits::of(match literal_sign { 22 | IntegerSign::Unsigned => value.bits(), 23 | IntegerSign::Signed => value.bits() + 1, 24 | }); 25 | 26 | (preferred_sign.is_signed() || literal_sign.is_unsigned()) 27 | && literal_bits <= preferred_bits.bits() 28 | } 29 | _ => false, 30 | }) 31 | } 32 | -------------------------------------------------------------------------------- /src/components/build_ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_ast" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | ast = { version = "0.1.0", path = "../../representations/ast" } 8 | attributes = { version = "0.1.0", path = "../../representations/attributes" } 9 | derivative.workspace = true 10 | derive_more.workspace = true 11 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 12 | indexmap.workspace = true 13 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 14 | lazy_format.workspace = true 15 | num.workspace = true 16 | num-bigint.workspace = true 17 | num-traits.workspace = true 18 | optional_string = { version = "0.1.0", path = "../../support/optional_string" } 19 | primitives = { version = "0.1.0", path = "../../representations/primitives" } 20 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 21 | text = { version = "0.1.0", path = "../../support/text" } 22 | token = { version = "0.1.0", path = "../../representations/token" } 23 | -------------------------------------------------------------------------------- /src/components/build_ast/src/parse_expr/mod.rs: -------------------------------------------------------------------------------- 1 | mod post; 2 | mod primary; 3 | 4 | use super::{ParseError, Parser, is_right_associative, is_terminating_token}; 5 | use ast::Expr; 6 | use infinite_iterator::InfinitePeekable; 7 | use token::Token; 8 | 9 | impl<'a, I: InfinitePeekable> Parser<'a, I> { 10 | pub fn parse_expr(&mut self) -> Result { 11 | let primary = self.parse_expr_primary()?; 12 | self.parse_operator_expr(0, primary) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/components/build_ast/src/parse_expr/post/array_access.rs: -------------------------------------------------------------------------------- 1 | use super::Parser; 2 | use crate::error::ParseError; 3 | use ast::{ArrayAccess, Expr, ExprKind}; 4 | use infinite_iterator::InfinitePeekable; 5 | use token::{Token, TokenKind}; 6 | 7 | impl<'a, I: InfinitePeekable> Parser<'a, I> { 8 | pub fn parse_array_access(&mut self, subject: Expr) -> Result { 9 | // subject[index] 10 | // ^ 11 | 12 | let source = self.input.here(); 13 | 14 | self.input 15 | .expect(TokenKind::OpenBracket, "for array access")?; 16 | 17 | self.ignore_newlines(); 18 | let index = self.parse_expr()?; 19 | self.ignore_newlines(); 20 | 21 | self.input 22 | .expect(TokenKind::CloseBracket, "to close array access")?; 23 | 24 | Ok(ExprKind::ArrayAccess(Box::new(ArrayAccess { subject, index })).at(source)) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/components/build_ast/src/parse_expr/post/is_match.rs: -------------------------------------------------------------------------------- 1 | use super::Parser; 2 | use crate::error::ParseError; 3 | use ast::{Expr, ExprKind}; 4 | use infinite_iterator::InfinitePeekable; 5 | use token::{Token, TokenKind}; 6 | 7 | impl<'a, I: InfinitePeekable> Parser<'a, I> { 8 | pub fn parse_is_match(&mut self, subject: Expr) -> Result { 9 | // subject is Variant 10 | // ^ 11 | 12 | let source = self.input.here(); 13 | 14 | self.input 15 | .expect(TokenKind::IsKeyword, "for 'is' expression")?; 16 | 17 | let variant_name = self.parse_identifier("for variant name")?; 18 | 19 | Ok(ExprKind::Is(Box::new(subject), variant_name).at(source)) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/components/build_ast/src/parse_expr/primary/declare_assign.rs: -------------------------------------------------------------------------------- 1 | use super::Parser; 2 | use crate::error::ParseError; 3 | use ast::{DeclareAssign, Expr, ExprKind}; 4 | use infinite_iterator::InfinitePeekable; 5 | use source_files::Source; 6 | use token::{Token, TokenKind}; 7 | 8 | impl<'a, I: InfinitePeekable> Parser<'a, I> { 9 | pub fn parse_declare_assign( 10 | &mut self, 11 | name: String, 12 | source: Source, 13 | ) -> Result { 14 | // variable_name := value 15 | // ^ 16 | 17 | self.input.expect( 18 | TokenKind::DeclareAssign, 19 | Some("for variable declaration assignment"), 20 | )?; 21 | self.ignore_newlines(); 22 | 23 | Ok(ExprKind::DeclareAssign(Box::new(DeclareAssign { 24 | name, 25 | value: self.parse_expr()?, 26 | })) 27 | .at(source)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/components/build_ast/src/parse_stmt/parse_declaration.rs: -------------------------------------------------------------------------------- 1 | use super::{super::error::ParseError, Parser}; 2 | use ast::{Declaration, Stmt, StmtKind}; 3 | use infinite_iterator::InfinitePeekable; 4 | use optional_string::NoneStr; 5 | use token::{Token, TokenKind}; 6 | 7 | impl<'a, I: InfinitePeekable> Parser<'a, I> { 8 | pub fn parse_declaration(&mut self) -> Result { 9 | let (name, source) = self 10 | .parse_identifier_keep_location("for variable name")? 11 | .tuple(); 12 | 13 | let variable_type = self.parse_type(NoneStr, "for variable")?; 14 | 15 | let initial_value = self 16 | .input 17 | .eat(TokenKind::Assign) 18 | .then(|| self.parse_expr()) 19 | .transpose()?; 20 | 21 | Ok(Stmt::new( 22 | StmtKind::Declaration(Box::new(Declaration { 23 | name, 24 | ast_type: variable_type, 25 | initial_value, 26 | })), 27 | source, 28 | )) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/components/build_ast/src/parse_stmt/parse_return.rs: -------------------------------------------------------------------------------- 1 | use super::{super::error::ParseError, Parser}; 2 | use ast::{Stmt, StmtKind}; 3 | use infinite_iterator::InfinitePeekable; 4 | use token::{Token, TokenKind}; 5 | 6 | impl<'a, I: InfinitePeekable> Parser<'a, I> { 7 | pub fn parse_return(&mut self) -> Result { 8 | // return VALUE 9 | // ^ 10 | 11 | let source = self.input.here(); 12 | 13 | self.input 14 | .expect(TokenKind::ReturnKeyword, "for return statement")?; 15 | 16 | let return_value = (!self.input.peek_is(TokenKind::Newline)) 17 | .then(|| self.parse_expr()) 18 | .transpose()?; 19 | 20 | Ok(StmtKind::Return(return_value).at(source)) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/components/build_c_ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_c_ast" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | ast = { version = "0.1.0", path = "../../representations/ast" } 8 | ast_workspace = { version = "0.1.0", path = "../../representations/ast_workspace" } 9 | attributes = { version = "0.1.0", path = "../../representations/attributes" } 10 | c_ast = { version = "0.1.0", path = "../../representations/c_ast" } 11 | c_token = { version = "0.1.0", path = "../../representations/c_token" } 12 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 13 | indexmap.workspace = true 14 | num-bigint.workspace = true 15 | num-traits.workspace = true 16 | primitives = { version = "0.1.0", path = "../../representations/primitives" } 17 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 18 | -------------------------------------------------------------------------------- /src/components/build_c_ast/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod parse; 2 | pub mod translate; 3 | 4 | pub use self::translate::translate_expr; 5 | use attributes::Privacy; 6 | 7 | #[derive(Copy, Clone, Debug)] 8 | pub enum CFileType { 9 | Header, 10 | Source, 11 | } 12 | 13 | impl CFileType { 14 | pub fn privacy(&self) -> Privacy { 15 | match self { 16 | CFileType::Header => Privacy::Protected, 17 | CFileType::Source => Privacy::Private, 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/components/build_c_ast/src/parse/speculate.rs: -------------------------------------------------------------------------------- 1 | macro_rules! speculate { 2 | ($input:expr, $expression:expr) => {{ 3 | $input.speculate(); 4 | 5 | match $expression { 6 | Ok(ok) => { 7 | $input.success(); 8 | Ok(ok) 9 | } 10 | Err(err) => { 11 | $input.backtrack(); 12 | Err(err) 13 | } 14 | } 15 | }}; 16 | } 17 | 18 | pub(crate) use speculate; 19 | -------------------------------------------------------------------------------- /src/components/build_c_ast/src/translate/expr/string.rs: -------------------------------------------------------------------------------- 1 | use crate::parse::{ParseError, error::ParseErrorKind}; 2 | use c_token::Encoding; 3 | use source_files::Source; 4 | use std::ffi::CString; 5 | 6 | pub fn translate_expr_string( 7 | encoding: &Encoding, 8 | content: &str, 9 | source: Source, 10 | ) -> Result { 11 | if let Encoding::Default = encoding { 12 | let Ok(content) = CString::new(content) else { 13 | return Err(ParseErrorKind::CannotContainNulInNullTerminatedString.at(source)); 14 | }; 15 | return Ok(ast::ExprKind::NullTerminatedString(content).at(source)); 16 | } 17 | 18 | todo!("translate non-default encoding C string") 19 | } 20 | -------------------------------------------------------------------------------- /src/components/build_c_token/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_c_token" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | c_token = { version = "0.1.0", path = "../../representations/c_token" } 8 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 9 | pp_token = { version = "0.1.0", path = "../../representations/pp_token" } 10 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 11 | -------------------------------------------------------------------------------- /src/components/build_c_token/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(string_remove_matches)] 2 | 3 | mod lexer; 4 | mod number; 5 | 6 | use c_token::CToken; 7 | pub use c_token::Invalid as LexError; 8 | use infinite_iterator::{Infinite, InfiniteIteratorPeeker, InfiniteIteratorTools}; 9 | pub use lexer::Lexer; 10 | use pp_token::{PreToken, PreTokenKind}; 11 | use source_files::Source; 12 | 13 | // Common lexing routine: 14 | // We usually want to convert all of the C preprocessor tokens into C tokens 15 | // at once for each file. This is for a few reasons: 16 | // 1) Our C preprocessor produces a whole document at once (since designed for caching) 17 | // 2) It's much easier to parse C code when you don't do it streaming (since lots of backtracking) 18 | pub fn lex_c_code(preprocessed: Vec, eof_source: Source) -> Vec { 19 | Lexer::new(InfiniteIteratorPeeker::new(Infinite::new( 20 | preprocessed.into_iter(), 21 | PreTokenKind::EndOfSequence.at(eof_source), 22 | ))) 23 | .collect_vec(true) 24 | } 25 | -------------------------------------------------------------------------------- /src/components/build_executable/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_executable" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | backend = { version = "0.1.0", path = "../../support/backend" } 8 | compiler = { version = "0.1.0", path = "../../support/compiler" } 9 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 10 | target = { version = "0.1.0", path = "../../support/target" } 11 | -------------------------------------------------------------------------------- /src/components/build_ir/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_ir" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | arena = { version = "0.1.0", path = "../../support/arena" } 9 | asg = { version = "0.1.0", path = "../../representations/asg" } 10 | attributes = { version = "0.1.0", path = "../../representations/attributes" } 11 | compiler = { version = "0.1.0", path = "../../support/compiler" } 12 | data_units = { version = "0.1.0", path = "../../support/data_units" } 13 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 14 | indexmap.workspace = true 15 | ir = { version = "0.1.0", path = "../../representations/ir" } 16 | num.workspace = true 17 | primitives = { version = "0.1.0", path = "../../representations/primitives" } 18 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 19 | target = { version = "0.1.0", path = "../../support/target" } 20 | target_layout = { version = "0.1.0", path = "../../support/target_layout" } 21 | -------------------------------------------------------------------------------- /src/components/build_ir/src/global.rs: -------------------------------------------------------------------------------- 1 | use super::error::LowerError; 2 | use crate::ModBuilder; 3 | 4 | pub fn lower_global( 5 | mod_builder: &ModBuilder, 6 | global_ref: asg::GlobalRef, 7 | ) -> Result<(), LowerError> { 8 | let global = &mod_builder.asg.globals[global_ref]; 9 | 10 | let mangled_name = if global.ownership.should_mangle() { 11 | global 12 | .name 13 | .display(&mod_builder.asg.workspace.fs) 14 | .to_string() 15 | } else { 16 | global.name.plain().to_string() 17 | }; 18 | 19 | mod_builder.globals.insert( 20 | global_ref, 21 | ir::Global { 22 | mangled_name, 23 | ir_type: mod_builder.lower_type(&global.ty)?, 24 | is_thread_local: global.is_thread_local, 25 | ownership: global.ownership, 26 | }, 27 | ); 28 | 29 | Ok(()) 30 | } 31 | -------------------------------------------------------------------------------- /src/components/build_ir/src/globals.rs: -------------------------------------------------------------------------------- 1 | use arena::{Arena, LockFreeArena}; 2 | use std::{collections::HashMap, sync::RwLock}; 3 | 4 | #[derive(Debug, Default)] 5 | pub struct Globals { 6 | globals: LockFreeArena, 7 | lowered: RwLock>, 8 | } 9 | 10 | impl Globals { 11 | pub fn build(self) -> Arena { 12 | self.globals.into_arena() 13 | } 14 | 15 | pub fn translate(&self, key: asg::GlobalRef) -> ir::GlobalRef { 16 | *self 17 | .lowered 18 | .read() 19 | .unwrap() 20 | .get(&key) 21 | .expect("global variable to have already been lowered") 22 | } 23 | 24 | pub fn insert(&self, asg_global_ref: asg::GlobalRef, global: ir::Global) -> ir::GlobalRef { 25 | let ir_global_ref = self.globals.alloc(global); 26 | 27 | self.lowered 28 | .write() 29 | .unwrap() 30 | .insert(asg_global_ref, ir_global_ref); 31 | 32 | ir_global_ref 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_llvm_ir" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | backend = { version = "0.1.0", path = "../../support/backend" } 9 | build_executable = { version = "0.1.0", path = "../build_executable" } 10 | colored.workspace = true 11 | compiler = { version = "0.1.0", path = "../../support/compiler" } 12 | cstr.workspace = true 13 | data_units = { version = "0.1.0", path = "../../support/data_units" } 14 | derive_more.workspace = true 15 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 16 | ir = { version = "0.1.0", path = "../../representations/ir" } 17 | itertools.workspace = true 18 | llvm-sys = { package = "llvm-sys", version = "181" } 19 | memo-map.workspace = true 20 | once_map.workspace = true 21 | primitives = { version = "0.1.0", path = "../../representations/primitives" } 22 | target = { version = "0.1.0", path = "../../support/target" } 23 | target_layout = { version = "0.1.0", path = "../../support/target_layout" } 24 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/abi_type/direct.rs: -------------------------------------------------------------------------------- 1 | use data_units::ByteUnits; 2 | use llvm_sys::prelude::LLVMTypeRef; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct DirectOptions { 6 | pub coerce_to_type: Option, 7 | pub offset: ByteUnits, 8 | pub padding: Option, 9 | pub can_be_flattened: bool, 10 | pub alignment: ByteUnits, 11 | pub in_register: bool, 12 | } 13 | 14 | impl Default for DirectOptions { 15 | fn default() -> Self { 16 | Self { 17 | coerce_to_type: None, 18 | offset: ByteUnits::of(0), 19 | can_be_flattened: true, 20 | padding: None, 21 | alignment: ByteUnits::of(0), 22 | in_register: false, 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/abi_type/extend.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug)] 2 | pub struct ExtendOptions { 3 | pub in_register: bool, 4 | } 5 | 6 | #[allow(clippy::derivable_impls)] 7 | impl Default for ExtendOptions { 8 | fn default() -> Self { 9 | Self { in_register: false } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/abi_type/indirect.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug)] 2 | pub struct IndirectOptions { 3 | pub in_register: bool, 4 | } 5 | 6 | #[allow(clippy::derivable_impls)] 7 | impl Default for IndirectOptions { 8 | fn default() -> Self { 9 | Self { in_register: false } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/abi_type/offset_align.rs: -------------------------------------------------------------------------------- 1 | use data_units::ByteUnits; 2 | 3 | #[derive(Copy, Clone, Debug, Default)] 4 | pub struct OffsetAlign { 5 | pub offset: ByteUnits, 6 | pub align: ByteUnits, 7 | } 8 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/abi_type/show_llvm_type.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::Debug; 2 | use llvm_sys::{core::LLVMPrintTypeToString, prelude::LLVMTypeRef}; 3 | use std::ffi::CString; 4 | 5 | pub struct ShowLLVMType(pub LLVMTypeRef); 6 | 7 | impl Debug for ShowLLVMType { 8 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 9 | let representation = unsafe { CString::from_raw(LLVMPrintTypeToString(self.0)) }; 10 | write!(f, "LLVMTypeRef::{}", representation.to_str().unwrap()) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/arch/x86_64/avx_level.rs: -------------------------------------------------------------------------------- 1 | use data_units::ByteUnits; 2 | 3 | #[derive(Clone, Debug)] 4 | pub enum AvxLevel { 5 | None, 6 | Avx, 7 | Avx512, 8 | } 9 | 10 | impl AvxLevel { 11 | pub fn native_vector_size(&self) -> ByteUnits { 12 | ByteUnits::of(match self { 13 | AvxLevel::None => 16, 14 | AvxLevel::Avx => 32, 15 | AvxLevel::Avx512 => 64, 16 | }) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/arch/x86_64/sysv/reg_class_pair.rs: -------------------------------------------------------------------------------- 1 | use super::reg_class::RegClass; 2 | 3 | #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] 4 | pub struct RegClassPair { 5 | pub high: RegClass, 6 | pub low: RegClass, 7 | } 8 | 9 | impl RegClassPair { 10 | pub fn merge_with(&mut self, other: RegClassPair) { 11 | self.high = self.high.merge(other.high); 12 | self.low = self.low.merge(other.low); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/abi/cxx/mod.rs: -------------------------------------------------------------------------------- 1 | mod itanium; 2 | 3 | pub use itanium::Itanium; 4 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/builder/int_cast.rs: -------------------------------------------------------------------------------- 1 | use super::Builder; 2 | use cstr::cstr; 3 | use llvm_sys::{ 4 | core::LLVMBuildIntCast2, 5 | prelude::{LLVMTypeRef, LLVMValueRef}, 6 | }; 7 | 8 | impl Builder { 9 | pub fn int_cast( 10 | &self, 11 | value: LLVMValueRef, 12 | integer_type: LLVMTypeRef, 13 | signed: bool, 14 | ) -> LLVMValueRef { 15 | unsafe { 16 | LLVMBuildIntCast2( 17 | self.get(), 18 | value, 19 | integer_type, 20 | signed as _, 21 | cstr!("").as_ptr(), 22 | ) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/builder/int_to_ptr.rs: -------------------------------------------------------------------------------- 1 | use super::Builder; 2 | use cstr::cstr; 3 | use llvm_sys::{ 4 | core::LLVMBuildIntToPtr, 5 | prelude::{LLVMTypeRef, LLVMValueRef}, 6 | }; 7 | 8 | impl Builder { 9 | pub fn int_to_ptr(&self, value: LLVMValueRef, integer_type: LLVMTypeRef) -> LLVMValueRef { 10 | unsafe { LLVMBuildIntToPtr(self.get(), value, integer_type, cstr!("").as_ptr()) } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/builder/memcpy.rs: -------------------------------------------------------------------------------- 1 | use super::Builder; 2 | use crate::address::Address; 3 | use llvm_sys::{core::LLVMBuildMemCpy, prelude::LLVMValueRef}; 4 | 5 | impl Builder { 6 | pub fn memcpy( 7 | &self, 8 | destination: &Address, 9 | source: &Address, 10 | size: LLVMValueRef, 11 | ) -> LLVMValueRef { 12 | unsafe { 13 | LLVMBuildMemCpy( 14 | self.get(), 15 | destination.base_pointer(), 16 | destination.base.alignment.bytes().try_into().unwrap(), 17 | source.base_pointer(), 18 | source.base.alignment.bytes().try_into().unwrap(), 19 | size, 20 | ) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/builder/phi_relocation.rs: -------------------------------------------------------------------------------- 1 | use llvm_sys::prelude::LLVMValueRef; 2 | 3 | pub struct PhiRelocation { 4 | pub phi_node: LLVMValueRef, 5 | pub incoming: Vec, 6 | } 7 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/builder/ptr_to_int.rs: -------------------------------------------------------------------------------- 1 | use super::Builder; 2 | use cstr::cstr; 3 | use llvm_sys::{ 4 | core::LLVMBuildPtrToInt, 5 | prelude::{LLVMTypeRef, LLVMValueRef}, 6 | }; 7 | 8 | impl Builder { 9 | pub fn ptr_to_int(&self, value: LLVMValueRef, integer_type: LLVMTypeRef) -> LLVMValueRef { 10 | unsafe { LLVMBuildPtrToInt(self.get(), value, integer_type, cstr!("").as_ptr()) } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/builder/store.rs: -------------------------------------------------------------------------------- 1 | use super::Builder; 2 | use crate::address::Address; 3 | use data_units::ByteUnits; 4 | use llvm_sys::{ 5 | core::{LLVMBuildStore, LLVMSetAlignment}, 6 | prelude::LLVMValueRef, 7 | }; 8 | 9 | impl Builder { 10 | pub fn store(&self, value: LLVMValueRef, destination: &Address) -> LLVMValueRef { 11 | self.store_aligned_raw( 12 | value, 13 | destination.base_pointer(), 14 | destination.base.alignment, 15 | ) 16 | } 17 | 18 | pub fn store_raw(&self, value: LLVMValueRef, destination: LLVMValueRef) -> LLVMValueRef { 19 | unsafe { LLVMBuildStore(self.get(), value, destination) } 20 | } 21 | 22 | pub fn store_aligned_raw( 23 | &self, 24 | value: LLVMValueRef, 25 | destination: LLVMValueRef, 26 | alignment: ByteUnits, 27 | ) -> LLVMValueRef { 28 | let store = unsafe { LLVMBuildStore(self.get(), value, destination) }; 29 | unsafe { LLVMSetAlignment(store, alignment.bytes().try_into().unwrap()) }; 30 | store 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/functions/attribute.rs: -------------------------------------------------------------------------------- 1 | use llvm_sys::{ 2 | core::{ 3 | LLVMAddAttributeAtIndex, LLVMCreateEnumAttribute, LLVMGetEnumAttributeKindForName, 4 | LLVMGetGlobalContext, 5 | }, 6 | prelude::{LLVMAttributeRef, LLVMValueRef}, 7 | LLVMAttributeFunctionIndex, 8 | }; 9 | use std::ffi::CStr; 10 | 11 | pub fn create_enum_attribute(name: &CStr, value: u64) -> LLVMAttributeRef { 12 | unsafe { 13 | LLVMCreateEnumAttribute( 14 | LLVMGetGlobalContext(), 15 | LLVMGetEnumAttributeKindForName(name.as_ptr(), name.count_bytes()), 16 | value, 17 | ) 18 | } 19 | } 20 | 21 | pub fn add_param_attribute( 22 | function: LLVMValueRef, 23 | param_index: usize, 24 | attribute: LLVMAttributeRef, 25 | ) { 26 | unsafe { LLVMAddAttributeAtIndex(function, 1 + u32::try_from(param_index).unwrap(), attribute) } 27 | } 28 | 29 | pub fn add_func_attribute(function: LLVMValueRef, attribute: LLVMAttributeRef) { 30 | unsafe { LLVMAddAttributeAtIndex(function, LLVMAttributeFunctionIndex, attribute) } 31 | } 32 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/functions/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod attribute; 2 | pub mod block; 3 | pub mod body; 4 | pub mod epilogue; 5 | pub mod function_type; 6 | pub mod head; 7 | mod helpers; 8 | pub mod param_values; 9 | pub mod params_mapping; 10 | pub mod prologue; 11 | pub mod return_location; 12 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/functions/param_values/mod.rs: -------------------------------------------------------------------------------- 1 | mod coerce_and_expand; 2 | mod direct; 3 | mod expand; 4 | mod ignore; 5 | mod inalloca; 6 | mod indirect; 7 | mod value; 8 | 9 | pub use self::value::ParamValue; 10 | use super::params_mapping::ParamRange; 11 | use crate::{ 12 | builder::Builder, 13 | ctx::{BackendCtx, FunctionSkeleton}, 14 | }; 15 | use llvm_sys::prelude::LLVMValueRef; 16 | 17 | pub struct ParamValues { 18 | values: Vec, 19 | } 20 | 21 | impl ParamValues { 22 | pub fn new() -> Self { 23 | Self { 24 | values: Vec::::with_capacity(16), 25 | } 26 | } 27 | 28 | pub fn get(&self, index: usize) -> Option<&ParamValue> { 29 | self.values.get(index) 30 | } 31 | } 32 | 33 | pub struct ParamValueConstructionCtx<'a> { 34 | pub builder: &'a Builder, 35 | pub ctx: &'a BackendCtx<'a>, 36 | pub skeleton: &'a FunctionSkeleton, 37 | pub param_range: ParamRange, 38 | pub ir_param_type: &'a ir::Type, 39 | pub alloca_point: LLVMValueRef, 40 | } 41 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/functions/param_values/value.rs: -------------------------------------------------------------------------------- 1 | use crate::address::Address; 2 | use derive_more::IsVariant; 3 | use llvm_sys::prelude::LLVMValueRef; 4 | 5 | #[derive(IsVariant)] 6 | pub enum ParamValue { 7 | Direct(LLVMValueRef), 8 | Indirect(Address), 9 | } 10 | 11 | impl ParamValue { 12 | pub fn value(&self) -> LLVMValueRef { 13 | match self { 14 | ParamValue::Direct(value) => *value, 15 | ParamValue::Indirect(address) => { 16 | assert!(address.offset.is_none()); 17 | address.base_pointer() 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/llvm_value_ref_ext.rs: -------------------------------------------------------------------------------- 1 | use llvm_sys::{ 2 | core::{LLVMConstInt, LLVMInt32Type, LLVMInt64Type}, 3 | prelude::LLVMValueRef, 4 | }; 5 | 6 | pub trait LLVMValueRefExt: Sized + Copy { 7 | fn new_i32(value: i32) -> Self; 8 | fn new_u64(value: u64) -> Self; 9 | } 10 | 11 | impl LLVMValueRefExt for LLVMValueRef { 12 | fn new_i32(value: i32) -> Self { 13 | unsafe { LLVMConstInt(LLVMInt32Type(), value as u64, true as _) } 14 | } 15 | 16 | fn new_u64(value: u64) -> Self { 17 | unsafe { LLVMConstInt(LLVMInt64Type(), value, false as _) } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/module.rs: -------------------------------------------------------------------------------- 1 | use llvm_sys::{ 2 | core::{LLVMDisposeModule, LLVMModuleCreateWithName}, 3 | prelude::LLVMModuleRef, 4 | }; 5 | use std::ffi::CStr; 6 | 7 | pub struct BackendModule { 8 | module: LLVMModuleRef, 9 | } 10 | 11 | impl BackendModule { 12 | pub unsafe fn new(module_name: &CStr) -> Self { 13 | Self { 14 | module: LLVMModuleCreateWithName(module_name.as_ptr()), 15 | } 16 | } 17 | 18 | pub unsafe fn get(&self) -> LLVMModuleRef { 19 | self.module 20 | } 21 | } 22 | 23 | impl Drop for BackendModule { 24 | fn drop(&mut self) { 25 | unsafe { 26 | LLVMDisposeModule(self.module); 27 | } 28 | } 29 | } 30 | 31 | impl From for LLVMModuleRef { 32 | fn from(value: BackendModule) -> Self { 33 | unsafe { value.get() } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/raw_address.rs: -------------------------------------------------------------------------------- 1 | use data_units::ByteUnits; 2 | use llvm_sys::{ 3 | LLVMTypeKind, 4 | core::{LLVMGetTypeKind, LLVMTypeOf}, 5 | prelude::{LLVMTypeRef, LLVMValueRef}, 6 | }; 7 | 8 | #[derive(Clone)] 9 | pub struct RawAddress { 10 | pub base: LLVMValueRef, 11 | pub nullable: bool, 12 | pub alignment: ByteUnits, 13 | pub element_type: LLVMTypeRef, 14 | } 15 | 16 | impl RawAddress { 17 | pub fn base_pointer(&self) -> LLVMValueRef { 18 | self.base 19 | } 20 | 21 | pub fn pointer_type(&self) -> LLVMTypeRef { 22 | unsafe { 23 | let ty = LLVMTypeOf(self.base); 24 | assert_eq!(LLVMGetTypeKind(ty), LLVMTypeKind::LLVMPointerTypeKind); 25 | ty 26 | } 27 | } 28 | 29 | pub fn element_type(&self) -> LLVMTypeRef { 30 | self.element_type 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/components/build_llvm_ir/src/value_catalog.rs: -------------------------------------------------------------------------------- 1 | use ir::ValueReference; 2 | use llvm_sys::prelude::LLVMValueRef; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct ValueCatalog { 6 | blocks: Vec, 7 | } 8 | 9 | #[derive(Clone, Debug, Default)] 10 | struct Block { 11 | values: Vec>, 12 | } 13 | 14 | impl ValueCatalog { 15 | pub fn new(num_blocks: usize) -> Self { 16 | Self { 17 | blocks: vec![Default::default(); num_blocks], 18 | } 19 | } 20 | 21 | pub fn get(&self, reference: &ValueReference) -> Option { 22 | self.blocks.get(reference.basicblock_id).and_then(|block| { 23 | block 24 | .values 25 | .get(reference.instruction_id) 26 | .and_then(|value| *value) 27 | }) 28 | } 29 | 30 | pub fn push(&mut self, basicblock_id: usize, value: Option) { 31 | self.blocks[basicblock_id].values.push(value); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/components/build_pp_ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_pp_ast" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 9 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 10 | itertools.workspace = true 11 | look_ahead = { version = "0.1.0", path = "../../support/look_ahead" } 12 | pp_ast = { version = "0.1.0", path = "../../representations/pp_ast" } 13 | pp_token = { version = "0.1.0", path = "../../representations/pp_token" } 14 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 15 | text = { version = "0.1.0", path = "../../support/text" } 16 | -------------------------------------------------------------------------------- /src/components/build_pp_ast/src/expand/embed.rs: -------------------------------------------------------------------------------- 1 | use super::{Environment, depleted::Depleted}; 2 | use crate::PreprocessorError; 3 | use pp_token::PreToken; 4 | 5 | pub fn expand_embed( 6 | _options: &[PreToken], 7 | _environment: &mut Environment, 8 | _depleted: &mut Depleted, 9 | ) -> Result, PreprocessorError> { 10 | unimplemented!("#embed is not implemented yet") 11 | } 12 | -------------------------------------------------------------------------------- /src/components/build_pp_ast/src/expand/environment.rs: -------------------------------------------------------------------------------- 1 | use pp_ast::Define; 2 | use std::collections::HashMap; 3 | 4 | #[derive(Clone, Debug, Default)] 5 | pub struct Environment { 6 | pub defines: HashMap, 7 | } 8 | 9 | impl Environment { 10 | pub fn add_define(&mut self, define: Define) { 11 | // NOTE: According to the C standard, macros are not supposed to be redefined unless they 12 | // are "identical", but most compilers allow redefining so we will follow suit. 13 | self.defines.insert(define.name.clone(), define); 14 | } 15 | 16 | pub fn find_define(&self, name: &str) -> Option<&Define> { 17 | self.defines.get(name) 18 | } 19 | 20 | pub fn remove_define(&mut self, name: &str) { 21 | self.defines.remove(name); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/components/build_pp_ast/src/stdc.rs: -------------------------------------------------------------------------------- 1 | use super::expand::Environment; 2 | use pp_ast::{Define, DefineKind, ObjMacro, PlaceholderAffinity}; 3 | use pp_token::PreTokenKind; 4 | use source_files::Source; 5 | 6 | pub fn stdc() -> Environment { 7 | let mut stdc = Environment::default(); 8 | 9 | stdc.add_define(Define { 10 | name: "__STDC__".into(), 11 | source: Source::internal(), 12 | kind: DefineKind::ObjMacro(ObjMacro::new(vec![], PlaceholderAffinity::Discard)), 13 | is_file_local_only: true, 14 | }); 15 | 16 | stdc.add_define(Define { 17 | name: "__STDC_VERSION__".into(), 18 | source: Source::internal(), 19 | kind: DefineKind::ObjMacro(ObjMacro::new( 20 | vec![PreTokenKind::Number("202311L".into()).at(Source::internal())], 21 | PlaceholderAffinity::Discard, 22 | )), 23 | is_file_local_only: true, 24 | }); 25 | 26 | stdc 27 | } 28 | -------------------------------------------------------------------------------- /src/components/build_token/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "build_token" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 9 | num-bigint.workspace = true 10 | num-traits.workspace = true 11 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 12 | text = { version = "0.1.0", path = "../../support/text" } 13 | token = { version = "0.1.0", path = "../../representations/token" } 14 | -------------------------------------------------------------------------------- /src/components/build_token/src/hex_number_state.rs: -------------------------------------------------------------------------------- 1 | use num_bigint::BigInt; 2 | use num_traits::Num; 3 | use source_files::Source; 4 | use token::{Token, TokenKind}; 5 | 6 | pub struct HexNumberState { 7 | pub value: String, 8 | pub start_source: Source, 9 | } 10 | 11 | impl HexNumberState { 12 | pub fn to_token(&self) -> Token { 13 | match BigInt::from_str_radix(&self.value, 16) { 14 | Ok(value) => TokenKind::Integer(value), 15 | Err(_) => TokenKind::Error(format!("Invalid hex number {}", &self.value)), 16 | } 17 | .at(self.start_source) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/components/build_token/src/number_state.rs: -------------------------------------------------------------------------------- 1 | use num_bigint::BigInt; 2 | use source_files::Source; 3 | use token::{Token, TokenKind}; 4 | 5 | pub struct NumberState { 6 | pub value: String, 7 | pub can_dot: bool, 8 | pub can_exp: bool, 9 | pub can_neg: bool, 10 | pub start_source: Source, 11 | } 12 | 13 | impl NumberState { 14 | pub fn new(value: String, start_source: Source) -> Self { 15 | Self { 16 | value, 17 | can_dot: true, 18 | can_exp: true, 19 | can_neg: false, 20 | start_source, 21 | } 22 | } 23 | 24 | pub fn to_token(&self) -> Token { 25 | if let Ok(value) = self.value.parse::() { 26 | return TokenKind::Integer(value).at(self.start_source); 27 | } 28 | 29 | if let Ok(value) = self.value.parse::() { 30 | return TokenKind::Float(value).at(self.start_source); 31 | } 32 | 33 | TokenKind::Error("Invalid number".into()).at(self.start_source) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/components/build_token/src/polymorph_state.rs: -------------------------------------------------------------------------------- 1 | use source_files::Source; 2 | use token::{Token, TokenKind}; 3 | 4 | pub struct PolymorphState { 5 | pub identifier: String, 6 | pub start_source: Source, 7 | } 8 | 9 | impl PolymorphState { 10 | pub fn finalize(&mut self) -> Token { 11 | let identifier = std::mem::take(&mut self.identifier); 12 | TokenKind::Polymorph(identifier).at(self.start_source) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/components/build_token/src/string_state.rs: -------------------------------------------------------------------------------- 1 | use source_files::Source; 2 | use token::StringModifier; 3 | 4 | pub struct StringState { 5 | pub value: String, 6 | pub closing_char: char, 7 | pub modifier: StringModifier, 8 | pub start_source: Source, 9 | } 10 | -------------------------------------------------------------------------------- /src/components/build_workspace/src/file.rs: -------------------------------------------------------------------------------- 1 | use super::{module_file::ModuleFile, normal_file::NormalFile}; 2 | use build_ast::Input; 3 | use derive_more::IsVariant; 4 | use fs_tree::FsNodeId; 5 | use infinite_iterator::InfinitePeekable; 6 | use std::path::Path; 7 | use token::Token; 8 | 9 | #[derive(IsVariant)] 10 | pub enum CodeFile<'a, I: InfinitePeekable> { 11 | Normal(NormalFile), 12 | Module(ModuleFile, Input<'a, I>), 13 | } 14 | 15 | impl<'a, I: InfinitePeekable> CodeFile<'a, I> { 16 | pub fn path(&self) -> &Path { 17 | match self { 18 | CodeFile::Normal(normal_file) => &normal_file.path, 19 | CodeFile::Module(module_file, _) => &module_file.path, 20 | } 21 | } 22 | 23 | pub fn fs_node_id(&self) -> FsNodeId { 24 | match self { 25 | CodeFile::Normal(normal_file) => normal_file.fs_node_id, 26 | CodeFile::Module(module_file, _) => module_file.fs_node_id, 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/components/build_workspace/src/module_file.rs: -------------------------------------------------------------------------------- 1 | use fs_tree::FsNodeId; 2 | use std::path::PathBuf; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct ModuleFile { 6 | pub path: PathBuf, 7 | pub fs_node_id: FsNodeId, 8 | } 9 | 10 | impl ModuleFile { 11 | pub fn new(fs_node_id: FsNodeId, path: PathBuf) -> Self { 12 | Self { fs_node_id, path } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/components/build_workspace/src/normal_file.rs: -------------------------------------------------------------------------------- 1 | use derive_more::IsVariant; 2 | use fs_tree::FsNodeId; 3 | use std::path::PathBuf; 4 | 5 | #[derive(Debug, IsVariant)] 6 | pub enum NormalFileKind { 7 | Adept, 8 | CSource, 9 | CHeader, 10 | } 11 | 12 | #[derive(Debug)] 13 | pub struct NormalFile { 14 | pub kind: NormalFileKind, 15 | pub path: PathBuf, 16 | pub fs_node_id: FsNodeId, 17 | } 18 | 19 | impl NormalFile { 20 | pub fn new(kind: NormalFileKind, fs_node_id: FsNodeId, path: PathBuf) -> Self { 21 | Self { 22 | kind, 23 | path, 24 | fs_node_id, 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/components/build_workspace/src/pragma_section/mod.rs: -------------------------------------------------------------------------------- 1 | use ast::RawAstFile; 2 | use source_files::Source; 3 | 4 | mod parse; 5 | mod run; 6 | 7 | pub struct PragmaSection { 8 | pub ast_file: RawAstFile, 9 | pub pragma_source: Source, 10 | } 11 | -------------------------------------------------------------------------------- /src/components/cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cli" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | build_pp_ast = { version = "0.1.0", path = "../build_pp_ast" } 8 | build_workspace = { version = "0.1.0", path = "../build_workspace" } 9 | compiler = { version = "0.1.0", path = "../../support/compiler" } 10 | derive_more.workspace = true 11 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 12 | enum_dispatch.workspace = true 13 | indoc.workspace = true 14 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 15 | target = { version = "0.1.0", path = "../../support/target" } 16 | text = { version = "0.1.0", path = "../../support/text" } 17 | -------------------------------------------------------------------------------- /src/components/cli/src/build/mod.rs: -------------------------------------------------------------------------------- 1 | use compiler::BuildOptions; 2 | mod invoke; 3 | mod parse; 4 | mod supported_targets; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct BuildCommand { 8 | pub filename: String, 9 | pub options: BuildOptions, 10 | } 11 | -------------------------------------------------------------------------------- /src/components/cli/src/help/invoke.rs: -------------------------------------------------------------------------------- 1 | use super::HelpCommand; 2 | use crate::Invoke; 3 | 4 | impl Invoke for HelpCommand { 5 | fn invoke(self) -> Result<(), ()> { 6 | println!("usage: adept FILENAME"); 7 | Err(()) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/components/cli/src/help/mod.rs: -------------------------------------------------------------------------------- 1 | mod invoke; 2 | mod parse; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct HelpCommand; 6 | -------------------------------------------------------------------------------- /src/components/cli/src/help/parse.rs: -------------------------------------------------------------------------------- 1 | use super::HelpCommand; 2 | 3 | impl HelpCommand { 4 | pub fn parse(_: impl Iterator) -> Result { 5 | Ok(Self) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/components/cli/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod build; 2 | mod help; 3 | mod new; 4 | 5 | use build::BuildCommand; 6 | use enum_dispatch::enum_dispatch; 7 | use help::HelpCommand; 8 | use new::NewCommand; 9 | 10 | #[enum_dispatch(Invoke)] 11 | #[derive(Clone, Debug)] 12 | pub enum Command { 13 | Help(HelpCommand), 14 | Build(BuildCommand), 15 | New(NewCommand), 16 | } 17 | 18 | impl Command { 19 | pub fn parse() -> Result { 20 | let mut args = std::env::args().skip(1).peekable(); 21 | 22 | match args.peek().map(String::as_str) { 23 | Some("-h" | "--help") | None => HelpCommand::parse(args).map(Self::from), 24 | Some("new") => NewCommand::parse(args).map(Self::from), 25 | _ => BuildCommand::parse(args).map(Self::from), 26 | } 27 | } 28 | } 29 | 30 | #[enum_dispatch] 31 | pub trait Invoke { 32 | fn invoke(self) -> Result<(), ()>; 33 | } 34 | -------------------------------------------------------------------------------- /src/components/cli/src/new/mod.rs: -------------------------------------------------------------------------------- 1 | mod invoke; 2 | mod parse; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct NewCommand { 6 | pub project_name: String, 7 | } 8 | -------------------------------------------------------------------------------- /src/components/cli/src/new/parse.rs: -------------------------------------------------------------------------------- 1 | use super::NewCommand; 2 | 3 | impl NewCommand { 4 | pub fn parse(mut args: impl Iterator) -> Result { 5 | args.next().expect("skip over 'new' command keyword"); 6 | 7 | let (Some(project_name), None) = (args.next(), args.next()) else { 8 | println!("adept new "); 9 | return Err(()); 10 | }; 11 | 12 | Ok(Self { project_name }) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/components/interpret/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "interpret" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | compiler_version = { version = "0.1.0", path = "../../support/compiler_version" } 8 | derive_more.workspace = true 9 | interpreter_api = { version = "0.1.0", path = "../../representations/interpreter_api" } 10 | ir = { version = "0.1.0", path = "../../representations/ir" } 11 | num.workspace = true 12 | num-derive.workspace = true 13 | num-traits.workspace = true 14 | -------------------------------------------------------------------------------- /src/components/interpret/src/ip.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, Default)] 2 | pub struct InstructionPointer { 3 | pub basicblock_id: usize, 4 | pub instruction_id: usize, 5 | } 6 | -------------------------------------------------------------------------------- /src/components/job/src/allocator.rs: -------------------------------------------------------------------------------- 1 | use std::num::NonZero; 2 | use std_ext::BoxedSlice; 3 | 4 | pub type BumpAllocator = bumpalo::Bump; 5 | 6 | pub struct BumpAllocatorPool { 7 | pub allocators: BoxedSlice, 8 | } 9 | 10 | impl BumpAllocatorPool { 11 | pub fn new(num_threads: NonZero) -> Self { 12 | Self { 13 | allocators: (0..num_threads.get()) 14 | .map(|_| BumpAllocator::new()) 15 | .collect(), 16 | } 17 | } 18 | 19 | pub fn len(&self) -> NonZero { 20 | NonZero::new(self.allocators.len()).unwrap() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/components/job/src/continuation.rs: -------------------------------------------------------------------------------- 1 | /* 2 | ================== components/job/src/continuation.rs =================== 3 | List of (non-completion) continuations that tasks can perform. 4 | 5 | Completion continuations are handled separately by returning Ok(result), 6 | instead of Err(continuation). 7 | --------------------------------------------------------------------------- 8 | */ 9 | 10 | use crate::Execution; 11 | use derive_more::From; 12 | use diagnostics::ErrorDiagnostic; 13 | 14 | #[derive(From)] 15 | pub enum Continuation<'env> { 16 | // NOTE: To delay waking back up, tasks must be waited on using `ctx.suspend_on` before 17 | // returning. Usually this is handled indirectly via macro. 18 | Suspend(Execution<'env>), 19 | Error(ErrorDiagnostic), 20 | } 21 | 22 | impl<'env> Continuation<'env> { 23 | #[inline] 24 | pub fn suspend(execution: impl Into>) -> Self { 25 | Self::Suspend(execution.into()) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/components/job/src/execution/diverge.rs: -------------------------------------------------------------------------------- 1 | use super::Executable; 2 | use crate::{Continuation, ExecutionCtx, Executor}; 3 | 4 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 5 | pub struct Diverge; 6 | 7 | impl<'env> Executable<'env> for Diverge { 8 | type Output = (); 9 | 10 | fn execute( 11 | self, 12 | executor: &Executor<'env>, 13 | ctx: &mut ExecutionCtx<'env>, 14 | ) -> Result> { 15 | ctx.suspend_on(executor.request(Diverge)); 16 | Err(Continuation::suspend(Diverge)) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/components/job/src/execution/print.rs: -------------------------------------------------------------------------------- 1 | use super::Executable; 2 | use crate::{Continuation, ExecutionCtx, Executor}; 3 | 4 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 5 | pub struct Print<'env>(pub &'env str); 6 | 7 | impl<'env> Executable<'env> for Print<'env> { 8 | type Output = (); 9 | 10 | fn execute( 11 | self, 12 | _executor: &Executor<'env>, 13 | _ctx: &mut ExecutionCtx<'env>, 14 | ) -> Result> { 15 | println!("{}", self.0); 16 | Ok(()) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/components/job/src/execution_ctx.rs: -------------------------------------------------------------------------------- 1 | use crate::{BumpAllocator, TaskRef}; 2 | use derive_more::Deref; 3 | 4 | #[derive(Deref)] 5 | pub struct ExecutionCtx<'env> { 6 | #[deref] 7 | allocator: &'env bumpalo::Bump, 8 | suspend_on: Vec>, 9 | } 10 | 11 | impl<'env> ExecutionCtx<'env> { 12 | pub fn new(allocator: &'env BumpAllocator) -> Self { 13 | Self { 14 | allocator, 15 | suspend_on: Vec::with_capacity(32), 16 | } 17 | } 18 | 19 | pub fn suspend_on(&mut self, tasks: impl IntoIterator>>) { 20 | self.suspend_on 21 | .extend(tasks.into_iter().map(|task| task.into())); 22 | } 23 | 24 | pub fn waiting_on(&self) -> &[TaskRef<'env>] { 25 | &self.suspend_on 26 | } 27 | 28 | pub fn reset_waiting_on(&mut self) { 29 | self.suspend_on.clear(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/components/job/src/repr/decl.rs: -------------------------------------------------------------------------------- 1 | use ast_workspace::TypeDeclRef; 2 | 3 | /// A symbol declaration 4 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 5 | pub enum Decl { 6 | Global(ast_workspace::GlobalRef), 7 | Func(ast_workspace::FuncRef), 8 | Type(TypeDeclRef), 9 | Impl(ast_workspace::ImplRef), 10 | Namespace(ast_workspace::NamespaceRef), 11 | ExprAlias(ast_workspace::ExprAliasRef), 12 | } 13 | -------------------------------------------------------------------------------- /src/components/job/src/repr/decl_scope.rs: -------------------------------------------------------------------------------- 1 | use super::{Decl, DeclScopeRef, DeclSet}; 2 | use std::collections::{HashMap, hash_map::Entry}; 3 | 4 | /// A collection of identifiers mapped to declaration sets 5 | #[derive(Clone, Debug, PartialEq, Eq)] 6 | pub struct DeclScope { 7 | parent: Option, 8 | names: HashMap, 9 | } 10 | 11 | impl DeclScope { 12 | pub fn new() -> Self { 13 | Self { 14 | parent: None, 15 | names: Default::default(), 16 | } 17 | } 18 | 19 | pub fn get(&self, name: &str) -> Option<&DeclSet> { 20 | self.names.get(name).as_ref().copied() 21 | } 22 | 23 | pub fn entry(&mut self, name: String) -> Entry { 24 | self.names.entry(name) 25 | } 26 | 27 | pub fn push_unique(&mut self, name: String, decl: Decl) { 28 | self.names.entry(name).or_default().push_unique(decl); 29 | } 30 | 31 | pub fn parent(&self) -> Option { 32 | self.parent 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/components/job/src/repr/decl_scope_origin.rs: -------------------------------------------------------------------------------- 1 | use ast_workspace::{AstWorkspace, ModuleRef, NameScopeRef}; 2 | use smallvec::{SmallVec, smallvec}; 3 | 4 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 5 | pub enum DeclScopeOrigin { 6 | Module(ModuleRef), 7 | NameScope(NameScopeRef), 8 | } 9 | 10 | impl DeclScopeOrigin { 11 | pub fn name_scopes(&self, workspace: &AstWorkspace) -> SmallVec<[NameScopeRef; 4]> { 12 | match self { 13 | DeclScopeOrigin::Module(module_ref) => { 14 | workspace.modules[*module_ref].name_scopes().collect() 15 | } 16 | DeclScopeOrigin::NameScope(name_scope_ref) => smallvec![*name_scope_ref], 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/components/job/src/repr/decl_scope_ref.rs: -------------------------------------------------------------------------------- 1 | use fs_tree::FsNodeId; 2 | 3 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 4 | pub struct DeclScopeRef { 5 | file: FsNodeId, 6 | } 7 | 8 | impl DeclScopeRef { 9 | pub fn new(file: FsNodeId) -> Self { 10 | Self { file } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/job/src/repr/decl_set.rs: -------------------------------------------------------------------------------- 1 | use super::Decl; 2 | use ast_workspace::TypeDeclRef; 3 | use std_ext::SmallVec4; 4 | 5 | /// A group of declarations under the same name 6 | #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] 7 | pub struct DeclSet(SmallVec4); 8 | 9 | impl<'env> DeclSet { 10 | pub fn push_unique(&mut self, decl: Decl) { 11 | self.0.push(decl); 12 | } 13 | 14 | pub fn type_decls(&self) -> impl Iterator { 15 | self.0.iter().filter_map(|decl| match decl { 16 | Decl::Type(type_decl_ref) => Some(*type_decl_ref), 17 | _ => None, 18 | }) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/components/job/src/repr/enum_body.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use attributes::Privacy; 3 | use indexmap::IndexMap; 4 | use num_bigint::BigInt; 5 | use source_files::Source; 6 | 7 | #[derive(Clone, Debug)] 8 | pub struct EnumBody<'env> { 9 | pub backing_type: &'env Type<'env>, 10 | pub variants: IndexMap<&'env str, EnumVariant>, 11 | pub privacy: Privacy, 12 | pub source: Source, 13 | } 14 | 15 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 16 | pub struct EnumVariant { 17 | pub value: BigInt, 18 | pub explicit_value: bool, 19 | } 20 | -------------------------------------------------------------------------------- /src/components/job/src/repr/func_body.rs: -------------------------------------------------------------------------------- 1 | use std::marker::PhantomData; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct FuncBody<'env> { 5 | _phantom: PhantomData<&'env ()>, 6 | // pub stmts: Vec, 7 | // pub vars: VariableStorage, 8 | } 9 | -------------------------------------------------------------------------------- /src/components/job/src/repr/func_head.rs: -------------------------------------------------------------------------------- 1 | use super::{Params, Type, TypeParams, UserDefinedType}; 2 | use attributes::{SymbolOwnership, Tag}; 3 | use indexmap::IndexMap; 4 | use source_files::Source; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct FuncHead<'env> { 8 | pub name: &'env str, 9 | pub type_params: TypeParams, 10 | pub params: Params<'env>, 11 | pub return_type: &'env Type<'env>, 12 | pub impl_params: ImplParams<'env>, 13 | pub source: Source, 14 | pub metadata: FuncMetadata, 15 | } 16 | 17 | #[derive(Clone, Debug)] 18 | pub struct FuncMetadata { 19 | pub abi: TargetAbi, 20 | pub ownership: SymbolOwnership, 21 | pub tag: Option, 22 | } 23 | 24 | #[derive(Copy, Clone, Debug)] 25 | pub enum TargetAbi { 26 | Abstract, 27 | C, 28 | } 29 | 30 | #[derive(Clone, Debug)] 31 | pub struct ImplParams<'env> { 32 | pub params: IndexMap<&'env str, &'env UserDefinedType<'env>>, 33 | } 34 | -------------------------------------------------------------------------------- /src/components/job/src/repr/mod.rs: -------------------------------------------------------------------------------- 1 | mod decl; 2 | mod decl_scope; 3 | mod decl_scope_origin; 4 | mod decl_scope_ref; 5 | mod decl_set; 6 | mod enum_body; 7 | mod func_body; 8 | mod func_head; 9 | mod params; 10 | mod struct_body; 11 | mod trait_body; 12 | mod ty; 13 | mod type_alias_body; 14 | mod type_head; 15 | 16 | use ast_workspace::TypeDeclRef; 17 | pub use decl::*; 18 | pub use decl_scope::*; 19 | pub use decl_scope_origin::*; 20 | pub use decl_scope_ref::*; 21 | pub use decl_set::*; 22 | pub use enum_body::*; 23 | pub use func_body::*; 24 | pub use func_head::*; 25 | pub use params::*; 26 | pub use struct_body::*; 27 | pub use trait_body::*; 28 | pub use ty::*; 29 | pub use type_alias_body::*; 30 | pub use type_head::*; 31 | 32 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 33 | pub struct AmbiguousType; 34 | 35 | pub type FindTypeResult = Result, AmbiguousType>; 36 | -------------------------------------------------------------------------------- /src/components/job/src/repr/params.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | 3 | #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] 4 | pub struct Params<'env> { 5 | pub required: &'env [Param<'env>], 6 | pub is_cstyle_vararg: bool, 7 | } 8 | 9 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 10 | pub struct Param<'env> { 11 | pub name: Option<&'env str>, 12 | pub ty: &'env Type<'env>, 13 | } 14 | -------------------------------------------------------------------------------- /src/components/job/src/repr/struct_body.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use attributes::Privacy; 3 | use indexmap::IndexMap; 4 | use source_files::Source; 5 | 6 | pub type TypeParams = ast::TypeParams; 7 | 8 | #[derive(Clone, Debug)] 9 | pub struct StructBody<'env> { 10 | pub fields: IndexMap<&'env str, Field<'env>>, 11 | pub is_packed: bool, 12 | pub params: TypeParams, 13 | pub source: Source, 14 | } 15 | 16 | #[derive(Copy, Clone, Debug)] 17 | pub struct Field<'env> { 18 | pub ty: &'env Type<'env>, 19 | pub privacy: Privacy, 20 | pub source: Source, 21 | } 22 | -------------------------------------------------------------------------------- /src/components/job/src/repr/trait_body.rs: -------------------------------------------------------------------------------- 1 | use super::{Params, Type, TypeParams}; 2 | use attributes::Privacy; 3 | use indexmap::IndexMap; 4 | use source_files::Source; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct TraitBody<'env> { 8 | pub params: TypeParams, 9 | pub funcs: IndexMap<&'env str, TraitFunc<'env>>, 10 | pub source: Source, 11 | pub privacy: Privacy, 12 | } 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct TraitFunc<'env> { 16 | pub params: Params<'env>, 17 | pub return_type: &'env Type<'env>, 18 | pub source: Source, 19 | } 20 | -------------------------------------------------------------------------------- /src/components/job/src/repr/type_alias_body.rs: -------------------------------------------------------------------------------- 1 | use super::{Type, TypeParams}; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct TypeAliasBody<'env> { 7 | pub target: &'env Type<'env>, 8 | pub params: TypeParams, 9 | pub privacy: Privacy, 10 | pub source: Source, 11 | } 12 | -------------------------------------------------------------------------------- /src/components/job/src/repr/type_head.rs: -------------------------------------------------------------------------------- 1 | use super::{EnumBody, StructBody, TypeAliasBody, trait_body::TraitBody}; 2 | 3 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 4 | pub struct TypeHead<'env> { 5 | pub name: &'env str, 6 | pub arity: usize, 7 | } 8 | 9 | impl<'env> TypeHead<'env> { 10 | pub fn new(name: &'env str, arity: usize) -> Self { 11 | Self { name, arity } 12 | } 13 | } 14 | 15 | #[derive(Clone, Debug)] 16 | pub enum TypeBody<'env> { 17 | Struct(StructBody<'env>), 18 | Enum(EnumBody<'env>), 19 | TypeAlias(TypeAliasBody<'env>), 20 | Trait(TraitBody<'env>), 21 | } 22 | -------------------------------------------------------------------------------- /src/components/job/src/suspend_condition.rs: -------------------------------------------------------------------------------- 1 | /* 2 | ================ components/job/src/suspend_condition.rs ================ 3 | Defines how tasks are allowed to suspend. 4 | --------------------------------------------------------------------------- 5 | */ 6 | 7 | use crate::{TaskRef, WaitingCount}; 8 | use smallvec::SmallVec; 9 | 10 | #[derive(Debug)] 11 | pub enum SuspendCondition<'env> { 12 | /// Wait for all dependent tasks to complete before waking up 13 | All(WaitingCount), 14 | 15 | /// Wait for any of these specified dependent tasks to complete before waking up 16 | Any(SmallVec<[TaskRef<'env>; 2]>), 17 | } 18 | -------------------------------------------------------------------------------- /src/components/job/src/task.rs: -------------------------------------------------------------------------------- 1 | /* 2 | ====================== components/job/src/task.rs ======================= 3 | Defines what a task is in the job system. 4 | --------------------------------------------------------------------------- 5 | */ 6 | 7 | use crate::{Artifact, TaskState}; 8 | use arena::{Idx, new_id_with_niche}; 9 | 10 | new_id_with_niche!(TaskId, u64); 11 | pub type TaskRef<'env> = Idx>; 12 | 13 | #[derive(Debug)] 14 | pub struct Task<'env> { 15 | pub state: TaskState<'env>, 16 | pub dependents: Vec>, 17 | } 18 | 19 | impl<'env> Task<'env> { 20 | pub fn completed(&self) -> Option<&Artifact<'env>> { 21 | self.state.completed() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/components/job/src/task_state.rs: -------------------------------------------------------------------------------- 1 | /* 2 | =================== components/job/src/task_state.rs ==================== 3 | Defines the different states that a task can be in. 4 | --------------------------------------------------------------------------- 5 | */ 6 | 7 | use crate::{Artifact, Execution, SuspendCondition}; 8 | 9 | #[derive(Debug, Default)] 10 | pub enum TaskState<'env> { 11 | #[default] 12 | Running, 13 | Suspended(Execution<'env>, SuspendCondition<'env>), 14 | Completed(Artifact<'env>), 15 | } 16 | 17 | impl<'env> TaskState<'env> { 18 | pub fn completed(&self) -> Option<&Artifact<'env>> { 19 | match self { 20 | TaskState::Running => None, 21 | TaskState::Suspended(..) => None, 22 | TaskState::Completed(artifact) => Some(artifact), 23 | } 24 | } 25 | 26 | pub fn unwrap_suspended_execution(self) -> Execution<'env> { 27 | match self { 28 | TaskState::Suspended(execution, _condition) => execution, 29 | _ => panic!("unwrap_suspended_execution failed!"), 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/components/job/src/typed_cfg/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | ================== components/job/src/typed_cfg/mod.rs ================== 3 | Contains definitions for typing and resolving references for a CFG 4 | --------------------------------------------------------------------------- 5 | */ 6 | 7 | mod value; 8 | 9 | use crate::repr::{Type, TypeKind}; 10 | use source_files::Source; 11 | pub use value::*; 12 | 13 | #[derive(Clone, Debug)] 14 | pub struct Typed<'env> { 15 | ty: Type<'env>, 16 | } 17 | 18 | impl<'env> Typed<'env> { 19 | pub fn from_type(ty: Type<'env>) -> Self { 20 | Self { ty } 21 | } 22 | 23 | pub fn void(source: Source) -> Self { 24 | Self::from_type(Type { 25 | kind: TypeKind::Void, 26 | source, 27 | }) 28 | } 29 | 30 | pub fn ty(&self) -> &Type<'env> { 31 | &self.ty 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/components/job/src/typed_cfg/value.rs: -------------------------------------------------------------------------------- 1 | use super::Typed; 2 | use crate::repr::Type; 3 | use arena::Id; 4 | use ast::NodeRef; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct Value<'env> { 8 | pub node_ref: NodeRef, 9 | pub cast_to: Cast<'env>, 10 | } 11 | 12 | impl<'env> Value<'env> { 13 | pub fn new(node_ref: NodeRef) -> Self { 14 | Self { 15 | node_ref, 16 | cast_to: Cast::Identity, 17 | } 18 | } 19 | } 20 | 21 | impl<'env> Value<'env> { 22 | pub fn ty<'a>(&'a self, types: &'a [Typed<'env>]) -> &'a Type<'env> { 23 | match &self.cast_to { 24 | Cast::Identity => &types[self.node_ref.into_raw().into_usize()].ty, 25 | Cast::Reinterpret(inner) => inner, 26 | Cast::Builtin(inner) => inner, 27 | } 28 | } 29 | } 30 | 31 | #[derive(Clone, Debug)] 32 | pub enum Cast<'env> { 33 | Identity, 34 | Reinterpret(Type<'env>), 35 | Builtin(Type<'env>), 36 | } 37 | -------------------------------------------------------------------------------- /src/components/job/src/unwrap_from.rs: -------------------------------------------------------------------------------- 1 | pub trait UnwrapFrom { 2 | fn unwrap_from<'a>(from: &'a T) -> &'a Self; 3 | } 4 | -------------------------------------------------------------------------------- /src/components/job/src/waiting_count.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Default)] 2 | pub struct WaitingCount(pub usize); 3 | 4 | impl WaitingCount { 5 | pub fn increment(&mut self) { 6 | self.0 += 1; 7 | } 8 | 9 | pub fn decrement(&mut self) -> bool { 10 | self.0 -= 1; 11 | self.0 == 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/representations/asg/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "asg" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | arena = { version = "0.1.0", path = "../../support/arena" } 8 | ast = { version = "0.1.0", path = "../ast" } 9 | ast_workspace = { version = "0.1.0", path = "../ast_workspace" } 10 | attributes = { version = "0.1.0", path = "../attributes" } 11 | derive_more.workspace = true 12 | diagnostics = { version = "0.1.0", path = "../../support/diagnostics" } 13 | fs_tree = { version = "0.1.0", path = "../fs_tree" } 14 | indexmap.workspace = true 15 | interpreter_api = { version = "0.1.0", path = "../interpreter_api" } 16 | itertools.workspace = true 17 | num.workspace = true 18 | ordered-float.workspace = true 19 | primitives = { version = "0.1.0", path = "../primitives" } 20 | slotmap.workspace = true 21 | source_files = { version = "0.1.0", path = "../source_files" } 22 | target = { version = "0.1.0", path = "../../support/target" } 23 | -------------------------------------------------------------------------------- /src/representations/asg/src/block.rs: -------------------------------------------------------------------------------- 1 | use super::{Stmt, StmtKind, Type, TypeKind}; 2 | use source_files::Source; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub struct Block { 6 | pub stmts: Vec, 7 | } 8 | 9 | impl Block { 10 | pub fn new(stmts: Vec) -> Self { 11 | Self { stmts } 12 | } 13 | 14 | pub fn get_result_type(&self, source: Source) -> Type { 15 | match self.stmts.last().map(|stmt| &stmt.kind) { 16 | Some(StmtKind::Expr(expr)) => expr.ty.clone(), 17 | Some(StmtKind::Return(..) | StmtKind::Declaration(..) | StmtKind::Assignment(..)) 18 | | None => TypeKind::Void.at(source), 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/representations/asg/src/datatype/kind/anonymous_enum.rs: -------------------------------------------------------------------------------- 1 | use crate::Type; 2 | use ast::EnumMember; 3 | use core::hash::Hash; 4 | use indexmap::IndexMap; 5 | use source_files::Source; 6 | 7 | #[derive(Clone, Debug)] 8 | pub struct AnonymousEnum { 9 | pub backing_type: Type, 10 | pub members: IndexMap, 11 | pub allow_implicit_integer_conversions: bool, 12 | pub source: Source, 13 | } 14 | 15 | impl PartialEq for AnonymousEnum { 16 | fn eq(&self, other: &Self) -> bool { 17 | self.backing_type.eq(&other.backing_type) && self.members.eq(&other.members) 18 | } 19 | } 20 | 21 | impl Hash for AnonymousEnum { 22 | fn hash(&self, state: &mut H) { 23 | self.backing_type.hash(state); 24 | 25 | for (key, value) in self.members.iter() { 26 | key.hash(state); 27 | value.hash(state); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/representations/asg/src/datatype/kind/fixed_array.rs: -------------------------------------------------------------------------------- 1 | use crate::Type; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct FixedArray { 5 | pub size: u64, 6 | pub inner: Type, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/datatype/kind/func_ptr.rs: -------------------------------------------------------------------------------- 1 | use crate::{Params, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct FuncPtr { 5 | pub params: Params, 6 | pub return_type: Box, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/destination/kind.rs: -------------------------------------------------------------------------------- 1 | use super::Destination; 2 | use crate::{ArrayAccess, Expr, GlobalVariable, StructRef, Type, Variable}; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub enum DestinationKind { 6 | Variable(Variable), 7 | GlobalVariable(GlobalVariable), 8 | Member { 9 | subject: Box, 10 | struct_ref: StructRef, 11 | index: usize, 12 | field_type: Type, 13 | }, 14 | ArrayAccess(Box), 15 | Dereference(Expr), 16 | } 17 | -------------------------------------------------------------------------------- /src/representations/asg/src/destination/mod.rs: -------------------------------------------------------------------------------- 1 | mod kind; 2 | 3 | use super::Type; 4 | use core::hash::Hash; 5 | pub use kind::*; 6 | use source_files::Source; 7 | 8 | #[derive(Clone, Debug)] 9 | pub struct Destination { 10 | pub kind: DestinationKind, 11 | pub ty: Type, 12 | pub source: Source, 13 | } 14 | 15 | impl Hash for Destination { 16 | fn hash(&self, state: &mut H) { 17 | self.kind.hash(state); 18 | self.ty.hash(state); 19 | } 20 | } 21 | 22 | impl PartialEq for Destination { 23 | fn eq(&self, other: &Self) -> bool { 24 | self.kind.eq(&other.kind) && self.ty.eq(&other.ty) 25 | } 26 | } 27 | 28 | impl Eq for Destination {} 29 | 30 | impl Destination { 31 | pub fn new(kind: DestinationKind, ty: Type, source: Source) -> Self { 32 | Self { kind, source, ty } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/representations/asg/src/enumeration.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use crate::name::ResolvedName; 3 | use ast::EnumMember; 4 | use indexmap::IndexMap; 5 | use source_files::Source; 6 | 7 | #[derive(Clone, Debug)] 8 | pub struct Enum { 9 | pub name: ResolvedName, 10 | pub ty: Type, 11 | pub source: Source, 12 | pub members: IndexMap, 13 | } 14 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/array_access.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | use crate::{Destination, Type}; 3 | use derive_more::From; 4 | 5 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 6 | pub struct ArrayAccess { 7 | pub subject: ArrayDestination, 8 | pub item_type: Type, 9 | pub index: Expr, 10 | } 11 | 12 | #[derive(Clone, Debug, Hash, PartialEq, Eq, From)] 13 | pub enum ArrayDestination { 14 | Expr(Expr), 15 | Destination(Destination), 16 | } 17 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/binary/basic.rs: -------------------------------------------------------------------------------- 1 | use crate::{Type, TypedExpr}; 2 | use primitives::{FloatOrInteger, FloatOrSignLax, NumericMode, SignOrIndeterminate}; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub struct BasicBinaryOperation { 6 | pub operator: BasicBinaryOperator, 7 | pub left: TypedExpr, 8 | pub right: TypedExpr, 9 | } 10 | 11 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 12 | pub enum BasicBinaryOperator { 13 | PrimitiveAdd(Type), 14 | Add(NumericMode), 15 | Subtract(NumericMode), 16 | Multiply(NumericMode), 17 | Divide(FloatOrSignLax), 18 | Modulus(FloatOrSignLax), 19 | Equals(FloatOrInteger), 20 | NotEquals(FloatOrInteger), 21 | LessThan(FloatOrSignLax), 22 | LessThanEq(FloatOrSignLax), 23 | GreaterThan(FloatOrSignLax), 24 | GreaterThanEq(FloatOrSignLax), 25 | BitwiseAnd, 26 | BitwiseOr, 27 | BitwiseXor, 28 | LeftShift, 29 | ArithmeticRightShift(SignOrIndeterminate), 30 | LogicalLeftShift, 31 | LogicalRightShift, 32 | } 33 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/binary/mod.rs: -------------------------------------------------------------------------------- 1 | mod basic; 2 | mod short_circuit; 3 | 4 | pub use basic::*; 5 | pub use short_circuit::*; 6 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/binary/short_circuit.rs: -------------------------------------------------------------------------------- 1 | use crate::TypedExpr; 2 | pub use ast::ShortCircuitingBinaryOperator; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub struct ShortCircuitingBinaryOperation { 6 | pub operator: ShortCircuitingBinaryOperator, 7 | pub left: TypedExpr, 8 | pub right: TypedExpr, 9 | } 10 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/call.rs: -------------------------------------------------------------------------------- 1 | use super::TypedExpr; 2 | use crate::{FuncRef, PolyRecipe}; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub struct Call { 6 | pub callee: Callee, 7 | pub args: Vec, 8 | } 9 | 10 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 11 | pub struct Callee { 12 | pub func_ref: FuncRef, 13 | pub recipe: PolyRecipe, 14 | } 15 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/cast.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct Cast { 5 | pub target_type: Type, 6 | pub value: Expr, 7 | } 8 | 9 | impl Cast { 10 | pub fn new(target_type: Type, value: Expr) -> Self { 11 | Self { target_type, value } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/cast_from.rs: -------------------------------------------------------------------------------- 1 | use crate::{Cast, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct CastFrom { 5 | pub cast: Cast, 6 | pub from_type: Type, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/conditional.rs: -------------------------------------------------------------------------------- 1 | use crate::{Block, Type, TypedExpr}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct Conditional { 5 | pub result_type: Option, 6 | pub branches: Vec, 7 | pub otherwise: Option, 8 | } 9 | 10 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 11 | pub struct Branch { 12 | pub condition: TypedExpr, 13 | pub block: Block, 14 | } 15 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/decl_assign.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type, VariableStorageKey}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct DeclareAssign { 5 | pub key: VariableStorageKey, 6 | pub value: Expr, 7 | pub ty: Type, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/enum_member.rs: -------------------------------------------------------------------------------- 1 | use crate::{EnumRef, HumanName, Type}; 2 | use core::hash::Hash; 3 | use num::BigInt; 4 | use source_files::Source; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct EnumMemberLiteral { 8 | pub human_name: HumanName, 9 | pub enum_target: EnumTarget, 10 | pub variant_name: String, 11 | pub source: Source, 12 | } 13 | 14 | impl Hash for EnumMemberLiteral { 15 | fn hash(&self, state: &mut H) { 16 | self.human_name.hash(state); 17 | self.enum_target.hash(state); 18 | self.variant_name.hash(state); 19 | } 20 | } 21 | 22 | impl PartialEq for EnumMemberLiteral { 23 | fn eq(&self, other: &Self) -> bool { 24 | self.human_name.eq(&other.human_name) 25 | && self.enum_target.eq(&other.enum_target) 26 | && self.variant_name.eq(&other.variant_name) 27 | } 28 | } 29 | 30 | impl Eq for EnumMemberLiteral {} 31 | 32 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 33 | pub enum EnumTarget { 34 | Named(EnumRef), 35 | Anonymous(BigInt, Type), 36 | } 37 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/global_variable.rs: -------------------------------------------------------------------------------- 1 | use crate::{GlobalRef, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct GlobalVariable { 5 | pub reference: GlobalRef, 6 | pub ty: Type, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/member.rs: -------------------------------------------------------------------------------- 1 | use crate::{Destination, StructRef, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct Member { 5 | pub subject: Destination, 6 | pub struct_ref: StructRef, 7 | pub index: usize, 8 | pub field_type: Type, 9 | } 10 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/poly_call.rs: -------------------------------------------------------------------------------- 1 | use super::TypedExpr; 2 | use crate::PolyRecipe; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub struct PolyCall { 6 | pub callee: PolyCallee, 7 | pub args: Vec, 8 | } 9 | 10 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 11 | pub struct PolyCallee { 12 | pub polymorph: String, 13 | pub member: String, 14 | pub recipe: PolyRecipe, 15 | } 16 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/struct_literal.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct StructLiteral { 5 | pub struct_type: Type, 6 | pub fields: Vec<(String, Expr, usize)>, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/typed.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct TypedExpr { 5 | pub ty: Type, 6 | pub expr: Expr, 7 | } 8 | 9 | impl TypedExpr { 10 | pub fn new(ty: Type, expr: Expr) -> Self { 11 | Self { ty, expr } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/unary/mod.rs: -------------------------------------------------------------------------------- 1 | use super::TypedExpr; 2 | pub use ast::UnaryMathOperator; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 5 | pub struct UnaryMathOperation { 6 | pub operator: UnaryMathOperator, 7 | pub inner: TypedExpr, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/variable.rs: -------------------------------------------------------------------------------- 1 | use crate::{Type, VariableStorageKey}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct Variable { 5 | pub key: VariableStorageKey, 6 | pub ty: Type, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/expr/while_loop.rs: -------------------------------------------------------------------------------- 1 | use crate::{Block, Expr}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct While { 5 | pub condition: Expr, 6 | pub block: Block, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/global.rs: -------------------------------------------------------------------------------- 1 | use super::{GlobalRef, Type}; 2 | use crate::name::ResolvedName; 3 | use attributes::{Privacy, SymbolOwnership}; 4 | use source_files::Source; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct Global { 8 | pub name: ResolvedName, 9 | pub ty: Type, 10 | pub source: Source, 11 | pub is_thread_local: bool, 12 | pub ownership: SymbolOwnership, 13 | } 14 | 15 | #[derive(Clone, Debug)] 16 | pub struct GlobalDecl { 17 | pub global_ref: GlobalRef, 18 | pub privacy: Privacy, 19 | } 20 | -------------------------------------------------------------------------------- /src/representations/asg/src/helper_expr.rs: -------------------------------------------------------------------------------- 1 | use attributes::Privacy; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct HelperExprDecl { 5 | pub value: ast::Expr, 6 | pub privacy: Privacy, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/human_name.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Display; 2 | 3 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 4 | pub struct HumanName(pub String); 5 | 6 | impl Display for HumanName { 7 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 8 | write!(f, "{}", self.0) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/representations/asg/src/impl_params.rs: -------------------------------------------------------------------------------- 1 | use super::GenericTraitRef; 2 | use indexmap::IndexMap; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct ImplParams { 6 | params: IndexMap, 7 | } 8 | 9 | impl ImplParams { 10 | pub fn new(params: IndexMap) -> Self { 11 | Self { params } 12 | } 13 | pub fn iter(&self) -> impl Iterator { 14 | self.params.iter() 15 | } 16 | 17 | pub fn get(&self, key: &str) -> Option<&GenericTraitRef> { 18 | self.params.get(key) 19 | } 20 | 21 | pub fn is_empty(&self) -> bool { 22 | self.params.is_empty() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/representations/asg/src/implementation.rs: -------------------------------------------------------------------------------- 1 | use super::{FuncRef, GenericTraitRef, ImplRef, TypeParams}; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | use std::collections::HashMap; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct Impl { 8 | pub params: TypeParams, 9 | pub target: GenericTraitRef, 10 | pub source: Source, 11 | pub body: HashMap, 12 | } 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct ImplDecl { 16 | pub impl_ref: ImplRef, 17 | pub source: Source, 18 | pub privacy: Privacy, 19 | } 20 | -------------------------------------------------------------------------------- /src/representations/asg/src/poly_value.rs: -------------------------------------------------------------------------------- 1 | use crate::{ImplRef, Type, TypedExpr}; 2 | use derive_more::IsVariant; 3 | 4 | #[derive(Clone, Debug, Hash, PartialEq, Eq, IsVariant)] 5 | pub enum PolyValue { 6 | Type(Type), 7 | Expr(TypedExpr), 8 | Impl(ImplRef), 9 | PolyImpl(String), 10 | } 11 | -------------------------------------------------------------------------------- /src/representations/asg/src/stmt/assignment.rs: -------------------------------------------------------------------------------- 1 | use crate::{BasicBinaryOperator, Destination, Expr}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct Assignment { 5 | pub destination: Destination, 6 | pub value: Expr, 7 | pub operator: Option, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/asg/src/stmt/declaration.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, VariableStorageKey}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub struct Declaration { 5 | pub key: VariableStorageKey, 6 | pub value: Option, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/asg/src/stmt/mod.rs: -------------------------------------------------------------------------------- 1 | mod assignment; 2 | mod declaration; 3 | 4 | use super::{Expr, TypedExpr}; 5 | pub use assignment::*; 6 | use core::hash::Hash; 7 | pub use declaration::*; 8 | use derive_more::Unwrap; 9 | use source_files::Source; 10 | 11 | #[derive(Clone, Debug)] 12 | pub struct Stmt { 13 | pub kind: StmtKind, 14 | pub source: Source, 15 | } 16 | 17 | impl Hash for Stmt { 18 | fn hash(&self, state: &mut H) { 19 | self.kind.hash(state) 20 | } 21 | } 22 | 23 | impl PartialEq for Stmt { 24 | fn eq(&self, other: &Self) -> bool { 25 | self.kind.eq(&other.kind) 26 | } 27 | } 28 | 29 | impl Eq for Stmt {} 30 | 31 | impl Stmt { 32 | pub fn new(kind: StmtKind, source: Source) -> Self { 33 | Self { kind, source } 34 | } 35 | } 36 | 37 | #[derive(Clone, Debug, Hash, PartialEq, Eq, Unwrap)] 38 | pub enum StmtKind { 39 | Return(Option), 40 | Expr(TypedExpr), 41 | Declaration(Declaration), 42 | Assignment(Assignment), 43 | } 44 | -------------------------------------------------------------------------------- /src/representations/asg/src/structure.rs: -------------------------------------------------------------------------------- 1 | use super::{Type, TypeParams}; 2 | use crate::name::ResolvedName; 3 | use attributes::Privacy; 4 | use indexmap::IndexMap; 5 | use source_files::Source; 6 | 7 | #[derive(Clone, Debug)] 8 | pub struct Struct { 9 | pub name: ResolvedName, 10 | pub fields: IndexMap, 11 | pub is_packed: bool, 12 | pub params: TypeParams, 13 | pub source: Source, 14 | } 15 | 16 | #[derive(Clone, Debug)] 17 | pub struct Field { 18 | pub ty: Type, 19 | pub privacy: Privacy, 20 | pub source: Source, 21 | } 22 | -------------------------------------------------------------------------------- /src/representations/asg/src/trait_constraint.rs: -------------------------------------------------------------------------------- 1 | use super::{HumanName, Params, Type, TypeParams}; 2 | use indexmap::IndexMap; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct Trait { 7 | pub human_name: HumanName, 8 | pub source: Source, 9 | pub params: TypeParams, 10 | pub funcs: IndexMap, 11 | } 12 | 13 | #[derive(Clone, Debug)] 14 | pub struct TraitFunc { 15 | pub params: Params, 16 | pub return_type: Type, 17 | pub source: Source, 18 | } 19 | -------------------------------------------------------------------------------- /src/representations/asg/src/type_alias.rs: -------------------------------------------------------------------------------- 1 | use super::{HumanName, Type, TypeParams}; 2 | use source_files::Source; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct TypeAlias { 6 | pub human_name: HumanName, 7 | pub source: Source, 8 | pub params: TypeParams, 9 | pub becomes: Type, 10 | } 11 | -------------------------------------------------------------------------------- /src/representations/asg/src/type_decl.rs: -------------------------------------------------------------------------------- 1 | use super::{Asg, TypeKind}; 2 | use attributes::Privacy; 3 | use fs_tree::FsNodeId; 4 | use source_files::Source; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct TypeDecl { 8 | pub kind: TypeKind, 9 | pub source: Source, 10 | pub privacy: Privacy, 11 | pub file_fs_node_id: FsNodeId, 12 | } 13 | 14 | impl TypeDecl { 15 | pub fn num_parameters(&self, asg: &Asg) -> usize { 16 | self.kind.num_target_parameters(asg) 17 | } 18 | } 19 | 20 | pub type TypeParams = ast::TypeParams; 21 | -------------------------------------------------------------------------------- /src/representations/ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ast" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | arena = { version = "0.1.0", path = "../../support/arena" } 9 | ast_workspace_settings = { version = "0.1.0", path = "../ast_workspace_settings" } 10 | attributes = { version = "0.1.0", path = "../attributes" } 11 | derive_more.workspace = true 12 | fs_tree = { version = "0.1.0", path = "../fs_tree" } 13 | indexmap.workspace = true 14 | interpreter_api = { version = "0.1.0", path = "../interpreter_api" } 15 | num.workspace = true 16 | num-bigint.workspace = true 17 | primitives = { version = "0.1.0", path = "../primitives" } 18 | smallvec = "1.15.0" 19 | source_files = { version = "0.1.0", path = "../source_files" } 20 | std_ext = { version = "0.1.0", path = "../../support/std_ext" } 21 | token = { version = "0.1.0", path = "../token" } 22 | -------------------------------------------------------------------------------- /src/representations/ast/src/block.rs: -------------------------------------------------------------------------------- 1 | use super::Stmt; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct Block { 5 | pub stmts: Vec, 6 | } 7 | 8 | impl Block { 9 | pub fn new(stmts: Vec) -> Self { 10 | Self { stmts } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/representations/ast/src/conforming.rs: -------------------------------------------------------------------------------- 1 | use primitives::CIntegerAssumptions; 2 | 3 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 4 | pub enum Language { 5 | Adept, 6 | C, 7 | } 8 | 9 | #[derive(Copy, Clone, Debug)] 10 | pub enum ConformBehavior { 11 | Adept(CIntegerAssumptions), 12 | C, 13 | } 14 | 15 | impl ConformBehavior { 16 | pub fn c_integer_assumptions(&self) -> CIntegerAssumptions { 17 | match self { 18 | Self::Adept(assumptions) => *assumptions, 19 | Self::C => Default::default(), 20 | } 21 | } 22 | 23 | pub fn auto_c_integer_to_bool_conversion(&self) -> bool { 24 | match self { 25 | Self::Adept(_) => false, 26 | Self::C => true, 27 | } 28 | } 29 | 30 | pub fn language(&self) -> Language { 31 | match self { 32 | ConformBehavior::Adept(_) => Language::Adept, 33 | ConformBehavior::C => Language::C, 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/representations/ast/src/datatype/fixed_array.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct FixedArray { 5 | pub ast_type: Type, 6 | pub count: Expr, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/ast/src/datatype/func_ptr.rs: -------------------------------------------------------------------------------- 1 | use crate::{Param, Type}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct FuncPtr { 5 | pub parameters: Vec, 6 | pub return_type: Box, 7 | pub is_cstyle_variadic: bool, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/datatype/generics.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub enum TypeArg { 5 | Type(Type), 6 | Expr(Expr), 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/ast/src/datatype/nameless_enumeration.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use crate::EnumMember; 3 | use indexmap::IndexMap; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct AnonymousEnum { 7 | pub members: IndexMap, 8 | pub backing_type: Option>, 9 | pub allow_implicit_integer_conversions: bool, 10 | } 11 | -------------------------------------------------------------------------------- /src/representations/ast/src/datatype/nameless_structure.rs: -------------------------------------------------------------------------------- 1 | use crate::Field; 2 | use indexmap::IndexMap; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct AnonymousStruct { 6 | pub fields: IndexMap, 7 | pub is_packed: bool, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/datatype/nameless_union.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug)] 2 | pub struct AnonymousUnion {} 3 | -------------------------------------------------------------------------------- /src/representations/ast/src/enumeration.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use attributes::Privacy; 3 | use indexmap::IndexMap; 4 | use num::BigInt; 5 | use source_files::Source; 6 | 7 | #[derive(Clone, Debug)] 8 | pub struct Enum { 9 | pub name: String, 10 | pub backing_type: Option, 11 | pub source: Source, 12 | pub members: IndexMap, 13 | pub privacy: Privacy, 14 | } 15 | 16 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] 17 | pub struct EnumMember { 18 | pub value: BigInt, 19 | pub explicit_value: bool, 20 | } 21 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/array_access.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct ArrayAccess { 5 | pub subject: Expr, 6 | pub index: Expr, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/binary/mod.rs: -------------------------------------------------------------------------------- 1 | mod regular; 2 | mod short_circuiting; 3 | 4 | pub use regular::*; 5 | pub use short_circuiting::*; 6 | 7 | #[derive(Clone, Debug)] 8 | pub enum BinaryOperator { 9 | Basic(BasicBinaryOperator), 10 | ShortCircuiting(ShortCircuitingBinaryOperator), 11 | } 12 | 13 | impl From for BinaryOperator { 14 | fn from(value: BasicBinaryOperator) -> Self { 15 | Self::Basic(value) 16 | } 17 | } 18 | 19 | impl From for BinaryOperator { 20 | fn from(value: ShortCircuitingBinaryOperator) -> Self { 21 | Self::ShortCircuiting(value) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/binary/short_circuiting.rs: -------------------------------------------------------------------------------- 1 | use crate::{ConformBehavior, Expr}; 2 | use std::fmt::Display; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct ShortCircuitingBinaryOperation { 6 | pub operator: ShortCircuitingBinaryOperator, 7 | pub left: Expr, 8 | pub right: Expr, 9 | pub conform_behavior: ConformBehavior, 10 | } 11 | 12 | #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] 13 | pub enum ShortCircuitingBinaryOperator { 14 | And, 15 | Or, 16 | } 17 | 18 | impl Display for ShortCircuitingBinaryOperator { 19 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 20 | f.write_str(match self { 21 | Self::And => "&&", 22 | Self::Or => "||", 23 | }) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/call.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | use crate::{Name, Type, TypeArg}; 3 | use source_files::Sourced; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct Call { 7 | pub name: Name, 8 | pub args: Vec, 9 | pub expected_to_return: Option, 10 | pub generics: Vec, 11 | pub using: Vec, 12 | } 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct Using { 16 | pub name: Option>, 17 | pub ty: Type, 18 | } 19 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/conditional.rs: -------------------------------------------------------------------------------- 1 | use crate::{Block, ConformBehavior, Expr}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct Conditional { 5 | pub conditions: Box<[(Expr, Block)]>, 6 | pub otherwise: Option, 7 | pub conform_behavior: ConformBehavior, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/constant.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct ConstExpr { 5 | pub value: Expr, 6 | } 7 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/declare_assign.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct DeclareAssign { 5 | pub name: String, 6 | pub value: Expr, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/integer.rs: -------------------------------------------------------------------------------- 1 | use num::BigInt; 2 | use primitives::IntegerRigidity; 3 | 4 | #[derive(Clone, Debug)] 5 | pub enum Integer { 6 | Known(Box), 7 | Generic(BigInt), 8 | } 9 | 10 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 11 | pub struct IntegerKnown { 12 | pub rigidity: IntegerRigidity, 13 | pub value: BigInt, 14 | } 15 | 16 | impl Integer { 17 | pub fn value(&self) -> &BigInt { 18 | match self { 19 | Integer::Known(known) => &known.value, 20 | Integer::Generic(value) => value, 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/interpreter_syscall.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct InterpreterSyscall { 5 | pub kind: interpreter_api::Syscall, 6 | pub args: Vec<(Type, Expr)>, 7 | pub result_type: Type, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/static_member.rs: -------------------------------------------------------------------------------- 1 | use crate::{Call, Type}; 2 | use source_files::Source; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct StaticMemberValue { 6 | pub subject: Type, 7 | pub value: String, 8 | pub value_source: Source, 9 | pub source: Source, 10 | } 11 | 12 | #[derive(Clone, Debug)] 13 | pub struct StaticMemberCall { 14 | pub subject: Type, 15 | pub call: Call, 16 | pub call_source: Source, 17 | pub source: Source, 18 | } 19 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/struct_literal.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Language, Type}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct StructLiteral { 5 | pub ast_type: Type, 6 | pub fields: Vec, 7 | pub fill_behavior: FillBehavior, 8 | pub language: Language, 9 | } 10 | 11 | #[derive(Clone, Debug)] 12 | pub struct FieldInitializer { 13 | pub name: Option, 14 | pub value: Expr, 15 | } 16 | 17 | #[derive(Copy, Clone, Debug)] 18 | pub enum FillBehavior { 19 | Forbid, 20 | Zeroed, 21 | } 22 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/unary/math.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | use derive_more::IsVariant; 3 | use std::fmt::Display; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct UnaryMathOperation { 7 | pub operator: UnaryMathOperator, 8 | pub inner: Expr, 9 | } 10 | 11 | #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, IsVariant)] 12 | pub enum UnaryMathOperator { 13 | Not, 14 | BitComplement, 15 | Negate, 16 | IsNonZero, 17 | } 18 | 19 | impl Display for UnaryMathOperator { 20 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 21 | f.write_str(match self { 22 | Self::Not => "!", 23 | Self::BitComplement => "~", 24 | Self::Negate => "-", 25 | Self::IsNonZero => "bool()", 26 | }) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/unary/mod.rs: -------------------------------------------------------------------------------- 1 | mod math; 2 | 3 | use crate::Expr; 4 | pub use math::*; 5 | 6 | #[derive(Clone, Debug)] 7 | pub enum UnaryOperator { 8 | Math(UnaryMathOperator), 9 | AddressOf, 10 | Dereference, 11 | } 12 | 13 | #[derive(Clone, Debug)] 14 | pub struct UnaryOperation { 15 | pub operator: UnaryOperator, 16 | pub inner: Expr, 17 | } 18 | 19 | impl UnaryOperation { 20 | pub fn new(operator: UnaryOperator, inner: Expr) -> Self { 21 | Self { operator, inner } 22 | } 23 | 24 | pub fn new_math(operator: UnaryMathOperator, inner: Expr) -> Self { 25 | Self { 26 | operator: UnaryOperator::Math(operator), 27 | inner, 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr/while_loop.rs: -------------------------------------------------------------------------------- 1 | use crate::{Block, Expr}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct While { 5 | pub condition: Expr, 6 | pub block: Block, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/ast/src/expr_alias.rs: -------------------------------------------------------------------------------- 1 | use super::Expr; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | 5 | #[derive(Debug, Clone)] 6 | pub struct ExprAlias { 7 | pub name: String, 8 | pub value: Expr, 9 | pub source: Source, 10 | pub is_file_local_only: bool, 11 | pub privacy: Privacy, 12 | } 13 | -------------------------------------------------------------------------------- /src/representations/ast/src/file.rs: -------------------------------------------------------------------------------- 1 | use crate::NamespaceItems; 2 | 3 | pub type RawAstFile = NamespaceItems; 4 | -------------------------------------------------------------------------------- /src/representations/ast/src/func/params.rs: -------------------------------------------------------------------------------- 1 | use crate::Type; 2 | 3 | #[derive(Clone, Debug, Default)] 4 | pub struct Params { 5 | pub required: Vec, 6 | pub is_cstyle_vararg: bool, 7 | } 8 | 9 | impl Params { 10 | pub fn normal(parameters: impl IntoIterator) -> Self { 11 | Self { 12 | required: parameters.into_iter().collect(), 13 | is_cstyle_vararg: false, 14 | } 15 | } 16 | } 17 | 18 | #[derive(Clone, Debug)] 19 | pub struct Param { 20 | pub name: Option, 21 | pub ast_type: Type, 22 | } 23 | 24 | impl Param { 25 | pub fn new(name: Option, ast_type: Type) -> Self { 26 | Self { name, ast_type } 27 | } 28 | 29 | pub fn named(name: String, ast_type: Type) -> Self { 30 | Self { 31 | name: Some(name), 32 | ast_type, 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/representations/ast/src/given.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use source_files::Sourced; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct Given { 6 | pub name: Option>, 7 | pub ty: Type, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/global_variable.rs: -------------------------------------------------------------------------------- 1 | use crate::Type; 2 | use attributes::{Privacy, SymbolOwnership}; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct Global { 7 | pub name: String, 8 | pub ast_type: Type, 9 | pub source: Source, 10 | pub is_thread_local: bool, 11 | pub privacy: Privacy, 12 | pub ownership: SymbolOwnership, 13 | } 14 | -------------------------------------------------------------------------------- /src/representations/ast/src/implementation.rs: -------------------------------------------------------------------------------- 1 | use super::{Func, Type, TypeParams}; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct Impl { 7 | pub name: Option, 8 | pub params: TypeParams, 9 | pub target: Type, 10 | pub source: Source, 11 | pub privacy: Privacy, 12 | pub body: Vec, 13 | } 14 | -------------------------------------------------------------------------------- /src/representations/ast/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod block; 2 | mod cfg; 3 | mod conforming; 4 | mod datatype; 5 | mod enumeration; 6 | mod expr; 7 | mod expr_alias; 8 | mod file; 9 | mod func; 10 | mod given; 11 | mod global_variable; 12 | mod implementation; 13 | mod namespace; 14 | mod stmt; 15 | mod structs; 16 | mod traits; 17 | mod type_alias; 18 | mod type_params; 19 | 20 | pub use block::*; 21 | pub use cfg::*; 22 | pub use conforming::*; 23 | pub use datatype::*; 24 | pub use enumeration::*; 25 | pub use expr::*; 26 | pub use expr_alias::*; 27 | pub use file::*; 28 | pub use func::*; 29 | pub use given::*; 30 | pub use global_variable::*; 31 | pub use implementation::*; 32 | pub use namespace::*; 33 | #[allow(unused_imports)] 34 | pub use stmt::*; 35 | pub use structs::*; 36 | pub use token::Name; 37 | pub use traits::*; 38 | pub use type_alias::*; 39 | pub use type_params::*; 40 | -------------------------------------------------------------------------------- /src/representations/ast/src/namespace.rs: -------------------------------------------------------------------------------- 1 | use crate::{Enum, ExprAlias, Func, Global, Impl, Struct, Trait, TypeAlias}; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug, Default)] 6 | pub struct NamespaceItems { 7 | pub funcs: Vec, 8 | pub structs: Vec, 9 | pub enums: Vec, 10 | pub globals: Vec, 11 | pub type_aliases: Vec, 12 | pub expr_aliases: Vec, 13 | pub traits: Vec, 14 | pub impls: Vec, 15 | pub namespaces: Vec, 16 | } 17 | 18 | #[derive(Clone, Debug)] 19 | pub struct Namespace { 20 | pub name: String, 21 | pub items: NamespaceItems, 22 | pub source: Source, 23 | pub privacy: Privacy, 24 | } 25 | -------------------------------------------------------------------------------- /src/representations/ast/src/stmt/assignment.rs: -------------------------------------------------------------------------------- 1 | use crate::{BasicBinaryOperator, Expr}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct Assignment { 5 | pub destination: Expr, 6 | pub value: Expr, 7 | pub operator: Option, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/stmt/declaration.rs: -------------------------------------------------------------------------------- 1 | use crate::{Expr, Type}; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct Declaration { 5 | pub name: String, 6 | pub ast_type: Type, 7 | pub initial_value: Option, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/ast/src/stmt/kind.rs: -------------------------------------------------------------------------------- 1 | use super::{Assignment, Declaration, Stmt}; 2 | use crate::Expr; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub enum StmtKind { 7 | Return(Option), 8 | Expr(Expr), 9 | Declaration(Box), 10 | Assignment(Box), 11 | } 12 | 13 | impl StmtKind { 14 | pub fn at(self, source: Source) -> Stmt { 15 | Stmt { kind: self, source } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/representations/ast/src/stmt/mod.rs: -------------------------------------------------------------------------------- 1 | mod assignment; 2 | mod declaration; 3 | mod kind; 4 | 5 | pub use assignment::*; 6 | pub use declaration::*; 7 | pub use kind::*; 8 | use source_files::Source; 9 | 10 | #[derive(Clone, Debug)] 11 | pub struct Stmt { 12 | pub kind: StmtKind, 13 | pub source: Source, 14 | } 15 | 16 | impl Stmt { 17 | pub fn new(kind: StmtKind, source: Source) -> Self { 18 | Self { kind, source } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/representations/ast/src/structs.rs: -------------------------------------------------------------------------------- 1 | use super::{Type, TypeParams}; 2 | use attributes::Privacy; 3 | use indexmap::IndexMap; 4 | use source_files::Source; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct Struct { 8 | pub name: String, 9 | pub params: TypeParams, 10 | pub fields: IndexMap, 11 | pub is_packed: bool, 12 | pub source: Source, 13 | pub privacy: Privacy, 14 | } 15 | 16 | #[derive(Clone, Debug)] 17 | pub struct Field { 18 | pub ast_type: Type, 19 | pub privacy: Privacy, 20 | pub source: Source, 21 | } 22 | -------------------------------------------------------------------------------- /src/representations/ast/src/traits.rs: -------------------------------------------------------------------------------- 1 | use super::{Params, Type, TypeParams}; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct Trait { 7 | pub name: String, 8 | pub params: TypeParams, 9 | pub source: Source, 10 | pub privacy: Privacy, 11 | pub funcs: Vec, 12 | } 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct TraitFunc { 16 | pub name: String, 17 | pub params: Params, 18 | pub return_type: Type, 19 | pub source: Source, 20 | } 21 | -------------------------------------------------------------------------------- /src/representations/ast/src/type_alias.rs: -------------------------------------------------------------------------------- 1 | use super::{Type, TypeParams}; 2 | use attributes::Privacy; 3 | use source_files::Source; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct TypeAlias { 7 | pub name: String, 8 | pub params: TypeParams, 9 | pub value: Type, 10 | pub source: Source, 11 | pub privacy: Privacy, 12 | } 13 | -------------------------------------------------------------------------------- /src/representations/ast_workspace/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ast_workspace" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | arena = { version = "0.1.0", path = "../../support/arena" } 8 | ast = { version = "0.1.0", path = "../ast" } 9 | ast_workspace_settings = { version = "0.1.0", path = "../ast_workspace_settings" } 10 | attributes = { version = "0.1.0", path = "../attributes" } 11 | compiler_version = { version = "0.1.0", path = "../../support/compiler_version" } 12 | fs_tree = { version = "0.1.0", path = "../fs_tree" } 13 | indexmap.workspace = true 14 | source_files = { version = "0.1.0", path = "../source_files" } 15 | -------------------------------------------------------------------------------- /src/representations/ast_workspace/src/ast_file.rs: -------------------------------------------------------------------------------- 1 | use crate::NameScopeRef; 2 | use ast::{Enum, ExprAlias, Func, Global, Impl, Struct, Trait, TypeAlias}; 3 | use ast_workspace_settings::{Settings, SettingsRef}; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct AstFile { 7 | pub settings: Option, 8 | pub names: NameScopeRef, 9 | } 10 | 11 | #[derive(Debug)] 12 | pub struct AstFileView<'workspace> { 13 | pub settings: Option<&'workspace Settings>, 14 | pub funcs: Vec<&'workspace Func>, 15 | pub structs: Vec<&'workspace Struct>, 16 | pub enums: Vec<&'workspace Enum>, 17 | pub globals: Vec<&'workspace Global>, 18 | pub type_aliases: Vec<&'workspace TypeAlias>, 19 | pub expr_aliases: Vec<&'workspace ExprAlias>, 20 | pub traits: Vec<&'workspace Trait>, 21 | pub impls: Vec<&'workspace Impl>, 22 | } 23 | -------------------------------------------------------------------------------- /src/representations/ast_workspace/src/configure_job.rs: -------------------------------------------------------------------------------- 1 | use arena::Idx; 2 | use ast_workspace_settings::{Settings, SettingsId}; 3 | use fs_tree::FsNodeId; 4 | 5 | pub struct ConfigureJob { 6 | pub fs_node_id: FsNodeId, 7 | pub settings: Idx, 8 | } 9 | 10 | impl ConfigureJob { 11 | pub fn new(fs_node_id: FsNodeId, settings: Idx) -> Self { 12 | Self { 13 | fs_node_id, 14 | settings, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/representations/ast_workspace/src/namespace.rs: -------------------------------------------------------------------------------- 1 | use crate::NameScopeRef; 2 | use attributes::Privacy; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct Namespace { 6 | pub name: String, 7 | pub names: NameScopeRef, 8 | pub privacy: Privacy, 9 | } 10 | -------------------------------------------------------------------------------- /src/representations/ast_workspace/src/type_decl_ref.rs: -------------------------------------------------------------------------------- 1 | use crate::{EnumRef, StructRef, TraitRef, TypeAliasRef}; 2 | 3 | /// An abstract reference to an AST type declaration 4 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 5 | pub enum TypeDeclRef { 6 | Struct(StructRef), 7 | Enum(EnumRef), 8 | Alias(TypeAliasRef), 9 | Trait(TraitRef), 10 | } 11 | -------------------------------------------------------------------------------- /src/representations/ast_workspace_settings/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ast_workspace_settings" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | arena = { version = "0.1.0", path = "../../support/arena" } 8 | compiler_version = { version = "0.1.0", path = "../../support/compiler_version" } 9 | fs_tree = { version = "0.1.0", path = "../fs_tree" } 10 | primitives = { version = "0.1.0", path = "../primitives" } 11 | -------------------------------------------------------------------------------- /src/representations/attributes/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "attributes" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | -------------------------------------------------------------------------------- /src/representations/attributes/src/exposure.rs: -------------------------------------------------------------------------------- 1 | use derive_more::IsVariant; 2 | 3 | #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, IsVariant)] 4 | pub enum Exposure { 5 | #[default] 6 | Hidden, 7 | Exposed, 8 | } 9 | 10 | #[derive(Copy, Clone, Debug, IsVariant)] 11 | pub enum SymbolOwnership { 12 | Reference, 13 | Owned(Exposure), 14 | } 15 | 16 | impl SymbolOwnership { 17 | pub fn from_foreign_and_exposed(is_foreign: bool, is_exposed: bool) -> Self { 18 | if is_exposed { 19 | Self::Owned(Exposure::Exposed) 20 | } else if is_foreign { 21 | Self::Reference 22 | } else { 23 | Self::Owned(Exposure::Hidden) 24 | } 25 | } 26 | 27 | pub fn should_mangle(&self) -> bool { 28 | !matches!(self, Self::Reference | Self::Owned(Exposure::Exposed)) 29 | } 30 | } 31 | 32 | impl Default for SymbolOwnership { 33 | fn default() -> Self { 34 | Self::Owned(Exposure::Hidden) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/representations/attributes/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod exposure; 2 | mod privacy; 3 | mod tag; 4 | 5 | pub use exposure::{Exposure, SymbolOwnership}; 6 | pub use privacy::Privacy; 7 | pub use tag::Tag; 8 | -------------------------------------------------------------------------------- /src/representations/attributes/src/privacy.rs: -------------------------------------------------------------------------------- 1 | use derive_more::IsVariant; 2 | 3 | #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, IsVariant)] 4 | pub enum Privacy { 5 | #[default] 6 | Public, 7 | Private, 8 | Protected, 9 | } 10 | -------------------------------------------------------------------------------- /src/representations/attributes/src/tag.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] 2 | pub enum Tag { 3 | InterpreterEntryPoint, 4 | Main, 5 | } 6 | -------------------------------------------------------------------------------- /src/representations/c_ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "c_ast" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | ast = { version = "0.1.0", path = "../ast" } 8 | c_token = { version = "0.1.0", path = "../c_token" } 9 | derive_more.workspace = true 10 | itertools.workspace = true 11 | source_files = { version = "0.1.0", path = "../source_files" } 12 | -------------------------------------------------------------------------------- /src/representations/c_token/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "c_token" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 9 | num-bigint.workspace = true 10 | pp_token = { version = "0.1.0", path = "../pp_token" } 11 | source_files = { version = "0.1.0", path = "../source_files" } 12 | -------------------------------------------------------------------------------- /src/representations/fs_tree/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fs_tree" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | arena = { version = "0.1.0", path = "../../support/arena" } 9 | once_map.workspace = true 10 | -------------------------------------------------------------------------------- /src/representations/fs_tree/src/fs_node_id.rs: -------------------------------------------------------------------------------- 1 | use crate::{Fs, FsNode}; 2 | use arena::{Id, NewId}; 3 | 4 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 5 | pub struct FsNodeId(pub(crate) usize); 6 | 7 | impl FsNodeId { 8 | pub fn parent(self, fs: &Fs) -> Option<&FsNode> { 9 | fs.get(self).parent.map(|parent| fs.get(parent)) 10 | } 11 | } 12 | 13 | impl Id for FsNodeId { 14 | const MAX: usize = usize::MAX; 15 | 16 | fn from_usize(idx: usize) -> Self { 17 | FsNodeId(idx) 18 | } 19 | 20 | fn into_usize(self) -> usize { 21 | self.0 22 | } 23 | 24 | fn successor(self) -> Self { 25 | Self(self.0 + 1) 26 | } 27 | } 28 | 29 | impl NewId for FsNodeId {} 30 | -------------------------------------------------------------------------------- /src/representations/interpreter_api/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "interpreter_api" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /src/representations/interpreter_api/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] 2 | pub enum Syscall { 3 | Println, 4 | BuildAddProject, 5 | BuildSetAdeptVersion, 6 | BuildLinkFilename, 7 | BuildLinkFrameworkName, 8 | Experimental, 9 | ImportNamespace, 10 | DontAssumeIntAtLeast32Bits, 11 | UseDependency, 12 | } 13 | -------------------------------------------------------------------------------- /src/representations/ir/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ir" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | arena = { version = "0.1.0", path = "../../support/arena" } 9 | attributes = { version = "0.1.0", path = "../attributes" } 10 | data_units = { version = "0.1.0", path = "../../support/data_units" } 11 | derivative.workspace = true 12 | derive_more.workspace = true 13 | interpreter_api = { version = "0.1.0", path = "../interpreter_api" } 14 | primitives = { version = "0.1.0", path = "../primitives" } 15 | source_files = { version = "0.1.0", path = "../source_files" } 16 | target = { version = "0.1.0", path = "../../support/target" } 17 | -------------------------------------------------------------------------------- /src/representations/ir/src/value.rs: -------------------------------------------------------------------------------- 1 | use super::Type; 2 | use derive_more::{From, IsVariant, Unwrap}; 3 | use std::ffi::CString; 4 | 5 | #[derive(Clone, Debug, From)] 6 | pub enum Value { 7 | Literal(Literal), 8 | Reference(ValueReference), 9 | } 10 | 11 | #[derive(Clone, Debug, Unwrap, IsVariant)] 12 | pub enum Literal { 13 | Void, 14 | Boolean(bool), 15 | Signed8(i8), 16 | Signed16(i16), 17 | Signed32(i32), 18 | Signed64(i64), 19 | Unsigned8(u8), 20 | Unsigned16(u16), 21 | Unsigned32(u32), 22 | Unsigned64(u64), 23 | Float32(f32), 24 | Float64(f64), 25 | NullTerminatedString(CString), 26 | Zeroed(Type), 27 | } 28 | 29 | #[derive(Clone, Debug)] 30 | pub struct ValueReference { 31 | pub basicblock_id: usize, 32 | pub instruction_id: usize, 33 | } 34 | -------------------------------------------------------------------------------- /src/representations/pp_ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pp_ast" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | num-traits.workspace = true 9 | pp_token = { version = "0.1.0", path = "../pp_token" } 10 | source_files = { version = "0.1.0", path = "../source_files" } 11 | -------------------------------------------------------------------------------- /src/representations/pp_token/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pp_token" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 9 | source_files = { version = "0.1.0", path = "../source_files" } 10 | -------------------------------------------------------------------------------- /src/representations/pp_token/src/encoding.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, Hash, PartialEq)] 2 | pub enum Encoding { 3 | Default, 4 | Utf8, // 'u8' 5 | Utf16, // 'u' 6 | Utf32, // 'U' 7 | Wide, // 'L' 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/primitives/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "primitives" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | data_units = { version = "0.1.0", path = "../../support/data_units" } 8 | derive_more.workspace = true 9 | num.workspace = true 10 | -------------------------------------------------------------------------------- /src/representations/primitives/src/float_or_integer.rs: -------------------------------------------------------------------------------- 1 | use super::{FloatOrSign, FloatOrSignLax}; 2 | 3 | #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] 4 | pub enum FloatOrInteger { 5 | Integer, 6 | Float, 7 | } 8 | 9 | impl From for FloatOrInteger { 10 | fn from(value: FloatOrSignLax) -> Self { 11 | match value { 12 | FloatOrSignLax::Integer(_) | FloatOrSignLax::IndeterminateInteger(_) => Self::Integer, 13 | FloatOrSignLax::Float => Self::Float, 14 | } 15 | } 16 | } 17 | 18 | impl From for FloatOrInteger { 19 | fn from(value: FloatOrSign) -> Self { 20 | match value { 21 | FloatOrSign::Integer(_) => Self::Integer, 22 | FloatOrSign::Float => Self::Float, 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/representations/primitives/src/float_or_sign.rs: -------------------------------------------------------------------------------- 1 | use super::IntegerSign; 2 | 3 | #[derive(Copy, Clone, Debug)] 4 | pub enum FloatOrSign { 5 | Integer(IntegerSign), 6 | Float, 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/primitives/src/float_or_sign_lax.rs: -------------------------------------------------------------------------------- 1 | use super::{CInteger, IntegerSign}; 2 | 3 | #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] 4 | pub enum FloatOrSignLax { 5 | Integer(IntegerSign), 6 | IndeterminateInteger(CInteger), 7 | Float, 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/primitives/src/float_size.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Hash)] 2 | pub enum FloatSize { 3 | Bits32, 4 | Bits64, 5 | } 6 | 7 | impl FloatSize { 8 | pub fn bits(self) -> u8 { 9 | match self { 10 | Self::Bits32 => 32, 11 | Self::Bits64 => 64, 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/representations/primitives/src/integer_rigidity.rs: -------------------------------------------------------------------------------- 1 | use crate::{CInteger, IntegerBits, IntegerSign}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub enum IntegerRigidity { 5 | Fixed(IntegerBits, IntegerSign), 6 | Loose(CInteger, Option), 7 | Size(IntegerSign), 8 | } 9 | -------------------------------------------------------------------------------- /src/representations/primitives/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod c_integer; 2 | mod float_or_integer; 3 | mod float_or_sign; 4 | mod float_or_sign_lax; 5 | mod float_size; 6 | mod integer_bits; 7 | mod integer_rigidity; 8 | mod integer_sign; 9 | mod numeric_mode; 10 | mod sign_or_indeterminate; 11 | 12 | pub use c_integer::{CInteger, CIntegerAssumptions, fmt_c_integer}; 13 | pub use float_or_integer::FloatOrInteger; 14 | pub use float_or_sign::FloatOrSign; 15 | pub use float_or_sign_lax::FloatOrSignLax; 16 | pub use float_size::FloatSize; 17 | pub use integer_bits::IntegerBits; 18 | pub use integer_rigidity::IntegerRigidity; 19 | pub use integer_sign::{IntegerSign, OptionIntegerSignExt}; 20 | pub use numeric_mode::NumericMode; 21 | pub use sign_or_indeterminate::SignOrIndeterminate; 22 | -------------------------------------------------------------------------------- /src/representations/primitives/src/numeric_mode.rs: -------------------------------------------------------------------------------- 1 | use super::{CInteger, IntegerBits, IntegerSign}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub enum NumericMode { 5 | Integer(IntegerSign), 6 | LooseIndeterminateSignInteger(CInteger), 7 | CheckOverflow(IntegerBits, IntegerSign), 8 | Float, 9 | } 10 | -------------------------------------------------------------------------------- /src/representations/primitives/src/sign_or_indeterminate.rs: -------------------------------------------------------------------------------- 1 | use super::{CInteger, IntegerSign}; 2 | 3 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] 4 | pub enum SignOrIndeterminate { 5 | Sign(IntegerSign), 6 | Indeterminate(CInteger), 7 | } 8 | -------------------------------------------------------------------------------- /src/representations/source_files/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "source_files" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | line_column = { version = "0.1.0", path = "../../support/line_column" } 9 | -------------------------------------------------------------------------------- /src/representations/source_files/src/file.rs: -------------------------------------------------------------------------------- 1 | use std::path::{Path, PathBuf}; 2 | 3 | #[derive(Debug)] 4 | pub struct SourceFile { 5 | filepath: PathBuf, 6 | content: String, 7 | } 8 | 9 | impl SourceFile { 10 | pub fn new(filename: PathBuf, content: String) -> Self { 11 | Self { 12 | filepath: filename, 13 | content, 14 | } 15 | } 16 | 17 | pub fn filename(&self) -> &str { 18 | self.filepath 19 | .to_str() 20 | .unwrap_or("") 21 | } 22 | 23 | pub fn filepath(&self) -> &Path { 24 | &self.filepath 25 | } 26 | 27 | pub fn content(&self) -> &str { 28 | &self.content 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/representations/source_files/src/key.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq, Hash)] 2 | pub struct SourceFileKey(pub u32); 3 | -------------------------------------------------------------------------------- /src/representations/token/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "token" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derivative.workspace = true 8 | derive_more.workspace = true 9 | infinite_iterator = { version = "0.1.0", path = "../../support/infinite_iterator" } 10 | num-bigint.workspace = true 11 | source_files = { version = "0.1.0", path = "../source_files" } 12 | -------------------------------------------------------------------------------- /src/support/append_only_vec/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "append_only_vec" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dev-dependencies] 7 | scaling = "0.1.3" 8 | parking_lot = "0.12" 9 | 10 | -------------------------------------------------------------------------------- /src/support/arena/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "arena" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | -------------------------------------------------------------------------------- /src/support/arena/src/id.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::Debug; 2 | 3 | /// A trait for index types used in arenas. 4 | /// 5 | /// An [`Id`] represents both the internal index in an arena and a type-level distinction 6 | /// (for example, when using multiple arenas with the same underlying numeric index type). 7 | pub trait Id: Copy + Ord + Debug { 8 | /// The maximum value (as a usize) this id type can represent. 9 | const MAX: usize; 10 | 11 | /// Converts a `usize` value to this id type. 12 | /// 13 | /// The input `idx` must be less or equal to `Self::MAX` 14 | fn from_usize(idx: usize) -> Self; 15 | 16 | /// Converts this id type into a `usize`. 17 | /// 18 | /// The returned value must be less or equal to `Self::MAX`. 19 | fn into_usize(self) -> usize; 20 | 21 | /// Gets the successor of this id 22 | fn successor(self) -> Self; 23 | } 24 | -------------------------------------------------------------------------------- /src/support/arena/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | /* 4 | ======================= support/arena/src/lib.rs ======================== 5 | An arena library based off of indexed_arena with some improvements 6 | --------------------------------------------------------------------------- 7 | */ 8 | 9 | mod arena; 10 | mod id; 11 | mod idx; 12 | mod idx_span; 13 | mod impl_id; 14 | mod iter; 15 | mod lock_free_arena; 16 | mod map; 17 | mod map_idx; 18 | mod map_idx_span; 19 | mod new_id; 20 | mod simple_type_name; 21 | mod values; 22 | 23 | extern crate alloc; 24 | 25 | pub use arena::Arena; 26 | pub use id::Id; 27 | pub use idx::Idx; 28 | pub use idx_span::IdxSpan; 29 | pub use lock_free_arena::LockFreeArena; 30 | pub use map::ArenaMap; 31 | pub use map_idx::MapIdx; 32 | pub use map_idx_span::MapIdxSpan; 33 | pub use new_id::NewId; 34 | -------------------------------------------------------------------------------- /src/support/arena/src/map_idx.rs: -------------------------------------------------------------------------------- 1 | use crate::{Idx, NewId}; 2 | 3 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 4 | pub struct MapIdx { 5 | pub(crate) raw: K, 6 | } 7 | 8 | impl From> for MapIdx { 9 | fn from(value: Idx) -> Self { 10 | Self { raw: value.raw } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/support/arena/src/map_idx_span.rs: -------------------------------------------------------------------------------- 1 | use crate::{IdxSpan, NewId}; 2 | 3 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 4 | pub struct MapIdxSpan { 5 | pub(crate) start: K, 6 | pub(crate) end: K, 7 | } 8 | 9 | impl From> for MapIdxSpan { 10 | fn from(value: IdxSpan) -> Self { 11 | Self { 12 | start: value.start, 13 | end: value.end, 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/support/arena/src/simple_type_name.rs: -------------------------------------------------------------------------------- 1 | pub(crate) fn simple_type_name() -> &'static str { 2 | let mut type_name = core::any::type_name::(); 3 | if let Some(idx) = type_name.rfind(':') { 4 | type_name = &type_name[idx + 1..] 5 | } 6 | type_name 7 | } 8 | -------------------------------------------------------------------------------- /src/support/backend/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "backend" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | diagnostics = { version = "0.1.0", path = "../diagnostics" } 8 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 9 | -------------------------------------------------------------------------------- /src/support/backend/src/lib.rs: -------------------------------------------------------------------------------- 1 | use diagnostics::Show; 2 | use source_files::SourceFiles; 3 | 4 | #[derive(Clone, Debug)] 5 | pub struct BackendError { 6 | pub message: String, 7 | } 8 | 9 | impl BackendError { 10 | pub fn plain(message: impl ToString) -> Self { 11 | Self { 12 | message: message.to_string(), 13 | } 14 | } 15 | } 16 | 17 | impl From for BackendError { 18 | fn from(message: String) -> Self { 19 | Self { message } 20 | } 21 | } 22 | 23 | impl From<&str> for BackendError { 24 | fn from(message: &str) -> Self { 25 | Self { 26 | message: message.into(), 27 | } 28 | } 29 | } 30 | 31 | impl Show for BackendError { 32 | fn show(&self, w: &mut dyn std::fmt::Write, _source_files: &SourceFiles) -> std::fmt::Result { 33 | write!(w, "error: {}", self.message) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/support/compiler/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compiler" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | compiler_version = { version = "0.1.0", path = "../compiler_version" } 8 | diagnostics = { version = "0.1.0", path = "../diagnostics" } 9 | num_cpus = "1.16.0" 10 | once_map.workspace = true 11 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 12 | target = { version = "0.1.0", path = "../target" } 13 | -------------------------------------------------------------------------------- /src/support/compiler/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod compiler; 2 | mod options; 3 | 4 | pub use compiler::Compiler; 5 | pub use options::BuildOptions; 6 | -------------------------------------------------------------------------------- /src/support/compiler_version/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compiler_version" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /src/support/data_units/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "data_units" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /src/support/diagnostics/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "diagnostics" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | append_only_vec = { version = "0.1.0", path = "../../support/append_only_vec" } 8 | source_files = { path = "../../representations/source_files" } 9 | -------------------------------------------------------------------------------- /src/support/diagnostics/src/show.rs: -------------------------------------------------------------------------------- 1 | use source_files::SourceFiles; 2 | 3 | pub trait Show { 4 | fn show(&self, w: &mut dyn std::fmt::Write, source_files: &SourceFiles) -> std::fmt::Result; 5 | 6 | fn eprintln(self: &Self, source_files: &SourceFiles) { 7 | let mut message = String::new(); 8 | self.show(&mut message, source_files).unwrap(); 9 | eprintln!("{}", message); 10 | } 11 | } 12 | 13 | pub fn into_show(show: T) -> Box { 14 | Box::new(show) 15 | } 16 | -------------------------------------------------------------------------------- /src/support/diagnostics/src/unerror.rs: -------------------------------------------------------------------------------- 1 | use crate::show::Show; 2 | use source_files::SourceFiles; 3 | 4 | pub fn unerror(result: Result, source_files: &SourceFiles) -> Result { 5 | match result { 6 | Ok(value) => Ok(value), 7 | Err(err) => { 8 | let mut message = String::new(); 9 | 10 | err.show(&mut message, source_files) 11 | .expect("show error message"); 12 | 13 | eprintln!("{message}"); 14 | Err(()) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "infinite_iterator" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/src/end.rs: -------------------------------------------------------------------------------- 1 | pub trait InfiniteIteratorEnd { 2 | fn is_end(&self) -> bool; 3 | } 4 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/src/infinite.rs: -------------------------------------------------------------------------------- 1 | use crate::{InfiniteIterator, InfiniteIteratorEnd}; 2 | use std::iter::Fuse; 3 | 4 | pub struct Infinite 5 | where 6 | T: Clone + InfiniteIteratorEnd, 7 | I: Iterator, 8 | { 9 | iterator: Fuse, 10 | end: T, 11 | } 12 | 13 | impl Infinite 14 | where 15 | T: Clone + InfiniteIteratorEnd, 16 | I: Iterator, 17 | { 18 | pub fn new(iterator: I, end: T) -> Self { 19 | Self { 20 | iterator: iterator.fuse(), 21 | end, 22 | } 23 | } 24 | } 25 | 26 | impl InfiniteIterator for Infinite 27 | where 28 | T: Clone + InfiniteIteratorEnd, 29 | I: Iterator, 30 | { 31 | type Item = T; 32 | 33 | fn next(&mut self) -> Self::Item { 34 | self.iterator.next().unwrap_or(self.end.clone()) 35 | } 36 | } 37 | 38 | unsafe impl Send for Infinite 39 | where 40 | T: Clone + Send + InfiniteIteratorEnd, 41 | I: Iterator + Send, 42 | { 43 | } 44 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/src/iter.rs: -------------------------------------------------------------------------------- 1 | use crate::InfiniteIteratorEnd; 2 | 3 | pub trait InfiniteIterator { 4 | type Item: InfiniteIteratorEnd; 5 | 6 | fn next(&mut self) -> Self::Item; 7 | } 8 | 9 | impl> InfiniteIterator for &mut I { 10 | type Item = T; 11 | 12 | fn next(&mut self) -> Self::Item { 13 | (**self).next() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(maybe_uninit_array_assume_init)] 2 | 3 | mod end; 4 | mod infinite; 5 | mod iter; 6 | mod peekable; 7 | mod peeker; 8 | mod tools; 9 | 10 | pub use end::InfiniteIteratorEnd; 11 | pub use infinite::Infinite; 12 | pub use iter::InfiniteIterator; 13 | pub use peekable::InfinitePeekable; 14 | pub use peeker::Peeker as InfiniteIteratorPeeker; 15 | pub use tools::InfiniteIteratorTools; 16 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/src/peekable.rs: -------------------------------------------------------------------------------- 1 | use crate::{InfiniteIterator, InfiniteIteratorEnd}; 2 | 3 | pub trait InfinitePeekable: InfiniteIterator { 4 | fn un_next(&mut self, item: Self::Item); 5 | 6 | fn peek_nth_mut(&mut self, n: usize) -> &mut T; 7 | fn peek_n(&mut self) -> [&T; N]; 8 | 9 | fn peek_nth(&mut self, n: usize) -> &T { 10 | &*self.peek_nth_mut(n) 11 | } 12 | 13 | fn peek(&mut self) -> &T { 14 | self.peek_nth(0) 15 | } 16 | 17 | fn peek_mut(&mut self) -> &mut T { 18 | self.peek_nth_mut(0) 19 | } 20 | } 21 | 22 | impl> InfinitePeekable for &mut I { 23 | fn un_next(&mut self, item: Self::Item) { 24 | (**self).un_next(item) 25 | } 26 | 27 | fn peek_nth_mut(&mut self, n: usize) -> &mut T { 28 | (**self).peek_nth_mut(n) 29 | } 30 | 31 | fn peek_n(&mut self) -> [&T; N] { 32 | (**self).peek_n::() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/support/infinite_iterator/src/tools.rs: -------------------------------------------------------------------------------- 1 | use crate::{InfiniteIterator, InfiniteIteratorEnd}; 2 | 3 | pub trait InfiniteIteratorTools: InfiniteIterator 4 | where 5 | T: InfiniteIteratorEnd, 6 | { 7 | fn collect_vec(&mut self, keep_end: bool) -> Vec { 8 | let mut collected = vec![]; 9 | 10 | loop { 11 | let item = self.next(); 12 | 13 | if item.is_end() { 14 | if keep_end { 15 | collected.push(item); 16 | } 17 | return collected; 18 | } 19 | 20 | collected.push(item); 21 | } 22 | } 23 | } 24 | 25 | impl InfiniteIteratorTools for I 26 | where 27 | T: InfiniteIteratorEnd, 28 | I: InfiniteIterator, 29 | { 30 | } 31 | -------------------------------------------------------------------------------- /src/support/line_column/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "line_column" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /src/support/look_ahead/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "look_ahead" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | -------------------------------------------------------------------------------- /src/support/optional_string/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "optional_string" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | -------------------------------------------------------------------------------- /src/support/repeating_last/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "repeating_last" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | derive_more.workspace = true 8 | -------------------------------------------------------------------------------- /src/support/std_ext/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "std_ext" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | indexmap.workspace = true 8 | smallvec = "1.15.0" 9 | -------------------------------------------------------------------------------- /src/support/std_ext/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod hash_map_ext; 2 | mod index_map_ext; 3 | 4 | pub use hash_map_ext::*; 5 | pub use index_map_ext::*; 6 | use smallvec::SmallVec; 7 | 8 | pub type BoxedSlice = Box<[T]>; 9 | pub type SmallVec1 = SmallVec<[T; 1]>; 10 | pub type SmallVec2 = SmallVec<[T; 2]>; 11 | pub type SmallVec4 = SmallVec<[T; 4]>; 12 | pub type SmallVec8 = SmallVec<[T; 8]>; 13 | pub type SmallVec16 = SmallVec<[T; 16]>; 14 | -------------------------------------------------------------------------------- /src/support/target/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "target" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | data_units = { version = "0.1.0", path = "../data_units" } 8 | primitives = { version = "0.1.0", path = "../../representations/primitives" } 9 | -------------------------------------------------------------------------------- /src/support/target/src/display.rs: -------------------------------------------------------------------------------- 1 | use super::{TargetArch, TargetOs}; 2 | use std::fmt::Display; 3 | 4 | pub trait IntoDisplay { 5 | fn display(self) -> impl Display; 6 | } 7 | 8 | impl IntoDisplay for Option { 9 | fn display(self) -> impl Display { 10 | DisplayOrUnknown(self) 11 | } 12 | } 13 | 14 | impl IntoDisplay for Option { 15 | fn display(self) -> impl Display { 16 | DisplayOrUnknown(self) 17 | } 18 | } 19 | 20 | struct DisplayOrUnknown(pub Option); 21 | 22 | impl Display for DisplayOrUnknown { 23 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 24 | match &self.0 { 25 | Some(inner) => inner.fmt(f), 26 | None => write!(f, "unknown"), 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/support/target_layout/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "target_layout" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | arena = { version = "0.1.0", path = "../arena" } 8 | asg = { version = "0.1.0", path = "../../representations/asg" } 9 | data_units = { version = "0.1.0", path = "../data_units" } 10 | derivative.workspace = true 11 | diagnostics = { version = "0.1.0", path = "../diagnostics" } 12 | ir = { version = "0.1.0", path = "../../representations/ir" } 13 | once_map.workspace = true 14 | primitives = { version = "0.1.0", path = "../../representations/primitives" } 15 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 16 | target = { version = "0.1.0", path = "../target" } 17 | -------------------------------------------------------------------------------- /src/support/target_layout/src/alignment_requirement.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/support/target_layout/src/record_layout/mod.rs: -------------------------------------------------------------------------------- 1 | use data_units::{BitUnits, ByteUnits}; 2 | 3 | mod itanium; 4 | mod record_info; 5 | 6 | pub use itanium::*; 7 | pub use record_info::*; 8 | 9 | #[derive(Debug)] 10 | pub struct ASTRecordLayout { 11 | pub size: ByteUnits, 12 | pub alignment: ByteUnits, 13 | pub preferred_alignment: ByteUnits, 14 | pub unadjusted_alignment: ByteUnits, 15 | pub required_alignment: ByteUnits, 16 | /// Size without tail padding 17 | pub data_size: ByteUnits, 18 | pub field_offsets: Vec, 19 | } 20 | -------------------------------------------------------------------------------- /src/support/target_layout/src/type_layout.rs: -------------------------------------------------------------------------------- 1 | use data_units::ByteUnits; 2 | 3 | #[derive(Copy, Clone, Debug, PartialEq)] 4 | pub struct TypeLayout { 5 | pub width: ByteUnits, 6 | pub alignment: ByteUnits, 7 | pub unadjusted_alignment: ByteUnits, 8 | pub align_requirement: AlignRequirement, 9 | } 10 | 11 | impl TypeLayout { 12 | pub fn basic(size: ByteUnits) -> Self { 13 | Self { 14 | width: size, 15 | alignment: size, 16 | unadjusted_alignment: size, 17 | align_requirement: AlignRequirement::None, 18 | } 19 | } 20 | } 21 | 22 | #[derive(Copy, Clone, Debug, Default, PartialEq)] 23 | pub enum AlignRequirement { 24 | #[default] 25 | None, 26 | RequiredByTypedefAttribute, 27 | RequiredByRecordAttribute, 28 | } 29 | -------------------------------------------------------------------------------- /src/support/text/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "text" 3 | version = "0.1.0" 4 | edition = "2024" 5 | 6 | [dependencies] 7 | infinite_iterator = { version = "0.1.0", path = "../infinite_iterator" } 8 | line_column = { version = "0.1.0", path = "../line_column" } 9 | source_files = { version = "0.1.0", path = "../../representations/source_files" } 10 | -------------------------------------------------------------------------------- /src/support/text/src/eatable.rs: -------------------------------------------------------------------------------- 1 | pub trait Eatable { 2 | fn chars(self) -> impl Iterator; 3 | } 4 | 5 | impl Eatable for char { 6 | fn chars(self) -> impl Iterator { 7 | std::iter::once(self) 8 | } 9 | } 10 | 11 | impl Eatable for &str { 12 | fn chars(self) -> impl Iterator { 13 | self.chars() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/c/0001/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | -------------------------------------------------------------------------------- /tests/c/0001/main.c: -------------------------------------------------------------------------------- 1 | 2 | int main(void) { 3 | return 21; 4 | } 5 | -------------------------------------------------------------------------------- /tests/c/0002/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | -------------------------------------------------------------------------------- /tests/c/0002/main.c: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | return 21; 4 | } 5 | -------------------------------------------------------------------------------- /tests/error/cannot_use_private_func/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | helloWorld() 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/error/cannot_use_private_func/sayMessage.adept: -------------------------------------------------------------------------------- 1 | 2 | #[foreign] 3 | func printf(format ptr#char, ...) int 4 | 5 | func sayMessage() { 6 | helloWorld() 7 | } 8 | 9 | #[private] 10 | func helloWorld { 11 | printf(c"Hello, world!\n") 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/error/cannot_use_private_type/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | name := Name { firstname: c"Isaac" } 6 | test() 7 | } 8 | -------------------------------------------------------------------------------- /tests/error/cannot_use_private_type/test.adept: -------------------------------------------------------------------------------- 1 | 2 | #[foreign] 3 | func printf(format ptr#char, ...) int 4 | 5 | #[private] 6 | struct Name (firstname ptr#char) 7 | 8 | func test { 9 | name := Name { firstname: c"John" } 10 | name.ptr().greet() 11 | } 12 | 13 | func greet(name ptr#Name) { 14 | printf(c"Hello %s\n", name.firstname) 15 | } 16 | -------------------------------------------------------------------------------- /tests/error/duplicate_type_names/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | struct Type1 () 5 | enum Type1 () 6 | 7 | func main { 8 | } 9 | -------------------------------------------------------------------------------- /tests/error/generics_trait_unsatisfied/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | value int = 0 9 | p ptr = &value 10 | 11 | // This will cause an error since no matching functions exist, 12 | // (because the trait PrimitiveAdd is not satisfied for ptr) 13 | printf(c"p + p = %p\n", p.plus(p)) 14 | } 15 | 16 | func plus(a $T: PrimitiveAdd, b $T) $T { 17 | return a + b 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/error/impl_dual_use_polymorph/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakAnything::speak(10, 11, 12) 9 | } 10 | 11 | trait Speak<$T> { 12 | func speak(self $T, other $X, other2 $X) void 13 | } 14 | 15 | #[public] 16 | impl Speak<$T> speakAnything { 17 | func speak(self $T, other $T, other2 $T) { 18 | printf(c"speak anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/error/impl_inconsistent/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakInt::speak(10) 9 | } 10 | 11 | trait Speak<$T> { 12 | func speak(self $T) void 13 | } 14 | 15 | #[public] 16 | impl Speak speakInt { 17 | func speak(self float) { 18 | printf(c"int = %d\n", self) 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/error/impl_inconsistent_for_all/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakAnything::speak(10, 11, 12) 9 | } 10 | 11 | trait Speak<$T> { 12 | func speak(self $T, other $X, other2 $X) void 13 | } 14 | 15 | #[public] 16 | impl Speak<$T> speakAnything { 17 | func speak(self $T, other $W, other2 $Y) { 18 | printf(c"speak anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/error/impl_inconsistent_for_all_return_type/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | actAnything::act(10) 9 | } 10 | 11 | trait Act<$T> { 12 | func act(self $T) $X 13 | } 14 | 15 | #[public] 16 | impl Act<$T> actAnything { 17 | func act(self $T) $T { 18 | printf(c"act anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/error/impl_missing_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakInt::speak(10) 9 | } 10 | 11 | trait Speak<$T> { 12 | func speak(self $T) void 13 | } 14 | 15 | #[public] 16 | impl Speak speakInt { 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/error/impl_unknown_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakInt::speak(10) 9 | } 10 | 11 | trait Speak<$T> { 12 | func speak(self $T) void 13 | } 14 | 15 | #[public] 16 | impl Speak speakInt { 17 | func speak(self int) { 18 | printf(c"int = %d\n", self) 19 | } 20 | 21 | func speak2(self int) { 22 | printf(c"int = %d\n", self) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tests/error/impl_wrong_func_return_type/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | readWriteInt::write(readWriteInt::read()) 9 | } 10 | 11 | trait ReadWriter<$T> { 12 | func read() $T 13 | func write(self $T) void 14 | } 15 | 16 | #[public] 17 | impl ReadWriter readWriteInt { 18 | func read() int { 19 | return 10 20 | } 21 | 22 | func write(self int) int { 23 | printf(c"%d\n", self) 24 | return 0 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/error/impl_wrong_sub/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | actAnything::act(10) 9 | } 10 | 11 | trait Act<$T> { 12 | func act(self $T) void 13 | } 14 | 15 | #[public] 16 | impl Act<$T> actAnything { 17 | func act(self $Self) { 18 | printf(c"act anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/error/mismatching_yielded_types/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | condition := true 9 | 10 | printf(c"Result is %f\n", if condition { 11 | x i32 = 123 12 | x 13 | } elif !condition { 14 | 53 15 | } else { 16 | 3.1415 17 | }) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/error/pragma_adept_first/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => { 3 | println("This should be an error, since adept(\"3.0\") does not occur first") 4 | adept("3.0") 5 | } 6 | 7 | #[foreign] 8 | func printf(format ptr, ...) int 9 | 10 | func main { 11 | printf(c"Hello World!\n") 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/error/struct_missing_polymorph/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | struct Vector (items ptr<$T>, length ulonglong, capacity ulonglong) 5 | 6 | func main {} 7 | -------------------------------------------------------------------------------- /tests/error/undefined_impl/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | actAnything::act(10) 9 | } 10 | 11 | trait Act<$T> { 12 | func act(self $T) void 13 | } 14 | 15 | #[public] 16 | impl Act<$T> actAnyth { 17 | func act(self $T) { 18 | printf(c"act anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/error/unsuitable_type_for_literal/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a := u8(255) 9 | b := i8(-1) 10 | c := i16(65500) // NOTE: This does not fit and will cause an error 11 | d := u32(100000) 12 | e := i64(-123456) 13 | f := i64(123456) 14 | 15 | a_check u8 = a 16 | b_check i8 = b 17 | c_check i16 = c 18 | d_check u32 = d 19 | e_check i64 = e 20 | f_check u64 = f 21 | 22 | println(x + y) 23 | } 24 | -------------------------------------------------------------------------------- /tests/error/using_on_main/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | trait Say { 5 | func say() void 6 | } 7 | 8 | #[using $say Say] 9 | func main {} 10 | 11 | -------------------------------------------------------------------------------- /tests/error/using_trait_on_impl_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept(c"3.0") 3 | 4 | trait Speak<$T> { 5 | func speak(self $T) void 6 | } 7 | 8 | trait Act { 9 | func act() void 10 | } 11 | 12 | impl Act myExampleImpl { 13 | #[using Speak] 14 | func act() {} 15 | } 16 | 17 | func main {} 18 | 19 | -------------------------------------------------------------------------------- /tests/error/using_trait_on_trait_func/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept(c"3.0") 3 | 4 | trait Speak<$T> { 5 | func speak(self $T) void 6 | } 7 | 8 | trait InvalidTrait<$T> { 9 | #[using Speak<$T>] 10 | func invalidFunction(self $T) void 11 | } 12 | 13 | func main {} 14 | 15 | -------------------------------------------------------------------------------- /tests/success/and_or/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"true || oops() == %s\n", booleanName(true || oops())) 9 | printf(c"false || true == %s\n", booleanName(false || true)) 10 | printf(c"false || false == %s\n", booleanName(false || false)) 11 | printf(c"false && oops() == %s\n", booleanName(false && oops())) 12 | printf(c"true && false == %s\n", booleanName(true && false)) 13 | printf(c"true && true == %s\n", booleanName(true && true)) 14 | } 15 | 16 | func oops() bool { 17 | printf(c"Oops! This should never run!\n") 18 | return true // Doesn't matter what value we return 19 | } 20 | 21 | func booleanName(value bool) ptr { 22 | return if value { c"true" } else { c"false" } 23 | } 24 | -------------------------------------------------------------------------------- /tests/success/annotation_groups/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | { 6 | // NOTE: This is only macOS (also type is incorrect but it's a pointer so doesn't matter) 7 | __stdinp ptr 8 | 9 | func printf(format ptr, ...) int 10 | func fgets(string ptr, length int, stream ptr) void 11 | func malloc(size ulonglong) ptr 12 | func free(pointer ptr) void 13 | func strcmp(a ptr, b ptr) i32 14 | func atoi(string ptr) int 15 | } 16 | 17 | func main { 18 | printf(c"Hi World!\n") 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/success/array_access/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | { 6 | func printf(format ptr, ...) int 7 | func malloc(size ulonglong) ptr 8 | func free(pointer ptr) void 9 | } 10 | 11 | func main { 12 | items ptr = malloc(4 * 10) 13 | 14 | i i32 = 0 15 | while i < 10 { 16 | items[i] = 10 * i 17 | i = i + 1 18 | } 19 | 20 | i i32 = 0 21 | while i < 10 { 22 | printf(c"items[%d] = %d\n", i, items[i]) 23 | i = i + 1 24 | } 25 | 26 | free(items) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tests/success/auto_defer_ptr/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | struct Person (firstname ptr#char, lastname ptr#char) 8 | 9 | func main { 10 | john := Person { firstname: c"John", lastname: c"Smith" } 11 | person := &john 12 | 13 | printf(c"%s %s\n", person.firstname, person.lastname) 14 | } 15 | -------------------------------------------------------------------------------- /tests/success/bitwise_operators/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a := 13 9 | b := 8 10 | 11 | printf(c"%lld & %lld = %lld\n", a, b, a & b) 12 | printf(c"%lld | %lld = %lld\n", a, b, a | b) 13 | printf(c"%lld ^ %lld = %lld\n", a, b, a ^ b) 14 | printf(c"%lld >> %lld = %lld\n", a, b, a >> b) 15 | printf(c"%lld >>> %lld = %lld\n", a, b, a >>> b) 16 | printf(c"%lld << %lld = %lld\n", a, b, a << b) 17 | printf(c"%lld <<< %lld = %lld\n", a, b, a <<< b) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/success/break/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | i := int(0) 9 | 10 | while true { 11 | if i > 5 { 12 | break 13 | } 14 | 15 | printf(c"%d\n", i) 16 | i += 1 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/success/c_global_variable/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | #[foreign] 8 | special_value int 9 | 10 | func main { 11 | special_value = 1234 12 | printf(c"special_value = %d\n", special_value) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/c_global_variable/special_value.c: -------------------------------------------------------------------------------- 1 | 2 | int special_value; 3 | -------------------------------------------------------------------------------- /tests/success/c_global_variable_extern_thread_local/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | printf(c"errno = %s\n", strerror(errno)) 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/success/c_global_variable_extern_thread_local/errno.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _C_ERRNO_H_INCLUDED 3 | #define _C_ERRNO_H_INCLUDED 4 | 5 | thread_local extern int errno; 6 | 7 | char *strerror(int errnum); 8 | 9 | #endif // _C_ERRNO_H_INCLUDED 10 | 11 | -------------------------------------------------------------------------------- /tests/success/c_math/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | printf(c"3 + 4 = %d\n", ADD_RESULT) 9 | printf(c"3 - 4 = %d\n", SUBTRACT_RESULT) 10 | printf(c"3 * 4 = %d\n", MULTIPLY_RESULT) 11 | printf(c"21 / 4 = %d\n", DIVIDE_RESULT) 12 | printf(c"21 %% 4 = %d\n", MODULUS_RESULT) 13 | printf(c"21 || 0 = %d\n", OR_RESULT) 14 | printf(c"21 && 0 = %d\n", AND_RESULT) 15 | printf(c"21 | 2 = %d\n", BITWISE_OR_RESULT) 16 | printf(c"21 & 2 = %d\n", BITWISE_AND_RESULT) 17 | printf(c"21 ^ 2 = %d\n", BITWISE_XOR_RESULT) 18 | printf(c"21 == 2 = %d\n", EQ_RESULT) 19 | printf(c"21 != 2 = %d\n", NEQ_RESULT) 20 | printf(c"21 < 2 = %d\n", LT_RESULT) 21 | printf(c"21 > 2 = %d\n", GT_RESULT) 22 | printf(c"21 <= 2 = %d\n", LTE_RESULT) 23 | printf(c"21 >= 2 = %d\n", GTE_RESULT) 24 | printf(c"21 << 2 = %d\n", LSHIFT_RESULT) 25 | printf(c"21 >> 2 = %d\n", RSHIFT_RESULT) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/success/c_math/result.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _C_ADD_RESULT_H_INCLUDED 3 | #define _C_ADD_RESULT_H_INCLUDED 4 | 5 | #define ADD_RESULT 3 + 4 6 | #define SUBTRACT_RESULT 3 - 4 7 | #define MULTIPLY_RESULT 3 * 4 8 | #define DIVIDE_RESULT 21 / 4 9 | #define MODULUS_RESULT 21 % 4 10 | #define OR_RESULT 21 || 0 11 | #define AND_RESULT 21 && 0 12 | #define BITWISE_OR_RESULT 21 | 2 13 | #define BITWISE_AND_RESULT 21 & 2 14 | #define BITWISE_XOR_RESULT 21 ^ 2 15 | #define EQ_RESULT 21 == 2 16 | #define NEQ_RESULT 21 != 2 17 | #define LT_RESULT 21 < 2 18 | #define GT_RESULT 21 > 2 19 | #define LTE_RESULT 21 <= 2 20 | #define GTE_RESULT 21 >= 2 21 | #define LSHIFT_RESULT 21 << 2 22 | #define RSHIFT_RESULT 21 >> 2 23 | 24 | #endif // _C_ADD_RESULT_H_INCLUDED 25 | 26 | -------------------------------------------------------------------------------- /tests/success/c_printf/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"Hello, World!\n") 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/success/cast_trait/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => { 3 | adept("3.0") 4 | use("std", import("std")) 5 | importNamespace("std") 6 | } 7 | 8 | #[foreign] 9 | func printf(format ptr#char, ...) int 10 | 11 | func main { 12 | castTest(1234)::(std/castI32ToDouble, std/castI32ToLongLong) 13 | } 14 | 15 | #[using std/Cast] 16 | #[using std/Cast] 17 | func castTest(x i32) { 18 | printf(c"With long form generics syntax:\n") 19 | printf(c"%d %f %lld\n", x, x.cast(), x.cast()) 20 | printf(c"With shorthand generics syntax:\n") 21 | printf(c"%d %f %lld\n", x, x.cast#double(), x.cast#longlong()) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/success/character_literals/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | letter char = 'A' // Generic character literal 9 | another_letter := c'B' // C `char` literal 10 | 11 | printf(c"letter = %c\n", letter) 12 | printf(c"another_letter = %c\n", another_letter) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/compare_ints/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | test(8, 13) 9 | test(42, 42) 10 | } 11 | 12 | func test(a int, b int) { 13 | printf(c"%lld == %lld = %lld\n", a, b, a == b) 14 | printf(c"%lld != %lld = %lld\n", a, b, a != b) 15 | printf(c"%lld < %lld = %lld\n", a, b, a < b) 16 | printf(c"%lld <= %lld = %lld\n", a, b, a <= b) 17 | printf(c"%lld > %lld = %lld\n", a, b, a > b) 18 | printf(c"%lld >= %lld = %lld\n", a, b, a >= b) 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/success/continue/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | i := int(1) 9 | 10 | while i <= 10 { 11 | printf(c"%d", i) 12 | i += 1 13 | 14 | if i > 6 { 15 | printf(c"\n") 16 | continue 17 | } 18 | 19 | printf(c"!\n") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/success/defines/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | define FAVORITE_NUMBER = 12345 8 | 9 | func main { 10 | printf(c"X = %lld\n", FAVORITE_NUMBER) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/success/dereference/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | #[foreign] 8 | func strlen(string ptr) ulonglong 9 | 10 | func main { 11 | string := c"abcdefg" 12 | pointer := &string 13 | count := strlen(string) 14 | 15 | i := 0.ulonglong() 16 | while i < count { 17 | j := 0.ulonglong() 18 | while j < count { 19 | printf(c"%c", **pointer) 20 | j += 1 21 | } 22 | 23 | printf(c"\n") 24 | *pointer = &(*pointer)[1] 25 | i += 1 26 | } 27 | 28 | 29 | printf(c"Done\n") 30 | } 31 | -------------------------------------------------------------------------------- /tests/success/enums/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | enum Color (Red, Green, Blue) 5 | 6 | #[foreign] 7 | func printf(format ptr, ...) int 8 | 9 | func main { 10 | red := Color::Red 11 | green := Color::Green 12 | blue := Color::Blue 13 | 14 | // WARNING: This temporary way of proving it works is not very sound 15 | printf(c"red=%lld green=%lld blue=%lld\n", red, green, blue) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/success/float_literal/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | value := 3.14159 9 | printf(c"pi = %f\n", value) 10 | 11 | ones float = 1.11 12 | twos f64 = 2.22 13 | 14 | printf(c"ones = %f, twos = %f\n", ones, twos) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/success/function_parameters/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | greet(c"John") 9 | showNumber(getNumber()) 10 | } 11 | 12 | func greet(name ptr) { 13 | printf(c"Hello, %s!\n", name) 14 | } 15 | 16 | func getNumber() int { 17 | return 1234 18 | } 19 | 20 | func showNumber(number int) { 21 | printf(c"Your number is %d\n", number) 22 | } 23 | -------------------------------------------------------------------------------- /tests/success/function_simple/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | greet() 9 | } 10 | 11 | func greet() { 12 | printf(c"Welcome, World!") 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/generics/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"first(1, 2) = %d\n", 1.first(2)) 9 | printf(c"first(2.5, 3.0) = %f\n", 2.5.first(3.0)) 10 | } 11 | 12 | func first(a $T, b $T) $T { 13 | return a 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/success/generics_shorthand/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | message ptr#char = c"Hello from generics shorthand example!" 9 | printf(c"%s\n", message) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/success/generics_struct_simple/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct RawOption<$T> (value $T, has bool) 8 | 9 | func main { 10 | my_first_option := RawOption { value: 10, has: true } 11 | testing(my_first_option) 12 | } 13 | 14 | func testing(raw_option RawOption<$T>) { 15 | // NOTE: The following would result in an error message, 16 | // since it doesn't work in the general case: 17 | /* raw_option.value = 10 */ 18 | 19 | printf(c"raw_option.has = %s\n", if raw_option.has { c"true" } else { c"false" }) 20 | raw_option.has = false 21 | printf(c"raw_option.has = %s\n", if raw_option.has { c"true" } else { c"false" }) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/success/generics_type_alias/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | typealias t<$T> = $T 8 | 9 | func main { 10 | x t = 13 11 | 12 | printf(c"x = %d\n", x) 13 | } 14 | -------------------------------------------------------------------------------- /tests/success/global_variables/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | x int 8 | 9 | func main { 10 | x = 100 11 | printf(c"x = %lld\n", x) 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/success/global_variables_exposed/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | #[foreign] 8 | special_value int 9 | 10 | func main { 11 | special_value = 1234 12 | printf(c"special_value = %d\n", special_value) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/global_variables_exposed/special_variable.adept: -------------------------------------------------------------------------------- 1 | 2 | #[private, exposed] 3 | special_value int 4 | 5 | -------------------------------------------------------------------------------- /tests/success/hello_world/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"Hello, World!\n") 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/success/if/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | { 6 | func printf(format ptr, ...) int 7 | func strcmp(a ptr, b ptr) int 8 | func atoi(string ptr) int 9 | } 10 | 11 | func main(argc i32, argv ptr>) i32 { 12 | if argc < 2 { 13 | printf(c"USAGE: %s \n", argv[0]) 14 | return 1 15 | } 16 | 17 | number ptr = argv[1] 18 | 19 | printf(c"Your number is: %s\n", if strcmp(number, c"one") == 0 { 20 | c"1" 21 | } elif strcmp(number, c"two") == 0 { 22 | c"2" 23 | } elif strcmp(number, c"three") == 0 { 24 | c"3" 25 | } else { 26 | c"I'm not sure" 27 | }) 28 | 29 | return 0 30 | } 31 | -------------------------------------------------------------------------------- /tests/success/if_elif_else/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | { 6 | // NOTE: This is only macOS (also type is incorrect but it's a pointer so doesn't matter) 7 | __stdinp ptr 8 | 9 | func printf(format ptr, ...) int 10 | func fgets(string ptr, length int, stream ptr) void 11 | func malloc(size ulonglong) ptr 12 | func free(pointer ptr) void 13 | func strcmp(a ptr, b ptr) int 14 | func atoi(string ptr) int 15 | } 16 | 17 | func main { 18 | printf(c"Enter the name of a number: ") 19 | 20 | number ptr = malloc(1024) 21 | fgets(number, 1024, __stdinp) 22 | 23 | printf(c"Your number is: %s\n", if strcmp(number, c"one\n") == 0 { 24 | c"1" 25 | } elif strcmp(number, c"two\n") == 0 { 26 | c"2" 27 | } elif strcmp(number, c"three\n") == 0 { 28 | c"3" 29 | } else { 30 | c"I'm not sure" 31 | }) 32 | 33 | free(number) 34 | } 35 | -------------------------------------------------------------------------------- /tests/success/if_eval/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | use_firstname := true 9 | 10 | printf(c"Welcome, %s\n", if use_firstname { 11 | c"Isaac" 12 | } else { 13 | c"Shelton" 14 | }) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/success/if_neglect_result/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | if true { 9 | printf(c"Hello\n") 10 | } else { 11 | // Do nothing 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/success/impl_generic_simple/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | iterator := c"Hello, world!" 9 | 10 | running := true 11 | while running { 12 | c := iteratorCString::next(&iterator) 13 | 14 | if c == c'\0' { 15 | running = false 16 | } else { 17 | printf(c"%c\n", c) 18 | } 19 | } 20 | } 21 | 22 | trait Iterator<$Self, $Item> { 23 | func next(self ptr<$Self>) $Item 24 | } 25 | 26 | impl Iterator, char> iteratorCString { 27 | func next(self ptr>) char { 28 | c := **self 29 | rest := &(*self)[1] 30 | *self = rest 31 | return c 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/success/impl_generic_simple2/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | #[foreign] 8 | func strlen(string ptr) ulonglong 9 | 10 | func main { 11 | generator := c"Hello, world!" 12 | listOut(generator, strlen(generator)) 13 | } 14 | 15 | trait Generator<$Self, $Item> { 16 | func generate(self ptr<$Self>) $Item 17 | } 18 | 19 | impl Generator, $T> generateFromPointer { 20 | func generate(self ptr>) $T { 21 | c := **self 22 | rest := &(*self)[1] 23 | *self = rest 24 | return c 25 | } 26 | } 27 | 28 | func listOut(generator ptr<$GeneratedItem>, count ulonglong) { 29 | while count > 0 { 30 | value := generateFromPointer::generate(&generator) 31 | 32 | // We're going to pretend for now that we can print each item with %d. 33 | // This should probably become a compile-time error in the future. 34 | printf(c"%d\n", value) 35 | count -= 1 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/success/impl_generic_simple3/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | iterator := c"Hello, world!" 9 | 10 | running := true 11 | while running { 12 | c := iteratorCString::next(&iterator) 13 | 14 | if c == c'\0' { 15 | running = false 16 | } else { 17 | printf(c"%c\n", c) 18 | } 19 | } 20 | } 21 | 22 | trait Iterator<$Self, $Item> { 23 | func next(self ptr<$Self>) $Item 24 | } 25 | 26 | impl Iterator, char> iteratorCString { 27 | func next(self ptr>) char { 28 | c := **self 29 | 30 | if c == c'\0' { 31 | return c'\0' 32 | } 33 | 34 | *self = &(*self)[1] 35 | return c 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/success/impl_sub_renames/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | actAnything::act(10) 9 | } 10 | 11 | trait Act<$T> { 12 | func act(self $T) void 13 | } 14 | 15 | #[public] 16 | impl Act<$Self> actAnything { 17 | func act(s $Self) { 18 | printf(c"act anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/success/implicits_explicit/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakInt::speak(10) 9 | speakFloat::speak(11) 10 | speakCString::speak(c"Hello, World!") 11 | speakAnything::speak(int(10)) 12 | } 13 | 14 | trait Speak<$T> { 15 | func speak(self $T) void 16 | } 17 | 18 | #[public] 19 | impl Speak speakInt { 20 | func speak(self int) { 21 | printf(c"int = %d\n", self) 22 | } 23 | } 24 | 25 | #[public] 26 | impl Speak speakFloat { 27 | func speak(self float) { 28 | printf(c"float = %f\n", self) 29 | } 30 | } 31 | 32 | #[public] 33 | impl Speak> speakCString { 34 | func speak(self ptr) { 35 | printf(c"ptr = %s\n", self) 36 | } 37 | } 38 | 39 | #[public] 40 | impl Speak<$T> speakAnything<$T> { 41 | func speak(self $T) { 42 | printf(c"anything = ???\n") 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/success/implicits_for_all/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | speakAnything::speak(10, 11, 12) 9 | } 10 | 11 | trait Speak<$T> { 12 | func speak(self $T, other $X, other2 $X) void 13 | } 14 | 15 | #[public] 16 | impl Speak<$T> speakAnything { 17 | func speak(self $T, other $W, other2 $W) { 18 | printf(c"speak anything...\n") 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/success/implicits_multi_funcs/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | readWriteInt::write(readWriteInt::read()) 9 | } 10 | 11 | trait ReadWriter<$T> { 12 | func read() $T 13 | func write(self $T) void 14 | } 15 | 16 | #[public] 17 | impl ReadWriter readWriteInt { 18 | func read() int { 19 | return 10 20 | } 21 | 22 | func write(self int) { 23 | printf(c"%d\n", self) 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /tests/success/integer_and_float_literals_combining/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | condition := true 9 | 10 | printf(c"Result is %f\n", if condition { 11 | 123 12 | } elif !condition { 13 | 53 14 | } else { 15 | 3.1415 16 | }) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/success/integer_hex_literals/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"0x10 = %lld\n", 0x10) 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/success/integer_signed_overflow/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | x i64 = 9223372036854775807 6 | x = x + 1 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/success/integer_typed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a := u8(255) 9 | b := i8(-1) 10 | c := i16(32200) 11 | d := u32(100000) 12 | e := i64(-123456) 13 | f := u64(123456) 14 | 15 | a_check u8 = a 16 | b_check i8 = b 17 | c_check i16 = c 18 | d_check u32 = d 19 | e_check i64 = e 20 | f_check u64 = f 21 | 22 | printf(c"a = %d\n", a) 23 | printf(c"b = %d\n", b) 24 | printf(c"c = %d\n", c) 25 | printf(c"d = %u\n", d) 26 | printf(c"e = %lld\n", e) 27 | printf(c"f = %llu\n", f) 28 | } 29 | -------------------------------------------------------------------------------- /tests/success/integer_unsigned_overflow/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | x u64 = 18446744073709551615 6 | x = x + 1 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/success/math_floats/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a := 13.14 9 | b := 8.76543 10 | 11 | printf(c"%f + %f = %f\n", a, b, a + b) 12 | printf(c"%f - %f = %f\n", a, b, a - b) 13 | printf(c"%f * %f = %f\n", a, b, a * b) 14 | printf(c"%f / %f = %f\n", a, b, a / b) 15 | printf(c"%f %% %f = %f\n", a, b, a % b) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/success/math_simple/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a := 13 9 | b := 8 10 | 11 | printf(c"%lld + %lld = %lld\n", a, b, a + b) 12 | printf(c"%lld - %lld = %lld\n", a, b, a - b) 13 | printf(c"%lld * %lld = %lld\n", a, b, a * b) 14 | printf(c"%lld / %lld = %lld\n", a, b, a / b) 15 | printf(c"%lld %% %lld = %lld\n", a, b, a % b) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/success/member/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Vector3i (x int, y int, z int) 8 | 9 | func main { 10 | vector Vector3i = Vector3i { x: 0, y: 0, z: 0 } 11 | 12 | vector.x = 123 13 | vector.y = 456 14 | vector.z = 789 15 | 16 | printf(c"x = %lld, y = %lld, z = %lld\n", vector.x, vector.y, vector.z) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/success/modules_simple/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept(c"3.0") 3 | 4 | -------------------------------------------------------------------------------- /tests/success/modules_simple/greet.adept: -------------------------------------------------------------------------------- 1 | 2 | func greet(name ptr) { 3 | printf(c"Welcome, %s!\n", name) 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/success/modules_simple/main.adept: -------------------------------------------------------------------------------- 1 | 2 | func main { 3 | greet(c"Isaac") 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/success/modules_simple/printf.adept: -------------------------------------------------------------------------------- 1 | 2 | #[foreign] 3 | func printf(format ptr, ...) int 4 | 5 | -------------------------------------------------------------------------------- /tests/success/multiline_comments/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | /* 9 | This 10 | is 11 | a multi-line 12 | comment 13 | */ 14 | 15 | printf(c"Multi-Line ") 16 | 17 | /* 18 | They are also be /* nested 19 | */ 20 | */ 21 | 22 | printf(c"Comments!\n") 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tests/success/nested_expressions/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"Result is %lld\n", (1 + 2) * (3 + 4)) 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/success/null/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | message ptr#char = null 9 | printf(c"message\t= %010p\n", message) 10 | printf(c"null\t= %010p\n", null) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tests/success/object_mutation/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Vector3f (x double, y double, z double) 8 | 9 | func main { 10 | v := Vector3f { x: 1, y: 2, z: 3 } 11 | v2 := v 12 | 13 | printf(c"%f %f %f\n", v.x, v.y, v.z) 14 | 15 | v2.x = 4 16 | v2.y = 5 17 | v2.z = 6 18 | 19 | printf(c"%f %f %f\n", v.x, v.y, v.z) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/success/op_then_assign/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | x int = 0 9 | printf(c"%d\n", x) 10 | 11 | x += 10 12 | printf(c"%d\n", x) 13 | 14 | x -= 9 15 | printf(c"%d\n", x) 16 | 17 | x *= 13 18 | printf(c"%d\n", x) 19 | 20 | x /= 2 21 | printf(c"%d\n", x) 22 | 23 | x %= 5 24 | printf(c"%d\n", x) 25 | 26 | x <<= 2 27 | printf(c"%d\n", x) 28 | 29 | x >>= 2 30 | printf(c"%d\n", x) 31 | 32 | x <<<= 3 33 | printf(c"%d\n", x) 34 | 35 | x >>>= 3 36 | printf(c"%d\n", x) 37 | 38 | x |= 6 39 | printf(c"%d\n", x) 40 | 41 | x &= 3 42 | printf(c"%d\n", x) 43 | 44 | x ^= 2 45 | printf(c"%d\n", x) 46 | } 47 | 48 | -------------------------------------------------------------------------------- /tests/success/pointers/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | message i32 = 0x41000041 9 | printf(c"&message = %s\n", &message) 10 | 11 | stair long = 0 12 | stair_ptr ptr = &stair 13 | *stair_ptr = 1234 14 | printf(c"*stair_ptr = %ld\n", *stair_ptr) 15 | 16 | pi := 0.0 17 | pi_ptr ptr = &pi 18 | *pi_ptr = 3.14159 19 | printf(c"PI = %f\n", pi) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/success/preprocessor_toggle/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | printf(c"Hello world, from protected printf!\n") 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/success/private_func/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | sayMessage() 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/success/private_func/sayMessage.adept: -------------------------------------------------------------------------------- 1 | 2 | #[foreign] 3 | func printf(format ptr#char, ...) int 4 | 5 | func sayMessage() { 6 | helloWorld() 7 | } 8 | 9 | #[private] 10 | func helloWorld { 11 | printf(c"Hello, world!\n") 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/success/private_type/_.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main { 5 | test() 6 | } 7 | -------------------------------------------------------------------------------- /tests/success/private_type/test.adept: -------------------------------------------------------------------------------- 1 | 2 | #[foreign] 3 | func printf(format ptr#char, ...) int 4 | 5 | #[private] 6 | struct Name (firstname ptr#char) 7 | 8 | func test { 9 | name := Name { firstname: c"John" } 10 | name.ptr().greet() 11 | } 12 | 13 | func greet(name ptr#Name) { 14 | printf(c"Hello %s\n", name.firstname) 15 | } 16 | -------------------------------------------------------------------------------- /tests/success/return/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | func main int { 5 | return 123 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/success/return_message/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"Message is : %s\n", getMessage()) 9 | } 10 | 11 | func getMessage() ptr { 12 | return c"Hi this is a message" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/return_skipping/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | printf(c"1\n") 9 | return 10 | 11 | printf(c"2\n") 12 | return 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/signed_unsigned_promotion/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a i32 = 10 9 | b u32 = 4 10 | 11 | // This variable will be an i64, since i64 is the smallest type 12 | // that can safely represent the result of (i32 + u32) 13 | c := a + b 14 | 15 | printf(c"result is %lld\n", c) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/success/size_integers/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | func main { 8 | x usize = 1234 9 | printf(c"%zu\n", x) 10 | } 11 | -------------------------------------------------------------------------------- /tests/success/sizeof/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | struct FullName (firstname ptr#char, lastname ptr#char) 8 | 9 | func main { 10 | printf(c"sizeof#char = %d\n", sizeof#char.int()) 11 | printf(c"sizeof#short = %d\n", sizeof#short.int()) 12 | printf(c"sizeof#int = %d\n", sizeof#int.int()) 13 | printf(c"sizeof#long = %d\n", sizeof#long.int()) 14 | printf(c"sizeof#longlong = %d\n", sizeof#longlong.int()) 15 | printf(c"sizeof#ptr#char = %d\n", sizeof#ptr#char.int()) 16 | printf(c"sizeof#double = %d\n", sizeof#double.int()) 17 | 18 | // This syntax is also accepted 19 | printf(c"sizeof = %d\n", sizeof.int()) 20 | printf(c"sizeof = %d\n", sizeof.int()) 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/success/sizeof_value/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr#char, ...) int 6 | 7 | struct FullName (firstname ptr#char, lastname ptr#char) 8 | 9 | func main { 10 | c := c'A' 11 | sh := 123.short() 12 | i_3_2 := 0 13 | 14 | fullname := FullName { 15 | firstname: c"Isaac", 16 | lastname: c"Shelton", 17 | } 18 | 19 | printf(c"sizeof#(c) = %d\n", sizeof#(c).int()) 20 | printf(c"sizeof#(sh) = %d\n", sizeof#(sh).int()) 21 | printf(c"sizeof#(i_3_2) = %d\n", sizeof#(i_3_2).int()) 22 | printf(c"sizeof#(fullname) = %d\n", sizeof#(fullname).int()) 23 | 24 | // This syntax is also accepted 25 | printf(c"sizeof<(fullname)> = %d\n", sizeof<(fullname)>.int()) 26 | printf(c"sizeof<(fullname.firstname)> = %d\n", sizeof<(fullname.firstname)>.int()) 27 | printf(c"sizeof#(fullname.firstname.ptr()) = %d\n", sizeof#(fullname.firstname.ptr()).int()) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tests/success/structure_definitions/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Vector3i (x int, y int, z int) 8 | 9 | func main {} 10 | 11 | -------------------------------------------------------------------------------- /tests/success/structure_literals/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Vector3i (x int, y int, z int) 8 | 9 | func main { 10 | vector := Vector3i { 11 | x: 123, 12 | y: 456, 13 | z: 789, 14 | } 15 | 16 | printf(c"x: %lld, y: %lld, z: %lld\n", vector.x, vector.y, vector.z) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/success/structure_literals_abbr/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Vector3i (x i32, y i32, z i32) 8 | 9 | func main { 10 | x := 123 11 | y := 456 12 | z := 789 13 | 14 | v := Vector3i { :x, :y, :z } 15 | printf(c"x: %lld, y: %lld, z: %lld\n", v.x, v.y, v.z) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/success/type_aliases/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Integer (value s32) 8 | 9 | typealias s32 = i32 10 | 11 | func main { 12 | integer := Integer { value: 12345 } 13 | 14 | printf(c"value = %d\n", integer.value) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/success/ufcs/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | // NOTE: Adept has tiered Uniform Function Call Syntax 9 | // Functions can be called using `action(a, b, c)` OR `a.action(b, c)` 10 | 11 | // However, when formatting: 12 | // - Functions whose first parameter is named `self` will prefer to use `a.action(b, c)` 13 | // - Functions whose first parameter is named `this` will have no preference 14 | // - Functions whose first parameter is not named `self` or `this` will prefer to use `action(a, b, c)` 15 | 16 | // There is no semantic difference between functions or methods, 17 | // the only difference is in how they are auto-formatted. 18 | 19 | // For example, the below would change if formatted, since it prefers to use `action(a, b, c)` syntax 20 | c"Hello World!\n".printf() 21 | } 22 | 23 | -------------------------------------------------------------------------------- /tests/success/unary_operators/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | a := 100 9 | printf(c"!%lld = %lld\n", a, !a) 10 | printf(c"-%lld = %lld\n", a, -a) 11 | printf(c"~%lld = %lld\n", a, ~a) 12 | printf(c"!!%lld = %lld\n", a, !!a) 13 | printf(c"--%lld = %lld\n", a, --a) 14 | printf(c"~~%lld = %lld\n", a, ~~a) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/success/variables/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | nice_number := 69 9 | printf(c"nice_number = %lld\n", nice_number) 10 | 11 | hello_world := c"Hello World" 12 | printf(c"%s\n", hello_world) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/success/variables_override/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | message := c"Hi, World!" 9 | printf(c"%s\n", message) 10 | 11 | message := c"What is your age World?" 12 | printf(c"%s\n", message) 13 | 14 | message := 4543000000 15 | printf(c"I am %lld years old\n", message) 16 | 17 | message := c"Goodbye, World." 18 | printf(c"%s\n", message) 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/success/variables_typed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | func main { 8 | x i32 = 0 9 | x = 50 10 | 11 | y i32 = 100 12 | 13 | printf(c"x = %d\n", x) 14 | printf(c"y = %d\n", y) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/success/while/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | { 6 | // NOTE: This is only macOS (also type is incorrect but it's a pointer so doesn't matter) 7 | __stdinp ptr 8 | 9 | func printf(format ptr, ...) int 10 | func fgets(string ptr, length int, stream ptr) void 11 | func malloc(size ulonglong) ptr 12 | func free(pointer ptr) void 13 | func strcmp(a ptr, b ptr) int 14 | func atoi(string ptr) int 15 | } 16 | 17 | func main { 18 | printf(c"Enter a number: ") 19 | number ptr = malloc(1024) 20 | fgets(number, 1024, __stdinp) 21 | i := atoi(number) 22 | free(number) 23 | 24 | while i > 0 { 25 | printf(c"i = %d\n", i) 26 | i = i - 1 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tests/success/zeroed/main.adept: -------------------------------------------------------------------------------- 1 | 2 | pragma => adept("3.0") 3 | 4 | #[foreign] 5 | func printf(format ptr, ...) int 6 | 7 | struct Vector3i (x i32, y i32, z i32) 8 | 9 | func main { 10 | a := Vector3i { ..zeroed } 11 | b := Vector3i { x: 3, ..zeroed } 12 | c := Vector3i { x: 3, y: 5, ..zeroed } 13 | d := Vector3i { x: 3, y: 5, z: 7, ..zeroed } 14 | e := Vector3i { z: 7, ..zeroed } 15 | f := Vector3i { y: 5, ..zeroed, x: 3 } 16 | 17 | print_vector(a) 18 | print_vector(b) 19 | print_vector(c) 20 | print_vector(d) 21 | print_vector(e) 22 | print_vector(f) 23 | } 24 | 25 | func print_vector(v Vector3i) { 26 | printf(c"x=%d, y=%d, z=%d\n", v.x, v.y, v.z) 27 | } 28 | 29 | --------------------------------------------------------------------------------