diff -r 37fc2317b3d3 builtins/project.lip --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/builtins/project.lip Sun Aug 31 13:15:34 2008 +0200 @@ -0,0 +1,64 @@ +Section Header + + + name := PROJECT; + + - author := "Mildred Ki'Lya "; + - copyright := "2008 Mildred Ki'Lya"; + - comment := ""; + + // Copyright (c) 2008 Mildred Ki'Lya + // + // Permission is hereby granted, free of charge, to any person + // obtaining a copy of this software and associated documentation + // files (the "Software"), to deal in the Software without + // restriction, including without limitation the rights to use, + // copy, modify, merge, publish, distribute, sublicense, and/or sell + // copies of the Software, and to permit persons to whom the + // Software is furnished to do so, subject to the following + // conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + // OTHER DEALINGS IN THE SOFTWARE. + +Section Public + + - main <- + ( + import_private "STD"; + scan public path "."; + + // TODO: + // import_private "TOTO_v1"; + // import_private "TOTO_v2" alias "TOTO"; + ); + + + basename :STRING_CONSTANT; + + prototype :STRING_CONSTANT; + + entry_slot :STRING_CONSTANT := "main"; + + language :STRING_CONSTANT := "C"; + + - private :INTEGER := 0; + - public :INTEGER := 1; + + - scan pub:INTEGER path path:STRING_CONSTANT <- scan pub path path name NULL; + - scan pub:INTEGER path path:STRING_CONSTANT name name:STRING_CONSTANT <- `1`; + + - import_private lib:STRING_CONSTANT <- import(private, lib); + - import_public lib:STRING_CONSTANT <- import(public, lib); + - import (pub:INTEGER, lib:STRING_CONSTANT) <- `2`; + + - import_path_add_first path:STRING_CONSTANT <- `10`; + - import_path_add_last path:STRING_CONSTANT <- `11`; + - import_path_clear <- `12`; + +// kate: hl Lisaac v0.2; indent-width 2; space-indent on; replace-tabs off; +// kate: tab-width 8; remove-trailing-space on; diff -r 37fc2317b3d3 pack_builtins.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pack_builtins.sh Sun Aug 31 13:15:34 2008 +0200 @@ -0,0 +1,26 @@ +#! /bin/zsh + +cd "`dirname "$0"`" + +dest="src/builtin_pack.li" + +cat >"$dest" <>"$dest" + cat "$f" \ + | sed -r 's/^(.*)$/ \\\1\\n\\/' \ + | sed -r 's/"/\\"/g' >>"$dest" + echo ' \";' >>"$dest" + echo >>"$dest" +done <<<"`find builtins -name "*.li" -o -name "*.lip"`" + diff -r 37fc2317b3d3 src/abstract_project.li --- a/src/abstract_project.li Sun Aug 31 13:14:18 2008 +0200 +++ b/src/abstract_project.li Sun Aug 31 13:15:34 2008 +0200 @@ -35,7 +35,7 @@ Section Public -Section Private +Section SELF - all_projects :HASHED_SET[ABSTRACT_PROJECT] := HASHED_SET[ABSTRACT_PROJECT].create; diff -r 37fc2317b3d3 src/builtin_pack.li --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/builtin_pack.li Sun Aug 31 13:15:34 2008 +0200 @@ -0,0 +1,73 @@ +Section Header + + + name := BUILTIN_PACK; + +Section Public + + - project_lip :STRING_CONSTANT := " + \Section Header\n\ + \\n\ + \ + name := PROJECT;\n\ + \\n\ + \ - author := \"Mildred Ki'Lya \";\n\ + \ - copyright := \"2008 Mildred Ki'Lya\";\n\ + \ - comment := \"\";\n\ + \\n\ + \ // Copyright (c) 2008 Mildred Ki'Lya \n\ + \ //\n\ + \ // Permission is hereby granted, free of charge, to any person\n\ + \ // obtaining a copy of this software and associated documentation\n\ + \ // files (the \"Software\"), to deal in the Software without\n\ + \ // restriction, including without limitation the rights to use,\n\ + \ // copy, modify, merge, publish, distribute, sublicense, and/or sell\n\ + \ // copies of the Software, and to permit persons to whom the\n\ + \ // Software is furnished to do so, subject to the following\n\ + \ // conditions:\n\ + \ //\n\ + \ // The above copyright notice and this permission notice shall be\n\ + \ // included in all copies or substantial portions of the Software.\n\ + \ //\n\ + \ // THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n\ + \ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n\ + \ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n\ + \ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n\ + \ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n\ + \ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n\ + \ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n\ + \ // OTHER DEALINGS IN THE SOFTWARE.\n\ + \\n\ + \Section Public\n\ + \\n\ + \ - main <-\n\ + \ (\n\ + \ import_private \"STD\";\n\ + \ scan public path \".\";\n\ + \\n\ + \ // TODO:\n\ + \ // import_private \"TOTO_v1\";\n\ + \ // import_private \"TOTO_v2\" alias \"TOTO\";\n\ + \ );\n\ + \\n\ + \ + basename :STRING_CONSTANT;\n\ + \ + prototype :STRING_CONSTANT;\n\ + \ + entry_slot :STRING_CONSTANT := \"main\";\n\ + \ + language :STRING_CONSTANT := \"C\";\n\ + \\n\ + \ - private :INTEGER := 0;\n\ + \ - public :INTEGER := 1;\n\ + \\n\ + \ - scan pub:INTEGER path path:STRING_CONSTANT <- scan pub path path name NULL;\n\ + \ - scan pub:INTEGER path path:STRING_CONSTANT name name:STRING_CONSTANT <- `1`;\n\ + \\n\ + \ - import_private lib:STRING_CONSTANT <- import(private, lib);\n\ + \ - import_public lib:STRING_CONSTANT <- import(public, lib);\n\ + \ - import (pub:INTEGER, lib:STRING_CONSTANT) <- `2`;\n\ + \\n\ + \ - import_path_add_first path:STRING_CONSTANT <- `10`;\n\ + \ - import_path_add_last path:STRING_CONSTANT <- `11`;\n\ + \ - import_path_clear <- `12`;\n\ + \\n\ + \// kate: hl Lisaac v0.2; indent-width 2; space-indent on; replace-tabs off;\n\ + \// kate: tab-width 8; remove-trailing-space on;\n\ + \"; + diff -r 37fc2317b3d3 src/builtin_project.li --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/builtin_project.li Sun Aug 31 13:15:34 2008 +0200 @@ -0,0 +1,161 @@ +Section Header + + + name := BUILTIN_PROJECT; + + - author := "Mildred Ki'Lya "; + - copyright := "2008 Mildred Ki'Lya"; + - comment := ""; + + // Copyright (c) 2008 Mildred Ki'Lya + // + // Permission is hereby granted, free of charge, to any person + // obtaining a copy of this software and associated documentation + // files (the "Software"), to deal in the Software without + // restriction, including without limitation the rights to use, + // copy, modify, merge, publish, distribute, sublicense, and/or sell + // copies of the Software, and to permit persons to whom the + // Software is furnished to do so, subject to the following + // conditions: + // + // The above copyright notice and this permission notice shall be + // included in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + // OTHER DEALINGS IN THE SOFTWARE. + +Section Inherit + + + parent :Expanded ABSTRACT_PROJECT; + +Section PROTOTYPE + + - get_source_of n:STRING_CONSTANT :STRING <- + ( + result :STRING; + (n = ALIAS_STR.prototype_builtin_project).if { + result := BUILTIN_PACK.project_lip.to_string; + }; + result + ); + +Section Public + + + name :STRING_CONSTANT; + // Project name: all in uppercase. Special project names include: + // SELF The current project + // ROOT The root project + // BUILTIN A project containing builtin prototypes + + - get_project project_name:STRING_CONSTANT :ABSTRACT_PROJECT <- + // Given a project name and the context in which it was found (Self), return + // the corresponding project or NULL if the project is not found. + [ + -? { Self != ABSTRACT_PROJECT }; // TODO: not true in TYPE + -? { project_name != ALIAS_STR.project_self }; + // SELF project should have been removed in the get_fully_qualified_name + // slot. It shouldn't appear here any more. + ] + ( + projects.fast_reference_at project_name; + ); + + - get_fully_qualified_name n:STRING_CONSTANT + from proto:PROTOTYPE :STRING_CONSTANT <- + // Return a fully qualified name given a partial name and the prototype in + // which it was found. This is the lookup algorithm. Return NULL if no + // prototype is found. TODO: check this in ITM_TYPE_(GENERIC|SIMPLE|STYLE) + ( + i:INTEGER; + + project_name :STRING_CONSTANT; + + project :ABSTRACT_PROJECT; + + is_fully_qualified, has_wildcard :BOOLEAN; + + result :STRING_CONSTANT; + + result_buffer, remainder :STRING; + + i := n.index_of ':'; + has_wildcard := n.has_substring "::"; + + // if the name contains separators and no wildcard, chances are that it is + // already fully qualified. It is considered as fully qualified if the first + // member matches a project name + ((n.valid_index i) && { ! has_wildcard }).if { + project_name := ALIAS_STR.get (n.substring (n.lower) to (i - 1)); + (project_name = ALIAS_STR.project_self).if { + project_name := not_yet_implemented; + is_fully_qualified := TRUE; + } else { + is_fully_qualified := projects.fast_has project_name; + } + }; + + is_fully_qualified.if { + result := n; + } else { + has_wildcard.if { + project_name := ALIAS_STR.get (n.substring (n.lower) to (i - 1)); + (project_name = ALIAS_STR.project_self).if { + project_name := not_yet_implemented; + project := not_yet_implemented; + } else { + project := projects.fast_get project_name; + }; + result_buffer.copy project_name; + result_buffer.add_last ':'; + (project = NULL).if_false { + remainder := n.substring (i+1) to (n.upper); + project.expand_prototype remainder append_in result_buffer; + result := ALIAS_STR.get result_buffer; + }; + } else { + not_yet_implemented; + /* + path := n.replace ":" by "/".to_lower + ".li"; + basepath := proto.fully_qualified_name.replace ":" by "/".to_lower.dirname; + file_exists (basepath + "/" + path) in Self.if { + result := (basepath + ":" + path).replace ":" by "/".to_upper; + }.elseif { file_exists path in Self } then { + result := path.replace "/" by ":".to_upper; + }; + */ + }; + }; + + result + ); + + - get_prototype fully_qualified_name:STRING_CONSTANT :PROTOTYPE <- + // Get a prototype corresponding to a fully qualified name + ( + deferred; + ); + +Section SELF + + - create_prototype n:STRING_CONSTANT file f:STRING_CONSTANT generic_count gen_count:INTEGER :PROTOTYPE <- + ( + entry :POINTER; + + result :PROTOTYPE; + result := PROTOTYPE.create (ALIAS_STR.get f) name n project Self generic_count gen_count; + PARSER.go_on result; + result + ); + +Section Public + + - fqn_get_project_name fqn:STRING_CONSTANT :STRING_CONSTANT <- + ( + i :INTEGER; + i := fqn.index_of ':' since (fqn.lower); + ALIAS_STR.get (fqn.substring (fqn.lower) to (i - 1)) + ); + + - fqn_get_last_name fqn:STRING_CONSTANT :STRING_CONSTANT <- + ( + i :INTEGER; + i := fqn.last_index_of ':' since (fqn.upper); + ALIAS_STR.get (fqn.substring (i+1) to (fqn.upper)) + ); + +// kate: hl Lisaac v0.2; indent-width 2; space-indent on; replace-tabs off; +// kate: tab-width 8; remove-trailing-space on; diff -r 37fc2317b3d3 src/tools/alias_str.li --- a/src/tools/alias_str.li Sun Aug 31 13:14:18 2008 +0200 +++ b/src/tools/alias_str.li Sun Aug 31 13:15:34 2008 +0200 @@ -101,6 +101,8 @@ - prototype_n_a_n_a_character:STRING_CONSTANT := "NATIVE_ARRAY__NATIVE_ARRAY__CHARACTER"; + - prototype_builtin_project :STRING_CONSTANT := "BUILTIN:PROJECT"; + - project_self :STRING_CONSTANT := prototype_self; - project_root :STRING_CONSTANT := "ROOT"; - project_builtin :STRING_CONSTANT := "BUILTIN"; @@ -182,7 +184,9 @@ - short_file_list_begin :STRING_CONSTANT := "file_list_begin"; - short_file_list_item :STRING_CONSTANT := "file_list_item"; - short_file_list_end :STRING_CONSTANT := "file_list_end"; - + + - file_builtin :STRING_CONSTANT := ""; + - is_integer n:STRING_CONSTANT :BOOLEAN <- ( (n = prototype_uinteger_64) || @@ -334,6 +338,8 @@ list.add prototype_n_a_character; list.add prototype_n_a_n_a_character; + list.add prototype_builtin_project; + list.add project_root; list.add project_builtin; list_add project_error; @@ -417,7 +423,9 @@ list.add short_directory_list_end; list.add short_file_list_begin; list.add short_file_list_item; - list.add short_file_list_end; + list.add short_file_list_end; + + list.add file_builtin; // Operator '=' and '!=' : operator_equal := operator slot_infix name symbol_equal; diff -r 37fc2317b3d3 src/type/prototype.li --- a/src/type/prototype.li Sun Aug 31 13:14:18 2008 +0200 +++ b/src/type/prototype.li Sun Aug 31 13:15:34 2008 +0200 @@ -168,15 +168,22 @@ // // Creation. // - + - create f:STRING_CONSTANT name n:STRING_CONSTANT project p:ABSTRACT_PROJECT generic_count c:INTEGER :SELF <- ( + result:SELF; result := clone; - result.make f name n project p generic_count c; + result.make f name n project p generic_count c builtin FALSE; + result + ); + + - create_builtin n:STRING_CONSTANT generic_count c:INTEGER :SELF <- + ( + result:SELF; + result := clone; + result.make (ALIAS_STR.file_builtin) name n project BUILTIN_PROJECT generic_count c builtin TRUE; result ); - - make f:STRING_CONSTANT name n:STRING_CONSTANT project p:ABSTRACT_PROJECT generic_count c:INTEGER <- + - make f:STRING_CONSTANT name n:STRING_CONSTANT project p:ABSTRACT_PROJECT generic_count c:INTEGER builtin builtin:BOOLEAN <- ( //+ file:STD_FILE; //+ entry:ENTRY; + file:POINTER; @@ -194,19 +201,23 @@ index := prototype_list.count; prototype_list.add_last Self; prototype_dico.fast_put Self to name; - - // Read file. - //entry := FILE_SYSTEM.get f; - //file ?= entry.open_read_only; - //source := STRING.create (file.size); - //file.read source size (file.size); - //file.close; - - file := FS_MIN.open_read f; - sz := FS_MIN.file_size file; - source := STRING.create (sz+1); - FS_MIN.read file in source size sz; - FS_MIN.close file; + + builtin.if { + source := BUILTIN_PROJECT.get_source_of n; + } else { + // Read file. + //entry := FILE_SYSTEM.get f; + //file ?= entry.open_read_only; + //source := STRING.create (file.size); + //file.read source size (file.size); + //file.close; + + file := FS_MIN.open_read f; + sz := FS_MIN.file_size file; + source := STRING.create (sz+1); + FS_MIN.read file in source size sz; + FS_MIN.close file; + }; // Init. slot_list := HASHED_DICTIONARY[ITM_SLOT,STRING_CONSTANT].create;