@@ -346,6 +346,14 @@ fn fold_ty(ty_fold fld, @t ty) -> @t {
346
346
}
347
347
ret rewrap( ty, ty_fn( proto, new_args, fold_ty( fld, ret_ty) ) ) ;
348
348
}
349
+ case ( ty_native_fn( ?args, ?ret_ty) ) {
350
+ let vec[ arg] new_args = vec( ) ;
351
+ for ( arg a in args) {
352
+ auto new_ty = fold_ty( fld, a. ty) ;
353
+ new_args += vec( rec( mode=a. mode, ty=new_ty) ) ;
354
+ }
355
+ ret rewrap( ty, ty_native_fn( new_args, fold_ty( fld, ret_ty) ) ) ;
356
+ }
349
357
case ( ty_obj( ?methods) ) {
350
358
let vec[ method] new_methods = vec( ) ;
351
359
for ( method m in methods) {
@@ -588,6 +596,7 @@ fn count_ty_params(@t ty) -> uint {
588
596
fn ty_fn_args( @t fty) -> vec[ arg] {
589
597
alt ( fty. struct ) {
590
598
case ( ty. ty_fn( _, ?a, _) ) { ret a; }
599
+ case ( ty. ty_native_fn( ?a, _) ) { ret a; }
591
600
}
592
601
}
593
602
@@ -600,12 +609,14 @@ fn ty_fn_proto(@t fty) -> ast.proto {
600
609
fn ty_fn_ret( @t fty) -> @t {
601
610
alt ( fty. struct ) {
602
611
case ( ty. ty_fn( _, _, ?r) ) { ret r; }
612
+ case ( ty. ty_native_fn( _, ?r) ) { ret r; }
603
613
}
604
614
}
605
615
606
616
fn is_fn_ty( @t fty) -> bool {
607
617
alt ( fty. struct ) {
608
618
case ( ty. ty_fn( _, _, _) ) { ret true; }
619
+ case ( ty. ty_native_fn( _, _) ) { ret true; }
609
620
case ( _) { ret false; }
610
621
}
611
622
ret false;
@@ -826,24 +837,23 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
826
837
ret ures_err( terr_mismatch, expected, actual) ;
827
838
}
828
839
829
- fn unify_fn( @hashmap[ int, @ty. t] bindings,
830
- ast. proto e_proto,
831
- ast. proto a_proto,
832
- @ty. t expected,
833
- @ty. t actual,
834
- & unify_handler handler,
835
- vec[ arg] expected_inputs, @t expected_output,
836
- vec[ arg] actual_inputs, @t actual_output)
837
- -> unify_result {
838
-
839
- if ( e_proto != a_proto) {
840
- ret ures_err( terr_mismatch, expected, actual) ;
841
- }
840
+ tag fn_common_res {
841
+ fn_common_res_err( unify_result) ;
842
+ fn_common_res_ok( vec[ arg] , @t) ;
843
+ }
842
844
845
+ fn unify_fn_common( @hashmap[ int, @ty. t] bindings,
846
+ @ty. t expected,
847
+ @ty. t actual,
848
+ & unify_handler handler,
849
+ vec[ arg] expected_inputs, @t expected_output,
850
+ vec[ arg] actual_inputs, @t actual_output)
851
+ -> fn_common_res {
843
852
auto expected_len = _vec. len[ arg] ( expected_inputs) ;
844
853
auto actual_len = _vec. len[ arg] ( actual_inputs) ;
845
854
if ( expected_len != actual_len) {
846
- ret ures_err( terr_arg_count, expected, actual) ;
855
+ ret fn_common_res_err( ures_err( terr_arg_count,
856
+ expected, actual) ) ;
847
857
}
848
858
849
859
// TODO: as above, we should have an iter2 iterator.
@@ -874,32 +884,75 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
874
884
}
875
885
876
886
case ( _) {
877
- ret result;
887
+ ret fn_common_res_err ( result) ;
878
888
}
879
889
}
880
890
881
891
i += 1 u;
882
892
}
883
893
884
894
// Check the output.
885
- auto result_out;
886
895
auto result = unify_step( bindings,
887
896
expected_output,
888
897
actual_output,
889
898
handler) ;
890
899
alt ( result) {
891
900
case ( ures_ok( ?rty) ) {
892
- result_out = rty;
901
+ ret fn_common_res_ok ( result_ins , rty) ;
893
902
}
894
903
895
904
case ( _) {
896
- ret result;
905
+ ret fn_common_res_err ( result) ;
897
906
}
898
907
}
908
+ }
899
909
900
- auto t = plain_ty( ty. ty_fn( e_proto, result_ins, result_out) ) ;
901
- ret ures_ok( t) ;
910
+ fn unify_fn( @hashmap[ int, @ty. t] bindings,
911
+ ast. proto e_proto,
912
+ ast. proto a_proto,
913
+ @ty. t expected,
914
+ @ty. t actual,
915
+ & unify_handler handler,
916
+ vec[ arg] expected_inputs, @t expected_output,
917
+ vec[ arg] actual_inputs, @t actual_output)
918
+ -> unify_result {
902
919
920
+ if ( e_proto != a_proto) {
921
+ ret ures_err( terr_mismatch, expected, actual) ;
922
+ }
923
+ auto t = unify_fn_common( bindings, expected, actual,
924
+ handler, expected_inputs, expected_output,
925
+ actual_inputs, actual_output) ;
926
+ alt ( t) {
927
+ case ( fn_common_res_err( ?r) ) {
928
+ ret r;
929
+ }
930
+ case ( fn_common_res_ok( ?result_ins, ?result_out) ) {
931
+ auto t2 = plain_ty( ty. ty_fn( e_proto, result_ins, result_out) ) ;
932
+ ret ures_ok( t2) ;
933
+ }
934
+ }
935
+ }
936
+
937
+ fn unify_native_fn( @hashmap[ int, @ty. t] bindings,
938
+ @ty. t expected,
939
+ @ty. t actual,
940
+ & unify_handler handler,
941
+ vec[ arg] expected_inputs, @t expected_output,
942
+ vec[ arg] actual_inputs, @t actual_output)
943
+ -> unify_result {
944
+ auto t = unify_fn_common( bindings, expected, actual,
945
+ handler, expected_inputs, expected_output,
946
+ actual_inputs, actual_output) ;
947
+ alt ( t) {
948
+ case ( fn_common_res_err( ?r) ) {
949
+ ret r;
950
+ }
951
+ case ( fn_common_res_ok( ?result_ins, ?result_out) ) {
952
+ auto t2 = plain_ty( ty. ty_native_fn( result_ins, result_out) ) ;
953
+ ret ures_ok( t2) ;
954
+ }
955
+ }
903
956
}
904
957
905
958
fn unify_obj( @hashmap[ int, @ty. t] bindings,
@@ -1258,6 +1311,20 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1258
1311
}
1259
1312
}
1260
1313
1314
+ case ( ty. ty_native_fn( ?expected_inputs, ?expected_output) ) {
1315
+ alt ( actual. struct ) {
1316
+ case ( ty. ty_native_fn( ?actual_inputs, ?actual_output) ) {
1317
+ ret unify_native_fn( bindings,
1318
+ expected, actual, handler,
1319
+ expected_inputs, expected_output,
1320
+ actual_inputs, actual_output) ;
1321
+ }
1322
+ case ( _) {
1323
+ ret ures_err( terr_mismatch, expected, actual) ;
1324
+ }
1325
+ }
1326
+ }
1327
+
1261
1328
case ( ty. ty_obj( ?expected_meths) ) {
1262
1329
alt ( actual. struct ) {
1263
1330
case ( ty. ty_obj( ?actual_meths) ) {
0 commit comments