@@ -33,7 +33,7 @@ use crate::module::SharedCompilerResource;
3333use crate :: ty:: constructors:: * ;
3434use crate :: ty:: free:: Constraint ;
3535use crate :: ty:: value:: ValueObj ;
36- use crate :: ty:: { BuiltinConstSubr , ConstSubr , ParamTy , Predicate , Type , Visibility } ;
36+ use crate :: ty:: { BuiltinConstSubr , ConstSubr , ParamTy , Predicate , TyParam , Type , Visibility } ;
3737use crate :: varinfo:: { AbsLocation , Mutability , VarInfo , VarKind } ;
3838use Mutability :: * ;
3939use ParamSpec as PS ;
@@ -198,6 +198,8 @@ const FUNC_CO_LNOTAB: &str = "co_lnotab";
198198const FUNC_CO_NLOCALS : & str = "co_nlocals" ;
199199const FUNC_CO_KWONLYARGCOUNT : & str = "co_kwonlyargcount" ;
200200const FUNC_CO_POSONLYARGCOUNT : & str = "co_posonlyargcount" ;
201+ const FUNC_MODULE : & str = "module" ;
202+ const FUNC_GLOBAL : & str = "global" ;
201203const GENERIC_MODULE : & str = "GenericModule" ;
202204const PATH : & str = "Path" ;
203205const MODULE : & str = "Module" ;
@@ -927,14 +929,6 @@ impl Context {
927929 } else {
928930 Visibility :: BUILTIN_PRIVATE
929931 } ;
930- // TODO: this is not a const, but a special property
931- self . register_builtin_py_impl (
932- FUNDAMENTAL_NAME ,
933- Str ,
934- Immutable ,
935- vis. clone ( ) ,
936- Some ( FUNDAMENTAL_NAME ) ,
937- ) ;
938932 self . register_builtin_py_impl (
939933 LICENSE ,
940934 mono ( SITEBUILTINS_PRINTER ) ,
@@ -963,7 +957,7 @@ impl Context {
963957 vis. clone ( ) ,
964958 Some ( NOT_IMPLEMENTED ) ,
965959 ) ;
966- self . register_builtin_py_impl ( ELLIPSIS , Ellipsis , Const , vis, Some ( ELLIPSIS ) ) ;
960+ self . register_builtin_py_impl ( ELLIPSIS , Ellipsis , Const , vis. clone ( ) , Some ( ELLIPSIS ) ) ;
967961 self . register_builtin_py_impl ( TRUE , Bool , Const , Visibility :: BUILTIN_PRIVATE , Some ( TRUE ) ) ;
968962 self . register_builtin_py_impl ( FALSE , Bool , Const , Visibility :: BUILTIN_PRIVATE , Some ( FALSE ) ) ;
969963 self . register_builtin_py_impl (
@@ -973,6 +967,39 @@ impl Context {
973967 Visibility :: BUILTIN_PRIVATE ,
974968 Some ( NONE ) ,
975969 ) ;
970+ if ERG_MODE {
971+ self . register_builtin_py_impl (
972+ FUNC_GLOBAL ,
973+ module ( TyParam :: value ( "<builtins>" ) ) ,
974+ Immutable ,
975+ vis,
976+ None ,
977+ ) ;
978+ }
979+ }
980+
981+ fn init_module_consts ( & mut self ) {
982+ let vis = if PYTHON_MODE {
983+ Visibility :: BUILTIN_PUBLIC
984+ } else {
985+ Visibility :: BUILTIN_PRIVATE
986+ } ;
987+ self . register_builtin_py_impl (
988+ FUNDAMENTAL_NAME ,
989+ Str ,
990+ Immutable ,
991+ vis. clone ( ) ,
992+ Some ( FUNDAMENTAL_NAME ) ,
993+ ) ;
994+ if ERG_MODE {
995+ self . register_builtin_py_impl (
996+ FUNC_MODULE ,
997+ module ( TyParam :: value ( self . get_module ( ) . unwrap ( ) . name . clone ( ) ) ) ,
998+ Immutable ,
999+ vis,
1000+ None ,
1001+ ) ;
1002+ }
9761003 }
9771004
9781005 pub ( crate ) fn init_builtins ( cfg : ErgConfig , shared : SharedCompilerResource ) {
@@ -1001,14 +1028,16 @@ impl Context {
10011028 cfg : ErgConfig ,
10021029 shared : SharedCompilerResource ,
10031030 ) -> Self {
1004- Context :: new (
1031+ let mut ctx = Context :: new (
10051032 name. into ( ) ,
10061033 cfg,
10071034 ContextKind :: Module ,
10081035 vec ! [ ] ,
10091036 None ,
10101037 Some ( shared) ,
10111038 Context :: TOP_LEVEL ,
1012- )
1039+ ) ;
1040+ ctx. init_module_consts ( ) ;
1041+ ctx
10131042 }
10141043}
0 commit comments