File tree Expand file tree Collapse file tree
Tests/EVIL.Ceres.LanguageTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 <AllowUnsafeBlocks >true</AllowUnsafeBlocks >
99 <EnableUnsafeBinaryFormatterSerialization >true</EnableUnsafeBinaryFormatterSerialization >
1010
11- <Version >9.2.0 </Version >
11+ <Version >9.2.1 </Version >
1212
1313 <IsPackable >false</IsPackable >
1414 </PropertyGroup >
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ namespace EVIL.Ceres.ExecutionEngine;
77using EVIL . Ceres . ExecutionEngine . Collections ;
88using EVIL . Ceres . ExecutionEngine . Concurrency ;
99using EVIL . Ceres . ExecutionEngine . Diagnostics ;
10+ using EVIL . Ceres . ExecutionEngine . Marshaling ;
1011using EVIL . Ceres . ExecutionEngine . TypeSystem ;
1112using EVIL . CommonTypes . TypeSystem ;
1213
@@ -1190,7 +1191,16 @@ public void Step()
11901191 }
11911192 else
11921193 {
1193- PushValue ( a . NativeObject ! . GetType ( ) . FullName ! ) ;
1194+ var obj = a . NativeObject ! ;
1195+
1196+ if ( obj is INativeTypeProvider nativeTypeProvider )
1197+ {
1198+ PushValue ( nativeTypeProvider . ProvideType ( ) ) ;
1199+ }
1200+ else
1201+ {
1202+ PushValue ( a . NativeObject ! . GetType ( ) . FullName ! ) ;
1203+ }
11941204 }
11951205
11961206 break ;
@@ -1449,7 +1459,7 @@ public void Step()
14491459
14501460 if ( value == DynamicValue . Nil )
14511461 {
1452- value = new Table ( ) ;
1462+ value = new Table ( ) ;
14531463 c . SetEntry ( a , value ) ;
14541464 }
14551465
Original file line number Diff line number Diff line change 1+ namespace EVIL . Ceres . ExecutionEngine . Marshaling ;
2+
3+ public interface INativeTypeProvider
4+ {
5+ string ProvideType ( ) ;
6+ }
Original file line number Diff line number Diff line change 1+ namespace EVIL . Ceres . LanguageTests ;
2+
3+ using EVIL . Ceres . ExecutionEngine . Marshaling ;
4+
5+ public class NativeTypeProviderObject : INativeTypeProvider
6+ {
7+ public string ProvideType ( )
8+ => "SomeNativeTypeLol" ;
9+ }
Original file line number Diff line number Diff line change @@ -144,6 +144,8 @@ private async Task<int> Execute(TestSet testSet)
144144 VM . Global . Set ( "__new_dummy_object_2" , new (
145145 ( _ , _ ) => DynamicValue . FromObject ( new DummyNativeClass ( ) ) )
146146 ) ;
147+ VM . Global . Set ( "__new_native_type_provider_object" , new (
148+ ( _ , _ ) => DynamicValue . FromObject ( new NativeTypeProviderObject ( ) ) ) ) ;
147149
148150 VM . Global . Set ( "__throw_test" , new (
149151 ( fiber , args ) => fiber . ThrowFromNative ( args [ 0 ] ) )
Original file line number Diff line number Diff line change 1- fn delay(ms) {
1+ //#[test;disasm("always")]
2+ //fn for_loop_table_fill {
3+ // val t = {};
4+ //
5+ // for (rw val i = 0; i < 4; i++) {
6+ // t[i] = i;
7+ // }
8+ //
9+ // assert.equal(t[0], 0);
10+ // assert.equal(t[1], 1);
11+ // assert.equal(t[2], 2);
12+ // assert.equal(t[3], 3);
13+ //}
14+ //
15+ //#[test;disasm("always")]
16+ //fn for_loop_closure_capture {
17+ // val funcs = {};
18+ //
19+ // for (rw val i = 0; i < 3; i++) {
20+ // funcs[i] = fn -> i;
21+ // }
22+ //
23+ // assert.equal(funcs[0](), 0);
24+ // assert.equal(funcs[1](), 1);
25+ // assert.equal(funcs[2](), 2);
26+ //}
27+
28+ fn delay(ms) {
229 val end = time.stamp.ms + ms;
330 while(time.stamp.ms < end){}
431
Original file line number Diff line number Diff line change @@ -75,4 +75,49 @@ fn for_multiple_statements {
7575
7676 assert.equal(i, 10);
7777 assert.equal(j, 20);
78+ }
79+
80+ #[test]
81+ fn for_loop_mutates_limit {
82+ rw val i, limit = 5;
83+
84+ for (i = 0; i < limit; i++) {
85+ if (i == 2) limit = 10;
86+ }
87+
88+ assert.equal(i, 10);
89+ }
90+
91+ #[test]
92+ fn for_loop_nested_skip_break {
93+ rw val count = 0;
94+
95+ for (rw val i = 0; i < 5; i++) {
96+ for (rw val j = 0; j < 5; j++) {
97+ if (j == 2) skip;
98+ if (j == 4) break;
99+ count += 1;
100+ }
101+ }
102+
103+ /* j=0,1,3; i=0..4 → 3 * 5 = 15 */
104+ assert.equal(count, 15);
105+ }
106+
107+ #[test]
108+ fn for_skip_increment {
109+ rw val i = 0, count = 0;
110+
111+ for (i; i < 10; i) {
112+ if (i % 2 == 0) {
113+ i++;
114+ skip;
115+ }
116+
117+ count++;
118+ i++;
119+ }
120+
121+ assert.equal(count, 5);
122+ assert.equal(i, 10);
78123}
Original file line number Diff line number Diff line change @@ -127,15 +127,30 @@ fn value_is_native_type_via_interpolated_string {
127127}
128128
129129#[test]
130- fn value_native_type_get_when_native_object() {
130+ fn value_native_type_get_when_native_object {
131131 val testval = __new_dummy_object();
132132 val type = typeof!(testval);
133133
134134 assert.equal(type, "EVIL.Ceres.LanguageTests.DummyNativeClass");
135135}
136136
137137#[test]
138- fn value_native_type_get_when_not_native_object() {
138+ fn value_native_type_get_when_not_native_object {
139139 val type = typeof!(21.37);
140140 assert.equal(type, nil);
141+ }
142+
143+ #[test]
144+ fn value_native_type_get_when_type_provider {
145+ val testval = __new_native_type_provider_object();
146+ val type = typeof!(testval);
147+
148+ assert.equal(type, "SomeNativeTypeLol");
149+ }
150+
151+ #[test]
152+ fn value_is_native_type_with_provider {
153+ val testval = __new_native_type_provider_object();
154+
155+ assert(testval is NativeObject "SomeNativeTypeLol");
141156}
You can’t perform that action at this time.
0 commit comments