├── .cargo └── config.toml ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .rustfmt.toml ├── .vscode └── settings.json ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── TODO.md ├── assets └── logo.svg ├── benches ├── .gitignore ├── README.md ├── benches │ ├── fib.js │ ├── fib.lua │ ├── fib.py │ ├── fib.rs │ ├── primes.js │ ├── primes.lua │ ├── primes.py │ ├── primes.rs │ └── startup.rs ├── main.js ├── main.lua ├── main.py ├── main.rs └── package.json ├── cli ├── Cargo.toml └── src │ ├── lib │ ├── commands.rs │ ├── common.rs │ ├── hebi.rs │ ├── lib.rs │ └── repl.rs │ └── main.rs ├── docs ├── .gitignore ├── book.toml └── src │ ├── SUMMARY.md │ ├── classes.md │ ├── codegen.md │ ├── functions.md │ ├── getting-started.md │ ├── internals.md │ ├── modules.md │ ├── parser.md │ ├── regalloc.md │ ├── syntax.md │ └── value.md ├── examples ├── async_json_request.rs ├── async_native_type.rs ├── async_request.rs ├── basic.rs ├── disasm.rs ├── dump_vm_state.rs ├── globals.rs ├── hebi │ ├── count_primes.hebi │ ├── fib.hebi │ └── tic-tac-toe.hebi ├── input_output.rs ├── list_map.rs ├── native_async_fn.rs ├── native_fn.rs ├── native_type.rs ├── optional_params.rs └── worker_pool.rs ├── grammar.ebnf ├── src ├── internal │ ├── bytecode.rs │ ├── bytecode │ │ ├── builder.rs │ │ ├── builder │ │ │ ├── snapshots │ │ │ │ ├── hebi__internal__bytecode__builder__tests__basic_emit.snap │ │ │ │ ├── hebi__internal__bytecode__builder__tests__emit_constant.snap │ │ │ │ ├── hebi__internal__bytecode__builder__tests__emit_forward_jump_8bit.snap │ │ │ │ ├── hebi__internal__bytecode__builder__tests__emit_jump_loop.snap │ │ │ │ └── hebi__internal__bytecode__builder__tests__emit_multi_label.snap │ │ │ └── tests.rs │ │ ├── disasm.rs │ │ ├── opcode.rs │ │ ├── opcode │ │ │ ├── macros.rs │ │ │ └── tests.rs │ │ └── operands.rs │ ├── codegen.rs │ ├── codegen │ │ ├── expr.rs │ │ ├── regalloc.rs │ │ ├── regalloc │ │ │ ├── snapshots │ │ │ │ ├── hebi__internal__codegen__regalloc__tests__alloc_register_slice.snap │ │ │ │ ├── hebi__internal__codegen__regalloc__tests__overlapping.snap │ │ │ │ └── hebi__internal__codegen__regalloc__tests__simple.snap │ │ │ └── tests.rs │ │ ├── snapshots │ │ │ ├── hebi__internal__codegen__tests__call_0.snap │ │ │ ├── hebi__internal__codegen__tests__call_1.snap │ │ │ ├── hebi__internal__codegen__tests__call_arg_subexpr.snap │ │ │ ├── hebi__internal__codegen__tests__call_n.snap │ │ │ ├── hebi__internal__codegen__tests__class_derived_in_nested_scope_with_closure_method.snap │ │ │ ├── hebi__internal__codegen__tests__class_derived_with_field.snap │ │ │ ├── hebi__internal__codegen__tests__class_derived_with_field_and_closure_method.snap │ │ │ ├── hebi__internal__codegen__tests__class_derived_with_field_and_method.snap │ │ │ ├── hebi__internal__codegen__tests__class_derived_with_multiple_fields.snap │ │ │ ├── hebi__internal__codegen__tests__class_in_nested_scope_with_closure_method.snap │ │ │ ├── hebi__internal__codegen__tests__class_instance.snap │ │ │ ├── hebi__internal__codegen__tests__class_with_field.snap │ │ │ ├── hebi__internal__codegen__tests__class_with_field_and_closure_method.snap │ │ │ ├── hebi__internal__codegen__tests__class_with_field_and_method.snap │ │ │ ├── hebi__internal__codegen__tests__class_with_multiple_fields.snap │ │ │ ├── hebi__internal__codegen__tests__closure.snap │ │ │ ├── hebi__internal__codegen__tests__closure_call.snap │ │ │ ├── hebi__internal__codegen__tests__conditional_exprs.snap │ │ │ ├── hebi__internal__codegen__tests__conditional_exprs_precedence.snap │ │ │ ├── hebi__internal__codegen__tests__empty_class.snap │ │ │ ├── hebi__internal__codegen__tests__empty_class_derived.snap │ │ │ ├── hebi__internal__codegen__tests__fn_in_module.snap │ │ │ ├── hebi__internal__codegen__tests__for_iter_array.snap │ │ │ ├── hebi__internal__codegen__tests__for_range_0_to_10_inclusive_break.snap │ │ │ ├── hebi__internal__codegen__tests__for_range_0_to_10_inclusive_continue.snap │ │ │ ├── hebi__internal__codegen__tests__for_range_0_to_10_inclusive_print.snap │ │ │ ├── hebi__internal__codegen__tests__for_range_0_to_10_print.snap │ │ │ ├── hebi__internal__codegen__tests__function_no_params.snap │ │ │ ├── hebi__internal__codegen__tests__function_with_default_param.snap │ │ │ ├── hebi__internal__codegen__tests__function_with_param.snap │ │ │ ├── hebi__internal__codegen__tests__generator_no_params.snap │ │ │ ├── hebi__internal__codegen__tests__generator_with_default_param.snap │ │ │ ├── hebi__internal__codegen__tests__generator_with_param.snap │ │ │ ├── hebi__internal__codegen__tests__if_stmt.snap │ │ │ ├── hebi__internal__codegen__tests__if_stmt_var_resolution.snap │ │ │ ├── hebi__internal__codegen__tests__import_multi.snap │ │ │ ├── hebi__internal__codegen__tests__import_symbol.snap │ │ │ ├── hebi__internal__codegen__tests__import_symbol_multi.snap │ │ │ ├── hebi__internal__codegen__tests__import_whole.snap │ │ │ ├── hebi__internal__codegen__tests__loop_break.snap │ │ │ ├── hebi__internal__codegen__tests__loop_continue.snap │ │ │ ├── hebi__internal__codegen__tests__loop_nested_loop.snap │ │ │ ├── hebi__internal__codegen__tests__loop_nested_loop_break.snap │ │ │ ├── hebi__internal__codegen__tests__loop_nested_while.snap │ │ │ ├── hebi__internal__codegen__tests__loop_nested_while_break.snap │ │ │ ├── hebi__internal__codegen__tests__loop_print.snap │ │ │ ├── hebi__internal__codegen__tests__method_call_0.snap │ │ │ ├── hebi__internal__codegen__tests__method_call_1.snap │ │ │ ├── hebi__internal__codegen__tests__method_call_n.snap │ │ │ ├── hebi__internal__codegen__tests__nested_call_0.snap │ │ │ ├── hebi__internal__codegen__tests__nested_call_subexpr.snap │ │ │ ├── hebi__internal__codegen__tests__opt_chaining.snap │ │ │ ├── hebi__internal__codegen__tests__print_field.snap │ │ │ ├── hebi__internal__codegen__tests__print_field_opt.snap │ │ │ ├── hebi__internal__codegen__tests__print_float.snap │ │ │ ├── hebi__internal__codegen__tests__print_global.snap │ │ │ ├── hebi__internal__codegen__tests__print_index.snap │ │ │ ├── hebi__internal__codegen__tests__print_index_opt.snap │ │ │ ├── hebi__internal__codegen__tests__print_int.snap │ │ │ ├── hebi__internal__codegen__tests__print_list.snap │ │ │ ├── hebi__internal__codegen__tests__print_module_var.snap │ │ │ ├── hebi__internal__codegen__tests__print_string.snap │ │ │ ├── hebi__internal__codegen__tests__print_table.snap │ │ │ ├── hebi__internal__codegen__tests__variable_scope_lifetime.snap │ │ │ ├── hebi__internal__codegen__tests__while_break.snap │ │ │ ├── hebi__internal__codegen__tests__while_continue.snap │ │ │ ├── hebi__internal__codegen__tests__while_nested_loop.snap │ │ │ ├── hebi__internal__codegen__tests__while_nested_loop_break.snap │ │ │ ├── hebi__internal__codegen__tests__while_nested_while.snap │ │ │ ├── hebi__internal__codegen__tests__while_nested_while_break.snap │ │ │ ├── hebi__internal__codegen__tests__while_print.snap │ │ │ └── hebi__internal__codegen__tests__while_print_0_to_10.snap │ │ ├── stmt.rs │ │ ├── tests.rs │ │ └── tests │ │ │ └── macros.rs │ ├── error.rs │ ├── object.rs │ ├── object │ │ ├── builtin.rs │ │ ├── class.rs │ │ ├── function.rs │ │ ├── list.rs │ │ ├── module.rs │ │ ├── native.rs │ │ ├── ptr.rs │ │ ├── string.rs │ │ └── table.rs │ ├── serde.rs │ ├── syntax.rs │ ├── syntax │ │ ├── ast.rs │ │ ├── lexer.rs │ │ ├── lexer │ │ │ ├── snapshots │ │ │ │ └── hebi__internal__syntax__lexer__tests__lex_design_file.snap │ │ │ └── tests.rs │ │ ├── parser.rs │ │ └── parser │ │ │ ├── common.rs │ │ │ ├── expr.rs │ │ │ ├── indent.rs │ │ │ ├── module.rs │ │ │ ├── snapshots │ │ │ ├── hebi__internal__syntax__parser__tests__array_literal_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__assign_expr-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__assign_expr-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__assign_expr-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__assign_expr-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__assign_expr-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__assign_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__bad_class_stmt_fields_after_methods.snap │ │ │ ├── hebi__internal__syntax__parser__tests__bad_class_stmt_indented_base.snap │ │ │ ├── hebi__internal__syntax__parser__tests__bad_class_stmt_indented_colon_1.snap │ │ │ ├── hebi__internal__syntax__parser__tests__bad_class_stmt_indented_colon_2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__bad_class_stmt_indented_name.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-10.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-11.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-12.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-13.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-14.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-15.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-16.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-17.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-18.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-19.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-7.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-8.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr-9.snap │ │ │ ├── hebi__internal__syntax__parser__tests__binary_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__call_expr-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__call_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-10.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-11.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-12.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-7.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-8.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super-9.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_self_and_super.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_statements_allow_oneliners_in_multiline_mode.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_statements_inline_method_scoping.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_statements_support_inline_fields.snap │ │ │ ├── hebi__internal__syntax__parser__tests__class_statements_support_inline_methods.snap │ │ │ ├── hebi__internal__syntax__parser__tests__ctrl_stmt-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__ctrl_stmt-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__ctrl_stmt-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__ctrl_stmt-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__ctrl_stmt.snap │ │ │ ├── hebi__internal__syntax__parser__tests__duplicate_fields-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__duplicate_fields-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__duplicate_fields.snap │ │ │ ├── hebi__internal__syntax__parser__tests__fn_statement_supports_semicolons.snap │ │ │ ├── hebi__internal__syntax__parser__tests__for_statement_supports_semicolons.snap │ │ │ ├── hebi__internal__syntax__parser__tests__for_statements_can_be_nested_on_the_same_line.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-10.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-11.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-12.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-7.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-8.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt-9.snap │ │ │ ├── hebi__internal__syntax__parser__tests__func_stmt.snap │ │ │ ├── hebi__internal__syntax__parser__tests__funky_inline_indentation_mix.snap │ │ │ ├── hebi__internal__syntax__parser__tests__grouping_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_statement_supports_semicolons.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-10.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-11.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-7.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-8.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt-9.snap │ │ │ ├── hebi__internal__syntax__parser__tests__if_stmt.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_statements_support_semicolons.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-7.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt-8.snap │ │ │ ├── hebi__internal__syntax__parser__tests__import_stmt.snap │ │ │ ├── hebi__internal__syntax__parser__tests__infinite_loop_statements_support_semicolons.snap │ │ │ ├── hebi__internal__syntax__parser__tests__inline_for_indentation_enforcement.snap │ │ │ ├── hebi__internal__syntax__parser__tests__inline_return_statements.snap │ │ │ ├── hebi__internal__syntax__parser__tests__inline_tic_tac_toe.snap │ │ │ ├── hebi__internal__syntax__parser__tests__inline_while_indentation_enforcement.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts-6.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts-7.snap │ │ │ ├── hebi__internal__syntax__parser__tests__loop_stmts.snap │ │ │ ├── hebi__internal__syntax__parser__tests__many_semicolons.snap │ │ │ ├── hebi__internal__syntax__parser__tests__postfix_expr-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__postfix_expr-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__postfix_expr-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__postfix_expr-5.snap │ │ │ ├── hebi__internal__syntax__parser__tests__postfix_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__print_stmt-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__print_stmt.snap │ │ │ ├── hebi__internal__syntax__parser__tests__scope_double_semi.snap │ │ │ ├── hebi__internal__syntax__parser__tests__scope_nested_no_semi.snap │ │ │ ├── hebi__internal__syntax__parser__tests__scope_nested_single_semi.snap │ │ │ ├── hebi__internal__syntax__parser__tests__scope_no_semi.snap │ │ │ ├── hebi__internal__syntax__parser__tests__scope_single_semi.snap │ │ │ ├── hebi__internal__syntax__parser__tests__scoped_nested_double_semi.snap │ │ │ ├── hebi__internal__syntax__parser__tests__simple_literal_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__table_literal_expr-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__table_literal_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__trailing_statements_of_nested_blocks_are_included_in_outer_block_body.snap │ │ │ ├── hebi__internal__syntax__parser__tests__unary_expr-2.snap │ │ │ ├── hebi__internal__syntax__parser__tests__unary_expr-3.snap │ │ │ ├── hebi__internal__syntax__parser__tests__unary_expr-4.snap │ │ │ ├── hebi__internal__syntax__parser__tests__unary_expr.snap │ │ │ ├── hebi__internal__syntax__parser__tests__valid_class_stmts.snap │ │ │ ├── hebi__internal__syntax__parser__tests__while_statements_support_semicolons.snap │ │ │ └── hebi__internal__syntax__parser__tests__whole_module.snap │ │ │ ├── stmt.rs │ │ │ └── tests.rs │ ├── value.rs │ ├── value │ │ ├── constant.rs │ │ ├── nanbox.rs │ │ ├── portable.rs │ │ ├── snapshots │ │ │ └── hebi__internal__value__tests__create_value.snap │ │ └── tests.rs │ ├── vm.rs │ └── vm │ │ ├── dispatch.rs │ │ ├── dispatch │ │ └── macros.rs │ │ ├── global.rs │ │ ├── snapshots │ │ ├── hebi__internal__vm__tests__add_objects.snap │ │ ├── hebi__internal__vm__tests__arithmetic.snap │ │ ├── hebi__internal__vm__tests__array_equality.snap │ │ ├── hebi__internal__vm__tests__basic_fn_call.snap │ │ ├── hebi__internal__vm__tests__bool_add_error.snap │ │ ├── hebi__internal__vm__tests__bool_div_error.snap │ │ ├── hebi__internal__vm__tests__bool_equality.snap │ │ ├── hebi__internal__vm__tests__bool_ge_error.snap │ │ ├── hebi__internal__vm__tests__bool_gt_error.snap │ │ ├── hebi__internal__vm__tests__bool_le_error.snap │ │ ├── hebi__internal__vm__tests__bool_lt_error.snap │ │ ├── hebi__internal__vm__tests__bool_mul_error.snap │ │ ├── hebi__internal__vm__tests__bool_pow_error.snap │ │ ├── hebi__internal__vm__tests__bool_rem_error.snap │ │ ├── hebi__internal__vm__tests__bool_sub_error.snap │ │ ├── hebi__internal__vm__tests__builtin_collect.snap │ │ ├── hebi__internal__vm__tests__builtin_collect_native.snap │ │ ├── hebi__internal__vm__tests__builtin_list_methods.snap │ │ ├── hebi__internal__vm__tests__builtin_list_methods_bound.snap │ │ ├── hebi__internal__vm__tests__builtin_list_methods_static.snap │ │ ├── hebi__internal__vm__tests__builtin_parse_int.snap │ │ ├── hebi__internal__vm__tests__builtin_str_lines_iter.snap │ │ ├── hebi__internal__vm__tests__builtin_str_methods.snap │ │ ├── hebi__internal__vm__tests__builtin_str_methods_bound.snap │ │ ├── hebi__internal__vm__tests__builtin_str_methods_static.snap │ │ ├── hebi__internal__vm__tests__call_class_method.snap │ │ ├── hebi__internal__vm__tests__call_class_method2.snap │ │ ├── hebi__internal__vm__tests__call_class_method_derived.snap │ │ ├── hebi__internal__vm__tests__call_class_method_derived2.snap │ │ ├── hebi__internal__vm__tests__call_class_method_derived3.snap │ │ ├── hebi__internal__vm__tests__call_class_method_derived4.snap │ │ ├── hebi__internal__vm__tests__call_class_method_derived_static.snap │ │ ├── hebi__internal__vm__tests__call_class_method_derived_static2.snap │ │ ├── hebi__internal__vm__tests__call_class_nested_inheritance_method.snap │ │ ├── hebi__internal__vm__tests__call_class_nested_inheritance_method_static_call.snap │ │ ├── hebi__internal__vm__tests__call_fn_recursive.snap │ │ ├── hebi__internal__vm__tests__call_fn_with_args.snap │ │ ├── hebi__internal__vm__tests__call_fn_with_args__error_not_enough_args.snap │ │ ├── hebi__internal__vm__tests__call_fn_with_args__error_too_many_args.snap │ │ ├── hebi__internal__vm__tests__class_derived_nested_init_call_chain.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_init.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_init_and_call_parent_init.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_init_and_no_call_parent_init.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_method.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_parent_init.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_parent_method.snap │ │ ├── hebi__internal__vm__tests__class_derived_with_parent_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__class_with_init.snap │ │ ├── hebi__internal__vm__tests__class_with_init_conditional_false.snap │ │ ├── hebi__internal__vm__tests__class_with_init_conditional_true.snap │ │ ├── hebi__internal__vm__tests__class_with_method.snap │ │ ├── hebi__internal__vm__tests__class_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__closure_call.snap │ │ ├── hebi__internal__vm__tests__data_class_derived_with_method.snap │ │ ├── hebi__internal__vm__tests__data_class_derived_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__data_class_derived_with_parent_method.snap │ │ ├── hebi__internal__vm__tests__data_class_derived_with_parent_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__data_class_with_method.snap │ │ ├── hebi__internal__vm__tests__data_class_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__empty_table.snap │ │ ├── hebi__internal__vm__tests__example.snap │ │ ├── hebi__internal__vm__tests__for_iter_iterable_class.snap │ │ ├── hebi__internal__vm__tests__for_iter_list.snap │ │ ├── hebi__internal__vm__tests__get_class_field.snap │ │ ├── hebi__internal__vm__tests__get_class_method.snap │ │ ├── hebi__internal__vm__tests__get_class_parent_field.snap │ │ ├── hebi__internal__vm__tests__get_class_parent_method.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_bool.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_float__bad_input.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_float__float.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_float__int.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_int__bad_input.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_int__float.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_int__int.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__to_str.snap │ │ ├── hebi__internal__vm__tests__global_builtin_functions__type_of.snap │ │ ├── hebi__internal__vm__tests__heterogenous_type_equality.snap │ │ ├── hebi__internal__vm__tests__heterogenous_type_unequality.snap │ │ ├── hebi__internal__vm__tests__if_stmt.snap │ │ ├── hebi__internal__vm__tests__if_stmt_false.snap │ │ ├── hebi__internal__vm__tests__import_fn.snap │ │ ├── hebi__internal__vm__tests__import_fn_named.snap │ │ ├── hebi__internal__vm__tests__import_value.snap │ │ ├── hebi__internal__vm__tests__import_value_named.snap │ │ ├── hebi__internal__vm__tests__init_class_derived_with_method.snap │ │ ├── hebi__internal__vm__tests__init_class_derived_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__init_class_derived_with_parent_method.snap │ │ ├── hebi__internal__vm__tests__init_class_derived_with_parent_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__init_class_with_method.snap │ │ ├── hebi__internal__vm__tests__init_class_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__init_data_class_derived_with_method.snap │ │ ├── hebi__internal__vm__tests__init_data_class_derived_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__init_data_class_derived_with_parent_method.snap │ │ ├── hebi__internal__vm__tests__init_data_class_derived_with_parent_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__init_data_class_with_method.snap │ │ ├── hebi__internal__vm__tests__init_data_class_with_multiple_methods.snap │ │ ├── hebi__internal__vm__tests__init_simple_class.snap │ │ ├── hebi__internal__vm__tests__init_simple_class_derived.snap │ │ ├── hebi__internal__vm__tests__init_simple_data_class.snap │ │ ├── hebi__internal__vm__tests__init_simple_data_class_derived.snap │ │ ├── hebi__internal__vm__tests__init_simple_data_class_derived_with_parent_field.snap │ │ ├── hebi__internal__vm__tests__list_indexing_invalid.snap │ │ ├── hebi__internal__vm__tests__list_indexing_invalid_opt.snap │ │ ├── hebi__internal__vm__tests__list_indexing_negative.snap │ │ ├── hebi__internal__vm__tests__list_indexing_negative_opt.snap │ │ ├── hebi__internal__vm__tests__list_indexing_oob.snap │ │ ├── hebi__internal__vm__tests__list_indexing_oob_opt.snap │ │ ├── hebi__internal__vm__tests__list_indexing_positive.snap │ │ ├── hebi__internal__vm__tests__list_indexing_positive_opt.snap │ │ ├── hebi__internal__vm__tests__list_indexing_zero.snap │ │ ├── hebi__internal__vm__tests__list_indexing_zero_opt.snap │ │ ├── hebi__internal__vm__tests__logical_and_expr_return_lhs.snap │ │ ├── hebi__internal__vm__tests__logical_and_expr_return_rhs.snap │ │ ├── hebi__internal__vm__tests__logical_or_expr_return_lhs.snap │ │ ├── hebi__internal__vm__tests__logical_or_expr_return_rhs.snap │ │ ├── hebi__internal__vm__tests__make_fn.snap │ │ ├── hebi__internal__vm__tests__make_fn_with_args.snap │ │ ├── hebi__internal__vm__tests__make_large_table.snap │ │ ├── hebi__internal__vm__tests__module_fail_to_parse.snap │ │ ├── hebi__internal__vm__tests__module_not_found.snap │ │ ├── hebi__internal__vm__tests__module_vars.snap │ │ ├── hebi__internal__vm__tests__module_vars_per_module.snap │ │ ├── hebi__internal__vm__tests__more_optional_access.snap │ │ ├── hebi__internal__vm__tests__nested_optional_access.snap │ │ ├── hebi__internal__vm__tests__nested_table.snap │ │ ├── hebi__internal__vm__tests__none_add_error.snap │ │ ├── hebi__internal__vm__tests__none_div_error.snap │ │ ├── hebi__internal__vm__tests__none_equality.snap │ │ ├── hebi__internal__vm__tests__none_ge_error.snap │ │ ├── hebi__internal__vm__tests__none_gt_error.snap │ │ ├── hebi__internal__vm__tests__none_le_error.snap │ │ ├── hebi__internal__vm__tests__none_lt_error.snap │ │ ├── hebi__internal__vm__tests__none_mul_error.snap │ │ ├── hebi__internal__vm__tests__none_pow_error.snap │ │ ├── hebi__internal__vm__tests__none_rem_error.snap │ │ ├── hebi__internal__vm__tests__none_sub_error.snap │ │ ├── hebi__internal__vm__tests__object_equality.snap │ │ ├── hebi__internal__vm__tests__order_of_eval.snap │ │ ├── hebi__internal__vm__tests__regression__variable_scope_ends_too_early.snap │ │ ├── hebi__internal__vm__tests__simple_class.snap │ │ ├── hebi__internal__vm__tests__simple_class_derived.snap │ │ ├── hebi__internal__vm__tests__simple_data_class.snap │ │ ├── hebi__internal__vm__tests__simple_data_class_derived.snap │ │ ├── hebi__internal__vm__tests__simple_data_class_derived_with_parent_field.snap │ │ ├── hebi__internal__vm__tests__small_jump.snap │ │ ├── hebi__internal__vm__tests__string_comparison.snap │ │ ├── hebi__internal__vm__tests__table_access_keyed.snap │ │ ├── hebi__internal__vm__tests__table_access_named.snap │ │ ├── hebi__internal__vm__tests__table_access_unknown.snap │ │ ├── hebi__internal__vm__tests__table_equality.snap │ │ ├── hebi__internal__vm__tests__table_nested_access_keyed.snap │ │ ├── hebi__internal__vm__tests__unary_invert.snap │ │ ├── hebi__internal__vm__tests__unary_not.snap │ │ ├── hebi__internal__vm__tests__unary_not_float.snap │ │ ├── hebi__internal__vm__tests__unary_not_int.snap │ │ ├── hebi__internal__vm__tests__unary_not_none.snap │ │ ├── hebi__internal__vm__tests__unary_not_str.snap │ │ ├── hebi__internal__vm__tests__use_import_in_nested_scope.snap │ │ ├── hebi__internal__vm__tests__use_named_import_in_nested_scope.snap │ │ ├── hebi__internal__vm__tests__wide_const_jump.snap │ │ └── hebi__internal__vm__tests__wide_jump.snap │ │ ├── tests.rs │ │ ├── tests │ │ └── macros.rs │ │ ├── thread.rs │ │ └── thread │ │ ├── macros.rs │ │ └── util.rs ├── lib.rs ├── macros.rs ├── public.rs ├── public │ ├── macros.rs │ ├── module.rs │ ├── object.rs │ ├── object │ │ ├── function.rs │ │ ├── list.rs │ │ ├── string.rs │ │ └── table.rs │ └── value.rs ├── serde.rs ├── span.rs ├── span │ ├── snapshots │ │ ├── hebi__span__tests__emit_report_multi_line.snap │ │ ├── hebi__span__tests__emit_report_multi_line_edge_case_sandwiched_newline.snap │ │ ├── hebi__span__tests__emit_report_multi_line_edge_case_sandwiched_newline_2.snap │ │ ├── hebi__span__tests__emit_report_multi_line_large.snap │ │ ├── hebi__span__tests__emit_report_single_line.snap │ │ ├── hebi__span__tests__snippet_multi_line-2.snap │ │ ├── hebi__span__tests__snippet_multi_line-3.snap │ │ ├── hebi__span__tests__snippet_multi_line-4.snap │ │ ├── hebi__span__tests__snippet_multi_line-5.snap │ │ ├── hebi__span__tests__snippet_multi_line-6.snap │ │ ├── hebi__span__tests__snippet_multi_line-7.snap │ │ ├── hebi__span__tests__snippet_multi_line-8.snap │ │ ├── hebi__span__tests__snippet_multi_line.snap │ │ └── hebi__span__tests__snippet_single_line.snap │ └── tests.rs └── util.rs ├── v2.md ├── vscode-hebi ├── .gitignore ├── .vscode │ └── launch.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── language-configuration.json ├── package.json ├── syntaxes │ ├── hebi.tmLanguage.json │ └── highlight-hebi-string.json ├── test.hebi ├── test.rs └── vsc-extension-quickstart.md └── xtask ├── Cargo.toml ├── README.md └── src ├── main.rs ├── task.rs └── task ├── bench.rs ├── common.rs ├── examples.rs ├── miri.rs ├── snap.rs ├── template.rs └── test.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [alias] 2 | xtask = "run --package xtask --" 3 | x = "run --package xtask --" 4 | hebi = "run --quiet --package hebi-cli --" 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | 3 | # Generated by Cargo 4 | # will have compiled files and executables 5 | debug/ 6 | target/ 7 | target_ra/ 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | .mypy_cache/ 13 | 14 | # Profiling and cargo-flamegraph output 15 | perf.data* 16 | *.zst 17 | flamegraph*.svg 18 | 19 | # insta 20 | *.snap.new 21 | 22 | fuzz/libfuzzer/corpus 23 | fuzz/libfuzzer/artifacts 24 | fuzz/afl/artifacts 25 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | tab_spaces = 2 2 | imports_granularity = "module" 3 | group_imports = "StdExternalCrate" 4 | wrap_comments = true 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.showUnlinkedFileNotification": false, 3 | "rust-analyzer.check.extraArgs": ["--target-dir=./target_ra"], 4 | "rust-analyzer.cargo.features": ["serde"] 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Jan Procházka 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /benches/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /benches/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | Hebi benchmarks may be run using `cargo bench`. 4 | 5 | There are also JavaScript and Python versions of each benchmark for the purposes of comparison. 6 | 7 | At the moment, it seems like Hebi is typically ~2x slower than Python. 8 | -------------------------------------------------------------------------------- /benches/benches/fib.js: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | if (n <= 1) { 3 | return n; 4 | } else { 5 | return fib(n - 2) + fib(n - 1); 6 | } 7 | } 8 | 9 | module.exports = { fib }; 10 | 11 | -------------------------------------------------------------------------------- /benches/benches/fib.lua: -------------------------------------------------------------------------------- 1 | local _M = {} 2 | 3 | function _M.fib(n) 4 | function inner(n) 5 | if n <= 1 then return n end 6 | return inner(n-2) + inner(n-1) 7 | end 8 | return inner(n) 9 | end 10 | 11 | return _M 12 | -------------------------------------------------------------------------------- /benches/benches/fib.py: -------------------------------------------------------------------------------- 1 | def fib(n): 2 | if n <= 1: 3 | return n 4 | else: 5 | return fib(n - 2) + fib(n - 1) 6 | -------------------------------------------------------------------------------- /benches/benches/primes.js: -------------------------------------------------------------------------------- 1 | function primes(max_number) { 2 | const prime_mask = Array(max_number).fill(true); 3 | 4 | prime_mask[0] = false; 5 | prime_mask[1] = false; 6 | 7 | let total_primes_found = 0; 8 | 9 | for (let p = 2; p <= max_number; p += 1) { 10 | if (!prime_mask[p]) continue; 11 | 12 | total_primes_found += 1; 13 | 14 | let i = 2 * p; 15 | while (i < max_number + 1) { 16 | prime_mask[i] = false; 17 | i += p; 18 | } 19 | } 20 | 21 | return total_primes_found; 22 | } 23 | 24 | module.exports = { primes }; 25 | 26 | -------------------------------------------------------------------------------- /benches/benches/primes.lua: -------------------------------------------------------------------------------- 1 | local _M = {} 2 | 3 | function _M.primes(max_number) 4 | local prime_mask = {} 5 | for i = 1,max_number do 6 | prime_mask[i] = true 7 | end 8 | 9 | prime_mask[0] = false 10 | prime_mask[1] = false 11 | 12 | local total_primes_found = 0 13 | 14 | for p = 2, max_number do 15 | if not prime_mask[p] then goto continue end 16 | 17 | total_primes_found = total_primes_found + 1 18 | 19 | local i = 2 * p 20 | while i < max_number + 1 do 21 | prime_mask[i] = false 22 | i = i + p 23 | end 24 | 25 | ::continue:: 26 | end 27 | 28 | return total_primes_found 29 | end 30 | 31 | return _M 32 | -------------------------------------------------------------------------------- /benches/benches/primes.py: -------------------------------------------------------------------------------- 1 | def primes(max_number): 2 | prime_mask = [True] * (max_number + 1) 3 | 4 | prime_mask[0] = False 5 | prime_mask[1] = False 6 | 7 | total_primes_found = 0 8 | for p in range(2, max_number + 1): 9 | if not prime_mask[p]: 10 | continue 11 | 12 | total_primes_found += 1 13 | 14 | i = 2 * p 15 | while i < max_number + 1: 16 | prime_mask[i] = False 17 | i += p 18 | 19 | return total_primes_found 20 | -------------------------------------------------------------------------------- /benches/benches/primes.rs: -------------------------------------------------------------------------------- 1 | use criterion::{criterion_group, Criterion}; 2 | use hebi::Hebi; 3 | 4 | #[allow(dead_code)] 5 | pub fn primes(c: &mut Criterion) { 6 | c.bench_function("primes", |b| { 7 | let mut hebi = Hebi::new(); 8 | 9 | let chunk = hebi 10 | .compile(indoc::indoc! { 11 | r#"#!hebi 12 | fn primes(max_number): 13 | prime_mask := [] 14 | prime_mask.extend(max_number+1, true) 15 | 16 | prime_mask[0] = false 17 | prime_mask[1] = false 18 | 19 | total_primes_found := 0 20 | for p in 2..=max_number: 21 | if !prime_mask[p]: continue 22 | 23 | total_primes_found += 1 24 | 25 | i := 2 * p 26 | while i < max_number + 1: 27 | prime_mask[i] = false 28 | i += p 29 | 30 | return total_primes_found 31 | 32 | primes(1000000) 33 | "#, 34 | }) 35 | .unwrap(); 36 | 37 | b.iter(|| { 38 | let answer = hebi.run(chunk.clone()).unwrap().as_int().unwrap(); 39 | assert_eq!(answer, 78_498); 40 | }) 41 | }); 42 | } 43 | 44 | criterion_group!(bench, primes); 45 | -------------------------------------------------------------------------------- /benches/main.lua: -------------------------------------------------------------------------------- 1 | local socket = require("socket") 2 | local fib = require("./benches/fib") 3 | local primes = require("./benches/primes") 4 | 5 | local UNITS = {"s", "ms", "μs", "ns", "ps"} 6 | function format_iter(iter) 7 | local unit = 1 8 | 9 | while iter < 1 do 10 | iter = iter * 1000 11 | unit = unit + 1 12 | end 13 | 14 | return string.format("%.3f %s/iter", iter, UNITS[unit]) 15 | end 16 | 17 | function run_bench(name, f, N) 18 | local N = N or 10000 19 | 20 | local total = 0 21 | for i = 1, N do 22 | local start = socket.gettime() 23 | f() 24 | total = total + (socket.gettime() - start) 25 | end 26 | 27 | return string.format("%s: %s", name, format_iter(total / N)) 28 | end 29 | 30 | 31 | local run = {} 32 | for _, v in ipairs(arg) do 33 | run[v] = true 34 | end 35 | 36 | local ran_something = false 37 | if run["fib"] then 38 | ran_something = true 39 | print(run_bench("fib(15)", function() fib.fib(15) end)) 40 | print(run_bench("fib(20)", function() fib.fib(20) end)) 41 | end 42 | 43 | if run["primes"] then 44 | ran_something = true 45 | print(run_bench("primes(1000000)", function() primes.primes(1000000) end, 1000)) 46 | end 47 | 48 | if not ran_something then 49 | print("no bench specified. options: fib, primes") 50 | end 51 | -------------------------------------------------------------------------------- /benches/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from benches.fib import fib # noqa: F401 3 | from benches.primes import primes # noqa: F401 4 | 5 | 6 | def format_iter(iter): 7 | units = ["s", "ms", "μs", "ns", "ps"] 8 | unit = 0 9 | 10 | while iter < 1: 11 | iter *= 1000 12 | unit += 1 13 | 14 | return f"{round(iter, ndigits=3)} {units[unit]}/iter" 15 | 16 | 17 | def run_bench(str, globals, N=10000): 18 | iter = timeit(str, globals=globals, number=N) / float(N) 19 | return f"{str}: {format_iter(iter)}" 20 | 21 | 22 | if __name__ == "__main__": 23 | from timeit import timeit 24 | 25 | if "fib" in sys.argv[1:]: 26 | print(run_bench("fib(15)", globals=locals())) 27 | print(run_bench("fib(20)", globals=locals())) 28 | if "primes" in sys.argv[1:]: 29 | print(run_bench("primes(1000000)", globals=locals(), N=100)) 30 | -------------------------------------------------------------------------------- /benches/main.rs: -------------------------------------------------------------------------------- 1 | use criterion::criterion_main; 2 | 3 | mod benches { 4 | pub mod fib; 5 | pub mod primes; 6 | pub mod startup; 7 | } 8 | 9 | #[cfg(enable_slow_bench)] 10 | criterion_main! { 11 | benches::fib::bench, 12 | benches::startup::bench, 13 | benches::primes::bench, 14 | } 15 | 16 | #[cfg(not(enable_slow_bench))] 17 | criterion_main! { 18 | benches::fib::bench, 19 | benches::startup::bench, 20 | } 21 | -------------------------------------------------------------------------------- /benches/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "benches", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "main.js", 6 | "scripts": { 7 | "bench": "node --jitless main.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "benchmark": "^2.1.4" 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hebi-cli" 3 | version = "0.0.0" 4 | edition = "2021" 5 | publish = false 6 | 7 | 8 | [[bin]] 9 | path = "src/main.rs" 10 | name = "hebi" 11 | 12 | [lib] 13 | path = "src/lib/lib.rs" 14 | name = "hebi_cli" 15 | 16 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 17 | 18 | [dependencies] 19 | anyhow = "1.0.71" 20 | atty = "0.2.14" 21 | clap = { version = "4.3.11", features = ["derive"] } 22 | crossterm = "0.26.1" 23 | hebi = { path = "../" } 24 | supports-color = "2.0.0" 25 | -------------------------------------------------------------------------------- /cli/src/lib/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod commands; 2 | pub mod common; 3 | mod hebi; 4 | pub mod repl; 5 | -------------------------------------------------------------------------------- /cli/src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | use hebi_cli::commands::Command; 3 | use hebi_cli::common::InputArgs; 4 | 5 | #[derive(Debug, Parser)] 6 | #[clap(name = "hebi", version)] 7 | pub struct App { 8 | #[clap(subcommand)] 9 | command: Option, 10 | 11 | // Args for the default run command 12 | #[clap(flatten)] 13 | input: InputArgs, 14 | } 15 | 16 | fn main() -> anyhow::Result<()> { 17 | let app = App::parse(); 18 | 19 | let command = app 20 | .command 21 | .unwrap_or_else(|| Command::run(app.input.clone())); 22 | 23 | command.execute()?; 24 | 25 | Ok(()) 26 | } 27 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | book 2 | -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["jprochazk"] 3 | language = "en" 4 | multilingual = false 5 | src = "src" 6 | title = "Hebi" 7 | -------------------------------------------------------------------------------- /docs/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Hebi 2 | 3 | - [Getting Started](./getting-started.md) 4 | 5 | ## Language 6 | 7 | - [Functions](./functions.md) 8 | - [Classes](./classes.md) 9 | - [Modules](./modules.md) 10 | 11 | --- 12 | 13 | - [Internals](./internals.md) 14 | - [Codegen](./codegen.md) 15 | - [Parser](./parser.md) 16 | - [Register Allocation](./regalloc.md) 17 | - [Value Representation](./value.md) 18 | -------------------------------------------------------------------------------- /docs/src/classes.md: -------------------------------------------------------------------------------- 1 | # Classes 2 | -------------------------------------------------------------------------------- /docs/src/functions.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | -------------------------------------------------------------------------------- /docs/src/getting-started.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jprochazk/hebi/edb15c5499b8549bd97240451f0a8f43df736941/docs/src/getting-started.md -------------------------------------------------------------------------------- /docs/src/internals.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jprochazk/hebi/edb15c5499b8549bd97240451f0a8f43df736941/docs/src/internals.md -------------------------------------------------------------------------------- /docs/src/modules.md: -------------------------------------------------------------------------------- 1 | # Modules 2 | -------------------------------------------------------------------------------- /docs/src/syntax.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jprochazk/hebi/edb15c5499b8549bd97240451f0a8f43df736941/docs/src/syntax.md -------------------------------------------------------------------------------- /examples/async_native_type.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | #[tokio::main] 4 | async fn main() { 5 | struct Client { 6 | inner: reqwest::Client, 7 | } 8 | 9 | impl Client { 10 | fn new() -> Self { 11 | Self { 12 | inner: reqwest::Client::new(), 13 | } 14 | } 15 | 16 | async fn get(scope: Scope<'_>, this: This<'_, Client>) -> hebi::Result { 17 | let url = scope.param::(0)?; 18 | let request = this.inner.get(url.as_str()); 19 | let response = request.send().await.map_err(hebi::Error::user)?; 20 | let bytes = response.bytes().await.map_err(hebi::Error::user)?.to_vec(); 21 | let str = String::from_utf8(bytes).map_err(hebi::Error::user)?; 22 | Ok(str) 23 | } 24 | } 25 | 26 | let module = NativeModule::builder("http") 27 | .class::("Client", |class| { 28 | class 29 | .init(|_| Ok(Client::new())) 30 | .async_method("get", Client::get) 31 | .finish() 32 | }) 33 | .finish(); 34 | 35 | let mut hebi = Hebi::new(); 36 | hebi.register(&module); 37 | 38 | hebi 39 | .eval_async( 40 | r#" 41 | import http 42 | 43 | c := http.Client() 44 | print c.get("https://jsonplaceholder.typicode.com/todos/1") 45 | "#, 46 | ) 47 | .await 48 | .unwrap(); 49 | } 50 | -------------------------------------------------------------------------------- /examples/basic.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | let mut hebi = Hebi::new(); 5 | hebi 6 | .eval( 7 | r#" 8 | print "Hello, world!" 9 | "#, 10 | ) 11 | .unwrap(); 12 | } 13 | -------------------------------------------------------------------------------- /examples/disasm.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | let mut hebi = Hebi::new(); 5 | let chunk = hebi.compile("1 + 1").unwrap(); 6 | println!("{}", chunk.disassemble()); 7 | println!("Result: {}", hebi.run(chunk).unwrap()); 8 | } 9 | -------------------------------------------------------------------------------- /examples/dump_vm_state.rs: -------------------------------------------------------------------------------- 1 | use std::panic::AssertUnwindSafe; 2 | 3 | use futures_util::FutureExt; 4 | use hebi::prelude::*; 5 | 6 | #[tokio::main] 7 | async fn main() -> Result<(), Box> { 8 | let mut hebi = Hebi::new(); 9 | 10 | let code = r#" 11 | args := ctx.args() 12 | 13 | if args: 14 | ws_sender.send("!pong " + args.join(" ")) 15 | else: 16 | ws_sender.send("!pong") 17 | "#; 18 | 19 | eprintln!("{hebi:#?}"); 20 | 21 | match AssertUnwindSafe(hebi.eval_async(code)).catch_unwind().await { 22 | Ok(result) => match result { 23 | Ok(value) => println!("Value: {value}"), 24 | Err(e) => println!("Error: {e}"), 25 | }, 26 | Err(e) => { 27 | eprintln!("{hebi:?}"); 28 | panic!("{e:?}"); 29 | } 30 | } 31 | 32 | eprintln!("{hebi:#?}"); 33 | 34 | Ok(()) 35 | } 36 | -------------------------------------------------------------------------------- /examples/globals.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | fn example(scope: Scope) -> hebi::Result<()> { 5 | scope 6 | .global() 7 | .set(scope.new_string("internal"), scope.param(0)?); 8 | Ok(()) 9 | } 10 | 11 | let module = NativeModule::builder("test") 12 | .function("example", example) 13 | .finish(); 14 | 15 | let mut hebi = Hebi::new(); 16 | hebi.register(&module); 17 | 18 | hebi.global().set( 19 | hebi.new_string("external"), 20 | (100i32).into_value(hebi.global()).unwrap(), 21 | ); 22 | 23 | hebi 24 | .eval( 25 | r#" 26 | from test import example 27 | 28 | example(50) 29 | 30 | print "in hebi" 31 | print "external:", external 32 | print "internal:", internal 33 | print "" 34 | "#, 35 | ) 36 | .unwrap(); 37 | 38 | println!("outside hebi"); 39 | for (key, value) in hebi.global().entries() { 40 | println!("{key}: {value}"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/hebi/count_primes.hebi: -------------------------------------------------------------------------------- 1 | fn count_primes(max_number): 2 | prime_mask := [] 3 | prime_mask.extend(max_number + 1, true) 4 | 5 | prime_mask[0] = false 6 | prime_mask[1] = false 7 | 8 | total_primes_found := 0 9 | for p in 2..=max_number: 10 | if !prime_mask[p]: continue 11 | total_primes_found += 1 12 | 13 | i := 2 * p 14 | while i < max_number + 1: 15 | prime_mask[i] = false 16 | i += p 17 | 18 | return total_primes_found 19 | 20 | print "π(1000) =", count_primes(1000) -------------------------------------------------------------------------------- /examples/hebi/fib.hebi: -------------------------------------------------------------------------------- 1 | fn fib(n): 2 | a := 0 3 | b := 1 4 | for _ in 0..n: 5 | tmp := a + b 6 | a = b 7 | b = tmp 8 | return a 9 | 10 | print "Fib(20) = ", fib(20) 11 | -------------------------------------------------------------------------------- /examples/input_output.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | fn print_value(scope: Scope) -> hebi::Result<()> { 5 | let value = scope.param::(0)?; 6 | scope.global().println(format_args!("value is: {value}"))?; 7 | Ok(()) 8 | } 9 | 10 | let module = NativeModule::builder("example") 11 | .function("print_value", print_value) 12 | .finish(); 13 | 14 | let mut hebi = Hebi::builder().output(Vec::::new()).finish(); 15 | hebi.register(&module); 16 | hebi 17 | .eval( 18 | r#" 19 | import example 20 | example.print_value(100) 21 | "#, 22 | ) 23 | .unwrap(); 24 | 25 | let output = String::from_utf8( 26 | hebi 27 | .global() 28 | .output() 29 | .as_any() 30 | .downcast_ref::>() 31 | .cloned() 32 | .unwrap(), 33 | ) 34 | .unwrap(); 35 | print!("{output}"); 36 | } 37 | -------------------------------------------------------------------------------- /examples/list_map.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | async fn map(mut scope: Scope<'_>) -> hebi::Result> { 5 | let (list, cb) = scope.params::<(List, Any)>()?; 6 | 7 | let out = scope.new_list(list.len()); 8 | for i in 0..list.len() { 9 | let value = scope.call(cb.clone(), &[list.get(i).unwrap()]).await?; 10 | out.push(value); 11 | } 12 | 13 | Ok(out) 14 | } 15 | 16 | let module = NativeModule::builder("test") 17 | .async_function("map", map) 18 | .finish(); 19 | 20 | let mut hebi = Hebi::new(); 21 | hebi.register(&module); 22 | 23 | let result = hebi 24 | .eval( 25 | r#" 26 | from test import map 27 | 28 | fn add1(v): 29 | return v + 1 30 | 31 | map([0, 1, 2], add1) 32 | "#, 33 | ) 34 | .unwrap(); 35 | 36 | println!("{result:?}") 37 | } 38 | -------------------------------------------------------------------------------- /examples/native_async_fn.rs: -------------------------------------------------------------------------------- 1 | use std::time::Duration; 2 | 3 | use hebi::prelude::*; 4 | 5 | #[tokio::main] 6 | async fn main() { 7 | async fn example(sender: flume::Sender) -> i32 { 8 | tokio::time::sleep(Duration::from_millis(10)).await; 9 | 10 | sender.send_async("test".into()).await.unwrap(); 11 | 12 | 10i32 13 | } 14 | 15 | let (tx, rx) = flume::bounded(256); 16 | 17 | let module = NativeModule::builder("test") 18 | .async_function("example", move |_| example(tx.clone())) 19 | .finish(); 20 | 21 | let mut hebi = Hebi::new(); 22 | hebi.register(&module); 23 | 24 | let result = hebi 25 | .eval_async( 26 | r#" 27 | from test import example 28 | example() 29 | "#, 30 | ) 31 | .await 32 | .unwrap(); 33 | 34 | println!("Result is: {result}"); 35 | println!("Channel got: {}", rx.recv_async().await.unwrap()); 36 | } 37 | -------------------------------------------------------------------------------- /examples/native_fn.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | fn example(_: Scope) -> i32 { 5 | 100i32 6 | } 7 | 8 | fn add1(scope: Scope) -> hebi::Result { 9 | let value = scope.param::(0)?; 10 | Ok(value + 1) 11 | } 12 | 13 | let module = NativeModule::builder("test") 14 | .function("example", example) 15 | .function("add1", add1) 16 | .finish(); 17 | 18 | let mut hebi = Hebi::new(); 19 | hebi.register(&module); 20 | 21 | let result = hebi 22 | .eval( 23 | r#" 24 | from test import example, add1 25 | add1(example()) 26 | "#, 27 | ) 28 | .unwrap(); 29 | 30 | println!("Result is: {result}"); 31 | } 32 | -------------------------------------------------------------------------------- /examples/optional_params.rs: -------------------------------------------------------------------------------- 1 | use hebi::prelude::*; 2 | 3 | fn main() { 4 | fn example(scope: Scope) { 5 | if scope.num_args() > 0 { 6 | if let Some(value) = scope.param::>(0).unwrap() { 7 | println!("Got: {value}"); 8 | return; 9 | } 10 | } 11 | println!("Got nothing"); 12 | } 13 | 14 | let module = NativeModule::builder("test") 15 | .function("example", example) 16 | .finish(); 17 | 18 | let mut hebi = Hebi::new(); 19 | hebi.register(&module); 20 | 21 | hebi 22 | .eval( 23 | r#" 24 | from test import example 25 | 26 | example() 27 | example(none) 28 | example("some") 29 | "#, 30 | ) 31 | .unwrap(); 32 | } 33 | -------------------------------------------------------------------------------- /src/internal/bytecode.rs: -------------------------------------------------------------------------------- 1 | pub mod builder; 2 | pub mod disasm; 3 | pub mod opcode; 4 | pub mod operands; 5 | -------------------------------------------------------------------------------- /src/internal/bytecode/builder/snapshots/hebi__internal__bytecode__builder__tests__basic_emit.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/bytecode/builder/tests.rs 3 | expression: "Disassembly::new(&bytecode, &constants, 0, true).to_string()" 4 | --- 5 | 0 | load_smi 10 6 | 2 | store r0 7 | 4 | load_smi 5 8 | 6 | add r0 9 | 8 | print 10 | -------------------------------------------------------------------------------- /src/internal/bytecode/builder/snapshots/hebi__internal__bytecode__builder__tests__emit_constant.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/bytecode/builder/tests.rs 3 | expression: "Disassembly::new(&bytecode, &constants, 0, true).to_string()" 4 | --- 5 | 0 | load_const [0]; 10 6 | 2 | load_const [1]; 5 7 | 4 | load_const [0]; 10 8 | -------------------------------------------------------------------------------- /src/internal/bytecode/builder/snapshots/hebi__internal__bytecode__builder__tests__emit_forward_jump_8bit.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/bytecode/builder/tests.rs 3 | expression: "Disassembly::new(&bytecode, &constants, 0, true).to_string()" 4 | --- 5 | 0 | nop 6 | 1 | jump 8 7 | 3 | nop 8 | 4 | nop 9 | 5 | nop 10 | 6 | nop 11 | 7 | nop 12 | 8 | nop 13 | 9 | return 14 | -------------------------------------------------------------------------------- /src/internal/bytecode/builder/snapshots/hebi__internal__bytecode__builder__tests__emit_jump_loop.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/bytecode/builder/tests.rs 3 | expression: "Disassembly::new(&bytecode, &constants, 0, true).to_string()" 4 | --- 5 | 0 | nop 6 | 1 | nop 7 | 2 | nop 8 | 3 | nop 9 | 4 | jump_loop 3 10 | 6 | return 11 | -------------------------------------------------------------------------------- /src/internal/bytecode/builder/snapshots/hebi__internal__bytecode__builder__tests__emit_multi_label.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/bytecode/builder/tests.rs 3 | expression: "Disassembly::new(&bytecode, &constants, 0, true).to_string()" 4 | --- 5 | 0 | nop 6 | 1 | jump 12 7 | 3 | nop 8 | 4 | jump 9 9 | 6 | nop 10 | 7 | jump 6 11 | 9 | nop 12 | 10 | jump 3 13 | 12 | nop 14 | 13 | return 15 | -------------------------------------------------------------------------------- /src/internal/codegen/regalloc/snapshots/hebi__internal__codegen__regalloc__tests__alloc_register_slice.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/regalloc/tests.rs 3 | expression: "DisplayGraph(®alloc.0.borrow(), registers, &map).to_string()" 4 | --- 5 | registers = 5 6 | r0 │ 0━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━● 7 | r1 │ 1━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━● 8 | r2 │ 2━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━● 9 | r3 │ 3━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━● 10 | r4 │ 4━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━● 11 | ┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | -------------------------------------------------------------------------------- /src/internal/codegen/regalloc/snapshots/hebi__internal__codegen__regalloc__tests__overlapping.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/regalloc/tests.rs 3 | expression: "DisplayGraph(®alloc.0.borrow(), registers, &map).to_string()" 4 | --- 5 | registers = 4 6 | r0 │ 0━━━━━━━● 7 | r1 │ 1━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━● 8 | r2 │ 0━━━━━━━━━━━━━━━━━━━● 9 | r3 │ 2━━━━━━━━━━━● 10 | r4 │ 3━━━● 11 | ┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12 | 0 1 2 3 4 5 6 7 8 9 10 13 | -------------------------------------------------------------------------------- /src/internal/codegen/regalloc/snapshots/hebi__internal__codegen__regalloc__tests__simple.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/regalloc/tests.rs 3 | expression: "DisplayGraph(®alloc.0.borrow(), registers, &map).to_string()" 4 | --- 5 | registers = 2 6 | r0 │ 0━━━━━● 7 | r1 │ 1━━━━━━━━━━━━━━━━━● 8 | r2 │ 0━━● 9 | ┕━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10 | 0 1 2 3 4 5 6 7 8 11 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__call_0.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | f() 7 | 8 | # Func: 9 | function `main` (registers: 1, length: 4, constants: 1) 10 | .code 11 | 0 | load_global [0]; f 12 | 2 | call0 13 | 3 | return 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__call_1.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | f(0) 7 | 8 | # Func: 9 | function `main` (registers: 3, length: 12, constants: 1) 10 | .code 11 | 0 | load_global [0]; f 12 | 2 | store r1 13 | 4 | load_smi 0 14 | 6 | store r2 15 | 8 | call r1, 1 16 | 11 | return 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__call_arg_subexpr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | f(a+b) 7 | 8 | # Func: 9 | function `main` (registers: 4, length: 18, constants: 3) 10 | .code 11 | 0 | load_global [0]; f 12 | 2 | store r1 13 | 4 | load_global [1]; a 14 | 6 | store r3 15 | 8 | load_global [2]; b 16 | 10 | add r3 17 | 12 | store r2 18 | 14 | call r1, 1 19 | 17 | return 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__call_n.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | f(0, 1, 2) 7 | 8 | # Func: 9 | function `main` (registers: 5, length: 20, constants: 1) 10 | .code 11 | 0 | load_global [0]; f 12 | 2 | store r1 13 | 4 | load_smi 0 14 | 6 | store r2 15 | 8 | load_smi 1 16 | 10 | store r3 17 | 12 | load_smi 2 18 | 14 | store r4 19 | 16 | call r1, 3 20 | 19 | return 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_derived_in_nested_scope_with_closure_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(): 7 | u := 0 8 | class T(U): 9 | v = 0 10 | fn test(self): 11 | print self.v, u 12 | 13 | 14 | # Func: 15 | function `T.test` (registers: 3, length: 14, constants: 1) 16 | .upvalues 17 | 0 <- r1 18 | .code 19 | 0 | load_self 20 | 1 | load_field [0]; v 21 | 3 | store r1 22 | 5 | load_upvalue ^0 23 | 7 | store r2 24 | 9 | print_n r1, 2 25 | 12 | load_none 26 | 13 | return 27 | 28 | 29 | function `test` (registers: 4, length: 19, constants: 2) 30 | .code 31 | 0 | load_smi 0 32 | 2 | store r1 33 | 4 | load_global [1]; U 34 | 6 | store r2 35 | 8 | load_smi 0 36 | 10 | store r3 37 | 12 | make_data_class_derived [0], r2; 38 | 15 | store r2 39 | 17 | load_none 40 | 18 | return 41 | 42 | 43 | function `main` (registers: 1, length: 5, constants: 2) 44 | .code 45 | 0 | make_fn [0]; 46 | 2 | store_global [1]; test 47 | 4 | return 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_derived_with_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T(U): 7 | v = 0 8 | 9 | 10 | # Func: 11 | function `main` (registers: 3, length: 14, constants: 3) 12 | .code 13 | 0 | load_global [1]; U 14 | 2 | store r1 15 | 4 | load_smi 0 16 | 6 | store r2 17 | 8 | make_data_class_derived [0], r1; 18 | 11 | store_global [2]; T 19 | 13 | return 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_derived_with_field_and_closure_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | u := 0 7 | class T(U): 8 | v = 0 9 | fn test(self): 10 | print self.v, u 11 | 12 | 13 | # Func: 14 | function `T.test` (registers: 3, length: 14, constants: 2) 15 | .code 16 | 0 | load_self 17 | 1 | load_field [0]; v 18 | 3 | store r1 19 | 5 | load_global [1]; u 20 | 7 | store r2 21 | 9 | print_n r1, 2 22 | 12 | load_none 23 | 13 | return 24 | 25 | 26 | function `main` (registers: 3, length: 18, constants: 4) 27 | .code 28 | 0 | load_smi 0 29 | 2 | store_global [0]; u 30 | 4 | load_global [2]; U 31 | 6 | store r1 32 | 8 | load_smi 0 33 | 10 | store r2 34 | 12 | make_data_class_derived [1], r1; 35 | 15 | store_global [3]; T 36 | 17 | return 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_derived_with_field_and_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T(U): 7 | v = 0 8 | fn test(self): 9 | print self.v 10 | 11 | 12 | # Func: 13 | function `T.test` (registers: 1, length: 6, constants: 1) 14 | .code 15 | 0 | load_self 16 | 1 | load_field [0]; v 17 | 3 | print 18 | 4 | load_none 19 | 5 | return 20 | 21 | 22 | function `main` (registers: 3, length: 14, constants: 3) 23 | .code 24 | 0 | load_global [1]; U 25 | 2 | store r1 26 | 4 | load_smi 0 27 | 6 | store r2 28 | 8 | make_data_class_derived [0], r1; 29 | 11 | store_global [2]; T 30 | 13 | return 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_derived_with_multiple_fields.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T(U): 7 | a = 0 8 | b = 1 9 | 10 | 11 | # Func: 12 | function `main` (registers: 4, length: 18, constants: 3) 13 | .code 14 | 0 | load_global [1]; U 15 | 2 | store r1 16 | 4 | load_smi 0 17 | 6 | store r2 18 | 8 | load_smi 1 19 | 10 | store r3 20 | 12 | make_data_class_derived [0], r1; 21 | 15 | store_global [2]; T 22 | 17 | return 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_in_nested_scope_with_closure_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(): 7 | u := 0 8 | class T: 9 | v = 0 10 | fn test(self): 11 | print self.v, u 12 | 13 | 14 | # Func: 15 | function `T.test` (registers: 3, length: 14, constants: 1) 16 | .upvalues 17 | 0 <- r1 18 | .code 19 | 0 | load_self 20 | 1 | load_field [0]; v 21 | 3 | store r1 22 | 5 | load_upvalue ^0 23 | 7 | store r2 24 | 9 | print_n r1, 2 25 | 12 | load_none 26 | 13 | return 27 | 28 | 29 | function `test` (registers: 3, length: 15, constants: 1) 30 | .code 31 | 0 | load_smi 0 32 | 2 | store r1 33 | 4 | load_smi 0 34 | 6 | store r2 35 | 8 | make_data_class [0], r2; 36 | 11 | store r2 37 | 13 | load_none 38 | 14 | return 39 | 40 | 41 | function `main` (registers: 1, length: 5, constants: 2) 42 | .code 43 | 0 | make_fn [0]; 44 | 2 | store_global [1]; test 45 | 4 | return 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_instance.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T: pass 7 | 8 | T() 9 | 10 | 11 | # Func: 12 | function `main` (registers: 1, length: 8, constants: 2) 13 | .code 14 | 0 | make_class [0]; 15 | 2 | store_global [1]; T 16 | 4 | load_global [1]; T 17 | 6 | call0 18 | 7 | return 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_with_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T: 7 | v = 0 8 | 9 | 10 | # Func: 11 | function `main` (registers: 2, length: 10, constants: 2) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store r1 15 | 4 | make_data_class [0], r1; 16 | 7 | store_global [1]; T 17 | 9 | return 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_with_field_and_closure_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | u := 0 7 | class T: 8 | v = 0 9 | fn test(self): 10 | print self.v, u 11 | 12 | 13 | # Func: 14 | function `T.test` (registers: 3, length: 14, constants: 2) 15 | .code 16 | 0 | load_self 17 | 1 | load_field [0]; v 18 | 3 | store r1 19 | 5 | load_global [1]; u 20 | 7 | store r2 21 | 9 | print_n r1, 2 22 | 12 | load_none 23 | 13 | return 24 | 25 | 26 | function `main` (registers: 2, length: 14, constants: 3) 27 | .code 28 | 0 | load_smi 0 29 | 2 | store_global [0]; u 30 | 4 | load_smi 0 31 | 6 | store r1 32 | 8 | make_data_class [1], r1; 33 | 11 | store_global [2]; T 34 | 13 | return 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_with_field_and_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T: 7 | v = 0 8 | fn test(self): 9 | print self.v 10 | 11 | 12 | # Func: 13 | function `T.test` (registers: 1, length: 6, constants: 1) 14 | .code 15 | 0 | load_self 16 | 1 | load_field [0]; v 17 | 3 | print 18 | 4 | load_none 19 | 5 | return 20 | 21 | 22 | function `main` (registers: 2, length: 10, constants: 2) 23 | .code 24 | 0 | load_smi 0 25 | 2 | store r1 26 | 4 | make_data_class [0], r1; 27 | 7 | store_global [1]; T 28 | 9 | return 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__class_with_multiple_fields.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T: 7 | a = 0 8 | b = 1 9 | 10 | 11 | # Func: 12 | function `main` (registers: 3, length: 14, constants: 2) 13 | .code 14 | 0 | load_smi 0 15 | 2 | store r1 16 | 4 | load_smi 1 17 | 6 | store r2 18 | 8 | make_data_class [0], r1; 19 | 11 | store_global [1]; T 20 | 13 | return 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__closure.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn a(): 7 | v := 0 8 | fn b(): 9 | fn c(): 10 | fn d(): 11 | print v 12 | 13 | 14 | # Func: 15 | function `d` (registers: 1, length: 5, constants: 0) 16 | .upvalues 17 | 0 <- ^0 18 | .code 19 | 0 | load_upvalue ^0 20 | 2 | print 21 | 3 | load_none 22 | 4 | return 23 | 24 | 25 | function `c` (registers: 2, length: 6, constants: 1) 26 | .upvalues 27 | 0 <- ^0 28 | .code 29 | 0 | make_fn [0]; 30 | 2 | store r1 31 | 4 | load_none 32 | 5 | return 33 | 34 | 35 | function `b` (registers: 2, length: 6, constants: 1) 36 | .upvalues 37 | 0 <- r1 38 | .code 39 | 0 | make_fn [0]; 40 | 2 | store r1 41 | 4 | load_none 42 | 5 | return 43 | 44 | 45 | function `a` (registers: 3, length: 10, constants: 1) 46 | .code 47 | 0 | load_smi 0 48 | 2 | store r1 49 | 4 | make_fn [0]; 50 | 6 | store r2 51 | 8 | load_none 52 | 9 | return 53 | 54 | 55 | function `main` (registers: 1, length: 5, constants: 2) 56 | .code 57 | 0 | make_fn [0]; 58 | 2 | store_global [1]; a 59 | 4 | return 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__closure_call.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn a(): 7 | v := 0 8 | fn b(): 9 | print v 10 | return b 11 | 12 | a()() 13 | 14 | 15 | # Func: 16 | function `b` (registers: 1, length: 5, constants: 0) 17 | .upvalues 18 | 0 <- r1 19 | .code 20 | 0 | load_upvalue ^0 21 | 2 | print 22 | 3 | load_none 23 | 4 | return 24 | 25 | 26 | function `a` (registers: 3, length: 13, constants: 1) 27 | .code 28 | 0 | load_smi 0 29 | 2 | store r1 30 | 4 | make_fn [0]; 31 | 6 | store r2 32 | 8 | load r2 33 | 10 | return 34 | 11 | load_none 35 | 12 | return 36 | 37 | 38 | function `main` (registers: 1, length: 9, constants: 2) 39 | .code 40 | 0 | make_fn [0]; 41 | 2 | store_global [1]; a 42 | 4 | load_global [1]; a 43 | 6 | call0 44 | 7 | call0 45 | 8 | return 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__empty_class.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T: pass 7 | 8 | 9 | # Func: 10 | function `main` (registers: 1, length: 5, constants: 2) 11 | .code 12 | 0 | make_class [0]; 13 | 2 | store_global [1]; T 14 | 4 | return 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__empty_class_derived.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | class T(U): pass 7 | 8 | 9 | # Func: 10 | function `main` (registers: 1, length: 7, constants: 3) 11 | .code 12 | 0 | load_global [1]; U 13 | 2 | make_class_derived [0]; 14 | 4 | store_global [2]; T 15 | 6 | return 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__fn_in_module.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | value := 100 7 | fn set(v): 8 | value = v 9 | fn get(): 10 | return value 11 | 12 | 13 | # Func: 14 | function `set` (registers: 2, length: 6, constants: 0) 15 | .code 16 | 0 | load r1 17 | 2 | store_module_var 0 18 | 4 | load_none 19 | 5 | return 20 | 21 | 22 | function `get` (registers: 1, length: 5, constants: 0) 23 | .code 24 | 0 | load_module_var 0 25 | 2 | return 26 | 3 | load_none 27 | 4 | return 28 | 29 | 30 | function `main` (registers: 1, length: 14, constants: 2) 31 | .code 32 | 0 | load_smi 100 33 | 2 | store_module_var 0 34 | 4 | make_fn [0]; 35 | 6 | store_module_var 1 36 | 8 | make_fn [1]; 37 | 10 | store_module_var 2 38 | 12 | finalize_module 39 | 13 | return 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__for_iter_array.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | a := [0, 1, 2] 7 | for v in a: 8 | print v 9 | 10 | 11 | # Func: 12 | function `main` (registers: 4, length: 48, constants: 5) 13 | .code 14 | 0 | load_smi 0 15 | 2 | store r1 16 | 4 | load_smi 1 17 | 6 | store r2 18 | 8 | load_smi 2 19 | 10 | store r3 20 | 12 | make_list r1, 3 21 | 15 | store_global [0]; a 22 | 17 | load_global [0]; a 23 | 19 | load_field [1]; iter 24 | 21 | call0 25 | 22 | store r1 26 | 24 | load_none 27 | 25 | store r2 28 | 27 | load r1 29 | 29 | load_field [3]; done 30 | 31 | call0 31 | 32 | not 32 | 33 | jump_if_false 14 33 | 35 | load r1 34 | 37 | load_field [2]; next 35 | 39 | call0 36 | 40 | store r2 37 | 42 | load r2 38 | 44 | print 39 | 45 | jump_loop 18 40 | 47 | return 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__for_range_0_to_10_inclusive_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | for i in 0..=10: 7 | break 8 | 9 | 10 | # Func: 11 | function `main` (registers: 3, length: 29, constants: 3) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store r1 15 | 4 | load_smi 10 16 | 6 | store r2 17 | 8 | load r2 18 | 10 | cmp_le r1 19 | 12 | jump_if_false 16 20 | 14 | jump 10 21 | 16 | load_smi 1 22 | 18 | add r1 23 | 20 | store r1 24 | 22 | jump_loop 14 25 | 24 | jump 4 26 | 26 | jump_loop 10 27 | 28 | return 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__for_range_0_to_10_inclusive_continue.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | for i in 0..=10: 7 | continue 8 | 9 | 10 | # Func: 11 | function `main` (registers: 3, length: 29, constants: 2) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store r1 15 | 4 | load_smi 10 16 | 6 | store r2 17 | 8 | load r2 18 | 10 | cmp_le r1 19 | 12 | jump_if_false 16 20 | 14 | jump 10 21 | 16 | load_smi 1 22 | 18 | add r1 23 | 20 | store r1 24 | 22 | jump_loop 14 25 | 24 | jump_loop 8 26 | 26 | jump_loop 10 27 | 28 | return 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__for_range_0_to_10_inclusive_print.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | for i in 0..=10: 7 | print i 8 | 9 | 10 | # Func: 11 | function `main` (registers: 3, length: 30, constants: 2) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store r1 15 | 4 | load_smi 10 16 | 6 | store r2 17 | 8 | load r2 18 | 10 | cmp_le r1 19 | 12 | jump_if_false 17 20 | 14 | jump 10 21 | 16 | load_smi 1 22 | 18 | add r1 23 | 20 | store r1 24 | 22 | jump_loop 14 25 | 24 | load r1 26 | 26 | print 27 | 27 | jump_loop 11 28 | 29 | return 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__for_range_0_to_10_print.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | for i in 0..10: 7 | print i 8 | 9 | 10 | # Func: 11 | function `main` (registers: 3, length: 30, constants: 2) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store r1 15 | 4 | load_smi 10 16 | 6 | store r2 17 | 8 | load r2 18 | 10 | cmp_lt r1 19 | 12 | jump_if_false 17 20 | 14 | jump 10 21 | 16 | load_smi 1 22 | 18 | add r1 23 | 20 | store r1 24 | 22 | jump_loop 14 25 | 24 | load r1 26 | 26 | print 27 | 27 | jump_loop 11 28 | 29 | return 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__function_no_params.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(): 7 | pass 8 | 9 | test() 10 | 11 | 12 | # Func: 13 | function `test` (registers: 1, length: 2, constants: 0) 14 | .code 15 | 0 | load_none 16 | 1 | return 17 | 18 | 19 | function `main` (registers: 1, length: 8, constants: 2) 20 | .code 21 | 0 | make_fn [0]; 22 | 2 | store_global [1]; test 23 | 4 | load_global [1]; test 24 | 6 | call0 25 | 7 | return 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__function_with_default_param.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(a, b=10): 7 | print a, b 8 | 9 | test(1) 10 | test(1, 2) 11 | 12 | 13 | # Func: 14 | function `test` (registers: 5, length: 22, constants: 1) 15 | .code 16 | 0 | load r2 17 | 2 | is_none 18 | 3 | jump_if_false 6 19 | 5 | load_smi 10 20 | 7 | store r2 21 | 9 | load r1 22 | 11 | store r3 23 | 13 | load r2 24 | 15 | store r4 25 | 17 | print_n r3, 2 26 | 20 | load_none 27 | 21 | return 28 | 29 | 30 | function `main` (registers: 4, length: 31, constants: 2) 31 | .code 32 | 0 | make_fn [0]; 33 | 2 | store_global [1]; test 34 | 4 | load_global [1]; test 35 | 6 | store r1 36 | 8 | load_smi 1 37 | 10 | store r2 38 | 12 | call r1, 1 39 | 15 | load_global [1]; test 40 | 17 | store r1 41 | 19 | load_smi 1 42 | 21 | store r2 43 | 23 | load_smi 2 44 | 25 | store r3 45 | 27 | call r1, 2 46 | 30 | return 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__function_with_param.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(a): 7 | print a 8 | 9 | test(0) 10 | 11 | 12 | # Func: 13 | function `test` (registers: 2, length: 5, constants: 0) 14 | .code 15 | 0 | load r1 16 | 2 | print 17 | 3 | load_none 18 | 4 | return 19 | 20 | 21 | function `main` (registers: 3, length: 16, constants: 2) 22 | .code 23 | 0 | make_fn [0]; 24 | 2 | store_global [1]; test 25 | 4 | load_global [1]; test 26 | 6 | store r1 27 | 8 | load_smi 0 28 | 10 | store r2 29 | 12 | call r1, 1 30 | 15 | return 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__generator_no_params.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(): 7 | yield "a" 8 | return "b" 9 | 10 | test() 11 | 12 | 13 | # Func: 14 | function `test` (registers: 1, length: 8, constants: 2) 15 | .code 16 | 0 | load_const [0]; a 17 | 2 | yield 18 | 3 | load_const [1]; b 19 | 5 | return 20 | 6 | load_none 21 | 7 | return 22 | 23 | 24 | function `main` (registers: 1, length: 8, constants: 2) 25 | .code 26 | 0 | make_fn [0]; 27 | 2 | store_global [1]; test 28 | 4 | load_global [1]; test 29 | 6 | call0 30 | 7 | return 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__generator_with_default_param.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(a, b=10): 7 | yield a 8 | return b 9 | 10 | test() 11 | 12 | 13 | # Func: 14 | function `test` (registers: 3, length: 17, constants: 1) 15 | .code 16 | 0 | load r2 17 | 2 | is_none 18 | 3 | jump_if_false 6 19 | 5 | load_smi 10 20 | 7 | store r2 21 | 9 | load r1 22 | 11 | yield 23 | 12 | load r2 24 | 14 | return 25 | 15 | load_none 26 | 16 | return 27 | 28 | 29 | function `main` (registers: 1, length: 8, constants: 2) 30 | .code 31 | 0 | make_fn [0]; 32 | 2 | store_global [1]; test 33 | 4 | load_global [1]; test 34 | 6 | call0 35 | 7 | return 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__generator_with_param.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(a): 7 | yield a 8 | return a 9 | 10 | test() 11 | 12 | 13 | # Func: 14 | function `test` (registers: 2, length: 8, constants: 0) 15 | .code 16 | 0 | load r1 17 | 2 | yield 18 | 3 | load r1 19 | 5 | return 20 | 6 | load_none 21 | 7 | return 22 | 23 | 24 | function `main` (registers: 1, length: 8, constants: 2) 25 | .code 26 | 0 | make_fn [0]; 27 | 2 | store_global [1]; test 28 | 4 | load_global [1]; test 29 | 6 | call0 30 | 7 | return 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__if_stmt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | if true: 7 | print a 8 | elif true: 9 | print b 10 | else: 11 | print c 12 | 13 | 14 | # Func: 15 | function `main` (registers: 1, length: 20, constants: 7) 16 | .code 17 | 0 | load_true 18 | 1 | jump_if_false 7 19 | 3 | load_global [1]; a 20 | 5 | print 21 | 6 | jump 13 22 | 8 | load_true 23 | 9 | jump_if_false 7 24 | 11 | load_global [4]; b 25 | 13 | print 26 | 14 | jump 5 27 | 16 | load_global [6]; c 28 | 18 | print 29 | 19 | return 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__if_stmt_var_resolution.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | if a: 7 | b := a 8 | print b 9 | else: 10 | print b 11 | 12 | 13 | # Func: 14 | function `main` (registers: 1, length: 17, constants: 4) 15 | .code 16 | 0 | load_global [0]; a 17 | 2 | jump_if_false 11 18 | 4 | load_global [0]; a 19 | 6 | store_global [2]; b 20 | 8 | load_global [2]; b 21 | 10 | print 22 | 11 | jump 5 23 | 13 | load_global [2]; b 24 | 15 | print 25 | 16 | return 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__import_multi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | from test.a0 import a1, a2 7 | from test.b0 import b1, b2 8 | print a1, a2 9 | print b1, b2 10 | 11 | 12 | # Func: 13 | function `main` (registers: 7, length: 55, constants: 6) 14 | .code 15 | 0 | import [0]; test.a0 16 | 2 | store r1 17 | 4 | load r1 18 | 6 | load_field [1]; a1 19 | 8 | store r2 20 | 10 | load r1 21 | 12 | load_field [2]; a2 22 | 14 | store r1 23 | 16 | import [3]; test.b0 24 | 18 | store r3 25 | 20 | load r3 26 | 22 | load_field [4]; b1 27 | 24 | store r4 28 | 26 | load r3 29 | 28 | load_field [5]; b2 30 | 30 | store r3 31 | 32 | load r2 32 | 34 | store r5 33 | 36 | load r1 34 | 38 | store r6 35 | 40 | print_n r5, 2 36 | 43 | load r4 37 | 45 | store r5 38 | 47 | load r3 39 | 49 | store r6 40 | 51 | print_n r5, 2 41 | 54 | return 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__import_symbol.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | from test import symbol 7 | print symbol 8 | 9 | 10 | # Func: 11 | function `main` (registers: 2, length: 14, constants: 2) 12 | .code 13 | 0 | import [0]; test 14 | 2 | store r1 15 | 4 | load r1 16 | 6 | load_field [1]; symbol 17 | 8 | store r1 18 | 10 | load r1 19 | 12 | print 20 | 13 | return 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__import_symbol_multi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | from test import a, b 7 | print a, b 8 | 9 | 10 | # Func: 11 | function `main` (registers: 5, length: 28, constants: 3) 12 | .code 13 | 0 | import [0]; test 14 | 2 | store r1 15 | 4 | load r1 16 | 6 | load_field [1]; a 17 | 8 | store r2 18 | 10 | load r1 19 | 12 | load_field [2]; b 20 | 14 | store r1 21 | 16 | load r2 22 | 18 | store r3 23 | 20 | load r1 24 | 22 | store r4 25 | 24 | print_n r3, 2 26 | 27 | return 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__import_whole.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | import test 7 | print test.symbol 8 | 9 | 10 | # Func: 11 | function `main` (registers: 2, length: 10, constants: 2) 12 | .code 13 | 0 | import [0]; test 14 | 2 | store r1 15 | 4 | load r1 16 | 6 | load_field [1]; symbol 17 | 8 | print 18 | 9 | return 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | break 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 5, constants: 1) 12 | .code 13 | 0 | jump 4 14 | 2 | jump_loop 2 15 | 4 | return 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_continue.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | continue 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 5, constants: 0) 12 | .code 13 | 0 | jump_loop 0 14 | 2 | jump_loop 2 15 | 4 | return 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_nested_loop.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | loop: 8 | continue 9 | continue 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 9, constants: 0) 14 | .code 15 | 0 | jump_loop 0 16 | 2 | jump_loop 2 17 | 4 | jump_loop 4 18 | 6 | jump_loop 6 19 | 8 | return 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_nested_loop_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | loop: 8 | break 9 | break 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 9, constants: 2) 14 | .code 15 | 0 | jump 4 16 | 2 | jump_loop 2 17 | 4 | jump 4 18 | 6 | jump_loop 6 19 | 8 | return 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_nested_while.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | while true: 8 | continue 9 | continue 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 12, constants: 1) 14 | .code 15 | 0 | load_true 16 | 1 | jump_if_false 6 17 | 3 | jump_loop 3 18 | 5 | jump_loop 5 19 | 7 | jump_loop 7 20 | 9 | jump_loop 9 21 | 11 | return 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_nested_while_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | while true: 8 | break 9 | break 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 12, constants: 3) 14 | .code 15 | 0 | load_true 16 | 1 | jump_if_false 6 17 | 3 | jump 4 18 | 5 | jump_loop 5 19 | 7 | jump 4 20 | 9 | jump_loop 9 21 | 11 | return 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__loop_print.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | loop: 7 | print "test" 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 6, constants: 1) 12 | .code 13 | 0 | load_const [0]; test 14 | 2 | print 15 | 3 | jump_loop 3 16 | 5 | return 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__method_call_0.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | o.f() 7 | 8 | # Func: 9 | function `main` (registers: 1, length: 6, constants: 2) 10 | .code 11 | 0 | load_global [1]; o 12 | 2 | load_field [0]; f 13 | 4 | call0 14 | 5 | return 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__method_call_1.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | o.f(0) 7 | 8 | # Func: 9 | function `main` (registers: 3, length: 14, constants: 2) 10 | .code 11 | 0 | load_global [1]; o 12 | 2 | load_field [0]; f 13 | 4 | store r1 14 | 6 | load_smi 0 15 | 8 | store r2 16 | 10 | call r1, 1 17 | 13 | return 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__method_call_n.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | o.f(1,2,3) 7 | 8 | # Func: 9 | function `main` (registers: 5, length: 22, constants: 2) 10 | .code 11 | 0 | load_global [1]; o 12 | 2 | load_field [0]; f 13 | 4 | store r1 14 | 6 | load_smi 1 15 | 8 | store r2 16 | 10 | load_smi 2 17 | 12 | store r3 18 | 14 | load_smi 3 19 | 16 | store r4 20 | 18 | call r1, 3 21 | 21 | return 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__nested_call_0.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | a(b(c())) 7 | 8 | # Func: 9 | function `main` (registers: 5, length: 22, constants: 3) 10 | .code 11 | 0 | load_global [0]; a 12 | 2 | store r1 13 | 4 | load_global [1]; b 14 | 6 | store r3 15 | 8 | load_global [2]; c 16 | 10 | call0 17 | 11 | store r4 18 | 13 | call r3, 1 19 | 16 | store r2 20 | 18 | call r1, 1 21 | 21 | return 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__nested_call_subexpr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | 0 + a(1 + b(2 + c(3 + 4, 5), 6), 7) 7 | 8 | 9 | # Func: 10 | function `main` (registers: 14, length: 66, constants: 3) 11 | .code 12 | 0 | load_smi 0 13 | 2 | store r1 14 | 4 | load_global [0]; a 15 | 6 | store r2 16 | 8 | load_smi 1 17 | 10 | store r5 18 | 12 | load_global [1]; b 19 | 14 | store r6 20 | 16 | load_smi 2 21 | 18 | store r9 22 | 20 | load_global [2]; c 23 | 22 | store r10 24 | 24 | load_smi 3 25 | 26 | store r13 26 | 28 | load_smi 4 27 | 30 | add r13 28 | 32 | store r11 29 | 34 | load_smi 5 30 | 36 | store r12 31 | 38 | call r10, 2 32 | 41 | add r9 33 | 43 | store r7 34 | 45 | load_smi 6 35 | 47 | store r8 36 | 49 | call r6, 2 37 | 52 | add r5 38 | 54 | store r3 39 | 56 | load_smi 7 40 | 58 | store r4 41 | 60 | call r2, 2 42 | 63 | add r1 43 | 65 | return 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__opt_chaining.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn f3(a, b, c, d): 7 | a ?? b ?? c 8 | 9 | 10 | # Func: 11 | function `f3` (registers: 7, length: 30, constants: 4) 12 | .code 13 | 0 | load r1 14 | 2 | store r6 15 | 4 | load r6 16 | 6 | is_none 17 | 7 | jump_if_false 6 18 | 9 | load r2 19 | 11 | jump 4 20 | 13 | load r6 21 | 15 | store r5 22 | 17 | load r5 23 | 19 | is_none 24 | 20 | jump_if_false 6 25 | 22 | load r3 26 | 24 | jump 4 27 | 26 | load r5 28 | 28 | load_none 29 | 29 | return 30 | 31 | 32 | function `main` (registers: 1, length: 5, constants: 2) 33 | .code 34 | 0 | make_fn [0]; 35 | 2 | store_global [1]; f3 36 | 4 | return 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := { a: 0 } 7 | print v.a 8 | v.a = 1 9 | 10 | 11 | # Func: 12 | function `main` (registers: 3, length: 28, constants: 2) 13 | .code 14 | 0 | load_const [0]; a 15 | 2 | store r1 16 | 4 | load_smi 0 17 | 6 | store r2 18 | 8 | make_table r1, 1 19 | 11 | store_global [1]; v 20 | 13 | load_global [1]; v 21 | 15 | load_field [0]; a 22 | 17 | print 23 | 18 | load_global [1]; v 24 | 20 | store r1 25 | 22 | load_smi 1 26 | 24 | store_field r1, [0]; a 27 | 27 | return 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_field_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := {} 7 | print ?v.a 8 | print ?v.a.b.c 9 | 10 | 11 | # Func: 12 | function `main` (registers: 1, length: 18, constants: 4) 13 | .code 14 | 0 | make_table_empty 15 | 1 | store_global [0]; v 16 | 3 | load_global [0]; v 17 | 5 | load_field_opt [1]; a 18 | 7 | print 19 | 8 | load_global [0]; v 20 | 10 | load_field_opt [1]; a 21 | 12 | load_field_opt [3]; b 22 | 14 | load_field_opt [2]; c 23 | 16 | print 24 | 17 | return 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_float.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | print 2.5 7 | 8 | # Func: 9 | function `main` (registers: 1, length: 4, constants: 1) 10 | .code 11 | 0 | load_const [0]; 2.5 12 | 2 | print 13 | 3 | return 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_global.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := 0 7 | print v 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 8, constants: 1) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store_global [0]; v 15 | 4 | load_global [0]; v 16 | 6 | print 17 | 7 | return 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_index.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := { a: 0 } 7 | print v["a"] 8 | v["a"] = 1 9 | 10 | 11 | # Func: 12 | function `main` (registers: 3, length: 36, constants: 2) 13 | .code 14 | 0 | load_const [0]; a 15 | 2 | store r1 16 | 4 | load_smi 0 17 | 6 | store r2 18 | 8 | make_table r1, 1 19 | 11 | store_global [1]; v 20 | 13 | load_global [1]; v 21 | 15 | store r1 22 | 17 | load_const [0]; a 23 | 19 | load_index r1 24 | 21 | print 25 | 22 | load_global [1]; v 26 | 24 | store r1 27 | 26 | load_const [0]; a 28 | 28 | store r2 29 | 30 | load_smi 1 30 | 32 | store_index r1, r2 31 | 35 | return 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_index_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := {} 7 | print ?v["a"] 8 | print ?v["a"]["b"]["c"] 9 | 10 | 11 | # Func: 12 | function `main` (registers: 4, length: 34, constants: 4) 13 | .code 14 | 0 | make_table_empty 15 | 1 | store_global [0]; v 16 | 3 | load_global [0]; v 17 | 5 | store r1 18 | 7 | load_const [1]; a 19 | 9 | load_index_opt r1 20 | 11 | print 21 | 12 | load_global [0]; v 22 | 14 | store r3 23 | 16 | load_const [1]; a 24 | 18 | load_index_opt r3 25 | 20 | store r2 26 | 22 | load_const [2]; b 27 | 24 | load_index_opt r2 28 | 26 | store r1 29 | 28 | load_const [3]; c 30 | 30 | load_index_opt r1 31 | 32 | print 32 | 33 | return 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_int.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | print 0 7 | 8 | # Func: 9 | function `main` (registers: 1, length: 4, constants: 0) 10 | .code 11 | 0 | load_smi 0 12 | 2 | print 13 | 3 | return 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_list.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | print [0, 1, 2] 7 | 8 | # Func: 9 | function `main` (registers: 4, length: 17, constants: 0) 10 | .code 11 | 0 | load_smi 0 12 | 2 | store r1 13 | 4 | load_smi 1 14 | 6 | store r2 15 | 8 | load_smi 2 16 | 10 | store r3 17 | 12 | make_list r1, 3 18 | 15 | print 19 | 16 | return 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_module_var.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := 0 7 | print v 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 9, constants: 0) 12 | .code 13 | 0 | load_smi 0 14 | 2 | store_module_var 0 15 | 4 | load_module_var 0 16 | 6 | print 17 | 7 | finalize_module 18 | 8 | return 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_string.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | print "test" 7 | 8 | # Func: 9 | function `main` (registers: 1, length: 4, constants: 1) 10 | .code 11 | 0 | load_const [0]; test 12 | 2 | print 13 | 3 | return 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__print_table.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | print { a: 0, b: 1, c: 2 } 7 | 8 | # Func: 9 | function `main` (registers: 7, length: 29, constants: 3) 10 | .code 11 | 0 | load_const [0]; a 12 | 2 | store r1 13 | 4 | load_smi 0 14 | 6 | store r2 15 | 8 | load_const [1]; b 16 | 10 | store r3 17 | 12 | load_smi 1 18 | 14 | store r4 19 | 16 | load_const [2]; c 20 | 18 | store r5 21 | 20 | load_smi 2 22 | 22 | store r6 23 | 24 | make_table r1, 3 24 | 27 | print 25 | 28 | return 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__variable_scope_lifetime.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | fn test(): 7 | if true: 8 | v := 0 9 | if true: 10 | print v 11 | v := 0 12 | print v 13 | v := 0 14 | b := 0 15 | print b 16 | 17 | 18 | # Func: 19 | function `test` (registers: 3, length: 37, constants: 4) 20 | .code 21 | 0 | load_true 22 | 1 | jump_if_false 34 23 | 3 | load_smi 0 24 | 5 | store r1 25 | 7 | load_true 26 | 8 | jump_if_false 14 27 | 10 | load r1 28 | 12 | print 29 | 13 | load_smi 0 30 | 15 | store r2 31 | 17 | load r2 32 | 19 | print 33 | 20 | jump 2 34 | 22 | load_smi 0 35 | 24 | store r1 36 | 26 | load_smi 0 37 | 28 | store r2 38 | 30 | load r2 39 | 32 | print 40 | 33 | jump 2 41 | 35 | load_none 42 | 36 | return 43 | 44 | 45 | function `main` (registers: 1, length: 5, constants: 2) 46 | .code 47 | 0 | make_fn [0]; 48 | 2 | store_global [1]; test 49 | 4 | return 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | break 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 8, constants: 2) 12 | .code 13 | 0 | load_true 14 | 1 | jump_if_false 6 15 | 3 | jump 4 16 | 5 | jump_loop 5 17 | 7 | return 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_continue.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | continue 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 8, constants: 1) 12 | .code 13 | 0 | load_true 14 | 1 | jump_if_false 6 15 | 3 | jump_loop 3 16 | 5 | jump_loop 5 17 | 7 | return 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_nested_loop.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | loop: 8 | continue 9 | continue 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 12, constants: 1) 14 | .code 15 | 0 | load_true 16 | 1 | jump_if_false 10 17 | 3 | jump_loop 0 18 | 5 | jump_loop 2 19 | 7 | jump_loop 7 20 | 9 | jump_loop 9 21 | 11 | return 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_nested_loop_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | loop: 8 | break 9 | break 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 12, constants: 3) 14 | .code 15 | 0 | load_true 16 | 1 | jump_if_false 10 17 | 3 | jump 4 18 | 5 | jump_loop 2 19 | 7 | jump 4 20 | 9 | jump_loop 9 21 | 11 | return 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_nested_while.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | while true: 8 | continue 9 | continue 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 15, constants: 2) 14 | .code 15 | 0 | load_true 16 | 1 | jump_if_false 13 17 | 3 | load_true 18 | 4 | jump_if_false 6 19 | 6 | jump_loop 3 20 | 8 | jump_loop 5 21 | 10 | jump_loop 10 22 | 12 | jump_loop 12 23 | 14 | return 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_nested_while_break.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | while true: 8 | break 9 | break 10 | 11 | 12 | # Func: 13 | function `main` (registers: 1, length: 15, constants: 4) 14 | .code 15 | 0 | load_true 16 | 1 | jump_if_false 13 17 | 3 | load_true 18 | 4 | jump_if_false 6 19 | 6 | jump 4 20 | 8 | jump_loop 5 21 | 10 | jump 4 22 | 12 | jump_loop 12 23 | 14 | return 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_print.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | while true: 7 | print "test" 8 | 9 | 10 | # Func: 11 | function `main` (registers: 1, length: 9, constants: 2) 12 | .code 13 | 0 | load_true 14 | 1 | jump_if_false 7 15 | 3 | load_const [1]; test 16 | 5 | print 17 | 6 | jump_loop 6 18 | 8 | return 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/internal/codegen/snapshots/hebi__internal__codegen__tests__while_print_0_to_10.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/codegen/tests.rs 3 | expression: snapshot 4 | --- 5 | # Input: 6 | v := 0 7 | while v < 10: 8 | print "less than 10:", v 9 | v += 1 10 | print "now it's 10" 11 | 12 | 13 | # Func: 14 | function `main` (registers: 3, length: 41, constants: 4) 15 | .code 16 | 0 | load_smi 0 17 | 2 | store_global [0]; v 18 | 4 | load_global [0]; v 19 | 6 | store r1 20 | 8 | load_smi 10 21 | 10 | cmp_lt r1 22 | 12 | jump_if_false 25 23 | 14 | load_const [2]; less than 10: 24 | 16 | store r1 25 | 18 | load_global [0]; v 26 | 20 | store r2 27 | 22 | print_n r1, 2 28 | 25 | load_global [0]; v 29 | 27 | store r1 30 | 29 | load_smi 1 31 | 31 | add r1 32 | 33 | store_global [0]; v 33 | 35 | jump_loop 31 34 | 37 | load_const [3]; now it's 10 35 | 39 | print 36 | 40 | return 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/internal/codegen/tests/macros.rs: -------------------------------------------------------------------------------- 1 | macro_rules! check { 2 | ($name:ident, $(as_module=$as_module:expr,)? $input:literal) => { 3 | #[allow(unused_mut, unused_assignments)] 4 | #[test] 5 | fn $name() { 6 | let mut as_module = false; 7 | $(as_module = $as_module;)? 8 | let global = $crate::internal::vm::global::Global::default(); 9 | let input = indoc::indoc!($input); 10 | let module = match syntax::parse(global.clone(), input) { 11 | Ok(module) => module, 12 | Err(e) => { 13 | for err in e.errors() { 14 | eprintln!("{}", err.report(input, true)); 15 | } 16 | panic!("Failed to parse source, see errors above.") 17 | } 18 | }; 19 | let module = emit(global, &module, "main", !as_module); 20 | let snapshot = format!( 21 | "# Input:\n{input}\n\n# Func:\n{}\n\n", 22 | module.root.disassemble(), 23 | ); 24 | assert_snapshot!(snapshot); 25 | } 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /src/internal/syntax.rs: -------------------------------------------------------------------------------- 1 | pub mod ast; 2 | pub mod lexer; 3 | pub mod parser; 4 | 5 | use std::error::Error as StdError; 6 | use std::fmt::Display; 7 | 8 | pub use ast::Module; 9 | pub use parser::parse; 10 | 11 | use crate::span::SpannedError; 12 | use crate::util::JoinIter; 13 | 14 | #[derive(Debug)] 15 | pub struct SyntaxError { 16 | errors: Vec, 17 | } 18 | 19 | impl SyntaxError { 20 | fn new(errors: Vec) -> Self { 21 | Self { errors } 22 | } 23 | 24 | pub fn errors(&self) -> &[SpannedError] { 25 | &self.errors 26 | } 27 | } 28 | 29 | impl Display for SyntaxError { 30 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 31 | write!(f, "{}", self.errors.iter().join("\n")) 32 | } 33 | } 34 | 35 | impl StdError for SyntaxError {} 36 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/common.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::span::Spanned; 3 | 4 | impl<'src> Parser<'src> { 5 | pub(super) fn ident(&mut self) -> Result, SpannedError> { 6 | self.expect(Lit_Ident)?; 7 | Ok(ast::Ident::new( 8 | self.previous().span, 9 | Cow::from(self.lex.lexeme(self.previous())), 10 | )) 11 | } 12 | 13 | pub(super) fn yield_(&mut self) -> Result>, SpannedError> { 14 | if self.state.current_func.is_none() { 15 | fail!(@self.current().span, "yield outside of function"); 16 | } 17 | 18 | self.expect(Kw_Yield)?; 19 | let start = self.previous().span.start; 20 | let value = self.no_indent().ok().map(|_| self.expr()).transpose()?; 21 | let end = self.previous().span.end; 22 | 23 | let current_func = self 24 | .state 25 | .current_func 26 | .as_mut() 27 | // TODO: improve `state` API to make this impossible? 28 | .expect("`state.current_func` set to `None` by a mysterious force outside of `Parser::func`"); 29 | current_func.has_yield = true; 30 | 31 | Ok(Spanned::new(start..end, ast::Yield { value })) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/indent.rs: -------------------------------------------------------------------------------- 1 | pub struct IndentStack { 2 | stack: Vec, 3 | level: u64, 4 | } 5 | 6 | impl IndentStack { 7 | pub fn new() -> Self { 8 | Self { 9 | stack: vec![0], 10 | level: 0, 11 | } 12 | } 13 | 14 | pub fn is_eq(&self, n: u64) -> bool { 15 | self.level == n 16 | } 17 | 18 | pub fn is_gt(&self, n: u64) -> bool { 19 | self.level < n 20 | } 21 | 22 | pub fn is_lt(&self, n: u64) -> bool { 23 | self.level > n 24 | } 25 | 26 | pub fn push(&mut self, n: u64) { 27 | self.stack.push(n); 28 | self.level = n; 29 | } 30 | 31 | pub fn pop(&mut self) { 32 | self.stack.pop().unwrap(); 33 | self.level = self 34 | .stack 35 | .last() 36 | .cloned() 37 | .expect("pop_indent should not empty the indent stack"); 38 | } 39 | 40 | pub fn reset(&mut self) { 41 | self.stack.clear(); 42 | self.stack.push(0); 43 | self.level = 0; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/module.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | impl<'src> Parser<'src> { 4 | pub(super) fn module(mut self) -> Result, Vec> { 5 | while !self.current().is(Tok_Eof) { 6 | if let Err(e) = self.top_level_stmt() { 7 | self.errors.push(e); 8 | self.sync(); 9 | } 10 | } 11 | 12 | if !self.errors.is_empty() { 13 | return Err(self.errors); 14 | } 15 | 16 | Ok(self.module) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__assign_expr-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | = b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__assign_expr-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__assign_expr-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid variable declaration 6 | | a.b := c 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__assign_expr-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid assignment target 6 | | a() = b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__bad_class_stmt_fields_after_methods.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | fields may not appear after methods 6 | | a = b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__bad_class_stmt_indented_base.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | (U): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__bad_class_stmt_indented_colon_1.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | : pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__bad_class_stmt_indented_colon_2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | : pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__bad_class_stmt_indented_name.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | T: pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-10.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: MoreEq, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-11.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Less, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-12.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: LessEq, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-13.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Is, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-14.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: In, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-15.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: And, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-16.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Or, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-17.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Maybe, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-19.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Sub, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Div, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Pow, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Mul, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Rem, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-7.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Eq, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-8.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Neq, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr-9.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: More, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__binary_expr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Binary( 6 | Binary { 7 | op: Add, 8 | left: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | right: GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | }, 23 | ) 24 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__call_expr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Call( 6 | Call { 7 | target: GetVar( 8 | GetVar { 9 | name: Ident( 10 | "a", 11 | ), 12 | }, 13 | ), 14 | args: [ 15 | GetVar( 16 | GetVar { 17 | name: Ident( 18 | "b", 19 | ), 20 | }, 21 | ), 22 | GetVar( 23 | GetVar { 24 | name: Ident( 25 | "c", 26 | ), 27 | }, 28 | ), 29 | ], 30 | }, 31 | ) 32 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-10.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `super` in a class with no parent class 6 | | print super 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-11.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `super` outside of a class method that takes `self` 6 | | v = super 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-12.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `super` outside of a class method that takes `self` 6 | | print super 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `self` outside of class method 6 | | self 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `self` outside of class method 6 | | v = self.f() 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `self` outside of class method 6 | | print self 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `self` outside of class method 6 | | print self 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `super` outside of class method 6 | | super 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-7.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `super` outside of class method 6 | | print super 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-8.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `self` outside of class method 6 | | print self 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__class_self_and_super-9.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | cannot access `super` in a class with no parent class 6 | | v = super 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__ctrl_stmt-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | return outside of function 6 | | return v 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__ctrl_stmt-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | yield outside of function 6 | | yield v 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__ctrl_stmt-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | continue outside of loop 6 | | continue 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__ctrl_stmt-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | break outside of loop 6 | | break 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__duplicate_fields-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | duplicate field a 6 | | fn a(): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__duplicate_fields-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | duplicate field a 6 | | fn a(): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__duplicate_fields.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | duplicate field a 6 | | a = 1 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-10.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn f(a, **a): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-11.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-12.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn(): 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | non-default argument follows default argument 6 | | fn f(a, b=c, d,): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn f(*,): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn f(**,): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn f(**kwargs, a,): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | unexpected token 6 | | fn f(a, b=,): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-7.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | duplicate argument `a` 6 | | fn f(a, a): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-8.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn f(a, *a): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__func_stmt-9.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | | fn f(a, *, a): pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__if_stmt-10.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | elif b: pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__if_stmt-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__if_stmt-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | : pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__if_stmt-7.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | : pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__if_stmt-8.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | : pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__if_stmt-9.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | else: pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__import_stmt-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | import b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__import_stmt-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | from m import b 7 | 8 | invalid indentation 9 | | from m import b 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__import_stmt-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | m 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__import_stmt-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | a 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__import_stmt-7.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__import_stmt-8.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | .b 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__inline_for_indentation_enforcement.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | invalid indentation 9 | | print x, y 10 | 11 | invalid indentation 12 | | print "---------" 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__inline_while_indentation_enforcement.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | if x != 46656: print "broken arithmetics" 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__loop_stmts-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__loop_stmts-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Module { 6 | body: [ 7 | Loop( 8 | While( 9 | While { 10 | cond: Literal( 11 | Bool( 12 | true, 13 | ), 14 | ), 15 | body: [ 16 | Pass, 17 | ], 18 | }, 19 | ), 20 | ), 21 | Loop( 22 | While( 23 | While { 24 | cond: Literal( 25 | Bool( 26 | true, 27 | ), 28 | ), 29 | body: [ 30 | Pass, 31 | ], 32 | }, 33 | ), 34 | ), 35 | ], 36 | } 37 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__loop_stmts-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__loop_stmts-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | pass 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__loop_stmts.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Module { 6 | body: [ 7 | Loop( 8 | Infinite( 9 | Infinite { 10 | body: [ 11 | Pass, 12 | ], 13 | }, 14 | ), 15 | ), 16 | Loop( 17 | Infinite( 18 | Infinite { 19 | body: [ 20 | Pass, 21 | ], 22 | }, 23 | ), 24 | ), 25 | ], 26 | } 27 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__postfix_expr-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | unexpected token 6 | | .b[c].d 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__postfix_expr-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | unexpected token 6 | | .d 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__postfix_expr-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | expected `identifier` 6 | 7 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__postfix_expr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | GetField( 6 | GetField { 7 | target: GetIndex( 8 | GetIndex { 9 | target: GetField( 10 | GetField { 11 | target: GetVar( 12 | GetVar { 13 | name: Ident( 14 | "a", 15 | ), 16 | }, 17 | ), 18 | name: Ident( 19 | "b", 20 | ), 21 | }, 22 | ), 23 | key: GetVar( 24 | GetVar { 25 | name: Ident( 26 | "c", 27 | ), 28 | }, 29 | ), 30 | }, 31 | ), 32 | name: Ident( 33 | "d", 34 | ), 35 | }, 36 | ) 37 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__print_stmt-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | "a" 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__scope_double_semi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__scope_nested_no_semi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__scope_nested_single_semi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__scope_no_semi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__scope_single_semi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__scoped_nested_double_semi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: errors 4 | --- 5 | invalid indentation 6 | | print y 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__unary_expr-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Unary( 6 | Unary { 7 | op: Minus, 8 | right: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | }, 16 | ) 17 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__unary_expr-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Unary( 6 | Unary { 7 | op: Not, 8 | right: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | }, 16 | ) 17 | -------------------------------------------------------------------------------- /src/internal/syntax/parser/snapshots/hebi__internal__syntax__parser__tests__unary_expr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/syntax/parser/tests.rs 3 | expression: module 4 | --- 5 | Unary( 6 | Unary { 7 | op: Plus, 8 | right: GetVar( 9 | GetVar { 10 | name: Ident( 11 | "a", 12 | ), 13 | }, 14 | ), 15 | }, 16 | ) 17 | -------------------------------------------------------------------------------- /src/internal/value/snapshots/hebi__internal__value__tests__create_value.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/value/tests.rs 3 | expression: snapshot 4 | --- 5 | [3.141592653589793, -1000000, true, none, Bar { value: 100 }] 6 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__add_objects.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | "a" + "b" 7 | 8 | 9 | # Result: 10 | Object( 11 | "ab", 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__arithmetic.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := 10 # 10 7 | v += 1 # 11 8 | v -= 1 # 10 9 | v **= 2 # 100 10 | v /= 5 # 20 11 | v %= 1 # 0 12 | v 13 | 14 | 15 | # Result: 16 | Float( 17 | 0.0, 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__array_equality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print [] == [] 7 | print [1] == [1] 8 | print [1, 2] == [1, 2] 9 | print [1] != [] 10 | print [] != [1] 11 | print [1, 2] != [2, 1] 12 | print [1, 2] != ["1", 2] 13 | print [to_int, to_str] == [to_int, to_str] 14 | 15 | 16 | # Result: 17 | None 18 | 19 | # Output: 20 | true 21 | true 22 | true 23 | true 24 | true 25 | true 26 | true 27 | true 28 | 29 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__basic_fn_call.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(): 7 | return "yo" 8 | 9 | test() 10 | 11 | 12 | # Result: 13 | Object( 14 | "yo", 15 | ) 16 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_add_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true + false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `+` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_div_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true / false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `/` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_equality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | a := true 7 | b := false 8 | if a == b: 9 | print "a == b" 10 | if a != b: 11 | print "a != b" 12 | 13 | 14 | # Result: 15 | None 16 | 17 | # Output: 18 | a != b 19 | 20 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_ge_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true >= false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `>=` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_gt_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true > false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `>` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_le_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true <= false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `<=` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_lt_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true < false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `<` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_mul_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true * false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `*` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_pow_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true ** false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `**` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_rem_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true % false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `%` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__bool_sub_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | true - false 7 | 8 | 9 | # Result: 10 | runtime error: cannot `-` `bool` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_collect.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class Counter: 7 | n = 0 8 | max = 0 9 | 10 | init(self, max): 11 | self.max = max 12 | 13 | fn iter(self): 14 | return self 15 | 16 | fn next(self): 17 | if self.n < self.max: 18 | n := self.n 19 | self.n += 1 20 | return n 21 | 22 | fn done(self): 23 | return self.n >= self.max 24 | 25 | collect(Counter(10)) 26 | 27 | 28 | # Result: 29 | Object( 30 | [ 31 | Int( 32 | 0, 33 | ), 34 | Int( 35 | 1, 36 | ), 37 | Int( 38 | 2, 39 | ), 40 | Int( 41 | 3, 42 | ), 43 | Int( 44 | 4, 45 | ), 46 | Int( 47 | 5, 48 | ), 49 | Int( 50 | 6, 51 | ), 52 | Int( 53 | 7, 54 | ), 55 | Int( 56 | 8, 57 | ), 58 | Int( 59 | 9, 60 | ), 61 | ], 62 | ) 63 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_collect_native.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | collect("a\nb\nc".lines()) 7 | 8 | 9 | # Result: 10 | Object( 11 | [ 12 | Object( 13 | "a", 14 | ), 15 | Object( 16 | "b", 17 | ), 18 | Object( 19 | "c", 20 | ), 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_list_methods.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := [0, 1, 2] 7 | 8 | print "len", v.len() 9 | print "is_empty", v.is_empty() 10 | print "get(1)", v.get(1) 11 | print "pop()", v.pop() 12 | print "set", v.set(0, v.get(1)) 13 | print "join", v.join(", ") 14 | print "push(2)", v.push(2) 15 | print "extend(3, 0)", v.extend(3, 0) 16 | print "join", v.join(", ") 17 | 18 | 19 | # Result: 20 | None 21 | 22 | # Output: 23 | len 3 24 | is_empty false 25 | get(1) 1 26 | pop() 2 27 | set none 28 | join 1, 1 29 | push(2) none 30 | extend(3, 0) none 31 | join 1, 1, 2, 0, 0, 0 32 | 33 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_list_methods_bound.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := [0, 1, 2] 7 | 8 | v_len := v.len 9 | v_is_empty := v.is_empty 10 | v_get := v.get 11 | v_pop := v.pop 12 | v_set := v.set 13 | v_join := v.join 14 | v_push := v.push 15 | v_extend := v.extend 16 | 17 | print "len", v_len() 18 | print "is_empty", v_is_empty() 19 | print "get(1)", v_get(1) 20 | print "pop()", v_pop() 21 | print "set", v_set(0, v_get(1)) 22 | print "join", v_join(", ") 23 | print "push(2)", v_push(2) 24 | print "extend(3, 0)", v_extend(3, 0) 25 | print "join", v_join(", ") 26 | 27 | 28 | # Result: 29 | None 30 | 31 | # Output: 32 | len 3 33 | is_empty false 34 | get(1) 1 35 | pop() 2 36 | set none 37 | join 1, 1 38 | push(2) none 39 | extend(3, 0) none 40 | join 1, 1, 2, 0, 0, 0 41 | 42 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_list_methods_static.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := [0, 1, 2] 7 | 8 | print "len", List.len(v) 9 | print "is_empty", List.is_empty(v) 10 | print "get(1)", List.get(v, 1) 11 | print "pop()", List.pop(v) 12 | print "set", List.set(v, 0, List.get(v, 1)) 13 | print "join", List.join(v, ", ") 14 | print "push(2)", List.push(v, 2) 15 | print "extend(3, 0)", List.extend(v, 3, 0) 16 | print "join", List.join(v, ", ") 17 | 18 | 19 | # Result: 20 | None 21 | 22 | # Output: 23 | len 3 24 | is_empty false 25 | get(1) 1 26 | pop() 2 27 | set none 28 | join 1, 1 29 | push(2) none 30 | extend(3, 0) none 31 | join 1, 1, 2, 0, 0, 0 32 | 33 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_parse_int.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print parse_int(10) 7 | print parse_int(10.0) 8 | print parse_int("10") 9 | 10 | 11 | # Result: 12 | None 13 | 14 | # Output: 15 | 10 16 | 10 17 | 10 18 | 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_str_lines_iter.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | strings := [ 7 | "a\n\nb\nc", 8 | "\na\n\nb\nc", 9 | "\na\n\nb\nc\n", 10 | ] 11 | 12 | for string in strings: 13 | for line in string.lines(): 14 | print "`" + line + "`" 15 | print "" 16 | 17 | 18 | # Result: 19 | None 20 | 21 | # Output: 22 | `a` 23 | `` 24 | `b` 25 | `c` 26 | 27 | `` 28 | `a` 29 | `` 30 | `b` 31 | `c` 32 | 33 | `` 34 | `a` 35 | `` 36 | `b` 37 | `c` 38 | `` 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_str_methods.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := "a\nb\nc" 7 | 8 | print "len", v.len() 9 | print "is_empty", v.is_empty() 10 | print "lines", v.lines() 11 | 12 | 13 | # Result: 14 | None 15 | 16 | # Output: 17 | len 5 18 | is_empty false 19 | lines 20 | 21 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_str_methods_bound.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := "a\nb\nc" 7 | 8 | v_len := v.len 9 | v_is_empty := v.is_empty 10 | v_lines := v.lines 11 | 12 | print "len", v_len() 13 | print "is_empty", v_is_empty() 14 | print "lines", v_lines() 15 | 16 | 17 | # Result: 18 | None 19 | 20 | # Output: 21 | len 5 22 | is_empty false 23 | lines 24 | 25 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__builtin_str_methods_static.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := "a\nb\nc" 7 | 8 | print "len", Str.len(v) 9 | print "is_empty", Str.is_empty(v) 10 | print "lines", Str.lines(v) 11 | 12 | 13 | # Result: 14 | None 15 | 16 | # Output: 17 | len 5 18 | is_empty false 19 | lines 20 | 21 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 10 8 | fn test(self): 9 | return self.v 10 | T().test() 11 | 12 | 13 | # Result: 14 | Int( 15 | 10, 16 | ) 17 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 10 8 | fn set(self, v): 9 | self.v = v 10 | fn get(self): 11 | return self.v 12 | 13 | t := T() 14 | t.set(20) 15 | t.get() 16 | 17 | 18 | # Result: 19 | Int( 20 | 20, 21 | ) 22 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method_derived.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | fn test(self): 9 | return self.v 10 | class U(T): 11 | fn test(self): 12 | return super.test() 13 | U().test() 14 | 15 | 16 | # Result: 17 | Int( 18 | 0, 19 | ) 20 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method_derived2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self, v): 8 | return v 9 | class U(T): 10 | fn test(self, v): 11 | return super.test(v) 12 | U().test(10) 13 | 14 | 15 | # Result: 16 | Int( 17 | 10, 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method_derived3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self, v=5): 8 | return v 9 | class U(T): 10 | fn test(self, v): 11 | return super.test(v) 12 | U().test(none) 13 | 14 | 15 | # Result: 16 | Int( 17 | 5, 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method_derived4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self, v): 8 | return v 9 | class U(T): 10 | fn test(self, v=5): 11 | return super.test(v) 12 | U().test() 13 | 14 | 15 | # Result: 16 | Int( 17 | 5, 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method_derived_static.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self, v): 8 | return v 9 | class U(T): 10 | fn test(self, v=5): 11 | return super.test(v) 12 | U.test(U()) 13 | 14 | 15 | # Result: 16 | Int( 17 | 5, 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_method_derived_static2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self, v): 8 | return v 9 | class U(T): 10 | fn test(self, v=5): 11 | return super.test(v) 12 | U.test(U(), 10) 13 | 14 | 15 | # Result: 16 | Int( 17 | 10, 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_nested_inheritance_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class A: 7 | fn test(self, v): 8 | return v + 1 9 | class B(A): 10 | fn test(self, v): 11 | return super.test(v) + 1 12 | class C(B): 13 | fn test(self, v): 14 | return super.test(v) + 1 15 | 16 | C().test(0) 17 | 18 | 19 | # Result: 20 | Int( 21 | 3, 22 | ) 23 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_class_nested_inheritance_method_static_call.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class A: 7 | fn test(self, v): 8 | return v + 1 9 | class B(A): 10 | fn test(self, v): 11 | return super.test(v) + 1 12 | class C(B): 13 | fn test(self, v): 14 | return super.test(v) + 1 15 | 16 | C.test(C(), 0) 17 | 18 | 19 | # Result: 20 | Int( 21 | 3, 22 | ) 23 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_fn_recursive.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(v): 7 | if v: return "yo" 8 | else: return test(true) 9 | 10 | test(true) 11 | test(false) 12 | 13 | 14 | # Result: 15 | Object( 16 | "yo", 17 | ) 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_fn_with_args.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(v): 7 | return v 8 | 9 | test(100) 10 | 11 | 12 | # Result: 13 | Int( 14 | 100, 15 | ) 16 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_fn_with_args__error_not_enough_args.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(v): 7 | return v 8 | 9 | test() 10 | 11 | 12 | # Result: 13 | runtime error: expected 1 arg, got 0 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__call_fn_with_args__error_too_many_args.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(v): 7 | return v 8 | 9 | test(100, 100) 10 | 11 | 12 | # Result: 13 | runtime error: expected 1 arg, got 2 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_derived_nested_init_call_chain.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | init(self): 8 | print("T.init") 9 | class U(T): 10 | init(self): 11 | super() 12 | print("U.init") 13 | class V(U): 14 | init(self): 15 | super() 16 | print("V.init") 17 | _ := V() 18 | 19 | 20 | # Result: 21 | None 22 | 23 | # Output: 24 | T.init 25 | U.init 26 | V.init 27 | 28 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_derived_with_init.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | pass 8 | class U(T): 9 | init(self): 10 | print("U.init") 11 | _ := U() 12 | 13 | 14 | # Result: 15 | None 16 | 17 | # Output: 18 | U.init 19 | 20 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_derived_with_init_and_call_parent_init.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | init(self): 8 | print("T.init") 9 | class U(T): 10 | init(self): 11 | super() 12 | print("U.init") 13 | _ := U() 14 | 15 | 16 | # Result: 17 | None 18 | 19 | # Output: 20 | T.init 21 | U.init 22 | 23 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_derived_with_init_and_no_call_parent_init.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | init(self): 8 | print("T.init") 9 | class U(T): 10 | init(self): 11 | print("U.init") 12 | _ := U() 13 | 14 | 15 | # Result: 16 | None 17 | 18 | # Output: 19 | U.init 20 | 21 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_derived_with_parent_init.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | init(self): 8 | print("T.init") 9 | class U(T): 10 | pass 11 | _ := U() 12 | 13 | 14 | # Result: 15 | None 16 | 17 | # Output: 18 | T.init 19 | 20 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_with_init.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | init(self): 9 | self.v = 10 10 | T().v 11 | 12 | 13 | # Result: 14 | Int( 15 | 10, 16 | ) 17 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_with_init_conditional_false.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = none 8 | init(self, v, set): 9 | if set: 10 | self.v = v 11 | ?T(10, false).v 12 | 13 | 14 | # Result: 15 | None 16 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_with_init_conditional_true.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = none 8 | init(self, v, set): 9 | if set: 10 | self.v = v 11 | ?T(10, true).v 12 | 13 | 14 | # Result: 15 | Int( 16 | 10, 17 | ) 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__class_with_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self): pass 8 | T 9 | 10 | 11 | # Result: 12 | Object( 13 | ClassType { 14 | name: "T", 15 | init: None, 16 | fields: {}, 17 | methods: { 18 | "test": Function { 19 | descriptor: FunctionDescriptor { 20 | name: "test", 21 | params: Params { 22 | has_self: true, 23 | min: 0, 24 | max: 0, 25 | }, 26 | upvalues: RefCell { 27 | value: [], 28 | }, 29 | frame_size: 1, 30 | instructions: 2, 31 | constants: 0, 32 | }, 33 | upvalues: [], 34 | module_id: ModuleId( 35 | None, 36 | ), 37 | }, 38 | }, 39 | parent: None, 40 | }, 41 | ) 42 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__closure_call.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn outer(): 7 | v := "yo" 8 | fn inner(): 9 | return v 10 | return inner 11 | 12 | outer()() 13 | 14 | 15 | # Result: 16 | Object( 17 | "yo", 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__data_class_with_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | fn test(self): pass 9 | T 10 | 11 | 12 | # Result: 13 | Object( 14 | ClassType { 15 | name: "T", 16 | init: None, 17 | fields: { 18 | "v": Int( 19 | 0, 20 | ), 21 | }, 22 | methods: { 23 | "test": Function { 24 | descriptor: FunctionDescriptor { 25 | name: "test", 26 | params: Params { 27 | has_self: true, 28 | min: 0, 29 | max: 0, 30 | }, 31 | upvalues: RefCell { 32 | value: [], 33 | }, 34 | frame_size: 1, 35 | instructions: 2, 36 | constants: 0, 37 | }, 38 | upvalues: [], 39 | module_id: ModuleId( 40 | None, 41 | ), 42 | }, 43 | }, 44 | parent: None, 45 | }, 46 | ) 47 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__empty_table.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := {} 7 | v 8 | 9 | 10 | # Result: 11 | Object( 12 | {}, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__example.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := 0 7 | v 8 | 9 | 10 | # Result: 11 | Int( 12 | 0, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__for_iter_iterable_class.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class Counter: 7 | n = 0 8 | max = 0 9 | 10 | init(self, max): 11 | self.max = max 12 | 13 | fn iter(self): 14 | return self 15 | 16 | fn next(self): 17 | if self.n < self.max: 18 | n := self.n 19 | self.n += 1 20 | return n 21 | 22 | fn done(self): 23 | return self.n >= self.max 24 | 25 | for v in Counter(10): 26 | print v 27 | 28 | 29 | # Result: 30 | None 31 | 32 | # Output: 33 | 0 34 | 1 35 | 2 36 | 3 37 | 4 38 | 5 39 | 6 40 | 7 41 | 8 42 | 9 43 | 44 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__for_iter_list.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | for item in ["a", "b", "c"]: 7 | print item 8 | 9 | 10 | # Result: 11 | None 12 | 13 | # Output: 14 | a 15 | b 16 | c 17 | 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__get_class_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 10 8 | T().v 9 | 10 | 11 | # Result: 12 | Int( 13 | 10, 14 | ) 15 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__get_class_parent_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 10 8 | class U(T): 9 | pass 10 | U().v 11 | 12 | 13 | # Result: 14 | Int( 15 | 10, 16 | ) 17 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_bool.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print "true", to_bool(true) 7 | print "false", to_bool(false) 8 | print "10.0", to_bool(10.0) 9 | print "0.0", to_bool(0.0) 10 | print "100", to_bool(100) 11 | print "0", to_bool(0) 12 | print "none", to_bool(none) 13 | print "{}", to_bool({}) 14 | print "[]", to_bool([]) 15 | print "\"test\"", to_bool("test") 16 | 17 | 18 | # Result: 19 | None 20 | 21 | # Output: 22 | true true 23 | false false 24 | 10.0 true 25 | 0.0 false 26 | 100 true 27 | 0 false 28 | none false 29 | {} true 30 | [] true 31 | "test" true 32 | 33 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_float__bad_input.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | to_float({}) 7 | 8 | 9 | # Result: 10 | runtime error: cannot convert `` to a float 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_float__float.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | to_float(10.5) 7 | 8 | 9 | # Result: 10 | Float( 11 | 10.5, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_float__int.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | to_float(10) 7 | 8 | 9 | # Result: 10 | Float( 11 | 10.0, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_int__bad_input.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | to_int({}) 7 | 8 | 9 | # Result: 10 | runtime error: cannot convert `
` to an int 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_int__float.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | to_int(10.5) 7 | 8 | 9 | # Result: 10 | Int( 11 | 10, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_int__int.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | to_int(10) 7 | 8 | 9 | # Result: 10 | Int( 11 | 10, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__to_str.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print to_str(true) 7 | print to_str(false) 8 | print to_str(100) 9 | print to_str(3.14) 10 | print to_str(none) 11 | print to_str({}) 12 | print to_str([]) 13 | print to_str("test") 14 | 15 | 16 | # Result: 17 | None 18 | 19 | # Output: 20 | true 21 | false 22 | 100 23 | 3.14 24 | none 25 |
26 | 27 | test 28 | 29 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__global_builtin_functions__type_of.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print type_of(true) 7 | print type_of(false) 8 | print type_of(100) 9 | print type_of(3.14) 10 | print type_of(none) 11 | print type_of({}) 12 | print type_of([]) 13 | print type_of("test") 14 | 15 | 16 | # Result: 17 | None 18 | 19 | # Output: 20 | bool 21 | bool 22 | int 23 | float 24 | none 25 | Table 26 | List 27 | String 28 | 29 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__heterogenous_type_equality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print 1 == "0" 7 | print 1 == false 8 | print 1 == true 9 | print 1 == none 10 | print none == "string" 11 | print none == [] 12 | print [] == "string" 13 | class Test: pass 14 | print Test() == "string" 15 | print Test() == none 16 | print Test() == [] 17 | print to_str == to_int 18 | print Test() == to_int 19 | 20 | 21 | # Result: 22 | None 23 | 24 | # Output: 25 | false 26 | false 27 | false 28 | false 29 | false 30 | false 31 | false 32 | false 33 | false 34 | false 35 | false 36 | false 37 | 38 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__heterogenous_type_unequality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print 1 != "0" 7 | print 1 != false 8 | print 1 != true 9 | print 1 != none 10 | print none != "string" 11 | print none != [] 12 | print [] != "string" 13 | class Test: pass 14 | print Test() != "string" 15 | print Test() != none 16 | print Test() != [] 17 | print to_str != to_int 18 | print Test() != to_int 19 | 20 | 21 | # Result: 22 | None 23 | 24 | # Output: 25 | true 26 | true 27 | true 28 | true 29 | true 30 | true 31 | true 32 | true 33 | true 34 | true 35 | true 36 | true 37 | 38 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__if_stmt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := true 7 | result := none 8 | if v: 9 | result = "true" 10 | else: 11 | result = "false" 12 | result 13 | 14 | 15 | # Result: 16 | Object( 17 | "true", 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__if_stmt_false.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := false 7 | result := none 8 | if v: 9 | result = "true" 10 | else: 11 | result = "false" 12 | result 13 | 14 | 15 | # Result: 16 | Object( 17 | "false", 18 | ) 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__import_fn.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | test.test("yo") 8 | 9 | 10 | # Result: 11 | Object( 12 | "yo", 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__import_fn_named.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | from test import test 7 | test("yo") 8 | 9 | 10 | # Result: 11 | Object( 12 | "yo", 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__import_value.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | test.value 8 | 9 | 10 | # Result: 11 | Int( 12 | 100, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__import_value_named.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | from test import value 7 | value 8 | 9 | 10 | # Result: 11 | Int( 12 | 100, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_class_with_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | fn test(self): pass 8 | T() 9 | 10 | 11 | # Result: 12 | Object( 13 | ClassInstance { 14 | name: "T", 15 | fields: { 16 | "test": Object( 17 | Function { 18 | descriptor: FunctionDescriptor { 19 | name: "test", 20 | params: Params { 21 | has_self: true, 22 | min: 0, 23 | max: 0, 24 | }, 25 | upvalues: RefCell { 26 | value: [], 27 | }, 28 | frame_size: 1, 29 | instructions: 2, 30 | constants: 0, 31 | }, 32 | upvalues: [], 33 | module_id: ModuleId( 34 | None, 35 | ), 36 | }, 37 | ), 38 | }, 39 | parent: None, 40 | }, 41 | ) 42 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_data_class_with_method.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | fn test(self): pass 9 | T() 10 | 11 | 12 | # Result: 13 | Object( 14 | ClassInstance { 15 | name: "T", 16 | fields: { 17 | "v": Int( 18 | 0, 19 | ), 20 | "test": Object( 21 | Function { 22 | descriptor: FunctionDescriptor { 23 | name: "test", 24 | params: Params { 25 | has_self: true, 26 | min: 0, 27 | max: 0, 28 | }, 29 | upvalues: RefCell { 30 | value: [], 31 | }, 32 | frame_size: 1, 33 | instructions: 2, 34 | constants: 0, 35 | }, 36 | upvalues: [], 37 | module_id: ModuleId( 38 | None, 39 | ), 40 | }, 41 | ), 42 | }, 43 | parent: None, 44 | }, 45 | ) 46 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_simple_class.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: pass 7 | T() 8 | 9 | 10 | # Result: 11 | Object( 12 | ClassInstance { 13 | name: "T", 14 | fields: {}, 15 | parent: None, 16 | }, 17 | ) 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_simple_class_derived.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: pass 7 | class U(T): pass 8 | U() 9 | 10 | 11 | # Result: 12 | Object( 13 | ClassInstance { 14 | name: "U", 15 | fields: {}, 16 | parent: Some( 17 | ClassType { 18 | name: "T", 19 | init: None, 20 | fields: {}, 21 | methods: {}, 22 | parent: None, 23 | }, 24 | ), 25 | }, 26 | ) 27 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_simple_data_class.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | T() 9 | 10 | 11 | # Result: 12 | Object( 13 | ClassInstance { 14 | name: "T", 15 | fields: { 16 | "v": Int( 17 | 0, 18 | ), 19 | }, 20 | parent: None, 21 | }, 22 | ) 23 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_simple_data_class_derived.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: pass 7 | class U(T): 8 | v = 0 9 | U() 10 | 11 | 12 | # Result: 13 | Object( 14 | ClassInstance { 15 | name: "U", 16 | fields: { 17 | "v": Int( 18 | 0, 19 | ), 20 | }, 21 | parent: Some( 22 | ClassType { 23 | name: "T", 24 | init: None, 25 | fields: {}, 26 | methods: {}, 27 | parent: None, 28 | }, 29 | ), 30 | }, 31 | ) 32 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__init_simple_data_class_derived_with_parent_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | class U(T): pass 9 | U() 10 | 11 | 12 | # Result: 13 | Object( 14 | ClassInstance { 15 | name: "U", 16 | fields: { 17 | "v": Int( 18 | 0, 19 | ), 20 | }, 21 | parent: Some( 22 | ClassType { 23 | name: "T", 24 | init: None, 25 | fields: { 26 | "v": Int( 27 | 0, 28 | ), 29 | }, 30 | methods: {}, 31 | parent: None, 32 | }, 33 | ), 34 | }, 35 | ) 36 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_invalid.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | [0, 1, 2]["yo"] 7 | 8 | 9 | # Result: 10 | runtime error: `yo` is not a valid index 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_invalid_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | ?[0, 1, 2]["yo"] 7 | 8 | 9 | # Result: 10 | runtime error: `yo` is not a valid index 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_negative.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | [0, 1, 2][-1] 7 | 8 | 9 | # Result: 10 | Int( 11 | 2, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_negative_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | ?[0, 1, 2][-1] 7 | 8 | 9 | # Result: 10 | Int( 11 | 2, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_oob.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | [0, 1, 2][100] 7 | 8 | 9 | # Result: 10 | runtime error: index `100` out of bounds, len was `3` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_oob_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | ?[0, 1, 2][100] 7 | 8 | 9 | # Result: 10 | None 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_positive.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | [0, 1, 2][1] 7 | 8 | 9 | # Result: 10 | Int( 11 | 1, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_positive_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | ?[0, 1, 2][1] 7 | 8 | 9 | # Result: 10 | Int( 11 | 1, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_zero.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | [0, 1, 2][0] 7 | 8 | 9 | # Result: 10 | Int( 11 | 0, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__list_indexing_zero_opt.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | ?[0, 1, 2][0] 7 | 8 | 9 | # Result: 10 | Int( 11 | 0, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__logical_and_expr_return_lhs.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | false && "b" 7 | 8 | 9 | # Result: 10 | Bool( 11 | false, 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__logical_and_expr_return_rhs.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | "a" && "b" 7 | 8 | 9 | # Result: 10 | Object( 11 | "b", 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__logical_or_expr_return_lhs.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | "a" || "b" 7 | 8 | 9 | # Result: 10 | Object( 11 | "a", 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__logical_or_expr_return_rhs.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | false || "b" 7 | 8 | 9 | # Result: 10 | Object( 11 | "b", 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__make_fn.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(): 7 | return "yo" 8 | 9 | test 10 | 11 | 12 | # Result: 13 | Object( 14 | Function { 15 | descriptor: FunctionDescriptor { 16 | name: "test", 17 | params: Params { 18 | has_self: false, 19 | min: 0, 20 | max: 0, 21 | }, 22 | upvalues: RefCell { 23 | value: [], 24 | }, 25 | frame_size: 1, 26 | instructions: 5, 27 | constants: 1, 28 | }, 29 | upvalues: [], 30 | module_id: ModuleId( 31 | None, 32 | ), 33 | }, 34 | ) 35 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__make_fn_with_args.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | fn test(v): 7 | return v 8 | 9 | test 10 | 11 | 12 | # Result: 13 | Object( 14 | Function { 15 | descriptor: FunctionDescriptor { 16 | name: "test", 17 | params: Params { 18 | has_self: false, 19 | min: 1, 20 | max: 1, 21 | }, 22 | upvalues: RefCell { 23 | value: [], 24 | }, 25 | frame_size: 2, 26 | instructions: 5, 27 | constants: 0, 28 | }, 29 | upvalues: [], 30 | module_id: ModuleId( 31 | None, 32 | ), 33 | }, 34 | ) 35 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__module_fail_to_parse.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | 8 | 9 | # Result: 10 | syntax error: 11 | expected `(` 12 | 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__module_not_found.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | 8 | 9 | # Result: 10 | runtime error: module `test` not found 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__module_vars.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | 8 | test.set(50) 9 | test.get() 10 | 11 | 12 | # Result: 13 | Int( 14 | 50, 15 | ) 16 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__module_vars_per_module.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | 8 | value := 200 9 | test.set(50) 10 | value = 0 11 | test.get() 12 | 13 | 14 | # Result: 15 | Int( 16 | 50, 17 | ) 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__more_optional_access.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | "a" ?? "b" 7 | 8 | 9 | # Result: 10 | Object( 11 | "a", 12 | ) 13 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__nested_optional_access.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := none 7 | 8 | ?v.a["b"].c ?? "test" 9 | 10 | 11 | # Result: 12 | Object( 13 | "test", 14 | ) 15 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__nested_table.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := {a: {b: 10}} 7 | v 8 | 9 | 10 | # Result: 11 | Object( 12 | { 13 | "a": Object( 14 | { 15 | "b": Int( 16 | 10, 17 | ), 18 | }, 19 | ), 20 | }, 21 | ) 22 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_add_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none + none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `+` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_div_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none / none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `/` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_equality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | a := none 7 | if a == none: 8 | print "a == none" 9 | if a != none: 10 | print "a != none" 11 | 12 | 13 | # Result: 14 | None 15 | 16 | # Output: 17 | a == none 18 | 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_ge_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none >= none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `>=` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_gt_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none > none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `>` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_le_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none <= none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `<=` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_lt_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none < none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `<` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_mul_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none * none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `*` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_pow_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none ** none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `**` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_rem_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none % none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `%` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__none_sub_error.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | none - none 7 | 8 | 9 | # Result: 10 | runtime error: cannot `-` `none` 11 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__object_equality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print to_int == to_int 7 | print to_str == to_str 8 | print to_int != to_str 9 | print [].push != [].push 10 | x := [] 11 | print x.push == x.push 12 | print x.is_empty != x.push 13 | print collect == collect 14 | print collect != to_int 15 | print "a" == "a" 16 | print "a" + "b" == "ab" 17 | print "a" + "b" != "ba" 18 | 19 | 20 | # Result: 21 | None 22 | 23 | # Output: 24 | true 25 | true 26 | true 27 | true 28 | true 29 | true 30 | true 31 | true 32 | true 33 | true 34 | true 35 | 36 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__order_of_eval.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | a := 1 7 | fn f(): 8 | a += 1 9 | return a 10 | print (a + f()) 11 | 12 | 13 | # Result: 14 | None 15 | 16 | # Output: 17 | 3 18 | 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__simple_class.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: pass 7 | T 8 | 9 | 10 | # Result: 11 | Object( 12 | ClassType { 13 | name: "T", 14 | init: None, 15 | fields: {}, 16 | methods: {}, 17 | parent: None, 18 | }, 19 | ) 20 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__simple_class_derived.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: pass 7 | class U(T): pass 8 | U 9 | 10 | 11 | # Result: 12 | Object( 13 | ClassType { 14 | name: "U", 15 | init: None, 16 | fields: {}, 17 | methods: {}, 18 | parent: Some( 19 | ClassType { 20 | name: "T", 21 | init: None, 22 | fields: {}, 23 | methods: {}, 24 | parent: None, 25 | }, 26 | ), 27 | }, 28 | ) 29 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__simple_data_class.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | T 9 | 10 | 11 | # Result: 12 | Object( 13 | ClassType { 14 | name: "T", 15 | init: None, 16 | fields: { 17 | "v": Int( 18 | 0, 19 | ), 20 | }, 21 | methods: {}, 22 | parent: None, 23 | }, 24 | ) 25 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__simple_data_class_derived.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: pass 7 | class U(T): 8 | v = 0 9 | U 10 | 11 | 12 | # Result: 13 | Object( 14 | ClassType { 15 | name: "U", 16 | init: None, 17 | fields: { 18 | "v": Int( 19 | 0, 20 | ), 21 | }, 22 | methods: {}, 23 | parent: Some( 24 | ClassType { 25 | name: "T", 26 | init: None, 27 | fields: {}, 28 | methods: {}, 29 | parent: None, 30 | }, 31 | ), 32 | }, 33 | ) 34 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__simple_data_class_derived_with_parent_field.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | class T: 7 | v = 0 8 | class U(T): pass 9 | U 10 | 11 | 12 | # Result: 13 | Object( 14 | ClassType { 15 | name: "U", 16 | init: None, 17 | fields: { 18 | "v": Int( 19 | 0, 20 | ), 21 | }, 22 | methods: {}, 23 | parent: Some( 24 | ClassType { 25 | name: "T", 26 | init: None, 27 | fields: { 28 | "v": Int( 29 | 0, 30 | ), 31 | }, 32 | methods: {}, 33 | parent: None, 34 | }, 35 | ), 36 | }, 37 | ) 38 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__small_jump.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | for i in 0..3: 7 | x := i + i + i + i + i + i + i + i + i 8 | print i 9 | 10 | 11 | # Result: 12 | None 13 | 14 | # Output: 15 | 0 16 | 1 17 | 2 18 | 19 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__string_comparison.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print "'a' < 'b'", "a" < "b" 7 | print "'b' >= 'a'", "b" >= "a" 8 | 9 | print "'b' < 'a'", "b" < "a" 10 | print "'a' >= 'b'", "a" >= "b" 11 | 12 | print "'a' == 'b'", "a" == "b" 13 | print "'b' == 'a'", "a" == "b" 14 | print "'a' == 'a'", "a" == "a" 15 | 16 | 17 | # Result: 18 | None 19 | 20 | # Output: 21 | 'a' < 'b' true 22 | 'b' >= 'a' true 23 | 'b' < 'a' false 24 | 'a' >= 'b' false 25 | 'a' == 'b' false 26 | 'b' == 'a' false 27 | 'a' == 'a' true 28 | 29 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__table_access_keyed.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := {a: 10} 7 | v["a"] 8 | 9 | 10 | # Result: 11 | Int( 12 | 10, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__table_access_named.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := {a: 10} 7 | v.a 8 | 9 | 10 | # Result: 11 | runtime error: `Table` does not support field access 12 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__table_access_unknown.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := {} 7 | v["a"] 8 | 9 | 10 | # Result: 11 | runtime error: `
` has no index `a` 12 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__table_equality.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | print {} == {} 7 | print {x: 3} == {x: 3} 8 | print {x: 3} != {x: none} 9 | print {x: 3} != {y: 3} 10 | print {x: 3} != {} 11 | print {x: 3} != {x: 3, y: 4} 12 | print {x: [1, 2]} == {x: [1, 2]} 13 | print {x: [1, 2]} != {x: [2, 3]} 14 | 15 | 16 | # Result: 17 | None 18 | 19 | # Output: 20 | true 21 | true 22 | true 23 | true 24 | true 25 | true 26 | true 27 | true 28 | 29 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__table_nested_access_keyed.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := {a: {b: 10}} 7 | v["a"]["b"] 8 | 9 | 10 | # Result: 11 | Int( 12 | 10, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__unary_invert.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := 20 7 | -v 8 | 9 | 10 | # Result: 11 | Int( 12 | -20, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__unary_not.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := false 7 | !v 8 | 9 | 10 | # Result: 11 | Bool( 12 | true, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__unary_not_float.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := 0.0 7 | !v 8 | 9 | 10 | # Result: 11 | Bool( 12 | true, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__unary_not_int.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := 0 7 | !v 8 | 9 | 10 | # Result: 11 | Bool( 12 | true, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__unary_not_none.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := none 7 | !v 8 | 9 | 10 | # Result: 11 | Bool( 12 | true, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__unary_not_str.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | v := "test" 7 | !v 8 | 9 | 10 | # Result: 11 | Bool( 12 | false, 13 | ) 14 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__use_import_in_nested_scope.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | import test 7 | fn foo(): 8 | print test 9 | foo() 10 | 11 | 12 | # Result: 13 | None 14 | 15 | # Output: 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__use_named_import_in_nested_scope.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | from test import value 7 | fn foo(): 8 | print value 9 | foo() 10 | 11 | 12 | # Result: 13 | None 14 | 15 | # Output: 16 | 100 17 | 18 | -------------------------------------------------------------------------------- /src/internal/vm/snapshots/hebi__internal__vm__tests__wide_jump.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/internal/vm/tests.rs 3 | expression: snapshot 4 | --- 5 | # Source: 6 | for i in 0..3: 7 | x := i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i 8 | print i 9 | 10 | 11 | # Result: 12 | None 13 | 14 | # Output: 15 | 0 16 | 1 17 | 2 18 | 19 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] // TEMP 2 | 3 | #[macro_use] 4 | pub mod macros; 5 | 6 | #[macro_use] 7 | mod util; 8 | 9 | mod internal { 10 | #[macro_use] 11 | pub(crate) mod object; 12 | 13 | pub(crate) mod bytecode; 14 | pub(crate) mod codegen; 15 | #[cfg(feature = "serde")] 16 | pub(crate) mod serde; 17 | pub(crate) mod syntax; 18 | pub(crate) mod value; 19 | pub(crate) mod vm; 20 | 21 | pub mod error; 22 | } 23 | 24 | pub mod public; 25 | #[cfg(feature = "serde")] 26 | pub mod serde; 27 | pub mod span; 28 | 29 | pub use beef::lean::Cow; 30 | 31 | pub mod prelude { 32 | pub use super::public::*; 33 | #[cfg(feature = "serde")] 34 | pub use super::serde::ValueDeserializer; 35 | } 36 | 37 | pub use internal::error::{Error, Result}; 38 | pub use public::*; 39 | -------------------------------------------------------------------------------- /src/public/object.rs: -------------------------------------------------------------------------------- 1 | pub mod function; 2 | pub mod list; 3 | pub mod string; 4 | pub mod table; 5 | 6 | use std::fmt::{Debug, Display}; 7 | 8 | use crate::internal::object::{self, Ptr}; 9 | use crate::public::{Bind, Global}; 10 | 11 | decl_ref! { 12 | struct Any(Ptr) 13 | } 14 | 15 | impl<'cx> Any<'cx> { 16 | pub fn cast>(self, global: Global<'cx>) -> Option { 17 | T::from_any(self, global) 18 | } 19 | } 20 | 21 | impl<'cx> ObjectRef<'cx> for Any<'cx> { 22 | fn as_any(&self, _: Global<'cx>) -> Any<'cx> { 23 | let ptr = self.inner.clone().into_any(); 24 | unsafe { ptr.bind_raw::<'cx>() } 25 | } 26 | 27 | fn from_any(v: Any<'cx>, _: Global<'cx>) -> Option { 28 | Some(v) 29 | } 30 | } 31 | 32 | impl<'cx> private::Sealed for Any<'cx> {} 33 | 34 | pub trait ObjectRef<'cx>: private::Sealed + Sized + Debug + Display { 35 | fn as_any(&self, global: Global<'cx>) -> Any<'cx>; 36 | fn from_any(v: Any<'cx>, global: Global<'cx>) -> Option; 37 | 38 | // TODO: add same methods as `Object` and delegate 39 | } 40 | 41 | mod private { 42 | pub trait Sealed {} 43 | } 44 | -------------------------------------------------------------------------------- /src/public/object/function.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::internal::object::{Function as OwnedFunction, Ptr}; 3 | 4 | decl_ref! { 5 | struct Function(Ptr) 6 | } 7 | 8 | impl_object_ref!(Function, OwnedFunction); 9 | 10 | impl<'cx> Function<'cx> {} 11 | -------------------------------------------------------------------------------- /src/public/object/string.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::internal::object::{Ptr, Str as OwnedStr}; 3 | use crate::public::{Hebi, Scope}; 4 | 5 | decl_ref! { 6 | struct Str(Ptr) 7 | } 8 | 9 | impl_object_ref!(Str, OwnedStr); 10 | 11 | impl<'cx> Str<'cx> { 12 | pub fn as_str(&self) -> &str { 13 | self.inner.as_str() 14 | } 15 | } 16 | 17 | impl<'cx> Global<'cx> { 18 | pub fn new_string(&self, v: impl ToString) -> Str<'cx> { 19 | self.inner.alloc(OwnedStr::owned(v)).bind(self.clone()) 20 | } 21 | } 22 | 23 | impl<'cx> Scope<'cx> { 24 | pub fn new_string(&self, v: impl ToString) -> Str<'cx> { 25 | self.global().new_string(v) 26 | } 27 | } 28 | 29 | impl Hebi { 30 | pub fn new_string(&self, v: impl ToString) -> Str { 31 | self.global().new_string(v) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/serde.rs: -------------------------------------------------------------------------------- 1 | use serde::de::DeserializeSeed; 2 | 3 | use crate::public::{Bind, Global, Value}; 4 | 5 | pub struct ValueDeserializer<'cx> { 6 | global: Global<'cx>, 7 | } 8 | 9 | impl<'cx> ValueDeserializer<'cx> { 10 | pub fn new(global: Global<'cx>) -> Self { 11 | Self { global } 12 | } 13 | } 14 | 15 | impl<'de, 'cx> DeserializeSeed<'de> for ValueDeserializer<'cx> { 16 | type Value = Value<'cx>; 17 | 18 | fn deserialize(self, deserializer: D) -> Result 19 | where 20 | D: serde::Deserializer<'de>, 21 | { 22 | crate::internal::serde::ValueDeserializer { 23 | global: self.global.inner, 24 | } 25 | .deserialize(deserializer) 26 | .map(|value| unsafe { value.bind_raw::<'cx>() }) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__emit_report_multi_line.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\",\n 13..36).report(\"let x: Foo = Bar {\\n a: 0,\\n b: 0,\\n};\", true)" 4 | --- 5 | error: test 6 | | let x: Foo = Bar { 7 | |  a: 0, 8 | |  b: 0, 9 | | }; 10 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__emit_report_multi_line_edge_case_sandwiched_newline.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 0..2).report(\"\\\"\\n\\\\\", true)" 4 | --- 5 | error: test 6 | | "\ 7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__emit_report_multi_line_edge_case_sandwiched_newline_2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 1..8).report(\"\\0\\\"\\nl\\n\\n\\n\\n\\\\\", true)" 4 | --- 5 | error: test 6 | | " 7 | | l 8 | | _ 9 | | _ 10 | | _\ 11 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__emit_report_multi_line_large.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\",\n 13..76).report(\"let x: Foo = Bar {\\n a: 0,\\n b: 0,\\n c: 0,\\n d: 0,\\n e: 0,\\n f: 0,\\n g: 0,\\n};\",\n true)" 4 | --- 5 | error: test 6 | | let x: Foo = Bar { 7 | |  a: 0, 8 | |  b: 0, 9 | |  c: 0, 10 | |  d: 0, 11 | |  e: 0, 12 | |  f: 0, 13 | |  g: 0, 14 | | }; 15 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__emit_report_single_line.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\",\n 10..11).report(\"let x = 10\\nlet y = 20;\", true)" 4 | --- 5 | error: test 6 | | let x = 10_let y = 20; 7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\",\n 17..31).report(\"lorem ipsum\\ndolor sit amet\\nconsectetur adipiscing elit\",\n true)" 4 | --- 5 | error: test 6 | | dolor sit amet 7 | | consectetur adipiscing elit 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 1..3).report(\"\\n\\\\n\", true)" 4 | --- 5 | error: test 6 | | \n 7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-4.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 19..19).report(\"d( \", true)" 4 | --- 5 | error: test 6 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-5.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 4..6).report(\"\\u{9389a}\\\"\\n\", true)" 4 | --- 5 | error: test 6 | | 򓢚" 7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-6.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 0..2).report(\"x \", true)" 4 | --- 5 | error: test 6 | | x  7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-7.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 0..2).report(\"З \", true)" 4 | --- 5 | error: test 6 | | З 7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line-8.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\", 0..2).report(\"\\\"\\n\\\\\", true)" 4 | --- 5 | error: test 6 | | "\ 7 | 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_multi_line.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\",\n 6..17).report(\"lorem ipsum\\ndolor sit amet\\nconsectetur adipiscing elit\",\n true)" 4 | --- 5 | error: test 6 | | lorem ipsum 7 | | dolor sit amet 8 | -------------------------------------------------------------------------------- /src/span/snapshots/hebi__span__tests__snippet_single_line.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: src/span/tests.rs 3 | expression: "SpannedError::new(\"error: test\",\n 6..17).report(\"lorem ipsum dolor sit amet consectetur adipiscing elit\",\n true)" 4 | --- 5 | error: test 6 | | lorem ipsum dolor sit amet consectetur adipiscing elit 7 | 8 | -------------------------------------------------------------------------------- /vscode-hebi/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.vsix -------------------------------------------------------------------------------- /vscode-hebi/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "args": [ 13 | "--extensionDevelopmentPath=${workspaceFolder}" 14 | ] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /vscode-hebi/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | .gitignore 4 | vsc-extension-quickstart.md 5 | -------------------------------------------------------------------------------- /vscode-hebi/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "vscode-hebi" extension will be documented in this file. 4 | 5 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. 6 | 7 | ## [Unreleased] 8 | 9 | - Initial release -------------------------------------------------------------------------------- /vscode-hebi/LICENSE.md: -------------------------------------------------------------------------------- 1 | Licensed under either of 2 | 3 | - Apache License, Version 2.0 4 | ([LICENSE-APACHE](https://github.com/jprochazk/hebi/blob/main/LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) 5 | - MIT license 6 | ([LICENSE-MIT](https://github.com/jprochazk/hebi/blob/main/LICENSE-MIT) or http://opensource.org/licenses/MIT) 7 | 8 | at your option. 9 | -------------------------------------------------------------------------------- /vscode-hebi/README.md: -------------------------------------------------------------------------------- 1 | # vscode-hebi 2 | 3 | Basic language support for Hebi 4 | 5 | - Syntax highlighting 6 | - Bracket pairs 7 | - Comments 8 | - On enter code hooks for indentation when entering a block 9 | -------------------------------------------------------------------------------- /vscode-hebi/language-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | // symbol used for single line comment. Remove this entry if your language does not support line comments 4 | "lineComment": "#" 5 | }, 6 | // symbols used as brackets 7 | "brackets": [ 8 | ["{", "}"], 9 | ["[", "]"], 10 | ["(", ")"] 11 | ], 12 | // symbols that are auto closed when typing 13 | "autoClosingPairs": [ 14 | ["{", "}"], 15 | ["[", "]"], 16 | ["(", ")"], 17 | ["\"", "\""], 18 | ], 19 | // symbols that can be used to surround a selection 20 | "surroundingPairs": [ 21 | ["{", "}"], 22 | ["[", "]"], 23 | ["(", ")"], 24 | ["\"", "\""], 25 | ], 26 | "onEnterRules": [ 27 | { 28 | "beforeText": "^\\s*(?:import|if|elif|else|for|while|loop|fn|class).*?:\\s*$\\n?", 29 | "action": { 30 | "indent": "indent" 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /vscode-hebi/syntaxes/highlight-hebi-string.json: -------------------------------------------------------------------------------- 1 | { 2 | "scopeName": "inline-hebi.injection", 3 | "fileTypes": "rs", 4 | "injectionSelector": "L:source -comment -string", 5 | "patterns": [ 6 | { 7 | "comment": "Rust multi-line raw strings", 8 | "begin": "(b?r)(#*)(\")(\\s*#\\s*\\!\\s*hebi)", 9 | "beginCaptures": { 10 | "1": { 11 | "name": "string.quoted.byte.raw.rust" 12 | }, 13 | "2": { 14 | "name": "string.quoted.raw.rust" 15 | }, 16 | "3": { 17 | "name": "string.quoted.double.rust" 18 | }, 19 | "4": { 20 | "name": "comment.hebi" 21 | } 22 | }, 23 | "end": "(\")(\\2)", 24 | "endCaptures": { 25 | "1": { 26 | "name": "string.quoted.double.rust" 27 | }, 28 | "2": { 29 | "name": "string.quoted.raw.rust" 30 | } 31 | }, 32 | "patterns": [ 33 | { 34 | "include": "source.hebi" 35 | } 36 | ] 37 | } 38 | ] 39 | } 40 | 41 | -------------------------------------------------------------------------------- /xtask/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xtask" 3 | version = "0.0.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] -------------------------------------------------------------------------------- /xtask/README.md: -------------------------------------------------------------------------------- 1 | # xtask 2 | 3 | This repository uses [cargo-xtask](https://github.com/matklad/cargo-xtask) for various utilities, scripts, and tasks. 4 | 5 | To see all available tasks, run: 6 | ``` 7 | $ cargo xtask 8 | ``` 9 | 10 | To run one of them, use: 11 | ``` 12 | $ cargo xtask 13 | ``` 14 | 15 | For example: 16 | ``` 17 | # Run all tests and examples 18 | $ cargo xtask test 19 | ``` 20 | 21 | ## Adding tasks 22 | 23 | To add a new task: 24 | 25 | * Think of a good name 26 | * Create a file for it under [`src/task`](./src/task/) 27 | * Expose a `run` function from it 28 | * This is the entrypoint to your task 29 | * In [`src/task.rs`](./src/task.rs): 30 | * Add it as a submodule 31 | * Add some help text for it to the `HELP` constant 32 | * Add a match arm for it in `run` 33 | 34 | That's it. Your task should now be available as `cargo xtask `. 35 | -------------------------------------------------------------------------------- /xtask/src/main.rs: -------------------------------------------------------------------------------- 1 | mod task; 2 | 3 | use std::env; 4 | use std::process::ExitCode; 5 | 6 | type Result = std::result::Result>; 7 | 8 | fn try_main() -> Result<()> { 9 | let mut args = env::args(); 10 | let task = args.nth(1); 11 | let args = args.collect::>(); 12 | match task.as_deref() { 13 | Some(task) => task::run(task, &args), 14 | None => task::print_help(), 15 | } 16 | } 17 | 18 | fn main() -> ExitCode { 19 | match try_main() { 20 | Ok(()) => ExitCode::SUCCESS, 21 | Err(e) => { 22 | eprintln!("{e}"); 23 | ExitCode::FAILURE 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /xtask/src/task.rs: -------------------------------------------------------------------------------- 1 | use crate::Result; 2 | 3 | const HELP: &str = " 4 | Usage: 5 | xtask 6 | 7 | Tasks: 8 | examples : run all examples 9 | snap : run snapshot tests in review mode 10 | miri : run cargo command under miri 11 | test : run tests and examples 12 | "; 13 | 14 | pub mod common; 15 | 16 | pub mod bench; 17 | pub mod examples; 18 | pub mod miri; 19 | pub mod snap; 20 | pub mod template; 21 | pub mod test; 22 | 23 | pub fn print_help() -> Result<()> { 24 | eprintln!("{HELP}"); 25 | Ok(()) 26 | } 27 | 28 | pub fn run(which: &str, args: &[String]) -> Result<()> { 29 | match which { 30 | "examples" => examples::run(args), 31 | "snap" => snap::run(args), 32 | "miri" => miri::run(args), 33 | "test" => test::run(args), 34 | "bench" => bench::run(args), 35 | // "template" => template::run(args), 36 | _ => print_help(), 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xtask/src/task/bench.rs: -------------------------------------------------------------------------------- 1 | use super::common::{cargo, CheckStatus}; 2 | use crate::Result; 3 | 4 | pub fn run(args: &[String]) -> Result<()> { 5 | cargo("bench") 6 | .env("RUSTFLAGS", "--cfg enable_slow_bench") 7 | .args(args) 8 | .spawn()? 9 | .wait()? 10 | .check()?; 11 | 12 | Ok(()) 13 | } 14 | -------------------------------------------------------------------------------- /xtask/src/task/common.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::OsStr; 2 | use std::process::{Command, ExitStatus}; 3 | use std::{env, path}; 4 | 5 | use crate::Result; 6 | 7 | pub fn project_root() -> path::PathBuf { 8 | path::Path::new(&env!("CARGO_MANIFEST_DIR")) 9 | .ancestors() 10 | .nth(1) 11 | .unwrap() 12 | .to_path_buf() 13 | } 14 | 15 | pub fn cargo(command: impl AsRef) -> Command { 16 | let mut process = Command::new(env!("CARGO")); 17 | process.arg(command); 18 | process 19 | } 20 | 21 | pub trait CheckStatus { 22 | fn check(&self) -> Result<()>; 23 | } 24 | 25 | impl CheckStatus for ExitStatus { 26 | fn check(&self) -> Result<()> { 27 | if !self.success() { 28 | Err( 29 | format!( 30 | "Process exited with error code {}", 31 | self.code().unwrap_or(-1) 32 | ) 33 | .into(), 34 | ) 35 | } else { 36 | Ok(()) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /xtask/src/task/examples.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::OsStr; 2 | use std::fs; 3 | 4 | use super::common::{cargo, project_root, CheckStatus}; 5 | use crate::Result; 6 | 7 | pub fn run(args: &[String]) -> Result<()> { 8 | let examples_dir = project_root().join("examples"); 9 | 10 | let mut examples = vec![]; 11 | for example in fs::read_dir(examples_dir)? { 12 | let example = example?; 13 | let metadata = example.metadata()?; 14 | let path = example.path(); 15 | if metadata.is_file() && path.extension() == Some(OsStr::new("rs")) { 16 | let name = path 17 | .file_stem() 18 | .ok_or_else(|| format!("invalid path {}", path.display()))?; 19 | examples.push(name.to_owned()); 20 | } 21 | } 22 | 23 | for example in examples { 24 | cargo("run") 25 | .arg("--example") 26 | .arg(&example) 27 | .arg("--all-features") 28 | .args(args.iter()) 29 | .spawn()? 30 | .wait()? 31 | .check()?; 32 | } 33 | 34 | Ok(()) 35 | } 36 | -------------------------------------------------------------------------------- /xtask/src/task/snap.rs: -------------------------------------------------------------------------------- 1 | use super::common::{cargo, CheckStatus}; 2 | use crate::Result; 3 | 4 | pub fn run(args: &[String]) -> Result<()> { 5 | cargo("insta") 6 | .args([ 7 | "test", 8 | "--all-features", 9 | "--review", 10 | "--delete-unreferenced-snapshots", 11 | "--no-ignore", 12 | "--", 13 | ]) 14 | .args(args.iter()) 15 | .spawn()? 16 | .wait()? 17 | .check() 18 | } 19 | -------------------------------------------------------------------------------- /xtask/src/task/template.rs: -------------------------------------------------------------------------------- 1 | //! Task template 2 | //! 3 | //! Copy it over to a new file to bootstrap a new task. 4 | 5 | #![allow(dead_code, unused_variables)] 6 | 7 | use crate::Result; 8 | 9 | pub fn run(args: &[String]) -> Result<()> { 10 | todo!("Template command") 11 | } 12 | -------------------------------------------------------------------------------- /xtask/src/task/test.rs: -------------------------------------------------------------------------------- 1 | use super::common::{cargo, CheckStatus}; 2 | use crate::Result; 3 | 4 | pub fn run(args: &[String]) -> Result<()> { 5 | cargo("test") 6 | .args(["--all-targets", "--all-features"]) 7 | .args(args) 8 | .spawn()? 9 | .wait()? 10 | .check()?; 11 | 12 | super::examples::run(args)?; 13 | 14 | Ok(()) 15 | } 16 | --------------------------------------------------------------------------------