4747
4848import com .oracle .graal .python .builtins .Builtin ;
4949import com .oracle .graal .python .builtins .CoreFunctions ;
50+ import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
5051import com .oracle .graal .python .builtins .PythonBuiltins ;
52+ import com .oracle .graal .python .builtins .objects .object .PythonObject ;
5153import com .oracle .graal .python .builtins .objects .str .PString ;
5254import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
55+ import com .oracle .graal .python .runtime .PythonCore ;
5356import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
5457import com .oracle .truffle .api .dsl .Cached ;
5558import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
@@ -63,6 +66,82 @@ protected List<? extends NodeFactory<? extends PythonBuiltinNode>> getNodeFactor
6366 return UnicodeDataModuleBuiltinsFactory .getFactories ();
6467 }
6568
69+ public static String getUnicodeVersion () {
70+
71+ // Preliminary Unicode 11 data obtained from
72+ // <https://www.unicode.org/Public/11.0.0/ucd/DerivedAge-11.0.0d13.txt>.
73+ if (Character .getType ('\u0560' ) != Character .UNASSIGNED )
74+ return "11.0.0" ; // 11.0, June 2018.
75+
76+ if (Character .getType ('\u0860' ) != Character .UNASSIGNED )
77+ return "10.0.0" ; // 10.0, June 2017.
78+
79+ if (Character .getType ('\u08b6' ) != Character .UNASSIGNED )
80+ return "9.0.0" ; // 9.0, June 2016.
81+
82+ if (Character .getType ('\u08b3' ) != Character .UNASSIGNED )
83+ return "8.0.0" ; // 8.0, June 2015.
84+
85+ if (Character .getType ('\u037f' ) != Character .UNASSIGNED )
86+ return "7.0.0" ; // 7.0, June 2014.
87+
88+ if (Character .getType ('\u061c' ) != Character .UNASSIGNED )
89+ return "6.3.0" ; // 6.3, September 2013.
90+
91+ if (Character .getType ('\u20ba' ) != Character .UNASSIGNED )
92+ return "6.2.0" ; // 6.2, September 2012.
93+
94+ if (Character .getType ('\u058f' ) != Character .UNASSIGNED )
95+ return "6.1.0" ; // 6.1, January 2012.
96+
97+ if (Character .getType ('\u0526' ) != Character .UNASSIGNED )
98+ return "6.0.0" ; // 6.0, October 2010.
99+
100+ if (Character .getType ('\u0524' ) != Character .UNASSIGNED )
101+ return "5.2.0" ; // 5.2, October 2009.
102+
103+ if (Character .getType ('\u0370' ) != Character .UNASSIGNED )
104+ return "5.1.0" ; // 5.1, March 2008.
105+
106+ if (Character .getType ('\u0242' ) != Character .UNASSIGNED )
107+ return "5.0.0" ; // 5.0, July 2006.
108+
109+ if (Character .getType ('\u0237' ) != Character .UNASSIGNED )
110+ return "4.1.0" ; // 4.1, March 2005.
111+
112+ if (Character .getType ('\u0221' ) != Character .UNASSIGNED )
113+ return "4.0.0" ; // 4.0, April 2003.
114+
115+ if (Character .getType ('\u0220' ) != Character .UNASSIGNED )
116+ return "3.2.0" ; // 3.2, March 2002.
117+
118+ if (Character .getType ('\u03f4' ) != Character .UNASSIGNED )
119+ return "3.1.0" ; // 3.1, March 2001.
120+
121+ if (Character .getType ('\u01f6' ) != Character .UNASSIGNED )
122+ return "3.0.0" ; // 3.0, September 1999.
123+
124+ if (Character .getType ('\u20ac' ) != Character .UNASSIGNED )
125+ return "2.1.0" ; // 2.1, May 1998.
126+
127+ if (Character .getType ('\u0591' ) != Character .UNASSIGNED )
128+ return "2.0.0" ; // 2.0, July 1996.
129+
130+ if (Character .getType ('\u0000' ) != Character .UNASSIGNED )
131+ return "1.1.0" ; // 1.1, June 1993.
132+
133+ return "1.0.0" ; // 1.0
134+ }
135+
136+ @ Override
137+ public void initialize (PythonCore core ) {
138+ builtinConstants .put ("version" , getUnicodeVersion ());
139+ PythonObject ucd_3_2_0 = core .factory ().createPythonObject (core .lookupType (PythonBuiltinClassType .PythonObject ));
140+ ucd_3_2_0 .setAttribute ("unidata_version" , "3.2.0" );
141+ builtinConstants .put ("ucd_3_2_0" , ucd_3_2_0 ); // TODO this is a fake object, just satisfy
142+ // pip installer import
143+ }
144+
66145 // unicodedata.normalize(form, unistr)
67146 @ Builtin (name = "normalize" , fixedNumOfPositionalArgs = 2 )
68147 @ GenerateNodeFactory
0 commit comments