├── testData ├── exec │ ├── basics.out │ ├── integers.out │ ├── optimizer_add.out │ ├── optimizer_mul.out │ ├── parenCallee.out │ ├── spec │ │ ├── closure.out │ │ ├── ifstmt.out │ │ ├── dowstmt.out │ │ ├── conditionalFor.out │ │ ├── constFolding.out │ │ ├── constFoldingCond.out │ │ ├── class_extend.out │ │ ├── enums.out │ │ ├── stringtmplt.out │ │ ├── classInher.out │ │ ├── const_with_expr.out │ │ ├── const.out │ │ ├── trystmt.out │ │ ├── destruct.out │ │ ├── func_pure_attr.out │ │ ├── stringtmplt.nut │ │ ├── conditionalFor.nut │ │ ├── constFoldingCond.nut │ │ ├── dowstmt.nut │ │ ├── class.out │ │ ├── generators.out │ │ ├── whilestmt.out │ │ ├── forstmt.out │ │ ├── enums.nut │ │ ├── forstmt.nut │ │ ├── ifstmt.nut │ │ ├── trystmt.nut │ │ ├── constFolding.nut │ │ ├── class_extend.nut │ │ ├── whilestmt.nut │ │ ├── generators.nut │ │ ├── const_with_expr.nut │ │ ├── destruct.nut │ │ ├── const.nut │ │ ├── class.nut │ │ ├── closure.nut │ │ ├── foreachstmt.out │ │ └── func_pure_attr.nut │ ├── weird │ │ ├── 2000_args.out │ │ ├── assign_to_optional_1.out │ │ ├── assign_to_optional_2.out │ │ ├── assign_to_optional_3.out │ │ ├── assign_to_optional_2.nut │ │ ├── assign_to_optional_1.nut │ │ └── assign_to_optional_3.nut │ ├── compare_int_float.out │ ├── compare_int_int.out │ ├── const_in_closures.out │ ├── fuzzer_seed_7200.out │ ├── mod_by_minus_one_vm.out │ ├── stack_metamethod.out │ ├── string_interpolation.out │ ├── div64_by_minus_one_opt.out │ ├── div64_by_minus_one_vm.out │ ├── mod64_by_minus_one_opt.out │ ├── mod64_by_minus_one_vm.out │ ├── mod_by_minus_one_opt.out │ ├── stack_metamethod_few_args.out │ ├── stack_metamethod_locals.out │ ├── stdlib │ │ ├── deep_hash.out │ │ ├── rawdelete.out │ │ ├── swap.out │ │ ├── regexp.out │ │ ├── swap_stack_check.out │ │ ├── math_min_max_clamp.out │ │ ├── obj_serialization_valid.out │ │ ├── docstring.out │ │ ├── copy_content_with_replace.out │ │ ├── debug.out │ │ ├── swap.nut │ │ ├── math_min_max_clamp.nut │ │ ├── string.out │ │ ├── obj_serialization_errors_arg.out │ │ ├── regexp.nut │ │ └── swap_stack_check.nut │ ├── div_by_minus_one_opt.out │ ├── div_by_minus_one_vm.out │ ├── fuzzer_seed_3250.out │ ├── inexpr_block │ │ ├── inexpr_block_1.out │ │ ├── inexpr_block_2.out │ │ ├── inexpr_block_4.out │ │ ├── inexpr_block_5.out │ │ ├── inexpr_block_6.out │ │ ├── inexpr_block_7.out │ │ ├── inexpr_block_3.out │ │ ├── inexpr_block_8.out │ │ ├── inexpr_block_2.nut │ │ ├── inexpr_block_6.nut │ │ ├── inexpr_block_7.nut │ │ ├── inexpr_block_1.nut │ │ ├── inexpr_block_4.nut │ │ ├── inexpr_block_5.nut │ │ ├── inexpr_block_3.nut │ │ └── inexpr_block_8.nut │ ├── ph_optimizer_null_call_1.out │ ├── ph_optimizer_null_call_2.out │ ├── ph_optimizer_null_call_3.out │ ├── staticmemo │ │ ├── static_opt2.out │ │ ├── static_freeze.out │ │ ├── static_reset2.out │ │ ├── static_loop.out │ │ ├── static_opt.out │ │ ├── static_reset1.out │ │ ├── static_exception.out │ │ ├── static_assign_itself.out │ │ ├── static_loop.nut │ │ ├── static_nested.out │ │ ├── static_tables.out │ │ ├── static_reset_module.out │ │ ├── static_freeze.nut │ │ ├── static_types.out │ │ ├── static_opt.nut │ │ ├── static_reset_module.nut │ │ ├── static_exception.nut │ │ ├── static_nested.nut │ │ ├── static_assign_itself.nut │ │ ├── static_opt2.nut │ │ └── static_tables.nut │ ├── locals_chain.out │ ├── deep_loop_variable.out │ ├── type_hints │ │ ├── var_decl.out │ │ ├── function_types.out │ │ └── var_decl.nut │ ├── div_by_minus_one_opt.nut │ ├── mod_by_minus_one_opt.nut │ ├── fuzzer_seed_7200.nut │ ├── import_correct.out │ ├── mod64_by_minus_one_opt.nut │ ├── ph_optimizer_null_call_1.nut │ ├── div_by_minus_one_vm.nut │ ├── mod_by_minus_one_vm.nut │ ├── parenCallee.nut │ ├── mod64_by_minus_one_vm.nut │ ├── ph_optimizer_null_call_3.nut │ ├── testNullPropagation.out │ ├── const_in_closures.nut │ ├── div64_by_minus_one_opt.nut │ ├── optimizer.out │ ├── ph_optimizer_null_call_2.nut │ ├── deep_loop_variable.nut │ ├── optimizer_add.nut │ ├── string_interpolation_new.out │ ├── optimizer_mul.nut │ ├── fuzzer_seed_3250.nut │ ├── locals_chain.nut │ ├── div64_by_minus_one_vm.nut │ ├── array_methods.out │ ├── coroutines.out │ ├── table_methods.out │ ├── stack_metamethod_few_args.nut │ ├── basics.nut │ ├── string_methods.out │ ├── is_frozen.out │ ├── optimizer.nut │ ├── import_correct.nut │ └── string_interpolation_new.nut ├── diagnostics │ ├── base_pp.nut │ ├── base_x_pp.nut │ ├── import_01.diag.txt │ ├── import_02.diag.txt │ ├── import_06.diag.txt │ ├── leading_zero_1.nut │ ├── leading_zero_2.nut │ ├── base_as_array_pp.nut │ ├── import_01.nut │ ├── leading_zero_3.nut │ ├── base_as_array_assign.nut │ ├── binding_assign.nut │ ├── import_04.nut │ ├── invalid_float_2.nut │ ├── invalid_float_3.nut │ ├── invalid_type_hint_1.nut │ ├── unfinished_hex.nut │ ├── assign_to_expr.nut │ ├── assign_to_expr2.nut │ ├── import_03.nut │ ├── import_07.nut │ ├── invalid_float_1.nut │ ├── invalid_string_interp_1.nut │ ├── invalid_type_hint_2.nut │ ├── hex_overflow.nut │ ├── integer_overflow_2.nut │ ├── integer_overflow_int_max.nut │ ├── interp_str_not_string.nut │ ├── import_05.nut │ ├── interp_str_wrong_template.nut │ ├── invalid_type_hint_3.nut │ ├── letAssign.nut │ ├── need_space_after_hex.nut │ ├── assign_to_optional_7.nut │ ├── const_scope_1.nut │ ├── import_error.nut │ ├── need_space_after_float.nut │ ├── need_space_after_int.nut │ ├── var_scope_1.nut │ ├── float_overflow.nut │ ├── integer_overflow.nut │ ├── var_scope_3.nut │ ├── const_scope_3.nut │ ├── interp_str_not_string_2.nut │ ├── var_scope_2.nut │ ├── const_scope_2.nut │ ├── type_hints_01.nut │ ├── type_hints_04.nut │ ├── delete_base.nut │ ├── interp_str_hanging_missed_ccurvy.nut │ ├── type_hints_02.nut │ ├── float_underflow.nut │ ├── type_hints_06.nut │ ├── type_hints_05.nut │ ├── type_hints_03.nut │ ├── 1000_local_variables.diag.txt │ ├── space_sep_name_space.nut.txt │ ├── var_scope_1.diag.txt │ ├── var_scope_2.diag.txt │ ├── const_scope_1.diag.txt │ ├── const_scope_2.diag.txt │ ├── import_04.diag.txt │ ├── base_pp.diag.txt │ ├── import_07.diag.txt │ ├── invalid_float_1.diag.txt │ ├── many_args_in_function_call.diag.txt │ ├── var_scope_3.diag.txt │ ├── assign_to_expr.diag.txt │ ├── const_scope_3.diag.txt │ ├── invalid_float_2.diag.txt │ ├── invalid_float_3.diag.txt │ ├── invalid_type_hint_1.diag.txt │ ├── base_x_pp.diag.txt │ ├── unfinished_hex.diag.txt │ ├── import_03.diag.txt │ ├── base_as_array_assign.diag.txt │ ├── clone_op_allowed.nut.txt │ ├── clone_op_forbiden.nut.txt │ ├── delete_base.diag.txt │ ├── interp_str_not_string.diag.txt │ ├── interp_str_not_string_2.diag.txt │ ├── invalid_string_interp_1.diag.txt │ ├── assign_to_expr2.diag.txt │ ├── base_as_array_pp.diag.txt │ ├── import_05.diag.txt │ ├── invalid_type_hint_2.diag.txt │ ├── import_02.nut │ ├── leading_zero_1.diag.txt │ ├── leading_zero_2.diag.txt │ ├── need_space_after_int.diag.txt │ ├── interp_str_wrong_template.diag.txt │ ├── leading_zero_3.diag.txt │ ├── need_space_after_float.diag.txt │ ├── space_sep_name.nut.txt │ ├── assign_to_optional_7.diag.txt │ ├── clone_op_allowed.diag.txt │ ├── need_space_after_hex.diag.txt │ ├── hex_overflow.diag.txt │ ├── import_error.diag.txt │ ├── integer_overflow_2.diag.txt │ ├── interp_str_hanging_missed_ccurvy.diag.txt │ ├── integer_overflow_int_max.diag.txt │ ├── clone_op_forbiden.diag.txt │ ├── letAssign.diag.txt │ ├── delete_forbid_pragma.diag.txt │ ├── binding_assign.diag.txt │ ├── invalid_type_hint_3.diag.txt │ ├── float_overflow.diag.txt │ ├── space_sep_name_space.diag.txt │ ├── integer_overflow.diag.txt │ ├── space_sep_name.diag.txt │ ├── float_underflow.diag.txt │ ├── type_hints_04.diag.txt │ ├── type_hints_05.diag.txt │ ├── type_hints_06.diag.txt │ ├── type_hints_01.diag.txt │ ├── type_hints_02.diag.txt │ ├── type_hints_03.diag.txt │ ├── import_06.nut │ ├── delete_forbid_pragma.nut.txt │ ├── 50k_paren_brackets.diag.txt │ └── 50k_square_brackets.diag.txt ├── static_analyzer │ ├── foo.diag.txt │ ├── w247.diag.txt │ ├── w302.diag.txt │ ├── w222_deep.diag.txt │ ├── w232_ter.diag.txt │ ├── w233_deep.diag.txt │ ├── w238_isis.diag.txt │ ├── w248_not.diag.txt │ ├── w248_oror.diag.txt │ ├── w302_loop.diag.txt │ ├── 248_instanceof.diag.txt │ ├── klass_check.diag.txt │ ├── param_check.diag.txt │ ├── w200_3wcmp.diag.txt │ ├── w217_cond_cont.diag.txt │ ├── w221_delete.diag.txt │ ├── w225_switch.diag.txt │ ├── w227_varargs.diag.txt │ ├── w232_lambda.diag.txt │ ├── w232_nerge.diag.txt │ ├── w238_sqconfig.diag.txt │ ├── w239_sqconfig.diag.txt │ ├── w248_andnad1.diag.txt │ ├── w248_complex2.diag.txt │ ├── w248_getfield.diag.txt │ ├── w248_nullc_3.diag.txt │ ├── w248_tyopeof1.diag.txt │ ├── w288_lambdas2.diag.txt │ ├── w288_native.diag.txt │ ├── w301_closure2.diag.txt │ ├── w302_dowhile.diag.txt │ ├── w302_try_catch.diag.txt │ ├── efferct_fropm_call.diag.txt │ ├── w225_empty_stmt.diag.txt │ ├── w233_inc_in_for.diag.txt │ ├── w241_conditional.diag.txt │ ├── w248_in_container.diag.txt │ ├── w248_while_cond.diag.txt │ ├── w260_table_sqconfig.diag.txt │ ├── intersected_assignment.diag.txt │ ├── foo.nut │ ├── w273.nut │ ├── w235.nut │ ├── w247.nut │ ├── w209.nut │ ├── w208.nut │ ├── w227_external.nut │ ├── w228_4.nut │ ├── w233.nut │ ├── w227_lambdas.nut │ ├── w233_destruct.nut │ ├── klass_check.nut │ ├── w216.nut │ ├── w221_delete.nut │ ├── w227_fn_with_same_param.nut │ ├── w231.nut │ ├── w232_ternary.nut │ ├── w238_idname.nut │ ├── w222.nut │ ├── w232_not.nut │ ├── w234.nut │ ├── w286.nut │ ├── w206.nut │ ├── w279_1.nut │ ├── w279_2.nut │ ├── w224_then.nut │ ├── w225_empty_stmt.nut │ ├── w228_table.nut │ ├── w233_deep.nut │ ├── w288_lambdas2.nut │ ├── w288_require.nut │ ├── w302.nut │ ├── w228.nut │ ├── w248_chain.nut │ ├── w205.nut │ ├── w223_method_is.nut │ ├── w264.nut │ ├── w204.nut │ ├── w229.nut │ ├── w248_getfield.nut │ ├── w248_special_name_func.nut │ ├── w280.nut │ ├── w200_arith.nut │ ├── w220.nut │ ├── w227_varargs.nut │ ├── w238_isis.nut │ ├── w273.diag.txt │ ├── w200.nut │ ├── w251.nut │ ├── w288_require_indirect.nut │ ├── w227_let_init_fun.nut │ ├── w248_in.nut │ ├── w248_nullc_2.nut │ ├── w260_table.nut │ ├── w274.nut │ ├── w289.nut │ ├── w215.nut │ ├── w228_2.nut │ ├── w248_in_container.nut │ ├── w260_local_function.nut │ ├── w260_table_sqconfig.nut │ ├── 248_instanceof.nut │ ├── w200_arith_deep.nut │ ├── w227_table.nut │ ├── w249.nut │ ├── w274_2.nut │ ├── w291.nut │ ├── w295.nut │ ├── w312_require.nut │ ├── w200_arith_plus_eq.nut │ ├── w205-2.nut │ ├── w238_sqconfig.nut │ ├── w249_array.nut │ ├── w302_dowhile.nut │ ├── w200_stringconcat.nut │ ├── w210.nut │ ├── w221.nut │ ├── w232_false.nut │ ├── w248_eq_get.nut │ ├── w286_2.nut │ ├── w225.nut │ ├── w233_const_key.nut │ ├── w248_assert.nut │ ├── w254_instanceof.nut │ ├── w309_require.nut │ ├── w310_require.nut │ ├── w200_static_memo_expr.nut │ ├── w224_while.nut │ ├── w232_true.nut │ ├── w200_special_func_name.nut │ ├── w220_deep.nut │ ├── w241.nut │ ├── w264.diag.txt │ ├── w266.nut │ ├── w288.nut │ ├── w217_break.nut │ ├── w248_override.nut │ ├── w254_notin.nut │ ├── efferct_fropm_call.nut │ ├── w206.diag.txt │ ├── w209.diag.txt │ ├── w224_then.diag.txt │ ├── w227_table.diag.txt │ ├── w251.diag.txt │ ├── w254.nut │ ├── param_check.nut │ ├── w190.nut │ ├── w210_deep.nut │ ├── w215_nullc.nut │ ├── w303_destruct.nut │ ├── w200_3wcmp.nut │ ├── w226.diag.txt │ ├── w228_3.nut │ ├── w248_andor.nut │ ├── w286_oror_andand.nut │ ├── w213.nut │ ├── w217_ret.diag.txt │ ├── w221.diag.txt │ ├── w222_deep.nut │ ├── w228_table.diag.txt │ ├── w248_relative_pred.nut │ ├── w210.diag.txt │ ├── w223.nut │ ├── w235.diag.txt │ ├── w236.nut │ ├── w270.nut │ ├── w284.nut │ ├── w301_closure2.nut │ ├── w208_rec.diag.txt │ ├── w210_deep.diag.txt │ ├── w216.diag.txt │ ├── w217_throw.diag.txt │ ├── w223.diag.txt │ ├── w225.diag.txt │ ├── w286.diag.txt │ ├── w306.nut │ ├── w213.diag.txt │ ├── w217_ret.nut │ ├── w217_throw.nut │ ├── w227.nut │ ├── w239_sqconfig.nut │ ├── w205-2.diag.txt │ ├── w206_arith.diag.txt │ ├── w232_cascade.diag.txt │ ├── w240.nut │ ├── w248_complexcond.nut │ ├── nullcheck_ternary.nut │ ├── w234.diag.txt │ ├── w289.diag.txt │ ├── function_rt_detect.diag.txt │ ├── nullcheck_ternary.diag.txt │ ├── w227.diag.txt │ ├── w248_type_func.nut │ ├── w274.diag.txt │ ├── w217_continue.nut │ ├── w222.diag.txt │ ├── w248.nut │ ├── w248_in.diag.txt │ ├── w248_override.diag.txt │ ├── w249.diag.txt │ ├── w254.diag.txt │ ├── w283.nut │ ├── w286_2.diag.txt │ ├── w306.diag.txt │ ├── 200_nullc.nut │ ├── w208.diag.txt │ ├── w233.diag.txt │ ├── w248_evaled.nut │ ├── w303_destruct.diag.txt │ ├── forloop_merge.diag.txt │ ├── w206_arith.nut │ ├── w248_tyopeof2.nut │ ├── w249_array.diag.txt │ ├── w250.nut │ ├── w302_loop.nut │ ├── w310_require.diag.txt │ ├── w248_andnad1.nut │ ├── w280.diag.txt │ ├── w200_arith_plus_eq.diag.txt │ ├── w211.diag.txt │ ├── w228.diag.txt │ ├── w231.diag.txt │ ├── w239.nut │ ├── w244.diag.txt │ ├── w254_notin.diag.txt │ ├── w271.diag.txt │ ├── w227_fn_with_same_param.diag.txt │ ├── w228_2.diag.txt │ ├── w228_3.diag.txt │ ├── w248_special_name_func.diag.txt │ ├── w288_native.nut │ ├── w309_require.diag.txt │ ├── w200_arith.diag.txt │ ├── w200_arith_deep.diag.txt │ ├── w210_nullc.diag.txt │ ├── w227_external.diag.txt │ ├── w232_false.diag.txt │ ├── w232_true.diag.txt │ ├── w301_closure.nut │ ├── w192.nut │ ├── w200_special_func_name.diag.txt │ ├── w214.diag.txt │ ├── w233_inc_in_for.nut │ ├── w238_idname.diag.txt │ ├── w248_assert.diag.txt │ ├── w248_chain.diag.txt │ ├── w277.nut.txt │ ├── w305.nut │ ├── w232_ternary.diag.txt │ ├── w275.diag.txt │ ├── loop_state.nut │ ├── w227_let_init_fun.diag.txt │ ├── w232_cascade.nut │ ├── w241.diag.txt │ ├── w248_nullc_2.diag.txt │ ├── w220.diag.txt │ ├── w227_lambdas.diag.txt │ ├── w248_complexcond.diag.txt │ ├── w274_2.diag.txt │ ├── w214.nut │ ├── w220_deep.diag.txt │ ├── w233_destruct.diag.txt │ ├── w239.diag.txt │ ├── w248_complex2.nut │ ├── w248_eq_get.diag.txt │ ├── w248_evaled.diag.txt │ ├── w248_nullc_3.nut │ ├── w279_2.diag.txt │ ├── w297.nut │ ├── w254_instanceof.diag.txt │ ├── w255.diag.txt │ ├── w255_2.diag.txt │ ├── w223_method_is.diag.txt │ ├── w248_complex_key.nut │ ├── w272.nut │ ├── w291.diag.txt │ ├── w215_nullc.diag.txt │ ├── w228_trivial.diag.txt │ ├── w232_lambda.nut │ ├── w200.diag.txt │ ├── w203.nut │ ├── w232_nerge.nut │ ├── w248_tyopeof1.nut │ ├── logic_ops_paren.nut │ ├── w248_while_cond.nut │ ├── w214_static_memo_expr.nut │ ├── w229.diag.txt │ ├── w232_ter.nut │ ├── w248_oror2.diag.txt │ ├── w214_static_memo_expr.diag.txt │ ├── w233_const_key.diag.txt │ ├── w257.diag.txt │ ├── w302_try_catch.nut │ ├── w308.diag.txt │ ├── forloop_merge.nut │ ├── w203.diag.txt │ ├── w215.diag.txt │ ├── w240.diag.txt │ ├── w244.nut │ ├── w301_closure.diag.txt │ ├── loop_state.diag.txt │ ├── w210_complex.nut │ ├── w233_inc.diag.txt │ ├── w269.nut │ ├── intersected_assignment.nut │ ├── w211.nut │ ├── w258.diag.txt │ ├── w258_2.diag.txt │ ├── w200_static_memo_expr.diag.txt │ ├── w204.diag.txt │ ├── w260_local_function.diag.txt │ ├── w208_rec.nut │ ├── w248_oror.nut │ ├── w275_complex.diag.txt │ ├── w248_oror2.nut │ ├── w236.diag.txt │ ├── w295.diag.txt │ ├── w270.diag.txt │ ├── w293.nut │ ├── w248_tyopeof2.diag.txt │ ├── w248_type_func.diag.txt │ ├── w205.diag.txt │ ├── w217_break.diag.txt │ ├── w260_table.diag.txt │ ├── w267.nut │ ├── w269.diag.txt │ ├── w308.nut │ ├── w248.diag.txt │ ├── function_rt_detect.nut │ ├── w228_4.diag.txt │ ├── w233_inc.nut │ ├── w248_not.nut │ ├── w305.diag.txt │ ├── w228_trivial.nut │ ├── w210_def.nut │ ├── w241_conditional.nut │ ├── w288_dp_va.nut │ └── w259.diag.txt ├── types │ └── type_suggestions.nut.txt └── ast │ └── optimizations │ └── closureHoisting │ ├── simple.nut │ ├── constDep.nut │ ├── recursion1.nut │ ├── simple2.nut │ ├── classSimple.nut │ ├── implicitChainedFuncs.nut │ ├── classCrossFunc.nut │ ├── manyFuncs.nut │ ├── implicitChainedFuncs2.nut │ ├── deepUnchained.nut │ └── externalSymbol.nut ├── doc ├── repl │ ├── .gitignore │ ├── static │ │ └── repl.ico │ └── build.txt ├── .gitignore ├── requirements.txt └── source │ ├── nut.ico │ ├── simple_nut.png │ ├── _static │ ├── nut.ico │ └── simple_nut.png │ └── reference │ └── language │ └── limitations.rst ├── scripts ├── samples │ ├── hello.nut │ ├── module_1.nut │ ├── module_2.nut │ ├── module_demo.nut │ ├── fibonacci.nut │ └── regex.nut └── std │ └── analyzer.nut ├── squirrel └── vartracestub.cpp ├── sqstdlib ├── sqstdhash.h └── sqstdserialization.h ├── squirrel-config.cmake.in ├── sqmodules ├── path.h └── helpers.h ├── sqrat └── README.txt ├── .gitignore ├── include ├── sqstdmath.h ├── sqstddebug.h ├── sqstddatetime.h └── sqstdsystem.h ├── sq └── CMakeLists.txt └── .travis.yml /testData/exec/basics.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/integers.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/repl/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /testData/exec/optimizer_add.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/optimizer_mul.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/parenCallee.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/spec/closure.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/spec/ifstmt.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/weird/2000_args.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.pyc 3 | -------------------------------------------------------------------------------- /testData/diagnostics/base_pp.nut: -------------------------------------------------------------------------------- 1 | base++ -------------------------------------------------------------------------------- /testData/exec/compare_int_float.out: -------------------------------------------------------------------------------- 1 | ok -------------------------------------------------------------------------------- /testData/exec/compare_int_int.out: -------------------------------------------------------------------------------- 1 | ok -------------------------------------------------------------------------------- /testData/exec/const_in_closures.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/fuzzer_seed_7200.out: -------------------------------------------------------------------------------- 1 | -11 -------------------------------------------------------------------------------- /testData/exec/mod_by_minus_one_vm.out: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testData/exec/spec/dowstmt.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testData/exec/stack_metamethod.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/string_interpolation.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/foo.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w247.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w302.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/diagnostics/base_x_pp.nut: -------------------------------------------------------------------------------- 1 | base.x++ -------------------------------------------------------------------------------- /testData/diagnostics/import_01.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/diagnostics/import_02.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/diagnostics/import_06.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/div64_by_minus_one_opt.out: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /testData/exec/div64_by_minus_one_vm.out: -------------------------------------------------------------------------------- 1 | OK -------------------------------------------------------------------------------- /testData/exec/mod64_by_minus_one_opt.out: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testData/exec/mod64_by_minus_one_vm.out: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testData/exec/mod_by_minus_one_opt.out: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /testData/exec/spec/conditionalFor.out: -------------------------------------------------------------------------------- 1 | XXXXX -------------------------------------------------------------------------------- /testData/exec/spec/constFolding.out: -------------------------------------------------------------------------------- 1 | 2371 -------------------------------------------------------------------------------- /testData/exec/spec/constFoldingCond.out: -------------------------------------------------------------------------------- 1 | 152 -------------------------------------------------------------------------------- /testData/exec/stack_metamethod_few_args.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/stack_metamethod_locals.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/stdlib/deep_hash.out: -------------------------------------------------------------------------------- 1 | ok 2 | -------------------------------------------------------------------------------- /testData/exec/stdlib/rawdelete.out: -------------------------------------------------------------------------------- 1 | ok 2 | -------------------------------------------------------------------------------- /testData/static_analyzer/w222_deep.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_ter.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_deep.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w238_isis.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_not.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_oror.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w302_loop.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/diagnostics/leading_zero_1.nut: -------------------------------------------------------------------------------- 1 | print(00) -------------------------------------------------------------------------------- /testData/diagnostics/leading_zero_2.nut: -------------------------------------------------------------------------------- 1 | print(01) -------------------------------------------------------------------------------- /testData/exec/div_by_minus_one_opt.out: -------------------------------------------------------------------------------- 1 | 2147483648 -------------------------------------------------------------------------------- /testData/exec/div_by_minus_one_vm.out: -------------------------------------------------------------------------------- 1 | 2147483648 -------------------------------------------------------------------------------- /testData/exec/spec/class_extend.out: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /testData/exec/spec/enums.out: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | -------------------------------------------------------------------------------- /testData/exec/spec/stringtmplt.out: -------------------------------------------------------------------------------- 1 | { foo = 123 } -------------------------------------------------------------------------------- /testData/exec/weird/assign_to_optional_1.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/weird/assign_to_optional_2.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/exec/weird/assign_to_optional_3.out: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/248_instanceof.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/klass_check.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/param_check.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_3wcmp.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_cond_cont.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w221_delete.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w225_switch.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_varargs.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_lambda.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_nerge.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w238_sqconfig.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w239_sqconfig.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_andnad1.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_complex2.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_getfield.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_nullc_3.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_tyopeof1.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w288_lambdas2.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w288_native.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w301_closure2.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w302_dowhile.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w302_try_catch.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/samples/hello.nut: -------------------------------------------------------------------------------- 1 | println("Hello World!") 2 | -------------------------------------------------------------------------------- /testData/diagnostics/base_as_array_pp.nut: -------------------------------------------------------------------------------- 1 | base[0]++ -------------------------------------------------------------------------------- /testData/diagnostics/import_01.nut: -------------------------------------------------------------------------------- 1 | import "a" 2 | -------------------------------------------------------------------------------- /testData/diagnostics/leading_zero_3.nut: -------------------------------------------------------------------------------- 1 | print(00.1) -------------------------------------------------------------------------------- /testData/exec/fuzzer_seed_3250.out: -------------------------------------------------------------------------------- 1 | -10 2 | ok 3 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_1.out: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_2.out: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_4.out: -------------------------------------------------------------------------------- 1 | 777 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_5.out: -------------------------------------------------------------------------------- 1 | 777 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_6.out: -------------------------------------------------------------------------------- 1 | 777 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_7.out: -------------------------------------------------------------------------------- 1 | 777 2 | -------------------------------------------------------------------------------- /testData/exec/ph_optimizer_null_call_1.out: -------------------------------------------------------------------------------- 1 | 444 2 | -------------------------------------------------------------------------------- /testData/exec/ph_optimizer_null_call_2.out: -------------------------------------------------------------------------------- 1 | 444 2 | -------------------------------------------------------------------------------- /testData/exec/ph_optimizer_null_call_3.out: -------------------------------------------------------------------------------- 1 | 444 2 | -------------------------------------------------------------------------------- /testData/exec/spec/classInher.out: -------------------------------------------------------------------------------- 1 | I'm the derived 2 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_opt2.out: -------------------------------------------------------------------------------- 1 | 3 2 | 5 3 | -------------------------------------------------------------------------------- /testData/static_analyzer/efferct_fropm_call.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w225_empty_stmt.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_inc_in_for.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w241_conditional.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_in_container.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_while_cond.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/static_analyzer/w260_table_sqconfig.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/diagnostics/base_as_array_assign.nut: -------------------------------------------------------------------------------- 1 | base["x"] = 1 -------------------------------------------------------------------------------- /testData/diagnostics/binding_assign.nut: -------------------------------------------------------------------------------- 1 | let a = 2 2 | a = 3 -------------------------------------------------------------------------------- /testData/diagnostics/import_04.nut: -------------------------------------------------------------------------------- 1 | import "a" as 2 | 3 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_float_2.nut: -------------------------------------------------------------------------------- 1 | println(1e4......) -------------------------------------------------------------------------------- /testData/diagnostics/invalid_float_3.nut: -------------------------------------------------------------------------------- 1 | println(1.2.3.4) -------------------------------------------------------------------------------- /testData/diagnostics/invalid_type_hint_1.nut: -------------------------------------------------------------------------------- 1 | let a:2 = 3 -------------------------------------------------------------------------------- /testData/diagnostics/unfinished_hex.nut: -------------------------------------------------------------------------------- 1 | println(0x) 2 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_freeze.out: -------------------------------------------------------------------------------- 1 | success 2 | -------------------------------------------------------------------------------- /testData/static_analyzer/intersected_assignment.diag.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /testData/diagnostics/assign_to_expr.nut: -------------------------------------------------------------------------------- 1 | local x 2 | x-- = 1 3 | -------------------------------------------------------------------------------- /testData/diagnostics/assign_to_expr2.nut: -------------------------------------------------------------------------------- 1 | local x; @() !x = 1 -------------------------------------------------------------------------------- /testData/diagnostics/import_03.nut: -------------------------------------------------------------------------------- 1 | /* 2 | import "a" as x 3 | -------------------------------------------------------------------------------- /testData/diagnostics/import_07.nut: -------------------------------------------------------------------------------- 1 | import "a 2 | " as a 3 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_float_1.nut: -------------------------------------------------------------------------------- 1 | println(1e4e-4) 2 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_string_interp_1.nut: -------------------------------------------------------------------------------- 1 | println($"{") -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_3.out: -------------------------------------------------------------------------------- 1 | 555 123 888 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_8.out: -------------------------------------------------------------------------------- 1 | -97 2 | null 3 | -------------------------------------------------------------------------------- /testData/exec/locals_chain.out: -------------------------------------------------------------------------------- 1 | 5, 5, 5, 5 2 | 6, 6, 6, 6 3 | -------------------------------------------------------------------------------- /testData/exec/stdlib/swap.out: -------------------------------------------------------------------------------- 1 | 2 1 2 | asd 123 3 | 789 456 4 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_type_hint_2.nut: -------------------------------------------------------------------------------- 1 | function fn(...:) {} -------------------------------------------------------------------------------- /testData/exec/deep_loop_variable.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | -------------------------------------------------------------------------------- /testData/exec/spec/const_with_expr.out: -------------------------------------------------------------------------------- 1 | -4 true 3 integer 2 | 255 3 | -------------------------------------------------------------------------------- /testData/exec/type_hints/var_decl.out: -------------------------------------------------------------------------------- 1 | 5 2 | array abc 3 | 1 null 4 | -------------------------------------------------------------------------------- /testData/diagnostics/hex_overflow.nut: -------------------------------------------------------------------------------- 1 | println(0x1_0000_0000_0000_0000) -------------------------------------------------------------------------------- /testData/diagnostics/integer_overflow_2.nut: -------------------------------------------------------------------------------- 1 | println(20496385583567863808) -------------------------------------------------------------------------------- /testData/exec/div_by_minus_one_opt.nut: -------------------------------------------------------------------------------- 1 | print( (-0x7FFFFFFF-1) / -1 ) 2 | -------------------------------------------------------------------------------- /testData/exec/mod_by_minus_one_opt.nut: -------------------------------------------------------------------------------- 1 | print( (-0x7FFFFFFF-1) % -1 ) 2 | -------------------------------------------------------------------------------- /testData/exec/spec/const.out: -------------------------------------------------------------------------------- 1 | 555 2 | foo 3 | 2 4 | 555 5 | 7 6 | 0 7 | -------------------------------------------------------------------------------- /testData/exec/spec/trystmt.out: -------------------------------------------------------------------------------- 1 | TRYING 1 2 | CAUGHT 2 3 | FINISHING 3 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/foo.nut: -------------------------------------------------------------------------------- 1 | 2 | return { foo = @(a, b) a+b } 3 | -------------------------------------------------------------------------------- /testData/diagnostics/integer_overflow_int_max.nut: -------------------------------------------------------------------------------- 1 | println(9223372036854775808) -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_not_string.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | println($'{{{{{{{{') -------------------------------------------------------------------------------- /testData/exec/spec/destruct.out: -------------------------------------------------------------------------------- 1 | 123 2 | 567 3 | 11 4 | 555 5 | 777 6 | 3 7 | -------------------------------------------------------------------------------- /testData/exec/spec/func_pure_attr.out: -------------------------------------------------------------------------------- 1 | false 2 | true 3 | false 4 | true 5 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_reset2.out: -------------------------------------------------------------------------------- 1 | 1000 2 | 2000 3 | 1000 4 | 2000 5 | -------------------------------------------------------------------------------- /testData/exec/type_hints/function_types.out: -------------------------------------------------------------------------------- 1 | -1000 2 | 15.25 3 | true abc 4 | -------------------------------------------------------------------------------- /testData/exec/weird/assign_to_optional_2.nut: -------------------------------------------------------------------------------- 1 | local t = {a = 5} 2 | t?.b <- 10 -------------------------------------------------------------------------------- /testData/static_analyzer/w273.nut: -------------------------------------------------------------------------------- 1 | //expect:w273 2 | 3 | x <- 6 4 | return x -------------------------------------------------------------------------------- /testData/diagnostics/import_05.nut: -------------------------------------------------------------------------------- 1 | from "../a\..\b\folder/file.nut" import * 2 | -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_wrong_template.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | println($"{{{{{{{{") -------------------------------------------------------------------------------- /testData/diagnostics/invalid_type_hint_3.nut: -------------------------------------------------------------------------------- 1 | let a = @(x: Integer): Integer x * x -------------------------------------------------------------------------------- /testData/diagnostics/letAssign.nut: -------------------------------------------------------------------------------- 1 | local x = 10 2 | x = 20 3 | let y = 30 4 | y = 40 -------------------------------------------------------------------------------- /testData/diagnostics/need_space_after_hex.nut: -------------------------------------------------------------------------------- 1 | let x = 123 2 | println([0xx][1]) 3 | -------------------------------------------------------------------------------- /testData/exec/fuzzer_seed_7200.nut: -------------------------------------------------------------------------------- 1 | let v0 = -11 2 | if (v0 > v0) { } 3 | print(v0) -------------------------------------------------------------------------------- /testData/exec/import_correct.out: -------------------------------------------------------------------------------- 1 | import value: 123 2 | from length: 3 3 | 0 5 4 | -------------------------------------------------------------------------------- /testData/exec/mod64_by_minus_one_opt.nut: -------------------------------------------------------------------------------- 1 | print( (-0x7FFFFFFF_FFFFFFFF-1) % -1 ) 2 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_loop.out: -------------------------------------------------------------------------------- 1 | 111 2 | 111 3 | 111 4 | 111 5 | 111 6 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_opt.out: -------------------------------------------------------------------------------- 1 | 15 2 | 15 3 | === 4 | 15 5 | 15 6 | === 7 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_reset1.out: -------------------------------------------------------------------------------- 1 | 3000 2 | 3000 3 | 4 | 6000 5 | 6000 6 | -------------------------------------------------------------------------------- /testData/exec/weird/assign_to_optional_1.nut: -------------------------------------------------------------------------------- 1 | local t = {a = 5} 2 | t?.a = 10 3 | -------------------------------------------------------------------------------- /testData/exec/weird/assign_to_optional_3.nut: -------------------------------------------------------------------------------- 1 | local t = {a = 5} 2 | t?["c"] <- 20 -------------------------------------------------------------------------------- /testData/diagnostics/assign_to_optional_7.nut: -------------------------------------------------------------------------------- 1 | local v = {v = {v = 0}} 2 | v.v ?? v = 3 -------------------------------------------------------------------------------- /testData/diagnostics/const_scope_1.nut: -------------------------------------------------------------------------------- 1 | if (true) 2 | const x = 5 3 | 4 | print(x) 5 | -------------------------------------------------------------------------------- /testData/diagnostics/import_error.nut: -------------------------------------------------------------------------------- 1 | // missing import list 2 | from "file1" import 3 | -------------------------------------------------------------------------------- /testData/diagnostics/need_space_after_float.nut: -------------------------------------------------------------------------------- 1 | local f = 333 2 | println([5.0f][1]) 3 | -------------------------------------------------------------------------------- /testData/diagnostics/need_space_after_int.nut: -------------------------------------------------------------------------------- 1 | local f = 333 2 | println([5f][1]) 3 | -------------------------------------------------------------------------------- /testData/diagnostics/var_scope_1.nut: -------------------------------------------------------------------------------- 1 | if (true) 2 | local x = 5 3 | 4 | print(x) 5 | -------------------------------------------------------------------------------- /testData/exec/spec/stringtmplt.nut: -------------------------------------------------------------------------------- 1 | local foo = 123 2 | print($"\{ foo = {foo} \}") 3 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_exception.out: -------------------------------------------------------------------------------- 1 | exception 2 | exception 3 | 61 4 | 61 5 | -------------------------------------------------------------------------------- /testData/static_analyzer/w235.nut: -------------------------------------------------------------------------------- 1 | //expect:w235 2 | 3 | ::aspect_ratio <- (1280 / (720)) -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx==8.2.3 2 | myst-parser==4.0.1 3 | sphinx-rtd-theme==3.0.2 4 | -------------------------------------------------------------------------------- /testData/diagnostics/float_overflow.nut: -------------------------------------------------------------------------------- 1 | println(1000000000000000000000000000000000000000.0) -------------------------------------------------------------------------------- /testData/diagnostics/integer_overflow.nut: -------------------------------------------------------------------------------- 1 | println(1000000000000000000000000000000000000000) -------------------------------------------------------------------------------- /testData/diagnostics/var_scope_3.nut: -------------------------------------------------------------------------------- 1 | if (true) 2 | local x = 6 3 | else 4 | print(x) 5 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_assign_itself.out: -------------------------------------------------------------------------------- 1 | 333 2 | 444 3 | 666 4 | 888 5 | 111 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w247.nut: -------------------------------------------------------------------------------- 1 | /* 2 | FIXME: Old test not working, need new one 3 | */ 4 | -------------------------------------------------------------------------------- /testData/diagnostics/const_scope_3.nut: -------------------------------------------------------------------------------- 1 | if (true) 2 | const x = 6 3 | else 4 | print(x) 5 | -------------------------------------------------------------------------------- /testData/exec/spec/conditionalFor.nut: -------------------------------------------------------------------------------- 1 | for (local i = 0; i < (true ? 5 : 1); i++) 2 | print("X") -------------------------------------------------------------------------------- /testData/static_analyzer/w209.nut: -------------------------------------------------------------------------------- 1 | //expect:w209 2 | 3 | local x = {y = 3} 4 | 5 | x.y = (((x.y))) -------------------------------------------------------------------------------- /doc/source/nut.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaijinEntertainment/quirrel/HEAD/doc/source/nut.ico -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_not_string_2.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function foo() {} 4 | 5 | println($foo()) -------------------------------------------------------------------------------- /testData/diagnostics/var_scope_2.nut: -------------------------------------------------------------------------------- 1 | local function f() { 2 | local x = 6 3 | } 4 | 5 | print(x) 6 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_2.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | println($${return 123;}) -------------------------------------------------------------------------------- /testData/exec/ph_optimizer_null_call_1.nut: -------------------------------------------------------------------------------- 1 | let x = [@() 444] 2 | let z = 0 3 | println(x[z]?()) 4 | -------------------------------------------------------------------------------- /squirrel/vartracestub.cpp: -------------------------------------------------------------------------------- 1 | #include "vartrace.h" 2 | 3 | void VarTrace::printStack(SQChar *, int) {} 4 | -------------------------------------------------------------------------------- /testData/diagnostics/const_scope_2.nut: -------------------------------------------------------------------------------- 1 | local function f() { 2 | const x = 6 3 | } 4 | 5 | print(x) 6 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_01.nut: -------------------------------------------------------------------------------- 1 | function fn(x: int|null) { 2 | return x 3 | } 4 | 5 | fn(5.4) 6 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_6.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | println(654 + $${return 123;}) -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_7.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | println($${return 123;} + 654) -------------------------------------------------------------------------------- /testData/exec/spec/constFoldingCond.nut: -------------------------------------------------------------------------------- 1 | print((((((-14 != 24)) ? (242) : (264)) + -12 - 78) & (157))) 2 | -------------------------------------------------------------------------------- /testData/exec/spec/dowstmt.nut: -------------------------------------------------------------------------------- 1 | local a=0 2 | do { 3 | println(a) 4 | a += 1 5 | } while(a>100) 6 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_loop.nut: -------------------------------------------------------------------------------- 1 | for (local x = 111; x < 116; x++) 2 | println(static x) 3 | 4 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_nested.out: -------------------------------------------------------------------------------- 1 | 111 2 | 111 3 | 111 4 | 5 | -444 6 | -444 7 | -444 8 | -444 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w208.nut: -------------------------------------------------------------------------------- 1 | //expect:w208 2 | local x = { z = {y = 3}} 3 | x.z?.y <- 6 4 | print(x.z.y) -------------------------------------------------------------------------------- /testData/static_analyzer/w227_external.nut: -------------------------------------------------------------------------------- 1 | function _foo(println) { 2 | return println + 1 3 | } 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228_4.nut: -------------------------------------------------------------------------------- 1 | //expect:w228 2 | 3 | let f = function foo() {} 4 | let c = class {} -------------------------------------------------------------------------------- /doc/repl/static/repl.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaijinEntertainment/quirrel/HEAD/doc/repl/static/repl.ico -------------------------------------------------------------------------------- /doc/source/simple_nut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaijinEntertainment/quirrel/HEAD/doc/source/simple_nut.png -------------------------------------------------------------------------------- /scripts/samples/module_1.nut: -------------------------------------------------------------------------------- 1 | function foo() { 2 | return "" 3 | } 4 | 5 | return foo 6 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_04.nut: -------------------------------------------------------------------------------- 1 | function fn(x: int, ...) { 2 | return x 3 | } 4 | 5 | fn("abc", "") 6 | -------------------------------------------------------------------------------- /testData/exec/div_by_minus_one_vm.nut: -------------------------------------------------------------------------------- 1 | local x = -0x7FFFFFFF - 1 2 | local y = @(a) -a 3 | print( x / y(1) ) 4 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_1.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | let a = $${return 123;} 3 | println(a) -------------------------------------------------------------------------------- /testData/exec/mod_by_minus_one_vm.nut: -------------------------------------------------------------------------------- 1 | local x = -0x7FFFFFFF - 1 2 | local y = @(a) -a 3 | print( x % y(1) ) 4 | -------------------------------------------------------------------------------- /testData/exec/parenCallee.nut: -------------------------------------------------------------------------------- 1 | 2 | let f = @(v) v + 1 3 | 4 | function foo() { 5 | return ((((f))))(10) 6 | } -------------------------------------------------------------------------------- /testData/exec/spec/class.out: -------------------------------------------------------------------------------- 1 | idx = 0 = stuff 2 | idx = 1 = 1 3 | idx = 2 = 2 4 | idx = 3 = 3 5 | idx = 4 = 42 6 | -------------------------------------------------------------------------------- /testData/exec/spec/generators.out: -------------------------------------------------------------------------------- 1 | FOR 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | FOREACH 8 | 0 9 | 1 10 | 2 11 | -------------------------------------------------------------------------------- /testData/exec/spec/whilestmt.out: -------------------------------------------------------------------------------- 1 | 10 2 | 9 3 | 8 4 | 7 5 | 6 6 | 5 7 | 4 8 | 3 9 | 2 10 | 1 11 | 0 12 | -------------------------------------------------------------------------------- /testData/exec/stdlib/regexp.out: -------------------------------------------------------------------------------- 1 | true 2 | false 3 | begin=1 4 | end=5 5 | begin=1 6 | end=5 7 | regexp 8 | 1 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233.nut: -------------------------------------------------------------------------------- 1 | //expect:w233 2 | 3 | ::flags <- 0x2040 4 | ::aspect_ratio <- (::flags && 0x40) -------------------------------------------------------------------------------- /doc/source/_static/nut.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaijinEntertainment/quirrel/HEAD/doc/source/_static/nut.ico -------------------------------------------------------------------------------- /scripts/samples/module_2.nut: -------------------------------------------------------------------------------- 1 | let exports = { 2 | bar = "BAR" 3 | baz = "BAZ" 4 | } 5 | 6 | return exports 7 | -------------------------------------------------------------------------------- /testData/diagnostics/delete_base.nut: -------------------------------------------------------------------------------- 1 | #allow-delete-operator 2 | delete base 3 | 4 | // ^ Legacy, to be removed 5 | -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_hanging_missed_ccurvy.nut: -------------------------------------------------------------------------------- 1 | function foo() { return "X" } 2 | 3 | println($"{foo()") -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_02.nut: -------------------------------------------------------------------------------- 1 | function fn(y, x: int|null) { 2 | return x 3 | } 4 | 5 | fn("abc", 5.4) 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_lambdas.nut: -------------------------------------------------------------------------------- 1 | 2 | local x = 10 3 | let y = x > 320 ? @() 20 : function() { return 30 } -------------------------------------------------------------------------------- /testData/static_analyzer/w233_destruct.nut: -------------------------------------------------------------------------------- 1 | 2 | local x = 10 3 | let y = x > 320 ? @() 20 : function() { return 30 } -------------------------------------------------------------------------------- /testData/types/type_suggestions.nut.txt: -------------------------------------------------------------------------------- 1 | fn(x: Float) 2 | fn(x: float|None) 3 | closure.fn() 4 | string.fn():integer -------------------------------------------------------------------------------- /testData/diagnostics/float_underflow.nut: -------------------------------------------------------------------------------- 1 | println(0.00000000000000000000000000000000000000000000000000000000000000001) 2 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_4.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | let a = 654 + $${return 123;} 3 | println(a) -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_5.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | let a = $${return 123;} + 654 3 | println(a) -------------------------------------------------------------------------------- /testData/exec/mod64_by_minus_one_vm.nut: -------------------------------------------------------------------------------- 1 | local x = -0x7FFFFFFF_FFFFFFFF - 1 2 | local y = @(a) -a 3 | print( x % y(1) ) 4 | -------------------------------------------------------------------------------- /testData/exec/ph_optimizer_null_call_3.nut: -------------------------------------------------------------------------------- 1 | let x = [[[[@() 444]]]] 2 | let z = 0 3 | println(x?[z][z][z][z]()) 4 | 5 | -------------------------------------------------------------------------------- /testData/exec/spec/forstmt.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | loops forever 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/klass_check.nut: -------------------------------------------------------------------------------- 1 | function foo() { return class {} } 2 | let x = foo() 3 | let _c = class(x) {} 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/w216.nut: -------------------------------------------------------------------------------- 1 | //expect:w216 2 | 3 | local a = {x=2, y=3} 4 | 5 | if (a.x < a.x) 6 | print("x < y") -------------------------------------------------------------------------------- /testData/static_analyzer/w221_delete.nut: -------------------------------------------------------------------------------- 1 | #allow-delete-operator 2 | 3 | let x = {} 4 | 5 | x.y <- "2" 6 | 7 | delete x.y -------------------------------------------------------------------------------- /testData/static_analyzer/w227_fn_with_same_param.nut: -------------------------------------------------------------------------------- 1 | //expect:w227 2 | 3 | function txt(txt) {} //-declared-never-used 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/w231.nut: -------------------------------------------------------------------------------- 1 | local x = 2 2 | local string = require("string") 3 | print(string.format("%d%%", 1, x)) -------------------------------------------------------------------------------- /testData/static_analyzer/w232_ternary.nut: -------------------------------------------------------------------------------- 1 | //expect:w232 2 | local foo = function() { } ? false : true 3 | return foo 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/w238_idname.nut: -------------------------------------------------------------------------------- 1 | let state = {} 2 | 3 | let isHaHoo = state.foo() 4 | 5 | state.isRepa(isHaHoo) -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_tables.out: -------------------------------------------------------------------------------- 1 | 222 2 | 222 3 | 333 4 | 333 5 | 6 | 222 7 | 222 8 | 333 9 | 333 10 | 11 | -------------------------------------------------------------------------------- /testData/exec/testNullPropagation.out: -------------------------------------------------------------------------------- 1 | begin A._get() call 2 | testField passed 3 | begin A._get() call 4 | testIndex passed 5 | -------------------------------------------------------------------------------- /testData/static_analyzer/w222.nut: -------------------------------------------------------------------------------- 1 | //expect:w222 2 | 3 | function foo(a,x,y) { //-declared-never-used 4 | print(a[x < y]) 5 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w232_not.nut: -------------------------------------------------------------------------------- 1 | //expect:w232 2 | local i = {x = true} 3 | print(i.x && !i.x) 4 | print(!i.x || i.x) 5 | -------------------------------------------------------------------------------- /testData/static_analyzer/w234.nut: -------------------------------------------------------------------------------- 1 | //expect:w234 2 | 3 | function foo() { //-declared-never-used 4 | print(1 / (0)) 5 | } 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w286.nut: -------------------------------------------------------------------------------- 1 | //expect:w286 2 | 3 | function fn1() {} 4 | 5 | return fn1 || ::fn2 // -undefined-global 6 | -------------------------------------------------------------------------------- /doc/source/_static/simple_nut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GaijinEntertainment/quirrel/HEAD/doc/source/_static/simple_nut.png -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_06.nut: -------------------------------------------------------------------------------- 1 | function fn(x: int, ...: array) { 2 | return x 3 | } 4 | 5 | fn(4, null, [], [], []) 6 | -------------------------------------------------------------------------------- /testData/exec/const_in_closures.nut: -------------------------------------------------------------------------------- 1 | function foo() { 2 | const x = "asdf" 3 | function bar() { 4 | let a = x 5 | } 6 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w206.nut: -------------------------------------------------------------------------------- 1 | //expect:w206 2 | local tab = {x=0, y=0, z=0} 3 | tab.x = 6 4 | tab.y = 7 5 | tab.x = 8 6 | 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w279_1.nut: -------------------------------------------------------------------------------- 1 | //expect:w279 2 | 3 | local j; 4 | for (local k = 0; j < 5; k++) { 5 | j = 10 6 | } 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w279_2.nut: -------------------------------------------------------------------------------- 1 | //expect:w279 2 | 3 | local j = 0; 4 | for (local k = 0; k < 5; j++) { 5 | k = 10 6 | } 7 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_05.nut: -------------------------------------------------------------------------------- 1 | function fn(x: int, ...: table) { 2 | return x 3 | } 4 | 5 | fn(4, {}, {}, {}, @() null) 6 | -------------------------------------------------------------------------------- /testData/exec/div64_by_minus_one_opt.nut: -------------------------------------------------------------------------------- 1 | try { 2 | print( (-0x7FFFFFFF_FFFFFFFF-1) / -1 ) 3 | } catch(e) { 4 | print("OK") 5 | } -------------------------------------------------------------------------------- /testData/exec/optimizer.out: -------------------------------------------------------------------------------- 1 | OPTIMIZER OFF 2 | X 3 | X 4 | X 5 | X 6 | X 7 | OPTIMIZER ON 8 | X 9 | X 10 | X 11 | X 12 | X 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w224_then.nut: -------------------------------------------------------------------------------- 1 | //expect:w224 2 | local x = 19 3 | 4 | if (x == 5); 5 | { 6 | x++; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w225_empty_stmt.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | let _load_das = function(filename) { assert(type(filename)=="string"); return {}; } -------------------------------------------------------------------------------- /testData/static_analyzer/w228_table.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function foo(y) { 4 | let x = y 5 | return { 6 | x = x 7 | } 8 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w233_deep.nut: -------------------------------------------------------------------------------- 1 | //expect:w233 2 | 3 | ::flags <- 10 4 | local mask = -0x40 5 | ::aspect_ratio <- (::flags && !mask) -------------------------------------------------------------------------------- /testData/static_analyzer/w288_lambdas2.nut: -------------------------------------------------------------------------------- 1 | 2 | for (local x = 0; x != 0; ++x) 3 | let _f = (@(val) @(arg) type(arg) == val)("sss") -------------------------------------------------------------------------------- /testData/static_analyzer/w288_require.nut: -------------------------------------------------------------------------------- 1 | let { foo } = require("testData/static_analyzer/foo.nut") 2 | return { bar = @(x) foo(x) } 3 | -------------------------------------------------------------------------------- /testData/static_analyzer/w302.nut: -------------------------------------------------------------------------------- 1 | //expect:w302 2 | 3 | local x 4 | local y = 10 5 | if (y > 20) { 6 | x = 30 7 | } 8 | 9 | print(x) -------------------------------------------------------------------------------- /testData/exec/ph_optimizer_null_call_2.nut: -------------------------------------------------------------------------------- 1 | let tab = { 2 | x = [ @() 444 ] 3 | } 4 | 5 | local zero = 0 6 | println(tab?.x[zero]()) 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228.nut: -------------------------------------------------------------------------------- 1 | //expect:w228 2 | 3 | function x() { //-declared-never-used 4 | local str = "string" 5 | return 6 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w248_chain.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | let x = {} 5 | let a = 10 6 | 7 | if ((x.w.v?[a] ?? 0) == 0) { 8 | x.foo() 9 | } -------------------------------------------------------------------------------- /testData/exec/deep_loop_variable.nut: -------------------------------------------------------------------------------- 1 | let x = { borders = [0, 0, 0, 0] } 2 | for (; x.borders[2] < 5; x.borders[2]++) 3 | println(x.borders[2]) -------------------------------------------------------------------------------- /testData/exec/spec/enums.nut: -------------------------------------------------------------------------------- 1 | enum Foo { 2 | x = 1, 3 | y = 2, 4 | z = 3 5 | } 6 | 7 | println(Foo.x) 8 | println(Foo.y) 9 | println(Foo.z) -------------------------------------------------------------------------------- /testData/static_analyzer/w205.nut: -------------------------------------------------------------------------------- 1 | //expect:w205 2 | 3 | function x(callback) { //-declared-never-used 4 | return 5 | callback() 6 | } 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w223_method_is.nut: -------------------------------------------------------------------------------- 1 | let sec = 10000 2 | let s = sec > 0 3 | let r = "" 4 | 5 | if (r.isVisible() != s) 6 | print("d") -------------------------------------------------------------------------------- /testData/static_analyzer/w264.nut: -------------------------------------------------------------------------------- 1 | //expect:w264 2 | 3 | local a = "{0}".subst(null) 4 | if (a != "") 5 | return null 6 | 7 | return a + 3 8 | -------------------------------------------------------------------------------- /doc/repl/build.txt: -------------------------------------------------------------------------------- 1 | Build instructions: 2 | 3 | * Install Emscripten SDK 4 | * mkdir build 5 | * cd build 6 | * emcmake cmake .. 7 | * emmake make 8 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/simple.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo(x, y) { 3 | return function(a, b) { 4 | return a + b; 5 | } 6 | } -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_03.nut: -------------------------------------------------------------------------------- 1 | function fn(y: null|string, x: int|null, z: null|table) { 2 | return x 3 | } 4 | 5 | fn(null, 5.4, null) 6 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_3.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | let x = 555 3 | let a = $${return 123;} 4 | let y = 888 5 | println(x, a, y) -------------------------------------------------------------------------------- /testData/exec/optimizer_add.nut: -------------------------------------------------------------------------------- 1 | let x = 0x7FFF_FFFF 2 | let y = 0x1 3 | assert(x + y == 0x8000_0000) 4 | assert(0x7FFF_FFFF + 0x1 == 0x8000_0000) 5 | -------------------------------------------------------------------------------- /testData/exec/string_interpolation_new.out: -------------------------------------------------------------------------------- 1 | #1: x1 = foo, x2 = [bar qux = foo] 2 | #2: 2 3 | #3: { gg = 123 } 4 | #4: foo bar 5 | #5: foo}}}}} 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w204.nut: -------------------------------------------------------------------------------- 1 | //expect:w204 2 | 3 | function foo(x){ //-declared-never-used 4 | if (x & 15 == 8) 5 | print("ok") 6 | } 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w229.nut: -------------------------------------------------------------------------------- 1 | //expect:w229 2 | 3 | local a ={x=0, y=0, z=1} 4 | if (a.x == 0 && a.y == 0 && a.x == 0) 5 | print("vector == zero") -------------------------------------------------------------------------------- /testData/static_analyzer/w248_getfield.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | 4 | let o = foo() 5 | 6 | if (o?.w == null) 7 | return 8 | 9 | o.x = true -------------------------------------------------------------------------------- /testData/static_analyzer/w248_special_name_func.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | 5 | let x = {} 6 | 7 | x.indexof(".").foo() -------------------------------------------------------------------------------- /testData/static_analyzer/w280.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w280 5 | 6 | let _x = require_optional("../a.nut") 7 | -------------------------------------------------------------------------------- /testData/diagnostics/1000_local_variables.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: internal compiler error: too many locals 2 | testData/diagnostics/1000_local_variables.nut:-1:-1 3 | -------------------------------------------------------------------------------- /testData/diagnostics/space_sep_name_space.nut.txt: -------------------------------------------------------------------------------- 1 | let t1 = {} 2 | 3 | 4 | t1 ?.foo // OK 5 | .bar // OK 6 | 7 | 8 | t1?.$ foo // NOT OK -------------------------------------------------------------------------------- /testData/diagnostics/var_scope_1.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/diagnostics/var_scope_1.nut:4:6 3 | 4 | print(x) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/var_scope_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/diagnostics/var_scope_2.nut:5:6 3 | 4 | print(x) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/optimizer_mul.nut: -------------------------------------------------------------------------------- 1 | let x = 0x100_0000 2 | let y = 0x100 3 | assert(x * y == 0x1_0000_0000) 4 | assert(0x100_0000 * 0x100 == 0x1_0000_0000) 5 | -------------------------------------------------------------------------------- /testData/exec/stdlib/swap_stack_check.out: -------------------------------------------------------------------------------- 1 | -1 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | 9 12 | 2 1 13 | asd 123 14 | 789 456 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_arith.nut: -------------------------------------------------------------------------------- 1 | //expect:w201 2 | local x = {y = 2} 3 | local a = x?.y - 8 4 | print(a) 5 | 6 | 7 | //-file:expr-cannot-be-null 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w220.nut: -------------------------------------------------------------------------------- 1 | //expect:w220 2 | 3 | function foo(a){ //-declared-never-used 4 | foreach(x in a?.y()) { 5 | print(x) 6 | } 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w227_varargs.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function foo(a, ...) { 4 | return function (b, ...) { return a + b; } 5 | } 6 | 7 | 8 | foo("...") -------------------------------------------------------------------------------- /testData/static_analyzer/w238_isis.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function isRePre(_p) { return true } 4 | function is_re_pre() { return true } 5 | 6 | isRePre(is_re_pre()) -------------------------------------------------------------------------------- /testData/static_analyzer/w273.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/static_analyzer/w273.nut:3:0 3 | 4 | x <- 6 5 | ^ 6 | return x 7 | 8 | 9 | -------------------------------------------------------------------------------- /sqstdlib/sqstdhash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | SQInteger sq_math_hash(HSQUIRRELVM v); 5 | SQInteger sq_math_deep_hash(HSQUIRRELVM v); 6 | -------------------------------------------------------------------------------- /testData/diagnostics/const_scope_1.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/diagnostics/const_scope_1.nut:4:6 3 | 4 | print(x) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/const_scope_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/diagnostics/const_scope_2.nut:5:6 3 | 4 | print(x) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/import_04.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'identifier' 2 | testData/diagnostics/import_04.nut:2:1 3 | 4 | import "a" as 5 | 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/fuzzer_seed_3250.nut: -------------------------------------------------------------------------------- 1 | //#disable-optimizer 2 | let v2 = 10 3 | let v34 = -10 4 | let v33 = (v2 > v34) ? v34 : 8 5 | println(v33) 6 | println("ok") 7 | -------------------------------------------------------------------------------- /testData/exec/locals_chain.nut: -------------------------------------------------------------------------------- 1 | local a=5, b=a, c=a, d=b 2 | println($"{a}, {b}, {c}, {d}") 3 | 4 | let x=6, y=x, z=x, w=y 5 | println($"{x}, {y}, {z}, {w}") 6 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_reset_module.out: -------------------------------------------------------------------------------- 1 | 11 2 | 12 3 | 11 4 | 22 5 | 3000 6 | 3000 7 | 8 | 6000 9 | 6000 10 | 31 11 | 32 12 | 31 13 | 42 14 | -------------------------------------------------------------------------------- /testData/exec/stdlib/math_min_max_clamp.out: -------------------------------------------------------------------------------- 1 | min(-1, 1, 2, 3, 4, 5, -1000, 6, 7): -1000 2 | max(-1, 1, 2, 3, 4, 5, -1000, 8, 9): 9 3 | clamp(10, -100, 300): 10 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200.nut: -------------------------------------------------------------------------------- 1 | //expect:w200 2 | 3 | function fn(mod, wpUnitRank) { //-declared-never-used 4 | return (mod?.reqRank > wpUnitRank) 5 | } 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w251.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w251 5 | 6 | return (::a != {}) 7 | 8 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w288_require_indirect.nut: -------------------------------------------------------------------------------- 1 | let mod = require("testData/static_analyzer/foo.nut") 2 | let foo = mod.foo 3 | return { bar = @(x) foo(x) } 4 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_let_init_fun.nut: -------------------------------------------------------------------------------- 1 | function foo(_p) {} 2 | let setGroup = foo(function setGroup(_crew, _group, _onFinishCb) { 3 | }) 4 | 5 | setGroup() 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_in.nut: -------------------------------------------------------------------------------- 1 | 2 | function _foo(dict, text = null) { 3 | if (text in dict) 4 | return dict[text] 5 | 6 | return text.d 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w248_nullc_2.nut: -------------------------------------------------------------------------------- 1 | let t = {} 2 | 3 | let i = 10 4 | 5 | let e = t.value?[i] 6 | if ((e?.a ?? false) && (e?.b ?? true)) { 7 | e.foo() 8 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w260_table.nut: -------------------------------------------------------------------------------- 1 | //expect:w260 2 | 3 | ::game <- { 4 | get_setting_by_blk_path = function(path) { return } //-declared-never-used 5 | } 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w274.nut: -------------------------------------------------------------------------------- 1 | //expect:w274 2 | 3 | local tab = [] 4 | 5 | foreach (v in [1, 2, 3]) 6 | tab.append(@() v) 7 | 8 | return tab 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w289.nut: -------------------------------------------------------------------------------- 1 | //expect:w289 2 | function fn(aaa_x, bbb, ...) {return aaa_x + bbb} 3 | 4 | local aaaX = 1; 5 | local b = -1; 6 | return fn(b, aaaX); -------------------------------------------------------------------------------- /testData/diagnostics/base_pp.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: argument of inc/dec operation is not assignable 2 | testData/diagnostics/base_pp.nut:1:0 3 | 4 | base++ 5 | ^--- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/import_07.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: newline in a constant 2 | testData/diagnostics/import_07.nut:1:7 3 | 4 | import "a 5 | ^-- 6 | " as a 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_float_1.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: malformed number 2 | testData/diagnostics/invalid_float_1.nut:1:8 3 | 4 | println(1e4e-4) 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/many_args_in_function_call.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: internal compiler error: too many locals 2 | testData/diagnostics/many_args_in_function_call.nut:-1:-1 3 | -------------------------------------------------------------------------------- /testData/diagnostics/var_scope_3.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/diagnostics/var_scope_3.nut:4:8 3 | 4 | else 5 | print(x) 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_freeze.nut: -------------------------------------------------------------------------------- 1 | let t = static {x = null} 2 | try { 3 | t.x = "fail" 4 | println(t.x) 5 | } catch (e) { 6 | println("success") 7 | } 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w215.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w215 5 | 6 | local flag = true 7 | local b = 10 + flag ? 1 : 2 8 | print(b) -------------------------------------------------------------------------------- /testData/static_analyzer/w228_2.nut: -------------------------------------------------------------------------------- 1 | //expect:w228 2 | 3 | function fn() { //-declared-never-used 4 | local f = 123 5 | local c = { f = 3 } 6 | return c.f 7 | } 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_in_container.nut: -------------------------------------------------------------------------------- 1 | function foo() {} 2 | function bar(_a) {} 3 | 4 | let { c = null} = foo() 5 | 6 | if ("xx" in c) { 7 | bar(c.xx) 8 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w260_local_function.nut: -------------------------------------------------------------------------------- 1 | //expect:w260 2 | 3 | local function getSettings(path) { return } //-declared-never-used 4 | 5 | return getSettings 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w260_table_sqconfig.nut: -------------------------------------------------------------------------------- 1 | //expect:w260 2 | 3 | ::game <- { 4 | make_and_return_object = function(x) { return } //-declared-never-used 5 | } 6 | -------------------------------------------------------------------------------- /testData/diagnostics/assign_to_expr.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't assign to expression 2 | testData/diagnostics/assign_to_expr.nut:2:0 3 | 4 | local x 5 | x-- = 1 6 | ^-- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/const_scope_3.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Unknown variable [x] 2 | testData/diagnostics/const_scope_3.nut:4:8 3 | 4 | else 5 | print(x) 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_float_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: malformed number 2 | testData/diagnostics/invalid_float_2.nut:1:8 3 | 4 | println(1e4......) 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_float_3.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: malformed number 2 | testData/diagnostics/invalid_float_3.nut:1:8 3 | 4 | println(1.2.3.4) 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_type_hint_1.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'TYPE_NAME' 2 | testData/diagnostics/invalid_type_hint_1.nut:1:6 3 | 4 | let a:2 = 3 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/248_instanceof.nut: -------------------------------------------------------------------------------- 1 | 2 | class Watched {} 3 | 4 | function _foo(text = null) { 5 | if (text instanceof Watched) 6 | text = text.value 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w200_arith_deep.nut: -------------------------------------------------------------------------------- 1 | //expect:w201 2 | local x = {y = 2} 3 | local z = x?.y 4 | local a = z - 8 5 | print(a) 6 | 7 | 8 | //-file:expr-cannot-be-null 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_table.nut: -------------------------------------------------------------------------------- 1 | let getSoldierFace = @() 1 2 | 3 | let fx = 10 4 | 5 | return { 6 | getSoldierFace = @() getSoldierFace() 7 | fx = 100 8 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w249.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w249 5 | 6 | local a = ::x?.b 7 | return a.b[6] 8 | 9 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w274_2.nut: -------------------------------------------------------------------------------- 1 | let a = [1, 2, 3, 4, 5] 2 | local m = [] 3 | 4 | foreach (_, x in a) { 5 | m.append(@() print(x)) 6 | m.each(@(_p) print(x)) 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w291.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | function _foo( 5 | x, 6 | _y, // EXPECTED 7 | _z // FP 8 | ) { 9 | return x + _y; 10 | } 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w295.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | 5 | 6 | 7 | ::f <- {} 8 | ::g <- 1 9 | 10 | ::g <- 2 11 | 12 | print(::h) -------------------------------------------------------------------------------- /testData/static_analyzer/w312_require.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | let baz = require("testData/static_analyzer/foo.nut").baz 5 | return baz(1) 6 | -------------------------------------------------------------------------------- /squirrel-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/squirrel-config-version.cmake") 4 | include("${CMAKE_CURRENT_LIST_DIR}/squirrel-targets.cmake") 5 | -------------------------------------------------------------------------------- /testData/diagnostics/base_x_pp.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: argument of inc/dec operation is not assignable 2 | testData/diagnostics/base_x_pp.nut:1:0 3 | 4 | base.x++ 5 | ^----- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/unfinished_hex.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected hex digits after '0x' 2 | testData/diagnostics/unfinished_hex.nut:1:8 3 | 4 | println(0x) 5 | ^- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/div64_by_minus_one_vm.nut: -------------------------------------------------------------------------------- 1 | try { 2 | local x = -0x7FFFFFFFFFFFFFFF - 1 3 | local y = @(a) -a 4 | print( x / y(1) ) 5 | } catch (e) { 6 | print("OK") 7 | } -------------------------------------------------------------------------------- /testData/exec/spec/forstmt.nut: -------------------------------------------------------------------------------- 1 | 2 | for (local a=0;a<10;a+=1) 3 | println(a) 4 | //or 5 | 6 | 7 | for (;;) { 8 | println("loops forever") 9 | break; 10 | } 11 | -------------------------------------------------------------------------------- /testData/exec/stdlib/obj_serialization_valid.out: -------------------------------------------------------------------------------- 1 | PASS: Valid string index test 2 | PASS: Valid string index test 3 | PASS: Valid class index test 4 | PASS: Valid class index test 5 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_arith_plus_eq.nut: -------------------------------------------------------------------------------- 1 | //expect:w201 2 | local x = {y = 2, z = 1} 3 | local a = x?.z 4 | a -= 10 5 | print(a) 6 | 7 | 8 | //-file:expr-cannot-be-null 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w205-2.nut: -------------------------------------------------------------------------------- 1 | //expect:w205 2 | 3 | function y() { //-declared-never-used 4 | return 5 | let t = { //-declared-never-used 6 | a = 1 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w238_sqconfig.nut: -------------------------------------------------------------------------------- 1 | //expect:w238 2 | 3 | function x() { //-declared-never-used 4 | ::a._must_be_utilized(::table2); 5 | } 6 | 7 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w249_array.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w249 5 | 6 | local a = ::x?.b 7 | return a[6]; 8 | 9 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w302_dowhile.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {return 10} 3 | 4 | let y = 5000 5 | local x 6 | do { 7 | x = foo() 8 | } while (x >= y) 9 | 10 | return 0 -------------------------------------------------------------------------------- /testData/diagnostics/import_03.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: missing "*/" in comment 2 | testData/diagnostics/import_03.nut:1:0 3 | 4 | /* 5 | ^-------------------- 6 | import "a" as x 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_stringconcat.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | let o = {} 6 | 7 | let s = o?.x 8 | 9 | let ss = "a" + o + s 10 | 11 | 12 | //-file:expr-cannot-be-null 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w210.nut: -------------------------------------------------------------------------------- 1 | //expect:w210 2 | local x = { b = 1 } 3 | local y = { a = "b" } 4 | 5 | ::f <- x[y?["a"]] 6 | 7 | 8 | //-file:expr-cannot-be-null 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w221.nut: -------------------------------------------------------------------------------- 1 | //expect:w221 2 | local z 3 | function foo(y){ //-declared-never-used 4 | ++z 5 | z-- 6 | ::x == y 7 | } 8 | 9 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w232_false.nut: -------------------------------------------------------------------------------- 1 | //expect:w232 2 | local a = 1 3 | ::XEnum <- { 4 | PARAM_A = 1 5 | PARAM_B = 2 6 | } 7 | print(a == ::XEnum.PARAM_A && a == ::XEnum.PARAM_B) 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_eq_get.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo(_p) {} 3 | let o = {} 4 | 5 | let u = o.value.findvalue(@(u) u.l == "999") 6 | let _x = u?.t != "a" || foo(u) ? null 7 | : u.t -------------------------------------------------------------------------------- /testData/static_analyzer/w286_2.nut: -------------------------------------------------------------------------------- 1 | //expect:w286 2 | 3 | 4 | local cls = class { 5 | 6 | } 7 | 8 | 9 | 10 | return cls || ::fn2 //-const-in-bool-expr -undefined-global 11 | -------------------------------------------------------------------------------- /testData/diagnostics/base_as_array_assign.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't assign to expression 2 | testData/diagnostics/base_as_array_assign.nut:1:0 3 | 4 | base["x"] = 1 5 | ^-------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/clone_op_allowed.nut.txt: -------------------------------------------------------------------------------- 1 | 2 | #allow-clone-operator 3 | 4 | let t = { 5 | a = 10, b = 20 6 | } 7 | 8 | 9 | let ct0 = clone t 10 | let ct1 = t.clone() 11 | -------------------------------------------------------------------------------- /testData/diagnostics/clone_op_forbiden.nut.txt: -------------------------------------------------------------------------------- 1 | 2 | #forbid-clone-operator 3 | 4 | let t = { 5 | a = 10, b = 20 6 | } 7 | 8 | 9 | let ct1 = t.clone() 10 | let ct0 = clone t 11 | -------------------------------------------------------------------------------- /testData/diagnostics/delete_base.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't delete 'base' 2 | testData/diagnostics/delete_base.nut:2:0 3 | 4 | #allow-delete-operator 5 | delete base 6 | ^---------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_not_string.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'expression' 2 | testData/diagnostics/interp_str_not_string.nut:3:8 3 | 4 | println($'{{{{{{{{') 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_not_string_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'expression' 2 | testData/diagnostics/interp_str_not_string_2.nut:5:8 3 | 4 | println($foo()) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_string_interp_1.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: unfinished string 2 | testData/diagnostics/invalid_string_interp_1.nut:1:11 3 | 4 | println($"{") 5 | ^- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w225.nut: -------------------------------------------------------------------------------- 1 | //expect:w225 2 | 3 | function x(y) { //-declared-never-used 4 | if (y == 1) 5 | return "y == 1" 6 | else if (y == 2) 7 | return "y == 2" 8 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w233_const_key.nut: -------------------------------------------------------------------------------- 1 | function bar(_g) {} 2 | function foo() {} 3 | 4 | let { s, o } = foo() 5 | 6 | const Z = "xxs" 7 | 8 | let _seen = bar(@() o.value && s.value?[Z]) -------------------------------------------------------------------------------- /testData/static_analyzer/w248_assert.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | function foo() {} 5 | 6 | let o = foo(); 7 | 8 | let c = o?.x 9 | 10 | 11 | assert(c != null) 12 | 13 | let _g = c.y 14 | -------------------------------------------------------------------------------- /testData/static_analyzer/w254_instanceof.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w254 5 | local x = 10 6 | if (x instanceof !"weapModSlotName") 7 | return null 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w309_require.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | let { foo bar } = require("testData/static_analyzer/foo.nut") 5 | 6 | return { foo bar } 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w310_require.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | let [ foo bar ] = require("testData/static_analyzer/foo.nut") 5 | 6 | return { foo, bar } 7 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/constDep.nut: -------------------------------------------------------------------------------- 1 | function foo() { 2 | const x = "asdf" 3 | println(x) 4 | 5 | function bar() { 6 | let a = x 7 | } 8 | bar() 9 | } 10 | -------------------------------------------------------------------------------- /testData/diagnostics/assign_to_expr2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't assign to expression 2 | testData/diagnostics/assign_to_expr2.nut:1:13 3 | 4 | local x; @() !x = 1 5 | ^--- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/base_as_array_pp.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: argument of inc/dec operation is not assignable 2 | testData/diagnostics/base_as_array_pp.nut:1:0 3 | 4 | base[0]++ 5 | ^------ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/import_05.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: unrecognised escaper char 2 | testData/diagnostics/import_05.nut:1:5 3 | 4 | from "../a\..\b\folder/file.nut" import * 5 | ^----- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_type_hint_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'TYPE_NAME' 2 | testData/diagnostics/invalid_type_hint_2.nut:1:16 3 | 4 | function fn(...:) {} 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_static_memo_expr.nut: -------------------------------------------------------------------------------- 1 | //expect:w200 2 | 3 | function fn(mod, wpUnitRank) { //-declared-never-used 4 | return (static(mod?.reqRank) > wpUnitRank) // -w316 5 | } 6 | -------------------------------------------------------------------------------- /testData/static_analyzer/w224_while.nut: -------------------------------------------------------------------------------- 1 | //expect:w224 2 | 3 | function foo(x){ //-declared-never-used 4 | while (x) { 5 | x++; 6 | if (x > 5) 7 | break; 8 | } while (x < 6) ; 9 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w232_true.nut: -------------------------------------------------------------------------------- 1 | //expect:w232 2 | local a = " " 3 | local s = { 4 | charAt = @(i) a[i] 5 | } 6 | local i = 2 7 | print(s.charAt(i) != ' ' || s.charAt(i) != '\t') 8 | -------------------------------------------------------------------------------- /scripts/samples/module_demo.nut: -------------------------------------------------------------------------------- 1 | let foo = require("module_1.nut") 2 | let {bar, baz} = require("module_2.nut") 3 | 4 | println($"foo() result = {foo()}") 5 | println($"bar = {bar}, baz = {baz}") 6 | -------------------------------------------------------------------------------- /testData/diagnostics/import_02.nut: -------------------------------------------------------------------------------- 1 | /* 2 | wretwert 3 | rtwrt 4 | */ 5 | // wtwrtwrt wrtwr t\ 6 | /* adsfadf/* // */ import /**/ "a" /**/ as x 7 | /* 8 | wretwert 9 | rtwrt 10 | */ 11 | -------------------------------------------------------------------------------- /testData/diagnostics/leading_zero_1.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: leading 0 is not allowed, octal numbers are not supported 2 | testData/diagnostics/leading_zero_1.nut:1:6 3 | 4 | print(00) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/leading_zero_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: leading 0 is not allowed, octal numbers are not supported 2 | testData/diagnostics/leading_zero_2.nut:1:6 3 | 4 | print(01) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/need_space_after_int.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: malformed number 2 | testData/diagnostics/need_space_after_int.nut:2:9 3 | 4 | local f = 333 5 | println([5f][1]) 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/spec/ifstmt.nut: -------------------------------------------------------------------------------- 1 | 2 | local a = 10, b = 20; 3 | if (a > b) 4 | a = b 5 | else 6 | b = a 7 | //// 8 | if ( a == 10 ) { 9 | b = a + b 10 | return a - 10 11 | } 12 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_types.out: -------------------------------------------------------------------------------- 1 | null 2 | true 3 | 123 4 | 123.25 5 | asdf 6 | 678 7 | 987 8 | false 9 | print 10 | null 11 | class 12 | instance 13 | function 14 | 444 15 | 444 16 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_special_func_name.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w247 5 | 6 | return ::a.b.c.indexof("x") + 6; 7 | 8 | //-file:undefined-global 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w220_deep.nut: -------------------------------------------------------------------------------- 1 | //expect:w220 2 | 3 | function foo(a){ //-declared-never-used 4 | local container = a?.y() 5 | foreach(x in container) { 6 | print(x) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w241.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w241 5 | 6 | local str1 = require("string") 7 | local str2 = require("string") 8 | print(str1, str2) 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w264.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w264 (plus-string) Usage of '+' for string concatenation. 2 | testData/static_analyzer/w264.nut:7:7 3 | 4 | return a + 3 5 | ^---- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w266.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w266 5 | 6 | { 7 | ::x++ 8 | } while (::x) 9 | ::x-- 10 | 11 | //-file:undefined-global 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w288.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w288 5 | local fn = function (aaa_x, bbb, ...) {return aaa_x + bbb} 6 | 7 | local b = 1; 8 | return fn(b); -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_wrong_template.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'IDENTIFIER' 2 | testData/diagnostics/interp_str_wrong_template.nut:3:12 3 | 4 | println($"{{{{{{{{") 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/leading_zero_3.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: leading 0 is not allowed, octal numbers are not supported 2 | testData/diagnostics/leading_zero_3.nut:1:6 3 | 4 | print(00.1) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_break.nut: -------------------------------------------------------------------------------- 1 | //expect:w217 2 | 3 | function foo(x,y,z){ //-declared-never-used 4 | for (;;) { 5 | x++; 6 | y--; 7 | break; 8 | z--; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_override.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | local x = foo()?.x 4 | 5 | 6 | if (foo() || !x) 7 | return 8 | let r = x 9 | x = null 10 | 11 | if (r.s) 12 | foo() -------------------------------------------------------------------------------- /testData/static_analyzer/w254_notin.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w254 5 | 6 | if (!"weapModSlotName" not in ::item) 7 | return null 8 | 9 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/diagnostics/need_space_after_float.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: malformed number 2 | testData/diagnostics/need_space_after_float.nut:2:9 3 | 4 | local f = 333 5 | println([5.0f][1]) 6 | ^-- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/space_sep_name.nut.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | let a1 = [1, 2, 3] 5 | 6 | a1.append(6) // OK 7 | .extend(7) // OK 8 | 9 | a1. 10 | append(8). // NOT OK 11 | extend(6) // NOT OK 12 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_opt.nut: -------------------------------------------------------------------------------- 1 | function fn() { 2 | println(static (1 + 2 + 4 + 8)) 3 | println(static (1 | 2 | 4 | 8)) 4 | let s = "===" 5 | println(s) 6 | } 7 | 8 | fn() 9 | fn() 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/efferct_fropm_call.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | function foo(_p) {} 5 | function bar(_p) {} 6 | function qux() {} 7 | 8 | let val = qux()?.z 9 | 10 | bar(foo(val) ? val.tointeger() : 0) -------------------------------------------------------------------------------- /testData/static_analyzer/w206.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w206 (assigned-twice) Variable is assigned twice successively. 2 | testData/static_analyzer/w206.nut:5:0 3 | 4 | tab.y = 7 5 | tab.x = 8 6 | ^-------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w209.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w209 (assigned-to-itself) The variable is assigned to itself. 2 | testData/static_analyzer/w209.nut:5:0 3 | 4 | x.y = (((x.y))) 5 | ^-------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w224_then.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w224 (empty-body) 'then' operator has an empty body. 2 | testData/static_analyzer/w224_then.nut:4:11 3 | 4 | if (x == 5); 5 | ^ 6 | { 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_table.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'fx' was declared but never used. 2 | testData/static_analyzer/w227_table.nut:3:0 3 | 4 | let fx = 10 5 | ^----- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w251.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w250 (cmp-with-container) Comparison with a declaration. 2 | testData/static_analyzer/w251.nut:6:8 3 | 4 | return (::a != {}) 5 | ^--------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w254.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w254 5 | 6 | if (!"weapModSlotName" in ::item) 7 | return null 8 | 9 | //-file:undefined-global 10 | -------------------------------------------------------------------------------- /testData/diagnostics/assign_to_optional_7.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't assign to expression 2 | testData/diagnostics/assign_to_optional_7.nut:2:0 3 | 4 | local v = {v = {v = 0}} 5 | v.v ?? v = 3 6 | ^------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/clone_op_allowed.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'IDENTIFIER' 2 | testData/diagnostics/clone_op_allowed.nut.txt:10:12 3 | 4 | let ct0 = clone t 5 | let ct1 = t.clone() 6 | ^---- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/need_space_after_hex.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected hex digits after '0x' 2 | testData/diagnostics/need_space_after_hex.nut:2:9 3 | 4 | let x = 123 5 | println([0xx][1]) 6 | ^- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/param_check.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | function _appls(ar) { 5 | foreach (_x in ar) { 6 | let a = @(perk) (perk?.items ?? []).len() > 0 7 | let _b = @(perk) !a(perk) 8 | } 9 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w190.nut: -------------------------------------------------------------------------------- 1 | //-file:suspicious-bracket 2 | 3 | function foo(_p) { return "X" } 4 | 5 | let x = { bar = "T" } 6 | 7 | let _a = [ 8 | foo(10) 9 | (x.bar) ? 10 : 20 10 | ] 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w210_deep.nut: -------------------------------------------------------------------------------- 1 | //expect:w210 2 | local y = { a = "b" } 3 | local index = y?["a"] 4 | local x = { b = 1 } 5 | 6 | ::f <- x[index] 7 | 8 | 9 | 10 | //-file:expr-cannot-be-null 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w215_nullc.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | 4 | let o = {} 5 | let s = foo() 6 | let r = foo() 7 | 8 | let _u = o?.u ?? s ? s / r : 0.0 9 | 10 | 11 | //-file:expr-cannot-be-null 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w303_destruct.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | 5 | function foo() { return "1" } 6 | function bar(u) {} 7 | 8 | let {x} = foo() 9 | 10 | 11 | bar(x) 12 | -------------------------------------------------------------------------------- /testData/diagnostics/hex_overflow.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: too many digits for an Hex number 2 | testData/diagnostics/hex_overflow.nut:1:8 3 | 4 | println(0x1_0000_0000_0000_0000) 5 | ^---------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/import_error.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: expected 'identifier or *' 2 | testData/diagnostics/import_error.nut:2:20 3 | 4 | // missing import list 5 | from "file1" import 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/integer_overflow_2.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: integer constant overflow 2 | testData/diagnostics/integer_overflow_2.nut:1:8 3 | 4 | println(20496385583567863808) 5 | ^------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/interp_str_hanging_missed_ccurvy.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: unfinished string 2 | testData/diagnostics/interp_str_hanging_missed_ccurvy.nut:3:16 3 | 4 | println($"{foo()") 5 | ^- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_3wcmp.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | local function _itemsSorter(a, b) { // -return-different-types 4 | a = a?.item 5 | b = b?.item 6 | if (!a || !b) 7 | return a <=> b 8 | return 42 9 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w226.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w226 (return-different-types) Function can return different types. 2 | testData/static_analyzer/w226.nut:7:4 3 | 4 | let function x(y) { 5 | ^ 6 | if (y == 1) 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228_3.nut: -------------------------------------------------------------------------------- 1 | //expect:w228 2 | 3 | function fn() { //-declared-never-used 4 | local f = 123 5 | local c = { f = 3 } 6 | return c?.f 7 | } 8 | 9 | 10 | //-file:expr-cannot-be-null 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_andor.nut: -------------------------------------------------------------------------------- 1 | function riIsEmptyGroup(x) { 2 | let list = x?.list 3 | let a = list != null && list.len() == 0 4 | let b = list != null || list.len() == 0 5 | 6 | return a && b; 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w286_oror_andand.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | let t = {} 4 | 5 | let _p = t?.x || {} 6 | let _x = {} || t?.y 7 | let _y = t?.z && [] 8 | let _z = [] && t?.g 9 | 10 | 11 | //-file:expr-cannot-be-null 12 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/recursion1.nut: -------------------------------------------------------------------------------- 1 | function foo(x, y) { 2 | function bar(a, b) { 3 | function qux(c, d) { 4 | return c(d) 5 | } 6 | 7 | return qux(bar, b) 8 | } 9 | } -------------------------------------------------------------------------------- /testData/diagnostics/integer_overflow_int_max.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: integer constant overflow 2 | testData/diagnostics/integer_overflow_int_max.nut:1:8 3 | 4 | println(9223372036854775808) 5 | ^------------------ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/stdlib/docstring.out: -------------------------------------------------------------------------------- 1 | null 2 | null 3 | null 4 | null 5 | Class docstring 6 | Class docstring 7 | Table docstring 8 | Function docstring 9 | Returns a documentation string for a function, class, or table 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w213.nut: -------------------------------------------------------------------------------- 1 | //expect:w213 2 | 3 | function foo(x) { //-declared-never-used 4 | if (x == 1) { 5 | x /= 4 6 | print(x) 7 | } 8 | else { 9 | x /= 4 10 | print(x) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_ret.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w217 (unconditional-terminated-loop) Unconditional 'return' inside a loop. 2 | testData/static_analyzer/w217_ret.nut:8:4 3 | 4 | return 5 | ^----- 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w221.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w221 (result-not-utilized) Result of operation is not used. 2 | testData/static_analyzer/w221.nut:6:4 3 | 4 | z-- 5 | ::x == y 6 | ^------- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w222_deep.nut: -------------------------------------------------------------------------------- 1 | //expect:w222 2 | local x, y; 3 | 4 | 5 | function b() {} 6 | 7 | function foo(a) { //-declared-never-used 8 | local index = x < y 9 | b() 10 | print(a[index]) 11 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w228_table.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'foo' was declared but never used. 2 | testData/static_analyzer/w228_table.nut:3:0 3 | 4 | function foo(y) { 5 | ^ 6 | let x = y 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_relative_pred.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | 4 | let x =foo() 5 | let y = x?.y 6 | 7 | 8 | local r = null 9 | 10 | let b = {} 11 | 12 | if (x && y > 0) { 13 | r = b[10] / (y * 60) 14 | } -------------------------------------------------------------------------------- /testData/diagnostics/clone_op_forbiden.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: end of statement expected (; or lf) 2 | testData/diagnostics/clone_op_forbiden.nut.txt:10:16 3 | 4 | let ct1 = t.clone() 5 | let ct0 = clone t 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/letAssign.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't assign to binding 'y' (probably declaring using 'local' was intended, but 'let' was used) 2 | testData/diagnostics/letAssign.nut:4:0 3 | 4 | let y = 30 5 | y = 40 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w210.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w210 (potentially-nulled-index) Potentially nullable expression used as array index. 2 | testData/static_analyzer/w210.nut:5:9 3 | 4 | ::f <- x[y?["a"]] 5 | ^------ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w223.nut: -------------------------------------------------------------------------------- 1 | //expect:w223 2 | 3 | local x = 1 4 | local y = 1 5 | local z = 2 6 | if (x == y > z) 7 | print("a") 8 | 9 | if ((x > y) != z) 10 | print("b") 11 | 12 | if (x == (y > z)) 13 | print("c") -------------------------------------------------------------------------------- /testData/static_analyzer/w235.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w235 (round-to-int) Result of division will be integer. 2 | testData/static_analyzer/w235.nut:3:19 3 | 4 | ::aspect_ratio <- (1280 / (720)) 5 | ^----------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w236.nut: -------------------------------------------------------------------------------- 1 | //expect:w236 2 | ::SCRIPT_STATE_USER_SHIFT <- 2 3 | function foo(berserkFx, state){ //-declared-never-used 4 | if (!berserkFx && (state & (1 << ::SCRIPT_STATE_USER_SHIFT + 4))) 5 | print(1) 6 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w270.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w270 5 | 6 | ::handlersManager[::PERSISTENT_DATA_PARAMS].extend([ "curControlsAllowMask", "isCurSceneBgBlurred" ]) // -undefined-global 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w284.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | function fn(x) { 5 | return ::y(x) 6 | } 7 | 8 | let _c1 = ::a > 2 || ::a > 100 9 | 10 | let _c2 = fn(1) != null ? fn(1) : null 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w301_closure2.nut: -------------------------------------------------------------------------------- 1 | function foo() {} 2 | let x = foo() 3 | local a = false 4 | 5 | function _sss() { 6 | if (a) 7 | return 8 | a = true 9 | x.st(function() { 10 | a = false 11 | }) 12 | } -------------------------------------------------------------------------------- /sqmodules/path.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void dd_simplify_fname_c(char *s); 4 | bool dd_fname_equal(const char *fn1, const char *fn2); 5 | void dd_append_slash_c(char *fn); 6 | char *dd_get_fname_location(char *buf, const char *filename); 7 | -------------------------------------------------------------------------------- /testData/diagnostics/delete_forbid_pragma.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Usage of 'delete' operator is forbidden. Use 'o.rawdelete("key")' instead 2 | testData/diagnostics/delete_forbid_pragma.nut.txt:10:0 3 | 4 | delete t.a // FP 1 5 | ^----- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/array_methods.out: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | false 4 | false 5 | true 6 | false 7 | true 8 | 3 9 | 1 10 | 0 11 | 4 12 | -1 13 | 1 14 | 6 15 | -1 16 | 0 17 | 1 18 | null 19 | 1 20 | 1 21 | 0 22 | -3 23 | true 24 | -3 25 | 1 26 | ok -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_reset_module.nut: -------------------------------------------------------------------------------- 1 | function fn(x) { 2 | x++ 3 | println(static x) 4 | x++ 5 | println(x) 6 | } 7 | 8 | fn(10) 9 | fn(20) 10 | 11 | require("static_reset1.nut") 12 | 13 | fn(30) 14 | fn(40) 15 | -------------------------------------------------------------------------------- /testData/exec/stdlib/copy_content_with_replace.out: -------------------------------------------------------------------------------- 1 | == a == 2 | 5 3 | 6 4 | 7 5 | == aRef == 6 | 5 7 | 6 8 | 7 9 | == b == 10 | 999 11 | 6 12 | 7 13 | == p == 14 | z = 777 15 | == pRef == 16 | z = 777 17 | == q == 18 | z = foo 19 | -------------------------------------------------------------------------------- /testData/static_analyzer/w208_rec.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) parameter 'x' was declared but never used. 2 | testData/static_analyzer/w208_rec.nut:7:14 3 | 4 | function bart(x) { return "" } 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w210_deep.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w210 (potentially-nulled-index) Potentially nullable expression used as array index. 2 | testData/static_analyzer/w210_deep.nut:6:9 3 | 4 | ::f <- x[index] 5 | ^---- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w216.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w216 (same-operands) Left and right operands of '<' operator are the same. 2 | testData/static_analyzer/w216.nut:5:4 3 | 4 | if (a.x < a.x) 5 | ^-------- 6 | print("x < y") 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_throw.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w217 (unconditional-terminated-loop) Unconditional 'throw' inside a loop. 2 | testData/static_analyzer/w217_throw.nut:8:4 3 | 4 | throw "err" 5 | ^---------- 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w223.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w223 (compared-with-bool) Comparison with boolean. 2 | testData/static_analyzer/w223.nut:6:4 3 | 4 | local z = 2 5 | if (x == y > z) 6 | ^--------- 7 | print("a") 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w225.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w225 (all-paths-return-value) Not all control paths return a value. 2 | testData/static_analyzer/w225.nut:3:0 3 | 4 | function x(y) { //-declared-never-used 5 | ^ 6 | if (y == 1) 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w286.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w286 (decl-in-expression) Declaration used in arith expression as operand. 2 | testData/static_analyzer/w286.nut:5:7 3 | 4 | return fn1 || ::fn2 // -undefined-global 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w306.nut: -------------------------------------------------------------------------------- 1 | //expect:w223 2 | 3 | local x = 1 4 | local y = 1 5 | local z = 2 6 | if (x == y != z) 7 | print("a") 8 | 9 | if ((x == y) != z) 10 | print("b") 11 | 12 | if (x == (y != z)) 13 | print("c") -------------------------------------------------------------------------------- /scripts/std/analyzer.nut: -------------------------------------------------------------------------------- 1 | 2 | function dynamic_content(o) { 3 | assert(type(o) == "table", $"expected table in dynamic_content(), got '{type(o)}'") 4 | o.__dynamic_content__ <- true 5 | return o 6 | } 7 | 8 | return { dynamic_content } 9 | -------------------------------------------------------------------------------- /testData/diagnostics/binding_assign.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: can't assign to binding 'a' (probably declaring using 'local' was intended, but 'let' was used) 2 | testData/diagnostics/binding_assign.nut:2:0 3 | 4 | let a = 2 5 | a = 3 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/diagnostics/invalid_type_hint_3.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Invalid type name 'Integer', did your mean 'int'? 2 | testData/diagnostics/invalid_type_hint_3.nut:1:13 3 | 4 | let a = @(x: Integer): Integer x * x 5 | ^------ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w213.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w213 (then-and-else-equals) then' statement is equivalent to 'else' statement. 2 | testData/static_analyzer/w213.nut:8:7 3 | 4 | } 5 | else { 6 | ^ 7 | x /= 4 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_ret.nut: -------------------------------------------------------------------------------- 1 | //expect:w217 2 | 3 | function foo(x){ //-declared-never-used 4 | while (x) { 5 | if (::a == x) 6 | ::h(::a, x) 7 | 8 | return 9 | } 10 | } 11 | 12 | //-file:undefined-global 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_throw.nut: -------------------------------------------------------------------------------- 1 | //expect:w217 2 | 3 | function foo(x){ //-declared-never-used 4 | while (x) { 5 | if (::a == x) 6 | ::h(::a, x) 7 | 8 | throw "err" 9 | } 10 | } 11 | 12 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w227.nut: -------------------------------------------------------------------------------- 1 | //expect:w227 2 | 3 | function foo(a, c) { //-declared-never-used 4 | local b = function() { 5 | local x = c 6 | local a = x 7 | print(a) 8 | return x 9 | } 10 | return b() 11 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w239_sqconfig.nut: -------------------------------------------------------------------------------- 1 | //expect:w239 2 | 3 | function returnBoolFunctionName() { //-declared-never-used 4 | if (::serverName == "") 5 | return 6 | 7 | return true; 8 | } 9 | 10 | //-file:undefined-global 11 | -------------------------------------------------------------------------------- /sqmodules/helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sqmodules.h" 4 | 5 | namespace sqm 6 | { 7 | 8 | SqModules::string format_string(const char *fmt, ...); 9 | void append_format(SqModules::string &s, const char *fmt, ...); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /testData/diagnostics/float_overflow.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: float constant overflow 2 | testData/diagnostics/float_overflow.nut:1:8 3 | 4 | println(1000000000000000000000000000000000000000.0) 5 | ^----------------------------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/diagnostics/space_sep_name_space.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Separate access operator '?.$' with it's following name is forbidden 2 | testData/diagnostics/space_sep_name_space.nut.txt:8:10 3 | 4 | t1?.$ foo // NOT OK 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w205-2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w205 (unreachable-code) Unreachable code after 'return'. 2 | testData/static_analyzer/w205-2.nut:5:2 3 | 4 | return 5 | let t = { //-declared-never-used 6 | ^ 7 | a = 1 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w206_arith.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w206 (assigned-twice) Variable is assigned twice successively. 2 | testData/static_analyzer/w206_arith.nut:11:0 3 | 4 | x /= foo(); 5 | x = foo(); 6 | ^-------- 7 | print(x) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_cascade.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'foo' was declared but never used. 2 | testData/static_analyzer/w232_cascade.nut:6:0 3 | 4 | function foo(size, a, b) { 5 | ^-- 6 | if (a && b) 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w240.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w240 5 | 6 | local a = ::x; // can be null 7 | local b = 1; 8 | 9 | print(a ?? b != 1) // expected boolean 10 | 11 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w248_complexcond.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | function foo(_p) {} 5 | 6 | local x = foo(1) 7 | 8 | 9 | if (x == null && foo(2)) 10 | foo(x.y) 11 | else 12 | foo(x.x) 13 | 14 | -------------------------------------------------------------------------------- /testData/diagnostics/integer_overflow.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: integer constant overflow 2 | testData/diagnostics/integer_overflow.nut:1:8 3 | 4 | println(1000000000000000000000000000000000000000) 5 | ^--------------------------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/spec/trystmt.nut: -------------------------------------------------------------------------------- 1 | function foo(a, b, c) { 2 | try { 3 | println($"TRYING {a}") 4 | throw b 5 | } catch (e) { 6 | println($"CAUGHT {e}") 7 | } 8 | println($"FINISHING {c}") 9 | } 10 | 11 | 12 | foo(1, 2, 3) 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/nullcheck_ternary.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | function foo(_p) {} 5 | let x = {} 6 | 7 | let p = foo(1) ? x?.x : x.y 8 | 9 | foo(p.z) 10 | 11 | 12 | 13 | //-file:expr-cannot-be-null 14 | -------------------------------------------------------------------------------- /testData/static_analyzer/w234.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w234 (div-by-zero) Integer division by zero. 2 | testData/static_analyzer/w234.nut:4:8 3 | 4 | function foo() { //-declared-never-used 5 | print(1 / (0)) 6 | ^------ 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w289.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w289 (param-pos) The function parameter 'aaax' seems to be in the wrong position. 2 | testData/static_analyzer/w289.nut:6:13 3 | 4 | local b = -1; 5 | return fn(b, aaaX); 6 | ^--- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/coroutines.out: -------------------------------------------------------------------------------- 1 | test coroutine 2 | suspend passed [suspend 1] 3 | the coroutine says ciao 1 4 | suspend passed [suspend 2] 5 | the coroutine says ciao 2 6 | suspend passed [suspend 3] 7 | the coroutine says ciao 3 8 | return passed [I'm done] 9 | -------------------------------------------------------------------------------- /testData/exec/spec/constFolding.nut: -------------------------------------------------------------------------------- 1 | let a = 1 2 | let c = a + 1 3 | print(c) 4 | let b = 1 5 | let d = 2 + b 6 | print(d) 7 | let e = 3 8 | let f = 4 9 | let g = e + f 10 | print(g) 11 | 12 | let v0 = 1 13 | if (v0 > v0) { } 14 | print(v0) 15 | 16 | -------------------------------------------------------------------------------- /testData/static_analyzer/function_rt_detect.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w226 (return-different-types) Function can return different types. 2 | testData/static_analyzer/function_rt_detect.nut:6:0 3 | 4 | function _foo(p) { // EXPECTED 5 | ^ 6 | if (p) 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/nullcheck_ternary.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/nullcheck_ternary.nut:9:4 3 | 4 | foo(p.z) 5 | ^ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w227 (ident-hides-ident) variable 'a' hides parameter with the same name. 2 | testData/static_analyzer/w227.nut:6:4 3 | 4 | local x = c 5 | local a = x 6 | ^---- 7 | print(a) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_type_func.nut: -------------------------------------------------------------------------------- 1 | 2 | function _foo(colorStr, f) { 3 | if ((type(colorStr) != "string" || (colorStr.len() != 8 && colorStr.len() != 6)) && (type(f) == "null") ) 4 | return f("first param must be string with len 6 or 8") 5 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w274.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w274 (iterator-in-lambda) Iterator 'v' is trying to be captured in closure. 2 | testData/static_analyzer/w274.nut:6:17 3 | 4 | foreach (v in [1, 2, 3]) 5 | tab.append(@() v) 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_continue.nut: -------------------------------------------------------------------------------- 1 | //expect:w217 2 | 3 | function foo(x) { //-declared-never-used 4 | do { 5 | if (::a == x) 6 | ::h(::a, x) 7 | continue; 8 | x--; 9 | } while (x) 10 | } 11 | 12 | //-file:undefined-global 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w222.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w222 (bool-as-index) Boolean used as array index. 2 | testData/static_analyzer/w222.nut:4:10 3 | 4 | function foo(a,x,y) { //-declared-never-used 5 | print(a[x < y]) 6 | ^---- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w248 5 | 6 | local a = ::x?.b 7 | local b = a 8 | if (b) { 9 | b() 10 | } else { 11 | a() 12 | } 13 | 14 | return a() 15 | 16 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w248_in.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/w248_in.nut:6:11 3 | 4 | return text.d 5 | ^--- 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_override.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/w248_override.nut:11:4 3 | 4 | if (r.s) 5 | ^ 6 | foo() 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w249.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/w249.nut:7:7 3 | 4 | local a = ::x?.b 5 | return a.b[6] 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w254.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w254 (bool-passed-to-strange) Boolean passed to 'in' operator. 2 | testData/static_analyzer/w254.nut:6:4 3 | 4 | if (!"weapModSlotName" in ::item) 5 | ^--------------------------- 6 | return null 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w283.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //-file:declared-never-used 5 | 6 | 7 | function fn(x) { 8 | return ::y.cc ?? x ?? null 9 | } 10 | 11 | local s = null 12 | local x = ::y ?? s 13 | return x 14 | -------------------------------------------------------------------------------- /testData/static_analyzer/w286_2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w286 (decl-in-expression) Declaration used in arith expression as operand. 2 | testData/static_analyzer/w286_2.nut:10:7 3 | 4 | return cls || ::fn2 //-const-in-bool-expr -undefined-global 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w306.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w306 (eq-paren-miss) Suspicious expression, probably parens are missed. 2 | testData/static_analyzer/w306.nut:6:4 3 | 4 | local z = 2 5 | if (x == y != z) 6 | ^---------- 7 | print("a") 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/diagnostics/space_sep_name.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: Separate access operator '.' with it's following name is forbidden 2 | testData/diagnostics/space_sep_name.nut.txt:10:0 3 | 4 | a1. 5 | append(8). // NOT OK 6 | ^----- 7 | extend(6) // NOT OK 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/exec/table_methods.out: -------------------------------------------------------------------------------- 1 | 3 2 | 1 3 | 4 4 | 4 5 | true 6 | false 7 | 2 8 | 3 9 | 1 10 | 6 11 | b 12 | null 13 | 3 14 | null 15 | 1 16 | true 17 | true 18 | null 19 | 20 20 | 5 21 | a 22 | 10 23 | true 24 | false 25 | true 26 | false 27 | 20 28 | 0 29 | ok -------------------------------------------------------------------------------- /testData/static_analyzer/200_nullc.nut: -------------------------------------------------------------------------------- 1 | function foo() {} 2 | 3 | let item = foo() 4 | let res = foo() 5 | 6 | 7 | let _x = (((item?.isPrimaryBuy ?? false) > (res?.isPrimaryBuy ?? null) ? item : res)) 8 | 9 | 10 | 11 | //-file:useless-null-coalescing 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w208.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w208 (potentially-nulled-assign) Assignment to potentially nullable expression. 2 | testData/static_analyzer/w208.nut:3:0 3 | 4 | local x = { z = {y = 3}} 5 | x.z?.y <- 6 6 | ^----- 7 | print(x.z.y) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w233 (const-in-bool-expr) Constant in a boolean expression. 2 | testData/static_analyzer/w233.nut:4:19 3 | 4 | ::flags <- 0x2040 5 | ::aspect_ratio <- (::flags && 0x40) 6 | ^-------------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_evaled.nut: -------------------------------------------------------------------------------- 1 | 2 | let t = {} 3 | 4 | function foo(_p) {} 5 | 6 | let sr = t.value.findvalue(@(s) s.s == 10 && (s?.e ?? 0) > 0 ) 7 | let r = sr != null 8 | let _timerObj = r ? foo({ 9 | ts = sr.e 10 | }) : null 11 | 12 | 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w303_destruct.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) parameter 'u' was declared but never used. 2 | testData/static_analyzer/w303_destruct.nut:6:13 3 | 4 | function foo() { return "1" } 5 | function bar(u) {} 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/spec/class_extend.nut: -------------------------------------------------------------------------------- 1 | class B {} 2 | 3 | class A(B) {} 4 | 5 | class D(class {}) {} 6 | 7 | class E(class(class {}) {}) {} 8 | 9 | class F(class(class(class{}) {}) {}) {} 10 | 11 | class G(class { a = 1 }) { a = 2 } { println(1) } { println(2) } 12 | -------------------------------------------------------------------------------- /testData/exec/spec/whilestmt.nut: -------------------------------------------------------------------------------- 1 | function testy(n) { 2 | local a = 0 3 | while (a < n) 4 | a += 1 5 | 6 | while (1) { 7 | if (a < 0) 8 | break 9 | println(a) 10 | a -= 1 11 | } 12 | } 13 | 14 | testy(10) 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/forloop_merge.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'findlast' was declared but never used. 2 | testData/static_analyzer/forloop_merge.nut:2:0 3 | 4 | function findlast(str, substr, startidx=0){ 5 | ^-- 6 | local ret = null 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w206_arith.nut: -------------------------------------------------------------------------------- 1 | function foo() { return 20 } 2 | 3 | local x = 10 4 | 5 | x = foo(); 6 | x += foo(); 7 | x -= foo(); 8 | x *= foo(); 9 | x %= foo(); 10 | x /= foo(); 11 | x = foo(); 12 | print(x) 13 | x = foo() 14 | print("") 15 | x = foo() -------------------------------------------------------------------------------- /testData/static_analyzer/w248_tyopeof2.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | function _foo(colorStr, f) { 5 | if ((typeof colorStr != "string" || (colorStr.len() != 8 && colorStr.len() != 6)) && (typeof f == "null") ) 6 | return f("first param must be string with len 6 or 8") 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w249_array.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/w249_array.nut:7:7 3 | 4 | local a = ::x?.b 5 | return a[6]; 6 | ^ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w250.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w250 5 | 6 | let t = [] 7 | 8 | let _x = (::a != []) 9 | let _y = (::a != {}) 10 | let _z = (::a != t) 11 | let _xx = (::a == @ (v) v) 12 | 13 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w302_loop.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | 4 | 5 | local z = foo() 6 | 7 | local { x = 20 } = foo() 8 | 9 | let a = {} 10 | 11 | while (foo()) { 12 | if (z) { 13 | x = 100 14 | } 15 | } 16 | 17 | 18 | a.x <- x 19 | 20 | -------------------------------------------------------------------------------- /testData/static_analyzer/w310_require.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w310 (destructured-type) Destructured type mismatch, right side is table. 2 | testData/static_analyzer/w310_require.nut:4:0 3 | 4 | let [ foo bar ] = require("testData/static_analyzer/foo.nut") 5 | ^----- 6 | 7 | 8 | -------------------------------------------------------------------------------- /sqrat/README.txt: -------------------------------------------------------------------------------- 1 | Sqrat - Quirrel Binding Utility 2 | 3 | © 2009 Brandon Jones 4 | © 2011-2014 Li-Cheng (Andy) Tai 5 | © 2013-2015 Brandon Haffen AKA Wizzard 6 | © 2016-2019 Gaijin Entertainment 7 | 8 | 9 | Sqrat is a C++ binding utility for the quirrel language. 10 | -------------------------------------------------------------------------------- /testData/exec/inexpr_block/inexpr_block_8.nut: -------------------------------------------------------------------------------- 1 | #allow-compiler-internals 2 | let lam = @(a, b) $${ return a - b } 3 | 4 | let xx = $${ 5 | let x = 4 6 | function fn(a) { return $${return a != 4 ? a * 2 : 3} } 7 | println(lam(fn(x), 100)) 8 | } 9 | println(xx) 10 | -------------------------------------------------------------------------------- /testData/exec/type_hints/var_decl.nut: -------------------------------------------------------------------------------- 1 | 2 | let i: int = 5 3 | let t: table = {a = [1, null], b = "abc"} 4 | let { a: array|null, b: string|null = "" } = t 5 | let [v0: int|null = -999, v1: int|null] = a 6 | 7 | println(i) 8 | println(type(a), b) 9 | println(v0, v1) 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_andnad1.nut: -------------------------------------------------------------------------------- 1 | function canEquipBothItems(_x) {} 2 | 3 | function _foo(data, onDropExceptionCb = null) { 4 | if (onDropExceptionCb != null && !canEquipBothItems(data) && data?.item != null) { 5 | onDropExceptionCb(data.item) 6 | } 7 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w280.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w280 (forbidden-parent-dir) Access to the parent directory is forbidden in this function. 2 | testData/static_analyzer/w280.nut:6:9 3 | 4 | let _x = require_optional("../a.nut") 5 | ^--------------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_arith_plus_eq.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w200 (potentially-nulled-ops) Arithmetic operation with potentially nullable expression. 2 | testData/static_analyzer/w200_arith_plus_eq.nut:4:0 3 | 4 | local a = x?.z 5 | a -= 10 6 | ^ 7 | print(a) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w211.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w211 (duplicate-case) Duplicate case value. 2 | testData/static_analyzer/w211.nut:14:7 3 | 4 | case MODE.MODE_2: print("2"); break; 5 | case MODE.MODE_1: print("3"); break; 6 | ^---------- 7 | default: 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) variable 'str' was declared but never used. 2 | testData/static_analyzer/w228.nut:4:2 3 | 4 | function x() { //-declared-never-used 5 | local str = "string" 6 | ^----- 7 | return 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w231.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w231 (format-arguments-count) Format string: arguments count mismatch. 2 | testData/static_analyzer/w231.nut:3:20 3 | 4 | local string = require("string") 5 | print(string.format("%d%%", 1, x)) 6 | ^----- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w239.nut: -------------------------------------------------------------------------------- 1 | //expect:w239 2 | 3 | function isLoggedIn() { //-declared-never-used 4 | if (::userName == "") 5 | return false; 6 | 7 | if (::serverName == "") 8 | return 9 | 10 | return true; 11 | } 12 | 13 | //-file:undefined-global 14 | -------------------------------------------------------------------------------- /testData/static_analyzer/w244.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w244 (used-from-static) Access 'this.y' from static member function. 2 | testData/static_analyzer/w244.nut:16:8 3 | 4 | this.sss(); // FP 3 5 | this.y = 30 // EXPECTED 1 6 | ^----- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w254_notin.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w254 (bool-passed-to-strange) Boolean passed to 'in' operator. 2 | testData/static_analyzer/w254_notin.nut:6:4 3 | 4 | if (!"weapModSlotName" not in ::item) 5 | ^------------------------------- 6 | return null 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w271.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w271 (forgot-subst) '{}' found inside string (forgot 'subst' or '$' ?). 2 | testData/static_analyzer/w271.nut:9:15 3 | 4 | else 5 | return "$ xxxx={x}" // EXPECTED 6 | ^----------- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Folders created at compilation 2 | bin/ 3 | lib/ 4 | 5 | # CMake output 6 | build*/ 7 | 8 | # Folders created at documentation generation 9 | doc/build/ 10 | 11 | Release/ 12 | .vs/ 13 | *.vcxproj 14 | *.vcxproj.filters 15 | *.vcxproj.user 16 | 17 | .vscode/ 18 | -------------------------------------------------------------------------------- /testData/exec/stdlib/debug.out: -------------------------------------------------------------------------------- 1 | Version: 4.10.0 2 | seterrorhandler: function 3 | setdebughook: function 4 | getstackinfos: function 5 | error: function 6 | errorln: function 7 | collectgarbage: OK 8 | resurrectunreachable: OK 9 | getobjflags: function 10 | getbuildinfo: function 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_fn_with_same_param.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w227 (ident-hides-ident) parameter 'txt' hides function with the same name. 2 | testData/static_analyzer/w227_fn_with_same_param.nut:3:13 3 | 4 | function txt(txt) {} //-declared-never-used 5 | ^-- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228_2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) variable 'f' was declared but never used. 2 | testData/static_analyzer/w228_2.nut:4:2 3 | 4 | function fn() { //-declared-never-used 5 | local f = 123 6 | ^---- 7 | local c = { f = 3 } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228_3.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) variable 'f' was declared but never used. 2 | testData/static_analyzer/w228_3.nut:4:2 3 | 4 | function fn() { //-declared-never-used 5 | local f = 123 6 | ^---- 7 | local c = { f = 3 } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_special_name_func.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/w248_special_name_func.nut:7:0 3 | 4 | x.indexof(".").foo() 5 | ^------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w288_native.nut: -------------------------------------------------------------------------------- 1 | // TODO: support imports in sq interpreter 2 | 3 | /* 4 | from "math" import floor, clamp 5 | 6 | if (__name__ == "__analysis__") 7 | return 8 | 9 | let _x = floor() 10 | let _y = floor(111.111, 222.222) 11 | let _z = clamp(1, 2) 12 | */ -------------------------------------------------------------------------------- /testData/static_analyzer/w309_require.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w309 (missing-destructured-value) No value for 'bar' in destructured declaration. 2 | testData/static_analyzer/w309_require.nut:4:10 3 | 4 | let { foo bar } = require("testData/static_analyzer/foo.nut") 5 | ^---- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/stack_metamethod_few_args.nut: -------------------------------------------------------------------------------- 1 | local A = class { 2 | function _call(...) {} 3 | } 4 | 5 | local a = A() 6 | 7 | function fn1(n, ...) { 8 | if (n > 0) { 9 | a(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) 10 | fn1(n - 1) 11 | } 12 | } 13 | 14 | fn1(10000) 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_arith.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w200 (potentially-nulled-ops) Arithmetic operation with potentially nullable expression. 2 | testData/static_analyzer/w200_arith.nut:3:10 3 | 4 | local x = {y = 2} 5 | local a = x?.y - 8 6 | ^--- 7 | print(a) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_arith_deep.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w200 (potentially-nulled-ops) Arithmetic operation with potentially nullable expression. 2 | testData/static_analyzer/w200_arith_deep.nut:4:10 3 | 4 | local z = x?.y 5 | local a = z - 8 6 | ^ 7 | print(a) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w210_nullc.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'requestCratesContent' was declared but never used. 2 | testData/static_analyzer/w210_nullc.nut:6:0 3 | 4 | function requestCratesContent(armyId, crates) { 5 | ^ 6 | if ((armyId ?? "") == "") 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_external.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w227 (ident-hides-ident) parameter 'println' hides external binding with the same name. 2 | testData/static_analyzer/w227_external.nut:1:14 3 | 4 | function _foo(println) { 5 | ^------ 6 | return println + 1 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_false.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w232 (always-true-or-false) Expression is always 'false'. 2 | testData/static_analyzer/w232_false.nut:7:6 3 | 4 | } 5 | print(a == ::XEnum.PARAM_A && a == ::XEnum.PARAM_B) 6 | ^------------------------------------------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_true.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w232 (always-true-or-false) Expression is always 'true'. 2 | testData/static_analyzer/w232_true.nut:7:6 3 | 4 | local i = 2 5 | print(s.charAt(i) != ' ' || s.charAt(i) != '\t') 6 | ^---------------------------------------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w301_closure.nut: -------------------------------------------------------------------------------- 1 | local c = null 2 | local cr = null 3 | function foo() {} 4 | let d = {} 5 | local dp = foo() 6 | let tree = foo() 7 | do { 8 | c = d[dp].o 9 | cr = tree.ci.f(@(v) v?.oc == c) 10 | if (cr){ 11 | dp++ 12 | } 13 | } while (cr && dp < 1000) -------------------------------------------------------------------------------- /testData/static_analyzer/w192.nut: -------------------------------------------------------------------------------- 1 | //expect:w192 2 | local test = true 3 | local a = 1, b = 2 4 | if (test == 3) 5 | a = 6; a = 10 6 | 7 | 8 | if (test == 5) 9 | a = 7 10 | else 11 | a = 6; a = 10 12 | 13 | 14 | while (a > b) 15 | a = 0; b = 20; 16 | 17 | 18 | 19 | print(a + b); -------------------------------------------------------------------------------- /testData/static_analyzer/w200_special_func_name.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w200 (potentially-nulled-ops) Arithmetic operation with potentially nullable expression. 2 | testData/static_analyzer/w200_special_func_name.nut:6:7 3 | 4 | return ::a.b.c.indexof("x") + 6; 5 | ^------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w214.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w214 (operator-returns-same-val) Both branches of operator '<> ? <> : <>' are equivalent. 2 | testData/static_analyzer/w214.nut:12:7 3 | 4 | ::x <- test ? REPLAY.SKIRMISH : REPLAY.SKIRMISH 5 | ^--------------------------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_inc_in_for.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | function foo(_a) {} 5 | 6 | local k 7 | local y = 0 8 | for (k = 0; k < 7; k++) { 9 | if (y & 1) { 10 | if (k) 11 | foo(6 - k); 12 | else 13 | foo(y + k); 14 | } 15 | 16 | y = y >> 1 17 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w238_idname.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'foo' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w238_idname.nut:3 6 | 7 | LOCALS 8 | [state] TABLE={} 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_assert.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [assertion failed] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w248_assert.nut:11 6 | 7 | LOCALS 8 | [c] NULL 9 | [o] NULL 10 | [foo] CLOSURE=FN:foo 11 | [vargv] ARRAY=[] 12 | [this] NULL 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_chain.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'w' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w248_chain.nut:7 6 | 7 | LOCALS 8 | [a] 10 9 | [x] TABLE={} 10 | [vargv] ARRAY=[] 11 | [this] NULL 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w277.nut.txt: -------------------------------------------------------------------------------- 1 | if (type(0) != "") 2 | return 3 | 4 | 5 | //expect:w277 6 | 7 | //expect:w277 8 | 9 | 10 | 11 | function _foo() { 12 | return 10 13 | } 14 | 15 | //expect:w277 16 | let _z = @"abc 17 | " 18 | 19 | 20 | 21 | /* aas 22 | */ 23 | 24 | -------------------------------------------------------------------------------- /testData/static_analyzer/w305.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | const B = true 5 | local x = 1 6 | local y = 1 7 | 8 | let b1 = true 9 | let b2 = false 10 | 11 | print(b1 > b2) 12 | 13 | if (B == x > y) 14 | print("a") 15 | 16 | if ((B == x) > y) 17 | print("a") -------------------------------------------------------------------------------- /testData/diagnostics/float_underflow.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: float constant underflow 2 | testData/diagnostics/float_underflow.nut:1:8 3 | 4 | println(0.00000000000000000000000000000000000000000000000000000000000000001) 5 | ^------------------------------------------------------------------ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_exception.nut: -------------------------------------------------------------------------------- 1 | local div = 0 2 | 3 | function fn() { 4 | try { 5 | let tab = static { x = 123 / div } 6 | println(tab.x) 7 | } catch (e) { 8 | println("exception") 9 | } 10 | } 11 | 12 | fn() 13 | fn() 14 | 15 | div = 2 16 | fn() 17 | fn() 18 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_ternary.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w232 (always-true-or-false) Expression is always 'true'. 2 | testData/static_analyzer/w232_ternary.nut:2:12 3 | 4 | //expect:w232 5 | local foo = function() { } ? false : true 6 | ^--------------- 7 | return foo 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w275.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w275 (missed-break) A 'break' statement is probably missing in a 'switch' statement. 2 | testData/static_analyzer/w275.nut:20:6 3 | 4 | case 4: 5 | print("ccc") 6 | ^----------- 7 | default: // <<<<<<< here 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_04.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [parameter 1 has an invalid type 'string' ; expected: 'integer'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/diagnostics/type_hints_04.nut:5 6 | 7 | LOCALS 8 | [fn] CLOSURE=FN:fn 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_05.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [parameter 5 has an invalid type 'function' ; expected: 'table'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/diagnostics/type_hints_05.nut:5 6 | 7 | LOCALS 8 | [fn] CLOSURE=FN:fn 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_06.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [parameter 2 has an invalid type 'null' ; expected: 'array'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/diagnostics/type_hints_06.nut:5 6 | 7 | LOCALS 8 | [fn] CLOSURE=FN:fn 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/loop_state.nut: -------------------------------------------------------------------------------- 1 | function foo() {} 2 | 3 | local found = false 4 | 5 | let diap = foo() 6 | 7 | 8 | foreach (_seg in diap) { 9 | // if (seg[1] - seg[0] < size) 10 | // continue 11 | 12 | if (found) 13 | continue 14 | 15 | found = true 16 | } 17 | 18 | return 0 -------------------------------------------------------------------------------- /testData/static_analyzer/w227_let_init_fun.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [attempt to call 'null'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w227_let_init_fun.nut:5 6 | 7 | LOCALS 8 | [setGroup] NULL 9 | [foo] CLOSURE=FN:foo 10 | [vargv] ARRAY=[] 11 | [this] NULL 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_cascade.nut: -------------------------------------------------------------------------------- 1 | 2 | function x(_i) {} 3 | function y(_i) {} 4 | function z(_i) {} 5 | 6 | function foo(size, a, b) { 7 | if (a && b) 8 | return x(size) 9 | if (a) 10 | return y(size) 11 | if (b) 12 | return z(size) 13 | return null 14 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w241.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w241 (already-required) Module 'string' has been required already. 2 | testData/static_analyzer/w241.nut:7:13 3 | 4 | local str1 = require("string") 5 | local str2 = require("string") 6 | ^---------------- 7 | print(str1, str2) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_nullc_2.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'value' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w248_nullc_2.nut:5 6 | 7 | LOCALS 8 | [i] 10 9 | [t] TABLE={} 10 | [vargv] ARRAY=[] 11 | [this] NULL 12 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/simple2.nut: -------------------------------------------------------------------------------- 1 | local z = 0 2 | function foo(x, y) { 3 | let f1 = function(a) { 4 | let f2 = function(x) { 5 | let f3 = function(c) { 6 | return a + c 7 | } 8 | return x + y 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_01.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [parameter 1 has an invalid type 'float' ; expected: 'null|integer'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/diagnostics/type_hints_01.nut:5 6 | 7 | LOCALS 8 | [fn] CLOSURE=FN:fn 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_02.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [parameter 2 has an invalid type 'float' ; expected: 'null|integer'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/diagnostics/type_hints_02.nut:5 6 | 7 | LOCALS 8 | [fn] CLOSURE=FN:fn 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/diagnostics/type_hints_03.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [parameter 2 has an invalid type 'float' ; expected: 'null|integer'] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/diagnostics/type_hints_03.nut:5 6 | 7 | LOCALS 8 | [fn] CLOSURE=FN:fn 9 | [vargv] ARRAY=[] 10 | [this] NULL 11 | -------------------------------------------------------------------------------- /testData/static_analyzer/w220.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w220 (potentially-nulled-container) 'foreach' on potentially nullable expression. 2 | testData/static_analyzer/w220.nut:4:15 3 | 4 | function foo(a){ //-declared-never-used 5 | foreach(x in a?.y()) { 6 | ^----- 7 | print(x) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w227_lambdas.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'y' was declared but never used. 2 | testData/static_analyzer/w227_lambdas.nut:3:0 3 | 4 | local x = 10 5 | let y = x > 320 ? @() 20 : function() { return 30 } 6 | ^-------------------------------------------------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_complexcond.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'expression' can be null, but is used as a container without checking. 2 | testData/static_analyzer/w248_complexcond.nut:10:8 3 | 4 | if (x == null && foo(2)) 5 | foo(x.y) 6 | ^ 7 | else 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w274_2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w274 (iterator-in-lambda) Iterator 'x' is trying to be captured in closure. 2 | testData/static_analyzer/w274_2.nut:5:23 3 | 4 | foreach (_, x in a) { 5 | m.append(@() print(x)) 6 | ^ 7 | m.each(@(_p) print(x)) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/classSimple.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo(x, y) { 3 | let c = class { 4 | x = 10 5 | function zed() { 6 | return function () { 7 | return x + 10; 8 | }() + this.x 9 | } 10 | } 11 | return c().zed() 12 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w214.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w214 5 | local test = ::f 6 | 7 | enum REPLAY { 8 | SKIRMISH = 2 9 | BATTLE = 3 //-declared-never-used 10 | } 11 | 12 | ::x <- test ? REPLAY.SKIRMISH : REPLAY.SKIRMISH 13 | 14 | //-file:undefined-global 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w220_deep.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w220 (potentially-nulled-container) 'foreach' on potentially nullable expression. 2 | testData/static_analyzer/w220_deep.nut:5:15 3 | 4 | local container = a?.y() 5 | foreach(x in container) { 6 | ^-------- 7 | print(x) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_destruct.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'y' was declared but never used. 2 | testData/static_analyzer/w233_destruct.nut:3:0 3 | 4 | local x = 10 5 | let y = x > 320 ? @() 20 : function() { return 30 } 6 | ^-------------------------------------------------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w239.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w239 (named-like-return-bool) Function name 'isLoggedIn' implies a return boolean type but not all control paths returns boolean. 2 | testData/static_analyzer/w239.nut:3:0 3 | 4 | function isLoggedIn() { //-declared-never-used 5 | ^ 6 | if (::userName == "") 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_complex2.nut: -------------------------------------------------------------------------------- 1 | function foo() {} 2 | 3 | let a = foo() 4 | let h = foo() 5 | 6 | let v = a?.v 7 | let c = h && (typeof v == "integer" || typeof v == "float") 8 | if (!c) 9 | return { ct = @() null 10 | } 11 | 12 | // value != null 13 | 14 | 15 | let _target = v.tointeger() -------------------------------------------------------------------------------- /testData/static_analyzer/w248_eq_get.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'value' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w248_eq_get.nut:5 6 | 7 | LOCALS 8 | [o] TABLE={} 9 | [foo] CLOSURE=FN:foo 10 | [vargv] ARRAY=[] 11 | [this] NULL 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_evaled.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'value' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w248_evaled.nut:6 6 | 7 | LOCALS 8 | [foo] CLOSURE=FN:foo 9 | [t] TABLE={} 10 | [vargv] ARRAY=[] 11 | [this] NULL 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_nullc_3.nut: -------------------------------------------------------------------------------- 1 | 2 | let us = {} 3 | 4 | foreach (u in us) { 5 | if (!u.t.isAvailable()) 6 | continue 7 | let es = u.t.et 8 | let d = ::g?[::f(u)] 9 | if (d?[es] ?? true) 10 | continue 11 | d[es] <- ::q(u) 12 | } 13 | 14 | //-file:undefined-global 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w279_2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w279 (mismatch-loop-variable) The variable used in for-loop does not match the initialized one. 2 | testData/static_analyzer/w279_2.nut:4:25 3 | 4 | local j = 0; 5 | for (local k = 0; k < 5; j++) { 6 | ^-- 7 | k = 10 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w297.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | let x = {} 4 | 5 | keepref(x) // FP 6 | 7 | 8 | function _foo(p) { 9 | keepref(p) // EXPECTED 1 10 | } 11 | 12 | 13 | let _z = @(y) keepref(y) // EXPECTED 2 14 | 15 | class _C { 16 | constructor(t){ 17 | keepref(t) // EXPECTED 3 18 | } 19 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w254_instanceof.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w254 (bool-passed-to-strange) Boolean passed to 'instanceof' operator. 2 | testData/static_analyzer/w254_instanceof.nut:6:4 3 | 4 | local x = 10 5 | if (x instanceof !"weapModSlotName") 6 | ^------------------------------- 7 | return null 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w255.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w255 (duplicate-function) Duplicate function body. Consider functions 'onTimer2' and 'onTimer'. 2 | testData/static_analyzer/w255.nut:29:21 3 | 4 | function onTimer(obj, dt) { 5 | ^ 6 | local curOffs = obj.cur_slide_offs.tofloat() 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w255_2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w255 (duplicate-function) Duplicate function body. Consider functions 'onTimer2' and 'onTimer'. 2 | testData/static_analyzer/w255_2.nut:31:21 3 | 4 | function onTimer(obj, dt) { 5 | ^ 6 | local curOffs = obj.cur_slide_offs.tofloat() 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w223_method_is.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'isVisible' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w223_method_is.nut:5 6 | 7 | LOCALS 8 | [r] "" 9 | [s] true 10 | [sec] 10000 11 | [vargv] ARRAY=[] 12 | [this] NULL 13 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_complex_key.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | 5 | function foo() {} 6 | 7 | function bar(_a, _b) {} 8 | function qux(_a, _b) {} 9 | 10 | let { a = null, h = null } = foo() 11 | 12 | if (a?.x[h]) { 13 | bar(a.x[h], h.x) 14 | } 15 | 16 | 17 | qux(a.z, h.z) 18 | -------------------------------------------------------------------------------- /testData/static_analyzer/w272.nut: -------------------------------------------------------------------------------- 1 | function foo(...) {} 2 | 3 | let _a = [ 0 4 | 2 5 | -3 // EXPECTED 1 6 | 4 7 | - 5 // FP 1 8 | ] 9 | 10 | foo( 11 | 0 12 | +1 // EXPECTED 2 13 | 2 14 | + 3 // FP 2 15 | 4 16 | * 5 // FP 3 17 | 14 18 | /7 // FP 4 19 | 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /testData/static_analyzer/w291.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w291 (invalid-underscore) The name of parameter '_y' is invalid. The identifier is marked as an unused with a prefix underscore, but it is used. 2 | testData/static_analyzer/w291.nut:6:4 3 | 4 | x, 5 | _y, // EXPECTED 6 | ^- 7 | _z // FP 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w215_nullc.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w215 (ternary-priority) The '?:' operator has lower priority than the '??' operator. Perhaps the '?:' operator works in a different way than it was expected. 2 | testData/static_analyzer/w215_nullc.nut:8:9 3 | 4 | let _u = o?.u ?? s ? s / r : 0.0 5 | ^-------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228_trivial.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'refreshOnWindowActivate' was declared but never used. 2 | testData/static_analyzer/w228_trivial.nut:5:0 3 | 4 | function refreshOnWindowActivate(repeatAmount = 1, refreshPeriodSec = 10.0) { 5 | ^------- 6 | readyRefreshTime = 0 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_lambda.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | 4 | let w = foo() 5 | 6 | local vv = true 7 | let wdata = foo() 8 | local _u 9 | 10 | if (type(w) == "table") { 11 | _u = w?.update ?? @(v) wdata(v) 12 | vv = w?.vv ?? vv 13 | } else { 14 | _u = w 15 | } 16 | 17 | 18 | if (vv) { 19 | foo() 20 | } -------------------------------------------------------------------------------- /scripts/samples/fibonacci.nut: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/) 4 | * 5 | */ 6 | 7 | function fib(n) { 8 | if (n < 2) return 1 9 | return fib(n-2) + fib(n-1) 10 | } 11 | 12 | local n = vargv.len()!=0 ? vargv[0].tointeger() : 1 13 | 14 | println(fib(n)) 15 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/implicitChainedFuncs.nut: -------------------------------------------------------------------------------- 1 | local z = 0 2 | function foo(x, y) { 3 | return function bar(a, b) { //<< this function does not use anything from outer scope 4 | return function qux(c, d) { //<< but this function does and coupled with `bar` function 5 | z = x + a - c; 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /testData/exec/spec/generators.nut: -------------------------------------------------------------------------------- 1 | function geny(n) { 2 | for (local i=0; i wpUnitRank) 6 | ^----------- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w203.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w203 5 | local condition1 = ::x 6 | local condition2 = ::y 7 | local condition3 = ::z 8 | local condition4 = ::w 9 | 10 | if (condition1 || condition2 || condition3 | condition4) 11 | print("ok") 12 | 13 | //-file:undefined-global -------------------------------------------------------------------------------- /testData/static_analyzer/w232_nerge.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | let codeSet = {} 4 | 5 | let curcode = 10 6 | local haveFound=false 7 | 8 | 9 | foreach (codes in codeSet){ 10 | foreach (code in codes){ 11 | if (curcode==code) { 12 | haveFound = true 13 | break 14 | } 15 | } 16 | if (haveFound) 17 | break 18 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w248_tyopeof1.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function fo(debrData) { 4 | if (typeof debrData?.players != "table") 5 | return 6 | 7 | let players = {} 8 | foreach (id, player in debrData.players) 9 | players[id.tointeger()] <- player 10 | debrData.players = players 11 | } 12 | 13 | 14 | fo({}) -------------------------------------------------------------------------------- /testData/static_analyzer/logic_ops_paren.nut: -------------------------------------------------------------------------------- 1 | //-file:declared-never-used 2 | //-file:const-in-bool-expr 3 | local x = 1, y = 2, z = 3; 4 | 5 | let a = x && y || z 6 | let b = x || y && z 7 | let c = (x && y) || z 8 | let d = x || (y && z) 9 | 10 | let e = x || y | z 11 | let f = x || y & z 12 | let g = x && y | z 13 | let h = x && y & z -------------------------------------------------------------------------------- /testData/static_analyzer/w248_while_cond.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo() {} 3 | 4 | let x = foo() 5 | local c = foo() 6 | let a = foo() 7 | let t = "skdhaljs" 8 | local d = 20 9 | 10 | while (c && (c?.o ?? "") != ""){ 11 | c = a?[x.value?[t][c.o]] 12 | if ((c?.d ?? 0) > d){ 13 | d = c.d 14 | } else { 15 | d = d.xyz 16 | } 17 | } -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_nested.nut: -------------------------------------------------------------------------------- 1 | for (local x = 111; x < 114; x++) 2 | println(static static static static static x) 3 | 4 | println("") 5 | local y = 222 6 | for (local x = y; x < 224; x++) { 7 | println(static static ~(static static static ~x + static(x * 2) + static x)) 8 | println(~(~y + (y * 2) + y)) 9 | } 10 | 11 | -------------------------------------------------------------------------------- /testData/exec/stdlib/math_min_max_clamp.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | let math = require("math") 4 | 5 | 6 | println($"min(-1, 1, 2, 3, 4, 5, -1000, 6, 7): {math.min(-1, 1, 2, 3, 4, 5, -1000, 6, 7)}") 7 | println($"max(-1, 1, 2, 3, 4, 5, -1000, 8, 9): {math.max(-1, 1, 2, 3, 4, 5, -1000, 8, 9)}") 8 | println($"clamp(10, -100, 300): {math.clamp(10, -100, 300)}") 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w214_static_memo_expr.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w214 5 | local test = ::f 6 | 7 | enum REPLAY { 8 | SKIRMISH = 2 9 | BATTLE = 3 //-declared-never-used 10 | } 11 | 12 | ::x <- static(test ? REPLAY.SKIRMISH : REPLAY.SKIRMISH) //-w316 13 | 14 | //-file:undefined-global 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w229.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w229 (copy-of-expression) Duplicate expression found inside the sequence of operations. 2 | testData/static_analyzer/w229.nut:4:16 3 | 4 | local a ={x=0, y=0, z=1} 5 | if (a.x == 0 && a.y == 0 && a.x == 0) 6 | ^------------------- 7 | print("vector == zero") 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w232_ter.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function d() { 4 | 5 | } 6 | 7 | function _foo(p, bb, qq) { 8 | let uu = qq.value?[bb] 9 | return { 10 | kk = [ 11 | uu == null ? null : {} 12 | { 13 | text = uu 14 | ? p 15 | : d() 16 | } 17 | ] 18 | } 19 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w248_oror2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'nullNotH' can be null, but is used as a function without checking. 2 | testData/static_analyzer/w248_oror2.nut:7:4 3 | 4 | onDoubleClickCb(itemDesc.__merge({ rectOrPos = event.targetRect })) 5 | nullNotH() 6 | ^------- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /include/sqstdmath.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_MATH_H_ 3 | #define _SQSTD_MATH_H_ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | SQUIRREL_API SQRESULT sqstd_register_mathlib(HSQUIRRELVM v); 10 | 11 | #ifdef __cplusplus 12 | } /*extern "C"*/ 13 | #endif 14 | 15 | #endif /*_SQSTD_MATH_H_*/ 16 | -------------------------------------------------------------------------------- /testData/exec/spec/const_with_expr.nut: -------------------------------------------------------------------------------- 1 | // Unary 2 | 3 | const o = 4 4 | const a = -o 5 | const b = !false 6 | const c = ~a 7 | const d = typeof(c) 8 | 9 | println(a, b, c, d) 10 | 11 | // Binary and ternary 12 | 13 | const tbl = {["integer"] = 5} 14 | const x = tbl[typeof o] + (o | 0xFF) + (o % 3) - (b ? 6 : o) 15 | 16 | println(x) 17 | 18 | -------------------------------------------------------------------------------- /testData/exec/spec/destruct.nut: -------------------------------------------------------------------------------- 1 | let arr = [123, 567] 2 | let [a, b = 22, c = 11] = arr 3 | println(a) // => 123 4 | println(b) // => 567 5 | println(c) // => 567 6 | 7 | function foo() { 8 | return {x = 555, y=777, z=999, w=111} 9 | } 10 | let {x, y=1, q=3} = foo() 11 | println(x) // => 555 12 | println(y) // => 777 13 | println(q) // => 3 14 | -------------------------------------------------------------------------------- /testData/exec/stdlib/string.out: -------------------------------------------------------------------------------- 1 | strip; 2 | lstrip ; 3 | rstrip; 4 | false 5 | true 6 | false 7 | true 8 | 9 | false 10 | true 11 | false 12 | true 13 | 14 | true 15 | true 16 | strip; 17 | lstrip ; 18 | rstrip; 19 | 20 | ~\x0a\"\'\\~ 21 | ~\x0a\"\'\\~ 22 | str:st; int:255; hex:ff 23 | str:st; int:255; hex:ff 24 | aaa;bb;c; 25 | aaa;bb;c; -------------------------------------------------------------------------------- /testData/exec/basics.nut: -------------------------------------------------------------------------------- 1 | //tests for local bindings, local variables and const 2 | const A = 2 3 | let a = 1 4 | local b = 3 5 | b = 10 6 | let b_0 = b 7 | b += a 8 | b -= 1 9 | b++ 10 | b-- 11 | b = b + A 12 | b = b - A 13 | 14 | b *= 2 15 | b /= 2 16 | b = b * 2 17 | b = b / 2 18 | b = (b + 1) * 2 19 | b = b / 2 -1 20 | 21 | assert(b == b_0) 22 | -------------------------------------------------------------------------------- /testData/static_analyzer/w214_static_memo_expr.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w214 (operator-returns-same-val) Both branches of operator '<> ? <> : <>' are equivalent. 2 | testData/static_analyzer/w214_static_memo_expr.nut:12:14 3 | 4 | ::x <- static(test ? REPLAY.SKIRMISH : REPLAY.SKIRMISH) //-w316 5 | ^--------------------------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_const_key.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 's' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w233_const_key.nut:4 6 | 7 | LOCALS 8 | [o] NULL 9 | [s] NULL 10 | [foo] CLOSURE=FN:foo 11 | [bar] CLOSURE=FN:bar 12 | [vargv] ARRAY=[] 13 | [this] NULL 14 | -------------------------------------------------------------------------------- /testData/static_analyzer/w257.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w257 (duplicate-assigned-expr) Duplicate of the assigned expression. 2 | testData/static_analyzer/w257.nut:17:26 3 | 4 | ] 5 | local numTextAnimations = [ 6 | ^ 7 | { prop=AnimProp.opacity, from=0.0, to=0.0, delay=0.0, duration=0.1, play=true easing=OutCubic } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w302_try_catch.nut: -------------------------------------------------------------------------------- 1 | local blk = null 2 | 3 | function foo() {} 4 | 5 | function bar(_x) {} 6 | 7 | if (foo()){ 8 | blk = foo() 9 | try 10 | blk.load("1111") 11 | catch(e) 12 | blk = null 13 | } 14 | else{ 15 | try 16 | blk = foo() 17 | catch(e) 18 | blk = null 19 | } 20 | 21 | bar(blk) 22 | 23 | -------------------------------------------------------------------------------- /testData/static_analyzer/w308.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w308 (bool-lambda-required) Function 'findindex' requires lambda which returns boolean. 2 | testData/static_analyzer/w308.nut:5:28 3 | 4 | let _expected = o.findindex(@(t) t.id = 10) // EXPECTED 5 | ^-------------- 6 | let _falsep = o.findvalue(@(t) t.id == 10) // FP 1 7 | 8 | 9 | -------------------------------------------------------------------------------- /include/sqstddebug.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_DEBUG_H_ 3 | #define _SQSTD_DEBUG_H_ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | SQUIRREL_API SQRESULT sqstd_register_debuglib(HSQUIRRELVM v); 10 | 11 | 12 | #ifdef __cplusplus 13 | } /*extern "C"*/ 14 | #endif 15 | 16 | #endif // _SQSTD_DEBUG_H_ 17 | -------------------------------------------------------------------------------- /testData/diagnostics/import_06.nut: -------------------------------------------------------------------------------- 1 | #strict 2 | 3 | // import b 4 | import "math" // as math2 5 | import "dagor2.math" as m 6 | from "generic/std.nut" import TMatrix as Matrix, /* Xyz as Qwe */ 7 | Point2 as point 8 | /* comment 9 | comment 10 | // */ 11 | from "module2" import * 12 | 13 | 14 | local a = require_optional("x.nut") 15 | return a?.x 16 | -------------------------------------------------------------------------------- /testData/exec/string_methods.out: -------------------------------------------------------------------------------- 1 | 13 2 | 123 3 | 12.34 4 | Hello, World! 5 | 4027599776755331851 6 | Hello 7 | 7 8 | null 9 | true 10 | false 11 | hello, world! 12 | HELLO, WORLD! 13 | Hi, World! 14 | Hello, Quirrel! 15 | a-b 16 | Hello, World! Test 17 | Hello 18 | test 19 | test 20 | test 21 | c 22 | true 23 | true 24 | true 25 | false 26 | false 27 | ok -------------------------------------------------------------------------------- /testData/static_analyzer/forloop_merge.nut: -------------------------------------------------------------------------------- 1 | 2 | function findlast(str, substr, startidx=0){ 3 | local ret = null 4 | for(local i=startidx; i 4 | 5 | SQRESULT sqstd_serialize_object_to_stream(HSQUIRRELVM vm, SQStream *dest, SQObjectPtr obj, SQObjectPtr available_classes); 6 | SQRESULT sqstd_deserialize_object_from_stream(HSQUIRRELVM vm, SQStream *src, SQObjectPtr available_classes); 7 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_inc.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index '0' (type='integer') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w233_inc.nut:17 6 | 7 | LOCALS 8 | [ismasked] CLOSURE=FN:ismasked 9 | [qrframe] TABLE={} 10 | [width] 100 11 | [r3x] 0 12 | [x] 0 13 | [y] 0 14 | [vargv] ARRAY=[] 15 | [this] NULL 16 | -------------------------------------------------------------------------------- /include/sqstddatetime.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_DATETIMELIB_H_ 3 | #define _SQSTD_DATETIMELIB_H_ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | SQUIRREL_API SQRESULT sqstd_register_datetimelib(HSQUIRRELVM v); 10 | 11 | #ifdef __cplusplus 12 | } /*extern "C"*/ 13 | #endif 14 | 15 | #endif /* _SQSTD_DATETIMELIB_H_ */ 16 | -------------------------------------------------------------------------------- /testData/static_analyzer/w269.nut: -------------------------------------------------------------------------------- 1 | let _a = [ 2 | 10 3 | 20 4 | 30, 5 | 40, 6 | 50 7 | ] 8 | 9 | let _b = [ 10 | 10, 11 | 20, 12 | 30 13 | 40 14 | 50 15 | ] 16 | 17 | let _c = [ 18 | 10, 19 | 20, 20 | 30, 21 | 40, 22 | 50 23 | ] 24 | 25 | 26 | let _d = [ 27 | 10 28 | 20 29 | 30 30 | 40 31 | 50 32 | ] -------------------------------------------------------------------------------- /sq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(sq sq.cpp) 2 | 3 | target_link_libraries(sq squirrel sqstdlib sqmodules quirrel-compiler) 4 | target_include_directories(sq PRIVATE 5 | # include/ and sqmodules/ are transitive from linked libraries 6 | "$" 7 | "$" # Needed for sqtypeparser.h 8 | ) 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/intersected_assignment.nut: -------------------------------------------------------------------------------- 1 | local curAction = null 2 | 3 | 4 | function foo() {} 5 | 6 | let func = foo() 7 | let leading = foo() 8 | 9 | function _throttled(...){ 10 | let doWait = curAction != null 11 | curAction = @() func.acall([null].extend(vargv)) 12 | if (doWait) { 13 | return 14 | } 15 | if (leading) { 16 | curAction() 17 | } 18 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w211.nut: -------------------------------------------------------------------------------- 1 | #allow-switch-statement 2 | 3 | //expect:w211 4 | local MODE = { 5 | MODE_1 = 1 6 | MODE_2 = 2 7 | MODE_3 = 3 8 | } 9 | 10 | local x = 1 11 | switch(x) { 12 | case MODE.MODE_1: print("1"); break; 13 | case MODE.MODE_2: print("2"); break; 14 | case MODE.MODE_1: print("3"); break; 15 | default: 16 | print("0") 17 | break; 18 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w258.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w258 (similar-function) Function bodies are very similar. Consider functions 'updateEventLb' and 'updateEventLbSelfRow'. 2 | testData/static_analyzer/w258.nut:46:34 3 | 4 | function updateEventLbSelfRow(requestData, id) { 5 | ^ 6 | local requestAction = (@(requestData, id) function () { 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w258_2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w258 (similar-function) Function bodies are very similar. Consider functions 'updateEventLb' and 'updateEventLbSelfRow'. 2 | testData/static_analyzer/w258_2.nut:47:34 3 | 4 | function updateEventLbSelfRow(requestData, id) { 5 | ^ 6 | local requestAction = (@(requestData, id) function () { 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w200_static_memo_expr.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w200 (potentially-nulled-ops) Comparison operation with potentially nullable expression. 2 | testData/static_analyzer/w200_static_memo_expr.nut:4:10 3 | 4 | function fn(mod, wpUnitRank) { //-declared-never-used 5 | return (static(mod?.reqRank) > wpUnitRank) // -w316 6 | ^--------------------- 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w204.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w204 (bitwise-apply-to-bool) The '&' or '|' operator is applied to boolean type. You've probably forgotten to include parentheses or intended to use the '&&' or '||' operator. 2 | testData/static_analyzer/w204.nut:4:6 3 | 4 | function foo(x){ //-declared-never-used 5 | if (x & 15 == 8) 6 | ^---------- 7 | print("ok") 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w260_local_function.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w260 (named-like-must-return-result) Function 'getSettings' has name like it should return a value, but not all control paths returns a value. 2 | testData/static_analyzer/w260_local_function.nut:3:6 3 | 4 | local function getSettings(path) { return } //-declared-never-used 5 | ^------------------------------------ 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/exec/is_frozen.out: -------------------------------------------------------------------------------- 1 | Array R: false 2 | Array F: true 3 | Table R: false 4 | Table F: true 5 | Class R: false 6 | Class F: true 7 | Instance R: false 8 | Instance F: true 9 | Array foreach 0: true 10 | Array foreach 1: true 11 | Array each 0: true 12 | Array each 1: true 13 | Table foreach: true true 14 | Table foreach: true true 15 | Table each: true true 16 | Table each: true true 17 | -------------------------------------------------------------------------------- /testData/static_analyzer/w208_rec.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | 5 | function foo() { return { editorIsActive = 42 } } 6 | 7 | function bart(x) { return "" } 8 | 9 | local editorState = null 10 | local editorIsActive = "null"; 11 | 12 | editorState = foo() 13 | editorIsActive = editorState?.editorIsActive ?? editorIsActive 14 | 15 | bart(editorIsActive.xx) 16 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/classCrossFunc.nut: -------------------------------------------------------------------------------- 1 | local z = 0 2 | function foo(x, y) { 3 | return function() { 4 | let c = class { 5 | x = 10 6 | function zed() { 7 | return function () { 8 | return x + 10; 9 | }() + this.x 10 | } 11 | } 12 | return c().zed() 13 | } 14 | } -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/manyFuncs.nut: -------------------------------------------------------------------------------- 1 | 2 | local z = 0 3 | function foo(x, y) { 4 | let ar = [function fff(a, b) { 5 | let c = class { 6 | x = 10 7 | function zed() { 8 | return 10 + this.x; 9 | } 10 | } 11 | return c().zed() 12 | }, function () { return 10 }, @(r) r * 2] 13 | ar[0](3, 4); 14 | } -------------------------------------------------------------------------------- /testData/exec/spec/const.nut: -------------------------------------------------------------------------------- 1 | const a = 5 2 | const b = "foo" 3 | const c = null 4 | const d = [1, 2, 3, {x=555}] 5 | const e = b 6 | const f = d[1] 7 | const g = d[3].x 8 | 9 | println(d[3].x) 10 | println(e) 11 | println(f) 12 | println(g) 13 | 14 | // Inline constant 15 | let x = const [5,6,7,d,e] 16 | println(x[2]) 17 | 18 | let y = 2>3 ? const [1,2,3] : const [8,9,0] 19 | println(y[2]) 20 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_assign_itself.nut: -------------------------------------------------------------------------------- 1 | local x = 333 2 | x = static x 3 | println(x) 4 | 5 | local y = {a = 444} 6 | y = static y 7 | println(y.a) 8 | 9 | local z = [555, 666] 10 | z = static z 11 | println(z[1]) 12 | 13 | local w = [777, 888] 14 | w = static w 15 | w = static w 16 | println(w[1]) 17 | 18 | local a = 111 19 | a = static a 20 | a = static a 21 | println(a) 22 | 23 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_oror.nut: -------------------------------------------------------------------------------- 1 | //-file:declared-never-used 2 | 3 | function foo() {} 4 | let gg = foo() 5 | 6 | 7 | function bar() { 8 | 9 | let { cfg = null, hasOwned = false } = gg.value 10 | 11 | if (cfg == null || hasOwned) 12 | return 13 | 14 | // !(cfg == null || hasOwned) -> cfg != null && hasOwned = true 15 | 16 | let { c, g } = cfg 17 | return 18 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w275_complex.diag.txt: -------------------------------------------------------------------------------- 1 | 2 | AN ERROR HAS OCCURRED [the index 'a' (type='string') does not exist] 3 | 4 | CALLSTACK 5 | *FUNCTION [__main__()] testData/static_analyzer/w275_complex.nut:12 6 | 7 | LOCALS 8 | [someBound] false 9 | [sb] NULL 10 | [ab] NULL 11 | [bgs] NULL 12 | [d] NULL 13 | [bar] CLOSURE=FN:bar 14 | [foo] CLOSURE=FN:foo 15 | [vargv] ARRAY=[] 16 | [this] NULL 17 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_oror2.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function onDoubleClick(itemDesc, event, isLocked, isInteractive, onDoubleClickCb = null, nullNotH = null) { 4 | if (isLocked || !isInteractive || onDoubleClickCb == null || nullNotH != null) 5 | return 6 | onDoubleClickCb(itemDesc.__merge({ rectOrPos = event.targetRect })) 7 | nullNotH() 8 | } 9 | 10 | 11 | onDoubleClick(1, 2, 3, 4, 5) -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/implicitChainedFuncs2.nut: -------------------------------------------------------------------------------- 1 | 2 | local z = 0 3 | function foo(x, y) { 4 | return function(a, b) { 5 | let fff = function() { 6 | return z 7 | } 8 | return function(c, d) { 9 | z = x + a - c; 10 | return function(f, g) { 11 | return f - g - x 12 | } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w236.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w236 (shift-priority) Shift operator has lower priority. Perhaps parentheses are missing? 2 | testData/static_analyzer/w236.nut:4:30 3 | 4 | function foo(berserkFx, state){ //-declared-never-used 5 | if (!berserkFx && (state & (1 << ::SCRIPT_STATE_USER_SHIFT + 4))) 6 | ^--------------------------------- 7 | print(1) 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/exec/optimizer.nut: -------------------------------------------------------------------------------- 1 | println("OPTIMIZER OFF") 2 | 3 | function test_opt_off() { 4 | #disable-optimizer 5 | for (local i = 0; i < (true ? 5 : 1); i++) 6 | println("X") 7 | } 8 | 9 | test_opt_off() 10 | 11 | 12 | println("OPTIMIZER ON") 13 | 14 | function test_opt_on() { 15 | #enable-optimizer 16 | for (local i = 0; i < (true ? 5 : 1); i++) 17 | println("X") 18 | } 19 | 20 | test_opt_on() 21 | -------------------------------------------------------------------------------- /testData/static_analyzer/w295.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w307 (global-id-redef) Redefinition of existed global name 'g'. 2 | testData/static_analyzer/w295.nut:8:0 3 | 4 | 5 | WARNING: w307 (global-id-redef) Redefinition of existed global name 'g'. 6 | testData/static_analyzer/w295.nut:10:0 7 | 8 | 9 | WARNING: w295 (undefined-global) Undefined global identifier 'h'. 10 | testData/static_analyzer/w295.nut:12:6 11 | 12 | 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | 6 | # Travis VMs are 64-bit but we compile both for 32 and 64 bit. To enable the 7 | # 32-bit builds to work, we need gcc-multilib. 8 | addons: 9 | apt: 10 | packages: 11 | - gcc-multilib 12 | - g++-multilib 13 | 14 | # Enable container-based builds. 15 | sudo: false 16 | 17 | script: mkdir build && cd build && cmake .. && make -j2 18 | -------------------------------------------------------------------------------- /testData/exec/stdlib/regexp.nut: -------------------------------------------------------------------------------- 1 | let { regexp } = require("string") 2 | 3 | let r = regexp(@"[a-z,A-Z]*") 4 | println(r.match("AxBy")) 5 | println(r.match("AB-")) 6 | 7 | let t = r.search("-AAAA----A", 1) 8 | foreach (k, v in t) 9 | println($"{k}={v}") 10 | 11 | let f = r.capture("-AAAA----A", 1) 12 | foreach (k, v in f[0]) 13 | println($"{k}={v}") 14 | 15 | println(typeof r) 16 | 17 | println(r.subexpcount()) 18 | -------------------------------------------------------------------------------- /testData/static_analyzer/w270.diag.txt: -------------------------------------------------------------------------------- 1 | HINT: h270 (extent-to-append) It is better to use 'append(A, B, ...)' instead of 'extend([A, B, ...])'. 2 | testData/static_analyzer/w270.nut:6:0 3 | 4 | ::handlersManager[::PERSISTENT_DATA_PARAMS].extend([ "curControlsAllowMask", "isCurSceneBgBlurred" ]) // -undefined-global 5 | ^---------------------------------------------------------------------------------------------------- 6 | 7 | 8 | -------------------------------------------------------------------------------- /testData/static_analyzer/w293.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | let _x = persist("x", @() {}) // FP 4 | let _y = persist("y", @() {}) // FP 5 | let _z = persist("x", @() {}) // EXPECTED 6 | 7 | function mkWatched(_f, _k) { } 8 | 9 | function foo(p) { return p } 10 | 11 | let _a = mkWatched(persist, "a") // FP 12 | let _b = mkWatched(persist, "b") // FP 13 | let _c = mkWatched(foo, "b") // FP 14 | let _d = mkWatched(persist, "a") // EXPECTED -------------------------------------------------------------------------------- /testData/exec/spec/class.nut: -------------------------------------------------------------------------------- 1 | class Foo { 2 | //constructor 3 | 4 | testy = null 5 | constructor(a) { 6 | this.testy = ["stuff",1,2,3,a] 7 | } 8 | //member function 9 | function PrintTesty() { 10 | foreach(i,val in this.testy) { 11 | println("idx = "+i+" = "+val) 12 | } 13 | } 14 | //property 15 | } 16 | 17 | let foo = Foo(42) 18 | 19 | foo.PrintTesty() 20 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_tyopeof2.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'f' can be null, but is used as a function without checking. 2 | testData/static_analyzer/w248_tyopeof2.nut:6:15 3 | 4 | if ((typeof colorStr != "string" || (colorStr.len() != 8 && colorStr.len() != 6)) && (typeof f == "null") ) 5 | return f("first param must be string with len 6 or 8") 6 | ^ 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248_type_func.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'f' can be null, but is used as a function without checking. 2 | testData/static_analyzer/w248_type_func.nut:4:15 3 | 4 | if ((type(colorStr) != "string" || (colorStr.len() != 8 && colorStr.len() != 6)) && (type(f) == "null") ) 5 | return f("first param must be string with len 6 or 8") 6 | ^ 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/deepUnchained.nut: -------------------------------------------------------------------------------- 1 | local z = 0 2 | function foo(x, y) { 3 | return function(a, b) { 4 | z = a + b 5 | return function(c, d) { 6 | z = c - d 7 | return function(e, f) { 8 | z = e * f 9 | return function(g, h) { 10 | return g / h 11 | } 12 | } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w205.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w205 (unreachable-code) Unreachable code after 'return'. 2 | testData/static_analyzer/w205.nut:5:4 3 | 4 | return 5 | callback() 6 | ^--------- 7 | } 8 | 9 | 10 | WARNING: w315 (invalid-indentation) Invalid indentation. Pay attention to lines 4 and 5. 11 | testData/static_analyzer/w205.nut:5:4 12 | 13 | return 14 | callback() 15 | ^--------- 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /testData/static_analyzer/w217_break.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w217 (unconditional-terminated-loop) Unconditional 'break' inside a loop. 2 | testData/static_analyzer/w217_break.nut:7:4 3 | 4 | y--; 5 | break; 6 | ^---- 7 | z--; 8 | 9 | 10 | WARNING: w205 (unreachable-code) Unreachable code after 'break'. 11 | testData/static_analyzer/w217_break.nut:8:4 12 | 13 | break; 14 | z--; 15 | ^-- 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /testData/static_analyzer/w260_table.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w260 (named-like-must-return-result) Function 'get_setting_by_blk_path' has name like it should return a value, but not all control paths returns a value. 2 | testData/static_analyzer/w260_table.nut:4:28 3 | 4 | ::game <- { 5 | get_setting_by_blk_path = function(path) { return } //-declared-never-used 6 | ^------------------------ 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /testData/static_analyzer/w267.nut: -------------------------------------------------------------------------------- 1 | // -file:paren-is-function-call 2 | function foo(...) {} 3 | 4 | foo("sum=" (6+7)) // EXPECTED 1 5 | 6 | foo("array:" [6]) // EXPECTED 2 access 7 | 8 | let _x = [ 9 | "x" 10 | // [6] // compilation error 11 | "t" [7] // EXPECTED 3 access 12 | "y" (6+7) // EXPECTED 4 13 | "z" 14 | (6+7) // EXPECTED 5 15 | ] 16 | 17 | 18 | foo(foo("b")) // FP 19 | 20 | -------------------------------------------------------------------------------- /testData/static_analyzer/w269.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w269 (mixed-separators) Mixed spaces and commas to separate elements of array. 2 | testData/static_analyzer/w269.nut:4:6 3 | 4 | 20 5 | 30, 6 | ^ 7 | 40, 8 | 9 | 10 | WARNING: w269 (mixed-separators) Mixed spaces and commas to separate elements of array. 11 | testData/static_analyzer/w269.nut:13:4 12 | 13 | 30 14 | 40 15 | ^- 16 | 50 17 | 18 | 19 | -------------------------------------------------------------------------------- /testData/static_analyzer/w308.nut: -------------------------------------------------------------------------------- 1 | let o = {} 2 | 3 | function startswith(_a, _b) { return false } 4 | 5 | let _expected = o.findindex(@(t) t.id = 10) // EXPECTED 6 | let _falsep = o.findvalue(@(t) t.id == 10) // FP 1 7 | 8 | 9 | let _sr = o.findvalue(@(s) s.s == 10 && (s?.e ?? 0) > 0 ) // FP 2 10 | 11 | o.findvalue(@(p) o?[p] ?? (p == "000")) // FP 3 12 | 13 | 14 | let _set = o.filter(@(a) a && startswith(a, "9")) // FP 4 15 | -------------------------------------------------------------------------------- /testData/ast/optimizations/closureHoisting/externalSymbol.nut: -------------------------------------------------------------------------------- 1 | function foo(x, y) { 2 | return function(a, b) { 3 | println(a + b) 4 | return function(c, d) { 5 | println(c - d) 6 | return function(e, f) { 7 | println(e * f) 8 | return function(g, h) { 9 | println(g / h) 10 | } 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /testData/exec/spec/closure.nut: -------------------------------------------------------------------------------- 1 | 2 | function foo(a, b, c) { 3 | if (a) { 4 | local x = 10 5 | local z = 20 6 | if (b) { 7 | local w = 30 8 | local y = 40 9 | if (c) { 10 | local u = 490 11 | return function(q) { 12 | return q + u + w 13 | } 14 | } 15 | } else { 16 | return function(t) { 17 | return t + x 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_opt2.nut: -------------------------------------------------------------------------------- 1 | let fni2 = @() 335 2 | let A8 = class { function _get(idx) { return idx + -3 }} 3 | let ci8 = A8() 4 | let fni11 = @() 11 5 | let fni9 = @(p10) p10 - fni11() 6 | let t12 = { f0=3 } 7 | let A13 = class { function _get(idx) { return idx + 3 }} 8 | let ci13 = A13() 9 | let t7 = { f0=(((static(ci8[((298) | (10 - -3))]) == 999)) ? (10) : (t12["f0"])) f1=ci13[2] } 10 | println(t7.f0) 11 | println(t7.f1) 12 | -------------------------------------------------------------------------------- /testData/static_analyzer/w248.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w248 (access-potentially-nulled) 'a' can be null, but is used as a function without checking. 2 | testData/static_analyzer/w248.nut:11:4 3 | 4 | } else { 5 | a() 6 | ^ 7 | } 8 | 9 | 10 | WARNING: w248 (access-potentially-nulled) 'a' can be null, but is used as a function without checking. 11 | testData/static_analyzer/w248.nut:14:7 12 | 13 | return a() 14 | ^ 15 | 16 | 17 | -------------------------------------------------------------------------------- /testData/static_analyzer/function_rt_detect.nut: -------------------------------------------------------------------------------- 1 | 2 | // -file:plus-string 3 | 4 | function trim(s) { return s } 5 | 6 | function _foo(p) { // EXPECTED 7 | if (p) 8 | return 1 9 | else 10 | return 1 + trim("A") + trim("B") + trim("C").join(true) + 9 11 | } 12 | 13 | function _bar(p) { // FP 14 | if (p) 15 | return "1" 16 | else 17 | return 2 + trim("A") + trim("B") + trim("C").join(true) + 8 18 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w228_4.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w228 (declared-never-used) let 'f' was declared but never used. 2 | testData/static_analyzer/w228_4.nut:3:0 3 | 4 | let f = function foo() {} 5 | ^-- 6 | let c = class {} 7 | 8 | 9 | WARNING: w228 (declared-never-used) let 'c' was declared but never used. 10 | testData/static_analyzer/w228_4.nut:4:0 11 | 12 | let f = function foo() {} 13 | let c = class {} 14 | ^--------------- 15 | 16 | 17 | -------------------------------------------------------------------------------- /testData/static_analyzer/w233_inc.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | local y = 0, x = 0, r3x = 0; 4 | 5 | let width = 100 6 | 7 | let qrframe = {} 8 | 9 | function ismasked(_a, _b) {} 10 | 11 | for (y = 0; y < width; y++) { 12 | r3x = 0; 13 | for (x = 0; x < width; x++) { 14 | if (r3x == 3) 15 | r3x = 0; 16 | if (!r3x && !ismasked(x, y)) 17 | qrframe[x + y * width] = qrframe[x + y * width] ^ 1; 18 | r3x++ 19 | } 20 | } -------------------------------------------------------------------------------- /testData/static_analyzer/w248_not.nut: -------------------------------------------------------------------------------- 1 | function foo(_p) {} 2 | let soldiers = {} 3 | let debriefing = foo(1) 4 | let squad = foo(2) 5 | let squads = foo(3) 6 | 7 | foreach (_soldierIdx, soldierStat in soldiers) { 8 | let soldierData = debriefing?.soldiers.items[soldierStat.soldierId] 9 | if (!soldierData) 10 | continue 11 | if (squads?[soldierData.squadId] != squad) 12 | continue 13 | 14 | foo(soldierData.guid) 15 | } -------------------------------------------------------------------------------- /scripts/samples/regex.nut: -------------------------------------------------------------------------------- 1 | let string = require("string") 2 | 3 | { 4 | let ex = string.regexp("[a-zA-Z]+") 5 | let s = "123 Test; strlen(str);" 6 | let res = ex.search(s) 7 | println(s.slice(res.begin,res.end)) //prints "Test" 8 | } 9 | 10 | { 11 | let ex = string.regexp(@"\m()"); 12 | let s = "123 Test; doSomething(str, getTemp(), (a+(b/c)));" 13 | let res = ex.search(s) 14 | println(s.slice(res.begin,res.end)) //prints "(...)" 15 | } -------------------------------------------------------------------------------- /testData/exec/spec/foreachstmt.out: -------------------------------------------------------------------------------- 1 | value=10 2 | value=23 3 | value=33 4 | value=41 5 | value=589 6 | value=56 7 | index=0 value=10 8 | index=1 value=23 9 | index=2 value=33 10 | index=3 value=41 11 | index=4 value=589 12 | index=5 value=56 13 | value=11.5 14 | value=str 15 | value=true 16 | value=10 17 | index=y value=11.5 18 | index=z value=str 19 | index=w value=true 20 | index=x value=10 21 | value=0 22 | value=1 23 | value=2 24 | 0 25 | 1 26 | 2 27 | -------------------------------------------------------------------------------- /testData/static_analyzer/w305.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w223 (compared-with-bool) Comparison with boolean. 2 | testData/static_analyzer/w305.nut:13:4 3 | 4 | if (B == x > y) 5 | ^--------- 6 | print("a") 7 | 8 | 9 | WARNING: w305 (relative-bool-cmp) Relative comparison non-boolean with boolean. It is potential runtime error 10 | testData/static_analyzer/w305.nut:16:4 11 | 12 | if ((B == x) > y) 13 | ^----------- 14 | print("a") 15 | 16 | 17 | -------------------------------------------------------------------------------- /testData/diagnostics/50k_paren_brackets.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: AST too big. Consider simplifying it 2 | testData/diagnostics/50k_paren_brackets.nut:1:35 3 | 4 | ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( 5 | ^ 6 | ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/import_correct.nut: -------------------------------------------------------------------------------- 1 | from "math" import sin, cos, abs 2 | from "string" import format, printf 3 | from "io" import * 4 | import "datetime" 5 | import "debug" as Debug 6 | 7 | // Test that keywords work as identifiers 8 | local import = 123 9 | local from = [1, 2, 3] 10 | function useKeywords() { 11 | println("import value:", import) 12 | println("from length:", from.len()) 13 | } 14 | 15 | useKeywords() 16 | println(sin(0), abs(-5)) 17 | -------------------------------------------------------------------------------- /testData/exec/staticmemo/static_tables.nut: -------------------------------------------------------------------------------- 1 | local add = 0 2 | 3 | function fn() { 4 | let x = static {a = 222 + add} 5 | println(x.a) 6 | 7 | let y = static({a = 222 + add}) 8 | println(y.a) 9 | 10 | let z = static {a = 222 + add}.__update({a = 333 + add}) 11 | println(z.a) 12 | 13 | let w = static {a = 222 + add}.__update(static {a = 333 + add}) 14 | println(z.a) 15 | 16 | println(""); 17 | } 18 | 19 | fn() 20 | add = 1 21 | fn() 22 | -------------------------------------------------------------------------------- /testData/static_analyzer/w228_trivial.nut: -------------------------------------------------------------------------------- 1 | local readyRefreshTime = 1; 2 | local timeLeftToUpdate = 2; 3 | local refreshPeriod = 3; 4 | 5 | function refreshOnWindowActivate(repeatAmount = 1, refreshPeriodSec = 10.0) { 6 | readyRefreshTime = 0 7 | timeLeftToUpdate = repeatAmount 8 | refreshPeriod = refreshPeriodSec 9 | } 10 | 11 | 12 | function xxx(_a, _b, _c) { 13 | 14 | } 15 | 16 | 17 | xxx(readyRefreshTime, timeLeftToUpdate, refreshPeriod) -------------------------------------------------------------------------------- /include/sqstdsystem.h: -------------------------------------------------------------------------------- 1 | /* see copyright notice in squirrel.h */ 2 | #ifndef _SQSTD_SYSTEMLIB_H_ 3 | #define _SQSTD_SYSTEMLIB_H_ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | SQUIRREL_API SQRESULT sqstd_register_command_line_args(HSQUIRRELVM v, int argc, char ** argv); 10 | SQUIRREL_API SQRESULT sqstd_register_systemlib(HSQUIRRELVM v); 11 | 12 | #ifdef __cplusplus 13 | } /*extern "C"*/ 14 | #endif 15 | 16 | #endif /* _SQSTD_SYSTEMLIB_H_ */ 17 | -------------------------------------------------------------------------------- /testData/diagnostics/50k_square_brackets.diag.txt: -------------------------------------------------------------------------------- 1 | ERROR: AST too big. Consider simplifying it 2 | testData/diagnostics/50k_square_brackets.nut:1:35 3 | 4 | [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ 5 | ^ 6 | [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/static_analyzer/w210_def.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | //expect:w210 5 | 6 | local buildBtnParams = ::kwarg(function(icon=null, option=null, count_list=null, counterFunc=null){ //-declared-never-used 7 | local list = ::contactsLists[count_list ?? option].list 8 | counterFunc = counterFunc ?? function(_){ return list } 9 | return counterFunc 10 | }) 11 | 12 | return buildBtnParams 13 | 14 | //-file:undefined-global 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w241_conditional.nut: -------------------------------------------------------------------------------- 1 | // Is this test correct? 2 | // It tests for `already-required` warning 3 | 4 | function foo() {} 5 | let x = foo() 6 | let d = foo() 7 | 8 | let { _m=null } = require_optional("m.nut") 9 | 10 | let { _g=null } = d ? require_optional("a.nut") 11 | : x?.is_x ? require_optional("b.nut") 12 | : x?.is_s ? require_optional("c.nut") 13 | : x?.is_a ? require_optional("d.nut") 14 | : require_optional("a.nut") 15 | -------------------------------------------------------------------------------- /testData/static_analyzer/w288_dp_va.nut: -------------------------------------------------------------------------------- 1 | if (__name__ == "__analysis__") 2 | return 3 | 4 | 5 | function comp(...) {} 6 | 7 | function foo(_x, _y = 10, _z = 20) {} 8 | 9 | function bar(_x, _y, ...) {} 10 | 11 | let FlowH = 30 12 | let hflow = @(...) comp(FlowH, vargv) 13 | 14 | foo(10, 20, 30, 40) 15 | foo(10, 20, 30) 16 | foo(10, 20) 17 | foo(10) 18 | foo() 19 | 20 | 21 | bar() 22 | bar(10) 23 | bar(10, 20) 24 | bar(10, 20, 30) 25 | bar(10, 20, 30, 40) -------------------------------------------------------------------------------- /testData/exec/stdlib/swap_stack_check.nut: -------------------------------------------------------------------------------- 1 | class D { 2 | x = 1 3 | y = 2 4 | } 5 | local d = D() 6 | local t = {"1": "123", "2": "asd"} 7 | local a = [123, 456, 789] 8 | 9 | function fn(n) { 10 | d.swap("x", "y") 11 | local x = n - 1 12 | t.swap("1", "2") 13 | a.swap(1, 2) 14 | if (n > 0) 15 | fn(x) 16 | println(x) 17 | } 18 | 19 | fn(10) 20 | 21 | println($"{d["x"]} {d["y"]}") 22 | println($"{t["1"]} {t["2"]}") 23 | println($"{a[1]} {a[2]}") 24 | -------------------------------------------------------------------------------- /testData/exec/string_interpolation_new.nut: -------------------------------------------------------------------------------- 1 | 2 | 3 | function foo() { return "foo" } 4 | function bar(p) { return $"[bar {p}]" } 5 | 6 | let s = $"x1 = {foo()}, x2 = {bar($"qux = {foo()}")}" 7 | 8 | print("#1: ") 9 | println(s) 10 | 11 | print("#2: ") 12 | println($"{$"{2}"}"); 13 | 14 | print("#3: ") 15 | local gg = 123 16 | println($"\{ gg = {gg} \}") 17 | 18 | print("#4: ") 19 | println($" foo bar ") 20 | 21 | print("#5: ") 22 | println($"{foo()}}}}}}") 23 | -------------------------------------------------------------------------------- /testData/static_analyzer/w259.diag.txt: -------------------------------------------------------------------------------- 1 | WARNING: w259 (similar-assigned-expr) Assigned expression is very similar to one of the previous ones. 2 | testData/static_analyzer/w259.nut:23:26 3 | 4 | local numAnimations = ::a + ::b + ::c + ::d - (::a + ::b + ::c + ::d) * ::x + 123 5 | local numTextAnimations = ::a + ::b + ::c + ::d - (::a + ::b + ::c + ::d) * ::x + 124 // EXPECTED 6 | ^---------------------------------------------------------- 7 | 8 | 9 | -------------------------------------------------------------------------------- /testData/exec/spec/func_pure_attr.nut: -------------------------------------------------------------------------------- 1 | local counter = 123 2 | 3 | function external() { 4 | return 0 5 | } 6 | 7 | function foo() { 8 | external() 9 | } 10 | 11 | function [pure] bar() { 12 | external() 13 | } 14 | 15 | let a = @() external()+123 16 | let b = @ [pure] () external()+123 17 | 18 | println($"{foo.getfuncinfos().pure}") 19 | println($"{bar.getfuncinfos().pure}") 20 | println($"{a.getfuncinfos().pure}") 21 | println($"{b.getfuncinfos().pure}") 22 | --------------------------------------------------------------------------------