mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			149 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			149 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| int foo(int x) {
 | |
|   try {
 | |
|     if (x == 7) {
 | |
|       throw(44);
 | |
|     }
 | |
|     return x;
 | |
|   } catch (_, _) {
 | |
|     return 2;
 | |
|   }
 | |
| }
 | |
| 
 | |
| int foo_inline(int x) inline {
 | |
|   try {
 | |
|     if (x == 7) {
 | |
|       throw(44);
 | |
|     }
 | |
|     return x;
 | |
|   } catch (_, _) {
 | |
|     return 2;
 | |
|   }
 | |
| }
 | |
| 
 | |
| int foo_inlineref(int x) inline_ref {
 | |
|   try {
 | |
|     if (x == 7) {
 | |
|       throw(44);
 | |
|     }
 | |
|     return x;
 | |
|   } catch (_, _) {
 | |
|     return 2;
 | |
|   }
 | |
| }
 | |
| 
 | |
| int test(int x, int y, int z) method_id(101) {
 | |
|   y = foo(y);
 | |
|   return x * 100 + y * 10 + z;
 | |
| }
 | |
| 
 | |
| int test_inline(int x, int y, int z) method_id(102) {
 | |
|   y = foo_inline(y);
 | |
|   return x * 100 + y * 10 + z;
 | |
| }
 | |
| 
 | |
| int test_inlineref(int x, int y, int z) method_id(103) {
 | |
|   y = foo_inlineref(y);
 | |
|   return x * 100 + y * 10 + z;
 | |
| }
 | |
| 
 | |
| int foo_inline_big(
 | |
|         int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10,
 | |
|         int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20
 | |
| ) inline {
 | |
|   try {
 | |
|     if (x1 == 7) {
 | |
|       throw(44);
 | |
|     }
 | |
|     return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20;
 | |
|   } catch (_, _) {
 | |
|     return 1;
 | |
|   }
 | |
| }
 | |
| 
 | |
| int test_inline_big(int x, int y, int z) method_id(104) {
 | |
|   y = foo_inline_big(
 | |
|           y, y + 1, y + 2, y + 3, y + 4, y + 5, y + 6, y + 7, y + 8, y + 9,
 | |
|           y + 10, y + 11, y + 12, y + 13, y + 14, y + 15, y + 16, y + 17, y + 18, y + 19);
 | |
|   return x * 1000000 + y * 1000 + z;
 | |
| }
 | |
| 
 | |
| int foo_big(
 | |
|         int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10,
 | |
|         int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20
 | |
| ) {
 | |
|   try {
 | |
|     if (x1 == 7) {
 | |
|       throw(44);
 | |
|     }
 | |
|     return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20;
 | |
|   } catch (_, _) {
 | |
|     return 1;
 | |
|   }
 | |
| }
 | |
| 
 | |
| int test_big(int x, int y, int z) method_id(105) {
 | |
|   y = foo_big(
 | |
|           y, y + 1, y + 2, y + 3, y + 4, y + 5, y + 6, y + 7, y + 8, y + 9,
 | |
|           y + 10, y + 11, y + 12, y + 13, y + 14, y + 15, y + 16, y + 17, y + 18, y + 19);
 | |
|   return x * 1000000 + y * 1000 + z;
 | |
| }
 | |
| 
 | |
| 
 | |
| () some_throwing(int op) impure {
 | |
|   if (op == 1) {
 | |
|     return ();
 | |
|   } elseif (op == 2) {
 | |
|     return ();
 | |
|   } else {
 | |
|     throw(1);
 | |
|   }
 | |
| }
 | |
| 
 | |
| int test106() method_id(106) {
 | |
|   try {
 | |
|     some_throwing(1337);
 | |
|     return 1337;
 | |
|   } catch(_, code) {
 | |
|     return code;
 | |
|   }
 | |
|   return -1;
 | |
| }
 | |
| 
 | |
| global int g_reg;
 | |
| 
 | |
| (int, int) test107() method_id(107) {
 | |
|   int l_reg = 10;
 | |
|   g_reg = 10;
 | |
|   try {
 | |
|     ;; note, that regardless of assignment, an exception RESTORES them to previous (to 10)
 | |
|     ;; it's very unexpected, but is considered to be a TVM feature, not a bug
 | |
|     g_reg = 999;
 | |
|     l_reg = 999;
 | |
|     some_throwing(999);
 | |
|   } catch(_, _) {
 | |
|   }
 | |
|   ;; returns (10,10) because of an exception, see a comment above
 | |
|   return (g_reg, l_reg);
 | |
| }
 | |
| 
 | |
| () main() {
 | |
| }
 | |
| 
 | |
| {-
 | |
|     method_id  | in    | out
 | |
| TESTCASE | 101 | 1 2 3 | 123
 | |
| TESTCASE | 101 | 3 8 9 | 389
 | |
| TESTCASE | 101 | 3 7 9 | 329
 | |
| TESTCASE | 102 | 1 2 3 | 123
 | |
| TESTCASE | 102 | 3 8 9 | 389
 | |
| TESTCASE | 102 | 3 7 9 | 329
 | |
| TESTCASE | 103 | 1 2 3 | 123
 | |
| TESTCASE | 103 | 3 8 9 | 389
 | |
| TESTCASE | 103 | 3 7 9 | 329
 | |
| TESTCASE | 104 | 4 8 9 | 4350009
 | |
| TESTCASE | 104 | 4 7 9 | 4001009
 | |
| TESTCASE | 105 | 4 8 9 | 4350009
 | |
| TESTCASE | 105 | 4 7 9 | 4001009
 | |
| TESTCASE | 106 |       | 1
 | |
| TESTCASE | 107 |       | 10 10
 | |
| -}
 |