@@ -5,8 +5,8 @@ use builtin_helpers::{
5
5
block_expression_to_value, byte_array_type, check_argument_count,
6
6
check_function_not_yet_resolved, check_one_argument, check_three_arguments,
7
7
check_two_arguments, get_bool, get_expr, get_field, get_format_string, get_function_def,
8
- get_module, get_quoted, get_slice, get_struct , get_trait_constraint, get_trait_def,
9
- get_trait_impl , get_tuple, get_type, get_typed_expr, get_u32, get_unresolved_type,
8
+ get_module, get_quoted, get_slice, get_trait_constraint, get_trait_def, get_trait_impl ,
9
+ get_tuple, get_type, get_type_id , get_typed_expr, get_u32, get_unresolved_type,
10
10
has_named_attribute, hir_pattern_to_tokens, mutate_func_meta_type, parse, quote_ident,
11
11
replace_func_meta_parameters, replace_func_meta_return_type,
12
12
} ;
@@ -182,24 +182,6 @@ impl Interpreter<'_, '_> {
182
182
"static_assert" => static_assert ( interner, arguments, location, call_stack) ,
183
183
"str_as_bytes" => str_as_bytes ( interner, arguments, location) ,
184
184
"str_as_ctstring" => str_as_ctstring ( interner, arguments, location) ,
185
- "struct_def_add_attribute" => struct_def_add_attribute ( interner, arguments, location) ,
186
- "struct_def_add_generic" => struct_def_add_generic ( interner, arguments, location) ,
187
- "struct_def_as_type" => struct_def_as_type ( interner, arguments, location) ,
188
- "struct_def_eq" => struct_def_eq ( arguments, location) ,
189
- "struct_def_fields" => struct_def_fields ( interner, arguments, location, call_stack) ,
190
- "struct_def_fields_as_written" => {
191
- struct_def_fields_as_written ( interner, arguments, location)
192
- }
193
- "struct_def_generics" => {
194
- struct_def_generics ( interner, arguments, return_type, location)
195
- }
196
- "struct_def_has_named_attribute" => {
197
- struct_def_has_named_attribute ( interner, arguments, location)
198
- }
199
- "struct_def_hash" => struct_def_hash ( arguments, location) ,
200
- "struct_def_module" => struct_def_module ( self , arguments, location) ,
201
- "struct_def_name" => struct_def_name ( interner, arguments, location) ,
202
- "struct_def_set_fields" => struct_def_set_fields ( interner, arguments, location) ,
203
185
"to_be_radix" => to_be_radix ( arguments, return_type, location) ,
204
186
"to_le_radix" => to_le_radix ( arguments, return_type, location) ,
205
187
"to_be_bits" => to_be_bits ( arguments, return_type, location) ,
@@ -223,8 +205,24 @@ impl Interpreter<'_, '_> {
223
205
}
224
206
"type_as_slice" => type_as_slice ( arguments, return_type, location) ,
225
207
"type_as_str" => type_as_str ( arguments, return_type, location) ,
226
- "type_as_struct " => type_as_struct ( arguments, return_type, location) ,
208
+ "type_as_data_type " => type_as_data_type ( arguments, return_type, location) ,
227
209
"type_as_tuple" => type_as_tuple ( arguments, return_type, location) ,
210
+ "type_def_add_attribute" => type_def_add_attribute ( interner, arguments, location) ,
211
+ "type_def_add_generic" => type_def_add_generic ( interner, arguments, location) ,
212
+ "type_def_as_type" => type_def_as_type ( interner, arguments, location) ,
213
+ "type_def_eq" => type_def_eq ( arguments, location) ,
214
+ "type_def_fields" => type_def_fields ( interner, arguments, location, call_stack) ,
215
+ "type_def_fields_as_written" => {
216
+ type_def_fields_as_written ( interner, arguments, location)
217
+ }
218
+ "type_def_generics" => type_def_generics ( interner, arguments, return_type, location) ,
219
+ "type_def_has_named_attribute" => {
220
+ type_def_has_named_attribute ( interner, arguments, location)
221
+ }
222
+ "type_def_hash" => type_def_hash ( arguments, location) ,
223
+ "type_def_module" => type_def_module ( self , arguments, location) ,
224
+ "type_def_name" => type_def_name ( interner, arguments, location) ,
225
+ "type_def_set_fields" => type_def_set_fields ( interner, arguments, location) ,
228
226
"type_eq" => type_eq ( arguments, location) ,
229
227
"type_get_trait_impl" => {
230
228
type_get_trait_impl ( interner, arguments, return_type, location)
@@ -379,7 +377,7 @@ fn str_as_ctstring(
379
377
}
380
378
381
379
// fn add_attribute<let N: u32>(self, attribute: str<N>)
382
- fn struct_def_add_attribute (
380
+ fn type_def_add_attribute (
383
381
interner : & mut NodeInterner ,
384
382
arguments : Vec < ( Value , Location ) > ,
385
383
location : Location ,
@@ -396,16 +394,16 @@ fn struct_def_add_attribute(
396
394
} ) ;
397
395
} ;
398
396
399
- let struct_id = get_struct ( self_argument) ?;
400
- interner. update_type_attributes ( struct_id , |attributes| {
397
+ let type_id = get_type_id ( self_argument) ?;
398
+ interner. update_type_attributes ( type_id , |attributes| {
401
399
attributes. push ( attribute) ;
402
400
} ) ;
403
401
404
402
Ok ( Value :: Unit )
405
403
}
406
404
407
405
// fn add_generic<let N: u32>(self, generic_name: str<N>)
408
- fn struct_def_add_generic (
406
+ fn type_def_add_generic (
409
407
interner : & NodeInterner ,
410
408
arguments : Vec < ( Value , Location ) > ,
411
409
location : Location ,
@@ -429,7 +427,7 @@ fn struct_def_add_generic(
429
427
} ) ;
430
428
} ;
431
429
432
- let struct_id = get_struct ( self_argument) ?;
430
+ let struct_id = get_type_id ( self_argument) ?;
433
431
let the_struct = interner. get_type ( struct_id) ;
434
432
let mut the_struct = the_struct. borrow_mut ( ) ;
435
433
let name = Rc :: new ( generic_name) ;
@@ -455,35 +453,35 @@ fn struct_def_add_generic(
455
453
}
456
454
457
455
/// fn as_type(self) -> Type
458
- fn struct_def_as_type (
456
+ fn type_def_as_type (
459
457
interner : & NodeInterner ,
460
458
arguments : Vec < ( Value , Location ) > ,
461
459
location : Location ,
462
460
) -> IResult < Value > {
463
461
let argument = check_one_argument ( arguments, location) ?;
464
- let struct_id = get_struct ( argument) ?;
465
- let struct_def_rc = interner. get_type ( struct_id) ;
466
- let struct_def = struct_def_rc . borrow ( ) ;
462
+ let struct_id = get_type_id ( argument) ?;
463
+ let type_def_rc = interner. get_type ( struct_id) ;
464
+ let type_def = type_def_rc . borrow ( ) ;
467
465
468
- let generics = vecmap ( & struct_def . generics , |generic| {
466
+ let generics = vecmap ( & type_def . generics , |generic| {
469
467
Type :: NamedGeneric ( generic. type_var . clone ( ) , generic. name . clone ( ) )
470
468
} ) ;
471
469
472
- drop ( struct_def ) ;
473
- Ok ( Value :: Type ( Type :: DataType ( struct_def_rc , generics) ) )
470
+ drop ( type_def ) ;
471
+ Ok ( Value :: Type ( Type :: DataType ( type_def_rc , generics) ) )
474
472
}
475
473
476
474
/// fn generics(self) -> [(Type, Option<Type>)]
477
- fn struct_def_generics (
475
+ fn type_def_generics (
478
476
interner : & NodeInterner ,
479
477
arguments : Vec < ( Value , Location ) > ,
480
478
return_type : Type ,
481
479
location : Location ,
482
480
) -> IResult < Value > {
483
481
let argument = check_one_argument ( arguments, location) ?;
484
- let struct_id = get_struct ( argument) ?;
485
- let struct_def = interner. get_type ( struct_id ) ;
486
- let struct_def = struct_def . borrow ( ) ;
482
+ let type_id = get_type_id ( argument) ?;
483
+ let type_def = interner. get_type ( type_id ) ;
484
+ let type_def = type_def . borrow ( ) ;
487
485
488
486
let expected = Type :: Slice ( Box :: new ( Type :: Tuple ( vec ! [
489
487
Type :: Quoted ( QuotedType :: Type ) ,
@@ -502,7 +500,7 @@ fn struct_def_generics(
502
500
_ => return Err ( InterpreterError :: TypeMismatch { expected, actual, location } ) ,
503
501
} ;
504
502
505
- let generics = struct_def
503
+ let generics = type_def
506
504
. generics
507
505
. iter ( )
508
506
. map ( |generic| {
@@ -519,39 +517,39 @@ fn struct_def_generics(
519
517
Ok ( Value :: Slice ( generics, slice_item_type) )
520
518
}
521
519
522
- fn struct_def_hash ( arguments : Vec < ( Value , Location ) > , location : Location ) -> IResult < Value > {
523
- hash_item ( arguments, location, get_struct )
520
+ fn type_def_hash ( arguments : Vec < ( Value , Location ) > , location : Location ) -> IResult < Value > {
521
+ hash_item ( arguments, location, get_type_id )
524
522
}
525
523
526
- fn struct_def_eq ( arguments : Vec < ( Value , Location ) > , location : Location ) -> IResult < Value > {
527
- eq_item ( arguments, location, get_struct )
524
+ fn type_def_eq ( arguments : Vec < ( Value , Location ) > , location : Location ) -> IResult < Value > {
525
+ eq_item ( arguments, location, get_type_id )
528
526
}
529
527
530
528
// fn has_named_attribute<let N: u32>(self, name: str<N>) -> bool {}
531
- fn struct_def_has_named_attribute (
529
+ fn type_def_has_named_attribute (
532
530
interner : & NodeInterner ,
533
531
arguments : Vec < ( Value , Location ) > ,
534
532
location : Location ,
535
533
) -> IResult < Value > {
536
534
let ( self_argument, name) = check_two_arguments ( arguments, location) ?;
537
- let struct_id = get_struct ( self_argument) ?;
535
+ let type_id = get_type_id ( self_argument) ?;
538
536
539
537
let name = get_str ( interner, name) ?;
540
538
541
- Ok ( Value :: Bool ( has_named_attribute ( & name, interner. type_attributes ( & struct_id ) ) ) )
539
+ Ok ( Value :: Bool ( has_named_attribute ( & name, interner. type_attributes ( & type_id ) ) ) )
542
540
}
543
541
544
542
/// fn fields(self, generic_args: [Type]) -> [(Quoted, Type)]
545
- /// Returns (name, type) pairs of each field of this StructDefinition .
543
+ /// Returns (name, type) pairs of each field of this TypeDefinition .
546
544
/// Applies the given generic arguments to each field.
547
- fn struct_def_fields (
545
+ fn type_def_fields (
548
546
interner : & mut NodeInterner ,
549
547
arguments : Vec < ( Value , Location ) > ,
550
548
location : Location ,
551
549
call_stack : & im:: Vector < Location > ,
552
550
) -> IResult < Value > {
553
551
let ( typ, generic_args) = check_two_arguments ( arguments, location) ?;
554
- let struct_id = get_struct ( typ) ?;
552
+ let struct_id = get_type_id ( typ) ?;
555
553
let struct_def = interner. get_type ( struct_id) ;
556
554
let struct_def = struct_def. borrow ( ) ;
557
555
@@ -565,7 +563,7 @@ fn struct_def_fields(
565
563
let s = if expected == 1 { "" } else { "s" } ;
566
564
let was_were = if actual == 1 { "was" } else { "were" } ;
567
565
let message = Some ( format ! (
568
- "`StructDefinition ::fields` expected {expected} generic{s} for `{}` but {actual} {was_were} given" ,
566
+ "`TypeDefinition ::fields` expected {expected} generic{s} for `{}` but {actual} {was_were} given" ,
569
567
struct_def. name
570
568
) ) ;
571
569
let location = args_location;
@@ -591,16 +589,16 @@ fn struct_def_fields(
591
589
}
592
590
593
591
/// fn fields_as_written(self) -> [(Quoted, Type)]
594
- /// Returns (name, type) pairs of each field of this StructDefinition .
592
+ /// Returns (name, type) pairs of each field of this TypeDefinition .
595
593
///
596
594
/// Note that any generic arguments won't be applied: if you need them to be, use `fields`.
597
- fn struct_def_fields_as_written (
595
+ fn type_def_fields_as_written (
598
596
interner : & mut NodeInterner ,
599
597
arguments : Vec < ( Value , Location ) > ,
600
598
location : Location ,
601
599
) -> IResult < Value > {
602
600
let argument = check_one_argument ( arguments, location) ?;
603
- let struct_id = get_struct ( argument) ?;
601
+ let struct_id = get_type_id ( argument) ?;
604
602
let struct_def = interner. get_type ( struct_id) ;
605
603
let struct_def = struct_def. borrow ( ) ;
606
604
@@ -623,25 +621,25 @@ fn struct_def_fields_as_written(
623
621
}
624
622
625
623
// fn module(self) -> Module
626
- fn struct_def_module (
624
+ fn type_def_module (
627
625
interpreter : & Interpreter ,
628
626
arguments : Vec < ( Value , Location ) > ,
629
627
location : Location ,
630
628
) -> IResult < Value > {
631
629
let self_argument = check_one_argument ( arguments, location) ?;
632
- let struct_id = get_struct ( self_argument) ?;
630
+ let struct_id = get_type_id ( self_argument) ?;
633
631
let parent = struct_id. parent_module_id ( interpreter. elaborator . def_maps ) ;
634
632
Ok ( Value :: ModuleDefinition ( parent) )
635
633
}
636
634
637
635
// fn name(self) -> Quoted
638
- fn struct_def_name (
636
+ fn type_def_name (
639
637
interner : & NodeInterner ,
640
638
arguments : Vec < ( Value , Location ) > ,
641
639
location : Location ,
642
640
) -> IResult < Value > {
643
641
let self_argument = check_one_argument ( arguments, location) ?;
644
- let struct_id = get_struct ( self_argument) ?;
642
+ let struct_id = get_type_id ( self_argument) ?;
645
643
let the_struct = interner. get_type ( struct_id) ;
646
644
647
645
let name = Token :: Ident ( the_struct. borrow ( ) . name . to_string ( ) ) ;
@@ -650,14 +648,14 @@ fn struct_def_name(
650
648
}
651
649
652
650
/// fn set_fields(self, new_fields: [(Quoted, Type)]) {}
653
- /// Returns (name, type) pairs of each field of this StructDefinition
654
- fn struct_def_set_fields (
651
+ /// Returns (name, type) pairs of each field of this TypeDefinition
652
+ fn type_def_set_fields (
655
653
interner : & mut NodeInterner ,
656
654
arguments : Vec < ( Value , Location ) > ,
657
655
location : Location ,
658
656
) -> IResult < Value > {
659
657
let ( the_struct, fields) = check_two_arguments ( arguments, location) ?;
660
- let struct_id = get_struct ( the_struct) ?;
658
+ let struct_id = get_type_id ( the_struct) ?;
661
659
662
660
let struct_def = interner. get_type ( struct_id) ;
663
661
let mut struct_def = struct_def. borrow_mut ( ) ;
@@ -1076,16 +1074,16 @@ fn type_as_str(
1076
1074
} )
1077
1075
}
1078
1076
1079
- // fn as_struct (self) -> Option<(StructDefinition , [Type])>
1080
- fn type_as_struct (
1077
+ // fn as_data_type (self) -> Option<(TypeDefinition , [Type])>
1078
+ fn type_as_data_type (
1081
1079
arguments : Vec < ( Value , Location ) > ,
1082
1080
return_type : Type ,
1083
1081
location : Location ,
1084
1082
) -> IResult < Value > {
1085
1083
type_as ( arguments, return_type, location, |typ| {
1086
1084
if let Type :: DataType ( struct_type, generics) = typ {
1087
1085
Some ( Value :: Tuple ( vec ! [
1088
- Value :: StructDefinition ( struct_type. borrow( ) . id) ,
1086
+ Value :: TypeDefinition ( struct_type. borrow( ) . id) ,
1089
1087
Value :: Slice (
1090
1088
generics. into_iter( ) . map( Value :: Type ) . collect( ) ,
1091
1089
Type :: Slice ( Box :: new( Type :: Quoted ( QuotedType :: Type ) ) ) ,
@@ -2841,7 +2839,7 @@ fn module_functions(
2841
2839
Ok ( Value :: Slice ( func_ids, slice_type) )
2842
2840
}
2843
2841
2844
- // fn structs(self) -> [StructDefinition ]
2842
+ // fn structs(self) -> [TypeDefinition ]
2845
2843
fn module_structs (
2846
2844
interpreter : & Interpreter ,
2847
2845
arguments : Vec < ( Value , Location ) > ,
@@ -2856,14 +2854,14 @@ fn module_structs(
2856
2854
. iter ( )
2857
2855
. filter_map ( |module_def_id| {
2858
2856
if let ModuleDefId :: TypeId ( id) = module_def_id {
2859
- Some ( Value :: StructDefinition ( * id) )
2857
+ Some ( Value :: TypeDefinition ( * id) )
2860
2858
} else {
2861
2859
None
2862
2860
}
2863
2861
} )
2864
2862
. collect ( ) ;
2865
2863
2866
- let slice_type = Type :: Slice ( Box :: new ( Type :: Quoted ( QuotedType :: StructDefinition ) ) ) ;
2864
+ let slice_type = Type :: Slice ( Box :: new ( Type :: Quoted ( QuotedType :: TypeDefinition ) ) ) ;
2867
2865
Ok ( Value :: Slice ( struct_ids, slice_type) )
2868
2866
}
2869
2867
0 commit comments