@@ -61,6 +61,11 @@ impl AcirType {
61
61
AcirType :: NumericType ( NumericType :: NativeField )
62
62
}
63
63
64
+ /// Returns an unsigned type of the specified bit size
65
+ pub ( crate ) fn unsigned ( bit_size : u32 ) -> Self {
66
+ AcirType :: NumericType ( NumericType :: Unsigned { bit_size } )
67
+ }
68
+
64
69
/// Returns a boolean type
65
70
fn boolean ( ) -> Self {
66
71
AcirType :: NumericType ( NumericType :: Unsigned { bit_size : 1 } )
@@ -74,6 +79,16 @@ impl AcirType {
74
79
} ;
75
80
matches ! ( numeric_type, NumericType :: Signed { .. } )
76
81
}
82
+
83
+ pub ( crate ) fn from_slice ( value : & SsaType , size : usize ) -> Self {
84
+ match value {
85
+ SsaType :: Slice ( elements) => {
86
+ let elements = elements. iter ( ) . map ( |e| e. into ( ) ) . collect ( ) ;
87
+ AcirType :: Array ( elements, size)
88
+ }
89
+ _ => unreachable ! ( "Attempted to use {value} where a slice was expected" ) ,
90
+ }
91
+ }
77
92
}
78
93
79
94
impl From < SsaType > for AcirType {
@@ -90,7 +105,7 @@ impl<'a> From<&'a SsaType> for AcirType {
90
105
let elements = elements. iter ( ) . map ( |e| e. into ( ) ) . collect ( ) ;
91
106
AcirType :: Array ( elements, * size)
92
107
}
93
- _ => unreachable ! ( "The type {value} cannot be represented in ACIR" ) ,
108
+ _ => unreachable ! ( "The type {value} cannot be represented in ACIR" ) ,
94
109
}
95
110
}
96
111
}
@@ -1220,6 +1235,8 @@ impl AcirContext {
1220
1235
if let Ok ( some_value) = value. clone ( ) . into_var ( ) {
1221
1236
values. push ( self . var_to_witness ( some_value) ?) ;
1222
1237
} else {
1238
+ dbg ! ( optional_values. clone( ) ) ;
1239
+ dbg ! ( "got here" ) ;
1223
1240
nested = true ;
1224
1241
break ;
1225
1242
}
@@ -1228,10 +1245,74 @@ impl AcirContext {
1228
1245
}
1229
1246
} ;
1230
1247
// we do not initialize nested arrays. This means that non-const indexes are not supported for nested arrays
1231
- if !nested {
1232
- self . acir_ir . push_opcode ( Opcode :: MemoryInit { block_id, init : initialized_values } ) ;
1233
- }
1248
+ // if !nested {
1249
+ // self.acir_ir.push_opcode(Opcode::MemoryInit { block_id, init: initialized_values });
1250
+ // }
1251
+ dbg ! ( nested) ;
1252
+ self . acir_ir . push_opcode ( Opcode :: MemoryInit { block_id, init : initialized_values } ) ;
1253
+
1254
+
1255
+ Ok ( ( ) )
1256
+ }
1257
+
1258
+ pub ( crate ) fn initialize_array_new (
1259
+ & mut self ,
1260
+ block_id : BlockId ,
1261
+ len : usize ,
1262
+ optional_value : Option < AcirValue > ,
1263
+ ) -> Result < ( ) , InternalError > {
1264
+ let initialized_values = match optional_value {
1265
+ None => {
1266
+ let zero = self . add_constant ( FieldElement :: zero ( ) ) ;
1267
+ let zero_witness = self . var_to_witness ( zero) ?;
1268
+ vec ! [ zero_witness; len]
1269
+ }
1270
+ Some ( optional_value) => {
1271
+ let mut values = Vec :: new ( ) ;
1272
+ self . initialize_array_inner ( & mut values, optional_value) ?;
1273
+ values
1274
+ }
1275
+ } ;
1234
1276
1277
+ self . acir_ir . push_opcode ( Opcode :: MemoryInit { block_id, init : initialized_values } ) ;
1278
+
1279
+ Ok ( ( ) )
1280
+ }
1281
+
1282
+ fn initialize_array_inner (
1283
+ & mut self ,
1284
+ witnesses : & mut Vec < Witness > ,
1285
+ input : AcirValue ,
1286
+ ) -> Result < ( ) , InternalError > {
1287
+ match input {
1288
+ AcirValue :: Var ( var, _) => {
1289
+ witnesses. push ( self . var_to_witness ( var) ?) ;
1290
+ }
1291
+ AcirValue :: Array ( values) => {
1292
+ for value in values {
1293
+ self . initialize_array_inner ( witnesses, value) ?;
1294
+ }
1295
+ }
1296
+ // AcirValue::DynamicArray(AcirDynamicArray { block_id, len }) => {
1297
+ AcirValue :: DynamicArray ( _) => {
1298
+ panic ! ( "dyn array should already be initialized" ) ;
1299
+ }
1300
+ // AcirValue::DynamicArray(AcirDynamicArray { block_id, len }) => {
1301
+ // for i in 0..len {
1302
+ // // We generate witnesses corresponding to the array values
1303
+ // let index = AcirValue::Var(
1304
+ // self.add_constant(FieldElement::from(i as u128)),
1305
+ // AcirType::NumericType(NumericType::NativeField),
1306
+ // );
1307
+
1308
+ // let index_var = index.into_var()?;
1309
+ // let value_read_var =
1310
+ // self.read_from_memory(block_id, &index_var)?;
1311
+
1312
+ // witnesses.push(self.var_to_witness(value_read_var)?);
1313
+ // }
1314
+ // }
1315
+ }
1235
1316
Ok ( ( ) )
1236
1317
}
1237
1318
}
0 commit comments