From b71cd333f37f662f3d89caf9c8b9cdd8b45782e1 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sat, 7 Sep 2024 23:07:16 +0300 Subject: [PATCH] Add trivial class static initialization --- tests/integration_test.rs | 27 ++++++++++++++ tests/test_data/Dependable.class | Bin 0 -> 294 bytes tests/test_data/Dependable.java | 8 ++++ tests/test_data/DependsOnDependable.class | Bin 0 -> 354 bytes tests/test_data/DependsOnDependable.java | 8 ++++ tests/test_data/StaticInitialization.class | Bin 0 -> 745 bytes tests/test_data/StaticInitialization.java | 35 ++++++++++++++++++ .../test_data/StaticInitializationUser.class | Bin 0 -> 349 bytes tests/test_data/StaticInitializationUser.java | 6 +++ vm/src/vm.rs | 8 ++++ 10 files changed, 92 insertions(+) create mode 100644 tests/test_data/Dependable.class create mode 100644 tests/test_data/Dependable.java create mode 100644 tests/test_data/DependsOnDependable.class create mode 100644 tests/test_data/DependsOnDependable.java create mode 100644 tests/test_data/StaticInitialization.class create mode 100644 tests/test_data/StaticInitialization.java create mode 100644 tests/test_data/StaticInitializationUser.class create mode 100644 tests/test_data/StaticInitializationUser.java diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 48d1a5ad..001bbf22 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -81,3 +81,30 @@ fn should_do_arrays() { let last_frame_value = vm.run("Array").unwrap(); assert_eq!(740, last_frame_value.unwrap()) } + +#[test] +fn should_do_class_static_initialization() { + let vm = VM::new( + vec!["tests/test_data/StaticInitialization.class"], + "tests/test_data/std", + ) + .unwrap(); + let last_frame_value = vm.run("StaticInitialization").unwrap(); + assert_eq!(257, last_frame_value.unwrap()) +} + +#[ignore] +#[test] +fn should_do_class_static_initialization_multiple_classes() { + let vm = VM::new( + vec![ + "tests/test_data/Dependable.class", + "tests/test_data/DependsOnDependable.class", + "tests/test_data/StaticInitializationUser.class", + ], + "tests/test_data/std", + ) + .unwrap(); + let last_frame_value = vm.run("StaticInitializationUser").unwrap(); + assert_eq!(350, last_frame_value.unwrap()) +} diff --git a/tests/test_data/Dependable.class b/tests/test_data/Dependable.class new file mode 100644 index 0000000000000000000000000000000000000000..4d367ab9021f603d992677ff0a4ad09f943cc5fd GIT binary patch literal 294 zcmYLD!D_-l6r7ht6Js>7cMsmIl==fASVa&-4=ufKlBFcXSj6~WrH6uto~0jEoJ7&f z%-gp!^XBjW_zU0#4=xOtHY^V{)CEDR4r-XG{A0KdQyuLE^-+>1`?0|6KfX8Mpkc%H z(1a&&XZlm;u?jOy;X!4Eo(NbWd|9#0u8DP$hwWN>CnVvDaXS;)1)59F&7wu$9;DRtoAq)*ij@Phaob_XZo-O+|g Ohgn58VN)Aa37s=Gfi64% literal 0 HcmV?d00001 diff --git a/tests/test_data/Dependable.java b/tests/test_data/Dependable.java new file mode 100644 index 00000000..93046ad5 --- /dev/null +++ b/tests/test_data/Dependable.java @@ -0,0 +1,8 @@ + +public class Dependable { + static int valueA = 100; + + static { + valueA = 200; + } +} diff --git a/tests/test_data/DependsOnDependable.class b/tests/test_data/DependsOnDependable.class new file mode 100644 index 0000000000000000000000000000000000000000..53681bda9e8aab4288c8927af905f7ce5f3736e5 GIT binary patch literal 354 zcmZvXPfx-?5XIlLz_ztOrTFLK!JB%JM6Sd{AS5OR4jRvH+l?uyi$Tiw0uCk|_yB$= z!)!5f(96th_V?bK`TAaO0CaKU!GbMN@=->G5RBzqwlb+-Tcc>K;u)dRNp(8ACD<32 z&n_Ie0-lcp_yn)7-jz;dlqm-1GRxH+f$m+@P!|Y%92zX#VIL#?m+ulvy-C9Q`a`PK zFn^2G^l9hlbmHtM+YpVzs|T5_wv;z vXiRpWm4I?!$+BApW>F9*_4@6;we!4V?Y6r-pLU-Jh=fuyFefR-q`u>O!Qn$$J8xj& zW@1xkV$r}7OaV=5Oe9*o>{f=KV>!(3vGP25i{g5$fIE zG{gbI08xxX#Dvy^e$!^QnwT9?X|BbwR(Yj|1R4c6CR`;}Sk*QWWN8rAvZ$ zU(CeO9JA3+)iTxP^R9=tRBQ;B-PiH{Nr^4l%x`;BLX;F$ndwJ%1Ka-%xN%-|a3ov0 zQv:()V") { + println!("About to initialize java class {class_name} java_method={java_method:?}"); + engine.execute(java_method)?; //todo implement multiclass correct initialization order + } + } + engine.execute(main_method) } }