diff options
author | johnvg | 2011-05-10 13:41:36 +0000 |
---|---|---|
committer | johnvg | 2011-05-10 13:41:36 +0000 |
commit | 2a5e67f4066d2ad670e9b8b20f5090b77987d14b (patch) | |
tree | d31ff70bb25a19092679ec5087f05c22f2c76030 /portToNewSyntax | |
parent | don't use freopen to redirect stdout and stderror, (diff) |
delete portToNewSyntax
git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@1938 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d
Diffstat (limited to 'portToNewSyntax')
-rw-r--r-- | portToNewSyntax/1.3-and-2.0-differences.txt | 315 | ||||
-rw-r--r-- | portToNewSyntax/help.txt | 115 | ||||
-rw-r--r-- | portToNewSyntax/merge.dcl | 3 | ||||
-rw-r--r-- | portToNewSyntax/merge.icl | 186 | ||||
-rw-r--r-- | portToNewSyntax/portToNewSyntax.dcl | 17 | ||||
-rw-r--r-- | portToNewSyntax/portToNewSyntax.icl | 264 | ||||
-rw-r--r-- | portToNewSyntax/readme.txt | 20 | ||||
-rw-r--r-- | portToNewSyntax/rmPreprop.icl | 190 |
8 files changed, 0 insertions, 1110 deletions
diff --git a/portToNewSyntax/1.3-and-2.0-differences.txt b/portToNewSyntax/1.3-and-2.0-differences.txt deleted file mode 100644 index ceadbd5..0000000 --- a/portToNewSyntax/1.3-and-2.0-differences.txt +++ /dev/null @@ -1,315 +0,0 @@ -This file describes differences between Clean 1.3.x and Clean 2.x. It is aimed -to help you to port Clean 1.3.x programs to Clean 2.x - -First of all: Clean 2.x is not downward compatible with Clean 1.3.x. Probably -you have to change your 1.3.x sources to get them through the Clean 2.x -compiler. - -To be able to write Clean programs that can be compiled with both compiler -versions we have built a simple preprocessor into the Clean 2.x compiler. This -feature allows you to exclude certain parts of your source, depending on which -compiler version you use. See section "The Preprocessor" for details. - -The following sections describe the differences in detail. - -New Features in Clean 2.0 -------------------------- - -Clean 2.x has dynamic types, multiparameter type classes and generic classes. -For these items see the Clean language report. - -With Clean 2.x cyclic dependencies between dcl modules are allowed. - -Differences in Expression Syntax --------------------------------- - -There is no strict let-before expression (let!) anymore in Clean 2.x. You still -can enforce strict evaluation using the strict hash let (#!). - -Differences in the Type System ------------------------------- - -1. Array handling has become different, see section "Differences in the - Standard environment - -2. - There is a difference in resolving overloading. Consider the following code: - - class c a :: a -> a - - instance c [Int] - where - c [1] = [2] - - f [x:xs] - = c xs - - Although this is accepted by Clean 1.3.x, Clean 2.x will complain - - Overloading error [...,..,f]: c no instance available of type [a] - - The Clean 2.x compiler applies no type unification after resolving - overloading. So c is in function f applied to a list with a polymorph element - type ([a]). And this is considered to be different from the instance type - [Int]. If you give f the type [Int] -> [Int] the upper code will be accepted. - -3. - Clean 2.x handles uniqueness attributes in type synonyms different than - Clean 1.3.x. Consider the following definitions: - - :: ListList a :== [[a]] - - f :: *(ListList *{Int}) -> *{Int} - f [[a]] = { a & [0]=0 } - - What does the ListList type synonym stand for in the type of f? In Clean 1.3.x the - ListList type synonym was expanded to - - f :: *[*[*{Int}]] -> *{Int} - - whereas Clean 2.x expands it to - - f :: *[[*{Int}]] -> *{Int} - - This yields a uniqueness error in Clean 2.x because the inner list is shared - but contains a unique object. Clean 1.3.x accepts the upper code. - - This problem happens only with type synonyms that have attributes "inbetween". - What does this mean? An "inbetween" attribute is neither the "root" attribute - nor the attribute of an actual argument. - - E.g. with the upper type synonym, the formal argument "a" is substituted with - *{Int}. Note that also the "*" is substituted for "a". Further the whole - result of expanding the type synonym gets the "root" attribute. Because we - wrote *(ListList ...) the root attribute is "*". So far the result of - expanding *(ListList *{Int}) is *[u:[*{Int]]. "u" is an attribute "inbetween" - because it is neither the root attribute nor the attribute of a formal - argument. Such attributes are made _non_unique_ in Clean 2.x and this is why - the upper code is not accepted. The code will be accepted if you redefine - ListList to - - :: ListList a :== [*[a]] - -4. - The String type has become a basic type. As a consequence you cannot import - this type explicitly: - - from StdString import :: String - - is not valid. - -5. - The Clean 1.3.x compiler has chosen lazy arrays whenever there was a choice. - The Clean 2.x compiler will complain in these cases that internal overloading - could not be solved. E.g. - - Start = size {1} - - is accepted by Clean 1.3.x but not by Clean 2.x. - -6. - Some bugs in the uniqueness typing system were fixed. - -Differences in the Module System --------------------------------- - - The syntax and semantics of explicit import statements has been completely - revised. With Clean 2.x it is - possible to discriminate the different namespaces in import statements. - In Clean 1.3.x the following statement - - from m import F - - could have caused the import of a function F together with a type F and a - class F with all its instances from m. The syntax of Clean 2.x import - statements is given below in the style that is also used in the Clean language - report: - - ExplicitImportDef = "from" ModuleName "import" {Imports}-list ";" - Imports = FunctionName - | "::" TypeName [ConstructorsOrFields] - | "class" ClassName [Members] - | "instance" ClassName {TypeName}+ - ConstructorsOrFields = "(" ".." ")" - | "{" ".." "}" - | "(" {ConstructorName}-list ")" - | "{" {FieldName}-list "}" - Members = "(" ".." ")" - | "(" {MemberName}-list ")" - - Explanation: - [notion] means that the presence of notion is optional - {notion}+ means that notion occurs at least once - {notion}-list means one or more occurrences of notion separated by commas - - Terminals are enclosed in apostrophes. All missing nonterminals are simply - identifiers. - - For example the following import statement - - from m import F, :: T1, :: T2(..), :: T3(C1, C2), :: T4{..}, - :: T5{field1, field2}, class C1, class C2(..), - class C3(mem1, mem2) - - causes the following declarations to be imported: - - the function or macro F, the type T1, the algebraic type T2 with all it's - constructors that are exported by m, the algebraic type T3 with it's - constructors C1 and C2, the record type T4 with all it's fields that are - exported by m, the record type T5 with it's fields field1 and field2, - the class C1, the class C2 with all it's members that are exported by m, - the class C3 with it's members mem1 and mem2. - - There is a tool called "coclPort" that is able to automatically convert - Clean sources with 1.3.x import syntax to sources with 2.x syntax. - - Hint: The appearance of the compiler error message "... not exported as a - function/macro by the specified module" is not a compiler bug. You probably - forgot the "::" before a type identifier - -Differences in the standard environment (StdEnv) ------------------------------------------------- - -*&^ HOI ALLEMAAL, DEZE WIJZIGINGEN IN HET STDENV ZIJN NOG NIET GEDAAN *&@#@ -*&^ THESE CHANGES IN THE STDENV ARE PLANNED BUT NOT DONE *&@#@ -1. - We removed some definitions from the StdEnv. - - instance toString [a] // in StdList - instance < (a,b), instance < (a,b,c) // in StdTuple - instance == (a,b), instance == (a,b,c) // in StdTuple - - We defined a module port.dcl/icl. This module contains these definitions. - -2. - We changed the behaviour of the following functions: - - take in StdList - Clean 1.3.x: i<0 => take i x==x - Clean 2.x : i<0 => take i x==[] - instance mod Int in StdInt - In Clean 2.0: sign m==sign (n mod m) - This keeps the invariant n == m*(n div m) + (n mod m) - where div is division truncated to minus infinity - This is the behaviour people expect from a mod operator. - In Clean 1.3 the following invariant was kept: - n == m*(n/m) + (n mod m) where "/" truncates to 0. - Note that a difference only appears if exactly one - argument is negative - -3. - We changed the argument order of the functions (s)freads, (s)fseek, freopen - in module StdFile such that the File argument is the last argument. - -4. - We fixed some bugs: - - the createArray instances in module StdArray don't crash anymore for - negative size arguments. - - gcd's results are now correct for the case that the result is in the range of - Int. In Clean 1.3.x it was not correct in cases when one argument was - minInt. - -5. - Array handling has become different. In Clean 2.x the Array class is a - multiparameter class, whose first argument type is the array and whose - second argument type is the array element. Therefore the following classes - have vanished: - - ArrayElem, _uselectf, _uselectn, _uselectl, _updatei, _createArrayc,select_u - uselect_u, uselectf_u, uselectn_u, uselectl_u, updatei_u, size_u, usize_u - update_u, createArray_u, createArrayc_u, replace_u - - Example: Assume a function "f" that does something with arrays that had - the following type in Clean 1.3: - - f :: (a b) -> b | select_u b & Array .a - - "(a b)" stands for "an array (can be strict, lazy or unboxed) with element b". - In Clean 2.x this simply becomes: - - f :: (a b) -> b | Array a b - - -Miscellaneous Differences -------------------------- - -1. - For multiparameter type classes a small change in the syntax for instance - definitions was necessary. In Clean 1.3.x it was assumed that every instance - definition only has one type argument. So in the following 1.3.x instance - definition - - instance c T1 T2 - - the type "(T1 T2)" was meant (the type T1 with the argument T2). If this was - the intention then this should be written in Clean 2.x as - - instance c (T1 T2) - - otherwise T1 and T2 will be interpreted as two types. - -2. - Anonymous uniqueness attributes in type contexts are not allowed in Clean 2.x. - So in the following function type - - f :: a | myClass .a - - simply remove the point. - -3. - There are differences in some libraries. See the library's documentation. - -The Preprocessor ----------------- - -We think that for a while it should be made possible to let every source code -file be compiled with both the 1.3 and the 2.0 compiler. How can this be -achieved when the 2.0 compiler is not fully downward compatible? With a -preprocessor of course. The simple preprocessor that we have built into -into the 2.0 compiler has to distinguish parts of code that are either ignored -by the 1.3 compiler or by the 2.0 compiler. To illustrate this we show how you -could use the preprocessor to cope with the principial incompatibilities -in conjunction with arrays. Let's suppose you have a function defined like this - - g a i - = a.[i] - -and you want to write down the type for that function. -This function has really different principial types in Clean 1.3.x and Clean 2.x. -Your code is still compilable with both compiler versions if you write the - following: - - //1.3 - g :: u:(a v:b) .Int -> v:b | select_u b & Array .a, [u <= v] - //3.1 - /*2.0 - g :: .(a u:b) v:Int -> u:b | Array a b, [v <= u] - 0.2*/ - g a i - = a.[i] - -For the 2.0 compiler this would be the same as - - g :: .(a u:b) v:Int -> u:b | Array a b, [v <= u] - g a i - = a.[i] - -because the preprocessor will take care that everything between "//1.3" and -"//3.1" will be ignored and that everything between "/*2.0" and "0.2*/" -will _not_ be treated as a comment. -For the 1.3 this would be the same as - - g :: u:(a v:b) .Int -> v:b | select_u b & Array .a, [u <= v] - g a i - = a.[i] - -Note that the "//1.3", "//3.1", "/*2.0" and "0.2*/" brackets have to be -the first characters of the line (no preceeding whitespace characters are -allowed). Otherwise they will be ignored. Furtheron such sections should -neither be nested nor overlapping. - -Finally we have written an application "rmPreprop" that can be used to remove -all these preprocessor directives when you don't want them anymore. - -We will remove the preprocessor in the future. Regard it as -a temporary feature. diff --git a/portToNewSyntax/help.txt b/portToNewSyntax/help.txt deleted file mode 100644 index aa70654..0000000 --- a/portToNewSyntax/help.txt +++ /dev/null @@ -1,115 +0,0 @@ - coclPort - a tool to port Clean 1.3 programs to Clean 2.0 - ---------------------------------------------------------------------------- - -Folder contents ---------------- - - coclPort.exe - a tool to port Clean 1.3 programs to Clean 2.0 - StdEnvPort - a necessary standard environment - help.txt - this file - - -Why to use coclPort -------------------- - - Clean 2.0 is not downward compatible to Clean 1.3.x: Due to changes in the - syntax there are Clean 1.3.x programs that cannot be compiled with the new - Clean 2.0 compiler. Fortunately these changes in syntax are rather small. - The most important syntax modification is concerned with explicit - import statements (see the documentation about differences between Clean - 1.3 and Clean 2.0 programs). - - Purpose of coclPort is to help you to port Clean 1.3.x programs to - this new syntax. - -What coclPort does ------------------- - - coclPort is indeed a Clean 2.0 compiler that is modified such that it can - handle Clean 1.3 import syntax. Therefore it cannot handle 2.0 import syntax. - To port a 1.3 module - just compile it with the coclPort compiler. Then for this "original" module - a copy of that module is written out in which the explicit import - statements have been adapted to Clean 2.0 syntax. This copy will be written - into a folder named "PortedModules" which will be a subfolder of the folder - that contains the original module. - - Due to some other slight changes - in the language it is possible that your Clean 1.3.x modules will not be accepted - by coclPort. For instance the "String" type has become a - basic type (so you can't import it explicitly). - In that case you have to modify the contents of the original module - and try again. - - coclPort has some insufficiencies. See section "Insufficiencies". - -The preprocessor ----------------- - - We have built a primitive preprocessor into the Clean 2.0 compiler - that allows conditional compilation. This enables you to write sources - that can be compiled with Clean 2.0 and Clean 1.3 regardless of - the incompatibility of these compiler versions. coclPort will generate - preprocessor directives, too, e.g consider the following statement: - - from module_name import == - - The produced output might look like this: - - //1.3 - from module_name import == - //3.1 - /*2.0 - from module_name import class ==, instance == Int, instance == Real - 0.2*/ - - The preprocessor is explained in the documentation about differences - between Clean 1.3 and Clean 2.0. - -How to use this program ------------------------ - - You have to tell the CleanIDE that for compiling a module it should - launch "coclPort.exe" instead "cocl.exe" (BTW "cocl" means "Concurrent - Clean"). In the CleanIDE select an environment that uses the Clean 2.0 - compiler. Now select "Environment/Edit Current" and select the "tools" - button. The field at "compiler:" determines where the CleanIDE finds the - Clean commpiler (cocl.exe). You should be sure that this entry indeed - refers to the Clean 2.0 compiler and not e.g. to a Clean 1.3 compiler! - Put the file "coclPort.exe" into the same folder as "cocl.exe" - and change the entry in the field at "compiler:" from "cocl.exe" - into "coclPort.exe". Now the CleanIDE will use coclPort as the compiler. - - But coclPort needs another standard environment than cocl. You have to replace - the path to StdEnv to a path to StdEnvPort. You can set paths with the - "Environment/Edit Current" or "Project/Project Options" dialog. - - Now simply try to compile your project. - -Insufficiencies ---------------- - - Certain restrictions are imposed on the source code that should be ported: - - For every explicit import statement the "from" token should be the first - non white space character in that line. After some white space characters - the line should then contain the module name (and not e.g. a comment first). - This excludes the following import statements - /* comment */ from module_name import f - from /* comment */ module_name import f - from - module_name import f - An explicit import statement that is outcommented with "//" will work fine, - since it will be ignored anyway: - // from module_name import f - - coclPort has problems when a line within a comment begins - with the "from" token this can be mistaken as an explicit import statement - by this program. As a consequence in the "ported" version there might appear - an explicit import statement within that comment that should appear somewhere - else. Example: - import aphrotisaica /* And I knew I loved her - from that moment on until forever */ - However we think that when something goes wrong with this program it should - be easy to adjust the ported modules manually after it has been tried to - compile them. The ported import statements will appear at least _somewhere_ - in the generated sources. -
\ No newline at end of file diff --git a/portToNewSyntax/merge.dcl b/portToNewSyntax/merge.dcl deleted file mode 100644 index bfd69a3..0000000 --- a/portToNewSyntax/merge.dcl +++ /dev/null @@ -1,3 +0,0 @@ -definition module merge - -mergeFiles :: !*File !*File !*File -> (!.File,!.File,!.File) diff --git a/portToNewSyntax/merge.icl b/portToNewSyntax/merge.icl deleted file mode 100644 index a0d97e9..0000000 --- a/portToNewSyntax/merge.icl +++ /dev/null @@ -1,186 +0,0 @@ -implementation module merge - -import StdEnv, RWSDebug, StdArrayExtensions - -from syntax import Optional, Yes, No -import utilities, portToNewSyntax - -mergeFiles :: !*File !*File !*File -> (!.File,!.File,!.File) -mergeFiles old inferred new - # (lines_within_comment, old) - = lines_in_comment old - = merge_files lines_within_comment 0 old inferred new - -merge_files :: ![Int] !Int !*File !*File !*File -> (!.File,!.File,!.File) -merge_files lines_within_comment line_nr old inferred new - # (end, old) = fend old - | end - # (inferred, new) - = copy_rest inferred new - = (old, inferred, new) - # (line, old) = my_freadline old - line_l = [ ch \\ ch<-:line ] - | not (begins_with_from line_l) || isMember line_nr lines_within_comment - = merge_files lines_within_comment (line_nr+1) old inferred (fwrites line new) - # new = fwrites ("//1.3\n"+++(complete_line line)) new - (new_line_nr, module_names, old, new) - = copy_original_from_statements line_nr line_l [] old new - // insert inferred part - new = fwrites ("//3.1\n/*2.0\n") new - (inferred, new) - = foldSt insert_inferred_from_stmnt module_names (inferred, new) - = merge_files lines_within_comment new_line_nr old inferred (fwrites "0.2*/\n" new) - -copy_original_from_statements line_nr line_l mod_names_accu old new - # (left_space, module_name) = get_ls_and_mn line_l - (line_nr, opt_next_from_statement, old, new) = layout_skip line_nr left_space old new - = case opt_next_from_statement of - No - -> (line_nr, reverse [module_name:mod_names_accu], old, new) - Yes line_l` - -> copy_original_from_statements line_nr line_l` [module_name:mod_names_accu] - old new - -insert_inferred_from_stmnt module_name (inferred, new) - # (first_line_of_import, inferred) = my_freadline inferred - new = foldSt fwrites ["from ", module_name, " ", first_line_of_import] new - = copy_rest_of_import inferred new - -begins_with_from line_l - # without_spaces = dropWhile isSpace line_l - = case without_spaces of - ['from'] -> True - ['from',ch:_] -> not (isAlphanum ch || isMember ch ['`_']) - _ -> False - -get_ls_and_mn line_l - # (spaces, rest1) = span isSpace line_l - without_from = drop 4 rest1 - (_, rest2) = span isSpace without_from - module_name = takeWhile (not o isSpace) rest2 - = (space_count spaces 0, toString module_name) - -space_count [] _ - = 0 -space_count [' ':spaces] modTabWidth - = 1+(space_count spaces ((modTabWidth+1) mod modTabWidth)) -space_count ['\t':spaces] modTabWidth - = (cTabWidth-modTabWidth)+(space_count spaces 0) -space_count ['\n':_] _ - = 0 - -layout_skip :: !Int !Int !*File !*File -> (!Int, !Optional [Char], !.File, !.File) -layout_skip line_nr left_space old new - # (end, old) = fend old - | end - = (line_nr, No, old, new) - # (cur_pos, old) = fposition old - (line, old) = my_freadline old - line_l = [ ch \\ ch<-:line ] - spaces = takeWhile isSpace line_l - | space_count spaces 0<=left_space - | begins_with_from line_l - = (line_nr+1, Yes line_l, old, fwrites (complete_line line) new) - = (line_nr+1, No, snd (fseek old cur_pos FSeekSet), new) - = layout_skip (line_nr+1) left_space old (fwrites (complete_line line) new) - -copy_rest_of_import :: !*File !*File -> (!.File, !.File) -copy_rest_of_import inferred new - # (end, inferred) = fend inferred - | end - = (inferred ,new) - # (cur_pos, inferred) = fposition inferred - (line, inferred) = my_freadline inferred - | line % (0,5)=="import" - = (snd (fseek inferred cur_pos FSeekSet), new) - = copy_rest_of_import inferred (fwrites line new) - -complete_line line - | line.[size line-1]<>'\n' - = line+++"\n" - = line - -copy_rest inferred new - # (end, inferred) = fend inferred - | end - = (inferred, new) - # (line, inferred) - = my_freadline inferred - = copy_rest inferred (fwrites line new) - -lines_in_comment file - # (cur_pos, file) - = fposition file - (rev_lines_within_comment, file) - = get_lic 0 [] file - = (reverse rev_lines_within_comment, snd (fseek file cur_pos FSeekSet)) - where - get_lic :: !Int ![Int] !*File -> (![Int], !*File) - get_lic line_nr line_nr_accu file - # (end, file) - = fend file - | end - = (line_nr_accu, file) - # (line, file) - = my_freadline file - line_l - = [ch \\ ch<-:line] - # (bwc, rest) - = begins_with_comment line_l - | bwc - = consider_comment 1 rest line_nr line_nr_accu file - = get_lic (line_nr+1) line_nr_accu file - - begins_with_comment ['//1.3':rest] - = (True, rest) - begins_with_comment line_l - # without_spaces - = dropWhile isSpace line_l - = case without_spaces of - ['/*':rest] - -> (True, rest) - _ - -> (False, []) - - consider_comment nesting_level ['*/':rest] line_nr line_nr_accu file - | nesting_level==1 - = get_lic line_nr line_nr_accu file - = consider_comment (nesting_level-1) rest line_nr line_nr_accu file - consider_comment nesting_level ['/*':rest] line_nr line_nr_accu file - = consider_comment (nesting_level+1) rest line_nr line_nr_accu file - consider_comment nesting_level [_:rest] line_nr line_nr_accu file - = consider_comment nesting_level rest line_nr line_nr_accu file - consider_comment nesting_level [] line_nr line_nr_accu file - # (end, file) - = fend file - | end - = ([], file) - # (line, file) - = my_freadline file - line_l - = [ch \\ ch<-:line] - = case line_l of - ['//3.1':rest] - | nesting_level==1 - -> get_lic (line_nr+1) [line_nr+1:line_nr_accu] file - -> consider_comment (nesting_level-1) rest (line_nr+1) [line_nr+1:line_nr_accu] file - _ - -> consider_comment nesting_level line_l (line_nr+1) [line_nr+1:line_nr_accu] file - -my_freadline :: !*File -> (!String, !*File) -my_freadline file - #! (line, file) = freadline file - last_char_ix = size line - 1 - last_printable_char_ix = findrArrElt isntNewlineOnAnyPlatform line last_char_ix - | last_printable_char_ix==(-1) - = ("\n", file) - | last_printable_char_ix==last_char_ix - = (line, file) - | last_printable_char_ix==last_char_ix-1 && line.[last_char_ix]=='\n' - = (line, file) - = ({line & [last_printable_char_ix+1] = '\n' } %(0, last_printable_char_ix+1), file) - -isntNewlineOnAnyPlatform '\xA' = False -isntNewlineOnAnyPlatform '\xD' = False -isntNewlineOnAnyPlatform _ = True - diff --git a/portToNewSyntax/portToNewSyntax.dcl b/portToNewSyntax/portToNewSyntax.dcl deleted file mode 100644 index 1668962..0000000 --- a/portToNewSyntax/portToNewSyntax.dcl +++ /dev/null @@ -1,17 +0,0 @@ -definition module portToNewSyntax - -from StdMisc import abort - -from StdFile import :: Files -from scanner import :: SearchPaths - -import checksupport - -switch_port_to_new_syntax port dont_port :== port - -cTabWidth :== 4 - -writeExplImportsToFile :: !String ![([Declaration],a)] !{#u:DclModule} !*CheckState - -> (!{#u:DclModule},!.CheckState) - -createPortedFiles :: !String !SearchPaths !*Files -> (!Bool, !*Files) diff --git a/portToNewSyntax/portToNewSyntax.icl b/portToNewSyntax/portToNewSyntax.icl deleted file mode 100644 index 9b948d0..0000000 --- a/portToNewSyntax/portToNewSyntax.icl +++ /dev/null @@ -1,264 +0,0 @@ -implementation module portToNewSyntax - -import StdEnv, scanner, Directory, merge, checksupport - -switch_port_to_new_syntax port dont_port :== port - -cTabWidth :== 4 - -resultFolderName =: "PortedModules" - -createPortedFiles :: !String !SearchPaths !*Files -> (!Bool, !*Files) -createPortedFiles fileName searchPaths files - # (ok, files) - = case findDirOfModule fileName searchPaths files of - (No, files) - -> (False, files) - (Yes path, files) - # (ok, files) - = ensureSubDirExists path fileName files - | not ok - -> (ok, files) - # (ok1, files) - = tryToCreatePortedFile fileName "icl" path files - (ok2, files) - = tryToCreatePortedFile fileName "dcl" path files - -> (ok1&&ok2, files) - (_, files) - = fremove (RelativePath [PathDown "icl.txt"]) files - (_, files) - = fremove (RelativePath [PathDown "dcl.txt"]) files - = (ok, files) - - -tryToCreatePortedFile :: !String !String !Path !*Files -> (!Bool,!*Files) -tryToCreatePortedFile file_name suffix path ms_files - # with_suffix - = file_name+++"."+++suffix - # (old_module_filename, ms_files) - = pathToPD_String (pathAppend path [PathDown with_suffix]) ms_files - (ok, old, ms_files) = fopen old_module_filename FReadData ms_files - | not ok - = (ok, ms_files) - # (new_module_filename, ms_files) - = pathToPD_String (pathAppend path [PathDown resultFolderName, - PathDown with_suffix]) ms_files - inferred_filename = suffix+++".txt" - (ok1, inferred, ms_files) = fopen inferred_filename FReadText ms_files - (ok2, new, ms_files) = fopen new_module_filename FWriteText ms_files - | not (ok1&&ok2) - = (False, ms_files) - # (old, inferred, new) = mergeFiles old inferred new - (ok3, ms_files) = fclose old ms_files - (ok4, ms_files) = fclose inferred ms_files - (ok5, ms_files) = fclose new ms_files - = (ok3&&ok4&&ok5, ms_files) - -findDirOfModule :: !{#Char} !SearchPaths *Files -> (!Optional Path, !*Files) -findDirOfModule fileName searchPaths files - # filtered_locations - = filter (\(moduleName,pd_path) -> moduleName == fileName) searchPaths.sp_locations - | not (isEmpty filtered_locations) - # ((ok, path), files) - = pd_StringToPath (snd (hd filtered_locations)) files - | not ok - = (No, files) - = (Yes path, files) - = loop searchPaths.sp_paths (fileName+++".icl") files - where - loop :: ![String] !String !*Files -> (!Optional Path, !*Files) - loop [] _ files - = (No, files) - loop [pd_path:pd_paths] fileName files - # ((ok, path), files) - = pd_StringToPath pd_path files - | not ok - = (No, files) - # ((dir_error, _), files) - = getFileInfo (pathAppend path [PathDown fileName]) files - | dir_error == NoDirError - = (Yes path, files) - = loop pd_paths fileName files - -pathAppend (RelativePath p) x = RelativePath (p++x) -pathAppend (AbsolutePath diskname p) x = AbsolutePath diskname (p++x) - -ensureSubDirExists path fileName files - # path_result_folder = pathAppend path [PathDown resultFolderName] - ((err_code, _), files) = getFileInfo path_result_folder files - (errorCode, files) = case err_code of - NoDirError -> (NoDirError, files) - _ -> createDirectory path_result_folder files - = (errorCode==NoDirError, files) - - - - -writeExplImportsToFile :: !String ![([Declaration],a)] !{#u:DclModule} !*CheckState - -> (!{#u:DclModule},!.CheckState) -writeExplImportsToFile file_name si_explicit dcl_modules cs - # (file, cs) - = openFile file_name cs - (dcl_modules, file) - = foldSt (write_expl_import (flatten (map fst si_explicit))) (reverse si_explicit) (dcl_modules, file) - = (dcl_modules, closeFile file cs) - -write_expl_import all_expl_imp_decls (declarations, _) (dcl_modules, file) - # (declaration_strings, dcl_modules) - = mapFilterYesSt (decl_to_opt_string all_expl_imp_decls) (reverse declarations) dcl_modules - = (dcl_modules, fwriteNewSyntax declaration_strings file) - -// only for portToNewSyntax -decl_to_opt_string all_expl_imp_decls (Declaration {decl_ident, decl_index, decl_kind=STE_Imported ste_kind def_mod_index}) - dcl_modules - = imported_decl_to_opt_string all_expl_imp_decls decl_ident decl_index ste_kind def_mod_index - dcl_modules -decl_to_opt_string _ (Declaration{decl_ident, decl_kind=STE_FunctionOrMacro _}) dcl_modules - = (Yes decl_ident.id_name, dcl_modules) - -// only for portToNewSyntax -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index STE_Constructor def_mod_index - dcl_modules - = (No, dcl_modules) -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index STE_Member def_mod_index - dcl_modules - = (No, dcl_modules) -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index STE_DclFunction def_mod_index - dcl_modules - = (Yes dcl_ident.id_name, dcl_modules) -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index STE_Class def_mod_index - dcl_modules - = (Yes ("class "+++dcl_ident.id_name+++"(..)"), dcl_modules) -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index (STE_Instance _) def_mod_index - dcl_modules - # ({ins_type}, dcl_modules) - = dcl_modules![def_mod_index].dcl_common.com_instance_defs.[dcl_index] - = (Yes ("instance "+++dcl_ident.id_name+++" "+++ - separated " " (map type_to_string ins_type.it_types)), dcl_modules) -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index STE_Type def_mod_index - dcl_modules - # ({td_rhs}, dcl_modules) - = dcl_modules![def_mod_index].dcl_common.com_type_defs.[dcl_index] - dcl_string - = ":: "+++(case td_rhs of - AlgType constructors - -> dcl_ident.id_name+++constructor_bracket def_mod_index all_expl_imp_decls constructors - RecordType _ - -> dcl_ident.id_name+++"{..}" - _ - -> dcl_ident.id_name) - = (Yes dcl_string, dcl_modules) -imported_decl_to_opt_string all_expl_imp_decls dcl_ident dcl_index STE_Generic def_mod_index - dcl_modules - = (Yes ("generic "+++dcl_ident.id_name+++"(..)"), dcl_modules) - -// only for portToNewSyntax -type_to_string (TA {type_name} _) = possibly_replace_predef_symbols type_name.id_name -type_to_string (TB type) = toString type -type_to_string (TV {tv_name}) = tv_name.id_name -type_to_string x = abort ("bug nr 945 in module check"--->x) - -possibly_replace_predef_symbols s - | s=="_list" - = "[]" - | s % (0,5) == "_tuple" - = (toString ['(':repeatn ((toInt (s%(6, (size s) - 1))) - 1) ','])+++")" - | s=="_array" - = "{}" - | s=="_!array" - = "{!}" - | s=="_#array" - = "{#}" - = s - -instance toString BasicType - where - toString BT_Int = "Int" - toString BT_Char = "Char" - toString BT_Real = "Real" - toString BT_Bool = "Bool" - toString BT_Dynamic = "Dynamic" - toString BT_File = "File" - toString BT_World = "World" - toString _ = abort "bug nr 346 in module check" - -// only for portToNewSyntax -separated _ [] - = "" -separated separator [h:t] - = foldl (\l r->l+++separator+++r) h t - -constructor_bracket def_mod_index all_expl_imp_decls constructors - # expl_imp_constructor_strings - = [ ds_ident.id_name \\ {ds_ident} <- constructors - | is_expl_imported_constructor def_mod_index ds_ident all_expl_imp_decls ] - | isEmpty expl_imp_constructor_strings - = "" - = "("+++separated "," expl_imp_constructor_strings+++")" - -// only for portToNewSyntax -is_expl_imported_constructor def_mod_index ds_ident [] - = False -is_expl_imported_constructor def_mod_index ds_ident [Declaration {decl_ident, decl_kind=STE_Imported STE_Constructor def_mod_index2}:_] - | decl_ident==ds_ident && def_mod_index==def_mod_index2 - = True - // GOTO next alternative -is_expl_imported_constructor def_mod_index ds_ident [h:t] - = is_expl_imported_constructor def_mod_index ds_ident t - -fwriteNewSyntax importStrings file - | isEmpty importStrings - = fwrites "import @#$@@!!" file - # with_commas = (map (\s->s+++", ") (butLast importStrings))++[last importStrings+++";"] - lines = split_in_lines 12 with_commas [] [] - lines = [hd lines:[["\t":line]\\ line<-tl lines]] - line_strings = [ foldl (+++) " " (line++["\n"]) \\ line<-lines ] - = fwrites (foldl (+++) "import" line_strings) file - where - max_line_length = 80 - split_in_lines i [] inner_accu outer_accu - # accu = if (isEmpty inner_accu) outer_accu [reverse inner_accu:outer_accu] - = reverse accu - split_in_lines i [h:t] inner_accu outer_accu - # s = size h - | s+i>max_line_length - | isEmpty inner_accu - = split_in_lines (s+i) t [h] outer_accu - = split_in_lines (s+cTabWidth) t [h] [inner_accu:outer_accu] - = split_in_lines (s+i) t [h:inner_accu] outer_accu -// only for portToNewSyntax - -butLast [] = [] -butLast [x] = [] -butLast [h:t] = [h: butLast t] - -// MW: fake.. -openFile file_name cs - # world = bigBang - (ok, newFile, world) = fopen file_name FWriteText world - cs = forget world cs - cs = case ok of - True -> cs - _ # cs_error = checkError "" ("can't open file \""+++file_name+++" in current directory.") cs.cs_error - -> { cs & cs_error=cs_error } - = (newFile, cs) - -closeFile file cs - # world = bigBang - (ok, world) = fclose file world - = forget world cs - -bigBang :: .World -bigBang = cast 1 -// creates a world from scratch - -forget :: !.x !.y -> .y -forget x y = y - -cast :: !.a -> .b -cast a - = code - { - pop_a 0 - } -// ..fake diff --git a/portToNewSyntax/readme.txt b/portToNewSyntax/readme.txt deleted file mode 100644 index b1dc277..0000000 --- a/portToNewSyntax/readme.txt +++ /dev/null @@ -1,20 +0,0 @@ -This file explains how to build a valid cocl that reads -Clean 1.3 sources and as a sideeffect produces sources -in which the explicit import statements have been -ported to 2.0 syntax ("coclPort" application) - -The module portToNewSyntax appears twice: in the "compiler" -folder and in the "portToNewSyntax" folder. Iff you want -to build coclPort then set the paths in such a way that -the portToNewSyntax.dcl/icl files from the portToNewSyntax -folder are preferred over the same files in the compiler -folder. - -Further set the "switch_import_syntax" macro in module -syntax to "one_point_three" - -The "switch_port_to_new_syntax" macro in module -portToNewSyntax is used to ed/disable the porting -facilities: -portToNewSyntax/portToNewSyntax.dcl: port -compiler/portToNewSyntax.dcl: dont_port diff --git a/portToNewSyntax/rmPreprop.icl b/portToNewSyntax/rmPreprop.icl deleted file mode 100644 index 1be1eef..0000000 --- a/portToNewSyntax/rmPreprop.icl +++ /dev/null @@ -1,190 +0,0 @@ -module rmPreprop - -import StdEnv, Directory, StdLib, StdDebug - -one_three =: "1.3" -two_zero =: "2.0" - -intro_text current_dir_string = - [ "This program can be used to remove the preprocessor statements\n" - , "from your Clean sources. Consult the documentation about\n" - , "differences between Clean 1.3 and Clean 2.0 to get more information\n" - , "about the Clean preprocessor.\n" - , "\n" - , "This program will perform it's task on all .icl and .dcl files\n" - , "in the current folder only. To process several folders you can move\n" - , "this executable.\n" - , "\n" - , "This program will not alter the files in the current folder, but will\n" - , "rather create two subfolders with the resulting 1.3 and 2.0 sources.\n" - , "The subfolders are called \"", one_three, "\" and \"", two_zero, "\".\n" - , "\n" - , "Current directory:", current_dir_string, "\n" - , "\n" - , "Should I start? (y/n):" - ] - - -appStdio f w - #! (io, w) - = stdio w - (x, io, w) - = f io w - (_, w) - = fclose io w - = (x, w) - -appStdio1 f w - #! (_, w) - = appStdio (\io w -> let io2 = f io in (0, io2, w)) w - = w - -intro io w - #! (current_dir_path, w) - = getCurrentDirectory w - (current_dir_string, w) - = pathToPD_String current_dir_path w - io - = foldlSt fwrites (intro_text current_dir_string) io - (answer, io) - = freadline io - io - = fwrites "\n" io - = (size answer>0 && (answer.[0]=='y' || answer.[0]=='Y'), io, w) - -perform w - #! (filenames, w) - = getFilenames w - | isEmpty filenames - = (False, w) - #! (ok, w) - = makeSubfolders w - | not ok - = (ok, w) - = loop filenames w - where - getFilenames w - #! ((err, dir_entries), w) - = getDirectoryContents (RelativePath []) w - | err<>NoDirError - #! w - = appStdio1 (fwrites "Error:can't retrieve contents of current directory\n\n") w - = ([], w) - = ([fileName \\ {fileName}<-dir_entries | endsWith fileName ".dcl" || endsWith fileName ".icl"], w) - endsWith s suffix - #! size_s = size s - = s % (size_s-size suffix, size_s-1)==suffix - makeSubfolders w - #! (ok1, w) - = makeSubfolder one_three w - (ok2, w) - = makeSubfolder two_zero w - = (ok1 && ok2, w) - makeSubfolder name w - #! (err, w) - = createDirectory (RelativePath [PathDown name]) w - = (err==NoDirError || err==AlreadyExists, w) - loop [] w - = (True, w) - loop [filename:filenames] w - #! (ok, w) - = performOnFile filename w - | not ok - = (ok, w) - = loop filenames w - performOnFile filename w - #! (ok, input, w) - = fopen filename FReadData w - | not ok - = (ok, w) - #! (ok1, out13, w) - = openOutputfile one_three filename w - (ok2, out20, w) - = openOutputfile two_zero filename w - | not ok1 || not ok2 - = (False, w) - #! (input, out13, out20) - = fileLoop input out13 out20 - (_, w) - = fclose input w - (_, w) - = fclose out13 w - (_, w) - = fclose out20 w - = (True, w) - where - fileLoop :: !*File !*File !*File -> (!*File, !*File, !*File) - fileLoop input out13 out20 - #! (isEof, input) - = fend input - | isEof - = (input, out13, out20) - #! (line, input) - = freadline input - | beginsWith "//1.3" line - = oneThree input out13 out20 - | beginsWith "/*2.0" line - = twoZero input out13 out20 - #! out13 - = fwrites line out13 - out20 - = fwrites line out20 - = fileLoop input out13 out20 - oneThree :: !*File !*File !*File -> (!*File, !*File, !*File) - oneThree input out13 out20 - #! (isEof, input) - = fend input - | isEof - = (input, out13, out20) - #! (line, input) - = freadline input - | beginsWith "//3.1" line - = fileLoop input out13 out20 - #! out13 - = fwrites line out13 - = oneThree input out13 out20 - twoZero :: !*File !*File !*File -> (!*File, !*File, !*File) - twoZero input out13 out20 - #! (isEof, input) - = fend input - | isEof - = (input, out13, out20) - #! (line, input) - = freadline input - | beginsWith "0.2*/" line - = fileLoop input out13 out20 - #! out20 - = fwrites line out20 - = twoZero input out13 out20 - beginsWith praefix line - = line % (0, size praefix-1) == praefix - openOutputfile subdir_name filename w - #! (pd_path, w) - = pathToPD_String (RelativePath [PathDown subdir_name, PathDown filename]) w - (ok, file, w) - = fopen pd_path FWriteData w - | not ok - #! w - = appStdio1 (fwrites ("Error:can't open "+++pd_path+++".\n\n")) w - = (ok, file, w) - = (ok, file, w) - -byebye ok io - #! io - = fwrites (if ok "Work done.\n\n" "Couldn't finish work.\n\n") io - io - = fwrites "Push enter to quit" io - (_, io) - = freadline io - = io - -Start w - #! (do_it, w) - = appStdio intro w - | not do_it - = w - #! (ok, w) - = perform w - w - = appStdio1 (byebye ok) w - = w
\ No newline at end of file |