@@ -26,6 +26,17 @@ pub struct PrintGasParameters {
26
26
pub base_cost : InternalGas ,
27
27
}
28
28
29
+ #[ inline]
30
+ fn native_print_nop (
31
+ gas_params : & PrintGasParameters ,
32
+ ty_args : Vec < Type > ,
33
+ args : VecDeque < Value > ,
34
+ ) -> PartialVMResult < NativeResult > {
35
+ debug_assert ! ( ty_args. len( ) == 1 ) ;
36
+ debug_assert ! ( args. len( ) == 1 ) ;
37
+ Ok ( NativeResult :: ok ( gas_params. base_cost , smallvec ! [ ] ) )
38
+ }
39
+
29
40
#[ inline]
30
41
fn native_print (
31
42
gas_params : & PrintGasParameters ,
@@ -68,14 +79,23 @@ fn native_print(
68
79
}
69
80
70
81
pub fn make_native_print (
82
+ silent : bool ,
71
83
gas_params : PrintGasParameters ,
72
84
move_std_addr : AccountAddress ,
73
85
) -> NativeFunction {
74
- Arc :: new (
75
- move |context, ty_args, args| -> PartialVMResult < NativeResult > {
76
- native_print ( & gas_params, context, ty_args, args, move_std_addr)
77
- } ,
78
- )
86
+ if silent {
87
+ Arc :: new (
88
+ move |_context, ty_args, args| -> PartialVMResult < NativeResult > {
89
+ native_print_nop ( & gas_params, ty_args, args)
90
+ } ,
91
+ )
92
+ } else {
93
+ Arc :: new (
94
+ move |context, ty_args, args| -> PartialVMResult < NativeResult > {
95
+ native_print ( & gas_params, context, ty_args, args, move_std_addr)
96
+ } ,
97
+ )
98
+ }
79
99
}
80
100
81
101
/***************************************************************************************************
@@ -88,6 +108,17 @@ pub struct PrintStackTraceGasParameters {
88
108
pub base_cost : InternalGas ,
89
109
}
90
110
111
+ #[ inline]
112
+ fn native_print_stack_trace_nop (
113
+ gas_params : & PrintStackTraceGasParameters ,
114
+ ty_args : Vec < Type > ,
115
+ args : VecDeque < Value > ,
116
+ ) -> PartialVMResult < NativeResult > {
117
+ debug_assert ! ( ty_args. is_empty( ) ) ;
118
+ debug_assert ! ( args. is_empty( ) ) ;
119
+ Ok ( NativeResult :: ok ( gas_params. base_cost , smallvec ! [ ] ) )
120
+ }
121
+
91
122
#[ allow( unused_variables) ]
92
123
#[ inline]
93
124
fn native_print_stack_trace (
@@ -109,12 +140,23 @@ fn native_print_stack_trace(
109
140
Ok ( NativeResult :: ok ( gas_params. base_cost , smallvec ! [ ] ) )
110
141
}
111
142
112
- pub fn make_native_print_stack_trace ( gas_params : PrintStackTraceGasParameters ) -> NativeFunction {
113
- Arc :: new (
114
- move |context, ty_args, args| -> PartialVMResult < NativeResult > {
115
- native_print_stack_trace ( & gas_params, context, ty_args, args)
116
- } ,
117
- )
143
+ pub fn make_native_print_stack_trace (
144
+ silent : bool ,
145
+ gas_params : PrintStackTraceGasParameters ,
146
+ ) -> NativeFunction {
147
+ if silent {
148
+ Arc :: new (
149
+ move |_context, ty_args, args| -> PartialVMResult < NativeResult > {
150
+ native_print_stack_trace_nop ( & gas_params, ty_args, args)
151
+ } ,
152
+ )
153
+ } else {
154
+ Arc :: new (
155
+ move |context, ty_args, args| -> PartialVMResult < NativeResult > {
156
+ native_print_stack_trace ( & gas_params, context, ty_args, args)
157
+ } ,
158
+ )
159
+ }
118
160
}
119
161
120
162
/***************************************************************************************************
@@ -127,14 +169,18 @@ pub struct GasParameters {
127
169
}
128
170
129
171
pub fn make_all (
172
+ silent : bool ,
130
173
gas_params : GasParameters ,
131
174
move_std_addr : AccountAddress ,
132
175
) -> impl Iterator < Item = ( String , NativeFunction ) > {
133
176
let natives = [
134
- ( "print" , make_native_print ( gas_params. print , move_std_addr) ) ,
177
+ (
178
+ "print" ,
179
+ make_native_print ( silent, gas_params. print , move_std_addr) ,
180
+ ) ,
135
181
(
136
182
"print_stack_trace" ,
137
- make_native_print_stack_trace ( gas_params. print_stack_trace ) ,
183
+ make_native_print_stack_trace ( silent , gas_params. print_stack_trace ) ,
138
184
) ,
139
185
] ;
140
186
0 commit comments