소스 검색

allow Enum.Ctor and Class.Static patterns

Simon Krajewski 12 년 전
부모
커밋
fcb011f8f8
2개의 변경된 파일8개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 1
      Makefile
  2. 7 1
      matcher.ml

+ 1 - 1
Makefile

@@ -94,7 +94,7 @@ genxml.cmx: type.cmx lexer.cmx common.cmx ast.cmx
 
 interp.cmx: typecore.cmx type.cmx lexer.cmx genneko.cmx common.cmx codegen.cmx ast.cmx genswf.cmx parser.cmx
 
-matcher.cmx: codegen.cmx typecore.cmx type.cmx typer.cmx common.cmx ast.cmx
+matcher.cmx: optimizer.cmx codegen.cmx typecore.cmx type.cmx typer.cmx common.cmx ast.cmx
 
 main.cmx: dce.cmx matcher.cmx typer.cmx typeload.cmx typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx interp.cmx genxml.cmx genswf.cmx genphp.cmx genneko.cmx genjs.cmx gencpp.cmx genas3.cmx common.cmx codegen.cmx ast.cmx gencommon.cmx
 

+ 7 - 1
matcher.ml

@@ -276,10 +276,16 @@ let to_pattern mctx e st =
 			mk_con_pat (CConst c) [] st.st_type p
 		| EField _ ->
 			let e = type_expr_with_type ctx e (Some st.st_type) false in
+			let e = match Optimizer.make_constant_expression ctx e with Some e -> e | None -> e in
 			(match e.eexpr with
 			| TConst c -> mk_con_pat (CConst c) [] st.st_type p
 			| TTypeExpr mt -> mk_con_pat (CType mt) [] st.st_type p
-			| TField(_, FStatic({cl_extern = true},cf)) -> mk_con_pat (CExpr e) [] cf.cf_type p
+			| TField(_, FStatic(_,cf)) when is_value_type cf.cf_type ->
+				mk_con_pat (CExpr e) [] cf.cf_type p
+			| TField(_, FEnum(en,ef)) ->
+				let tc = monomorphs ctx.type_params (st.st_type) in
+				unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_types) ef tc;
+				mk_con_pat (CEnum(en,ef)) [] st.st_type p
 			| _ -> error "Constant expression expected" p)
 		| ECall(ec,el) ->
 			let tc = monomorphs ctx.type_params (st.st_type) in