Changeset 963
- Timestamp:
- Jul 6, 2003, 7:03:26 AM (18 years ago)
- Location:
- to-imperative/trunk/compiler
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
to-imperative/trunk/compiler/rfp_as2as.rf
r793 r963 18 18 $func Unstick-Blocks e.Sentence = e.Sentence (e.Fe); 19 19 20 $func Generate-In- Out-Vars (e.in) (e.out) e.branch = (e.in) (e.out) e.branch;20 $func Generate-In-Vars (e.in) e.branch = (e.in) e.branch; 21 21 22 22 // rename variables local for the {}-blocks … … 53 53 <Unstick-Blocks e.branch> :: e.branch t, 54 54 { 55 <Format-Exp e.in> : e.in , <Format-Exp e.out> : e.out=56 <Generate-In- Out-Vars (e.in) (e.out) e.branch>;57 (e.in) (e.out)e.branch;58 } :: (e.in) (e.out)e.branch,55 <Format-Exp e.in> : e.in = 56 <Generate-In-Vars (e.in) e.branch>; 57 (e.in) e.branch; 58 } :: (e.in) e.branch, 59 59 <Rename-Vars 0 (<Vars e.in>) () e.branch> :: e.branch, 60 60 (s.link s.tag t.pragma t.name (e.in) (e.out) (BRANCH t.p e.branch)); … … 114 114 115 115 /* 116 * Generate variable names for input and output function parameters. Change117 * e.Sentence sothat it doesn't begin with pattern.116 * Generate variable names for input function parameters. Change e.Sentence so 117 * that it doesn't begin with pattern. 118 118 */ 119 Generate-In- Out-Vars (e.in) (e.out) e.Sentence, {119 Generate-In-Vars (e.in) e.Sentence, { 120 120 /* 121 121 * If input PAlt of a function is a sentence (not a block), format of … … 136 136 (e.Pe) e.Snt; 137 137 <Gener-Var-Indices 1 (e.in) "arg"> :: e.in-expr s = 138 (e.in ) (RESULT (PRAGMA) e.in-expr) e.Sentence;138 (e.in-expr) (RESULT (PRAGMA) e.in-expr) e.Sentence; 139 139 }; 140 140 /* … … 159 159 } :: (e.br) e.branches, 160 160 e.branches : /*empty*/ = 161 (e.in ) (s.block t.Pragma e.br) e.Snt;161 (e.in-expr) (s.block t.Pragma e.br) e.Snt; 162 162 /* 163 163 * Else sentence already hasn't begun with pattern, so left it as it is. … … 166 166 //! (e.in) e.Sentence; 167 167 } :: (e.in) e.Sentence = 168 // <Gener-Var-Indices 1 (e.out) "res"> :: e.out s, 169 (e.in) (e.out) e.Sentence; 168 (e.in) e.Sentence; 170 169 171 170 /* … … 256 255 Old-Var? e.vars (s.tag t (e.QualifiedName)) = e.vars : e (s.tag t (e.QualifiedName)) e; 257 256 258 Rename s.num (s.tag t.p (e.QualifiedName s.last)), { 259 <Int? s.last> = (s.tag t.p ("renew_" e.QualifiedName s.last s.num)); 260 (s.tag t.p ("ren_" e.QualifiedName s.last s.num)); 261 }; 257 Rename s.num (s.tag t.p (e.QualifiedName)) = 258 (s.tag t.p (e.QualifiedName "_" s.num)); 262 259 263 260 /* -
to-imperative/trunk/compiler/rfp_check.rf
r683 r963 3 3 // $Date$ 4 4 5 $use Access Box CompareStdIO Table;5 $use Access Arithm Box Compare Convert StdIO Table; 6 6 7 7 $use "rfpc"; 8 $use "rfp_err"; 8 9 $use "rfp_compile"; 9 10 $use "rfp_format"; … … 29 30 // returns the maximum (by length) sequence of cuts contained in the argument 30 31 $func? Get-Cuts t.Branch-or-Block = e.cuts-sequence; 32 33 // Print error or warning message 34 $func Print-Error s.warning-or-error? e.description t.pragma = ; 35 36 $func Print-Pragma s.channel t.Pragma = ; 37 38 $func AS-To-Ref e.AS-Expr = e.Refal-Expr; 31 39 32 40 … … 299 307 e.cuts; 300 308 309 310 311 Print-Error s.WE e.Descrip t.Pragma = 312 <? &Error-Counter> : s.n, 313 <Store &Error-Counter <"+" s.n 1>>, 314 <Print-Pragma &StdErr t.Pragma>, 315 <Print! &StdErr " " s.WE " ">, 316 s.WE e.Descrip : { 317 Error! Re = <PrintLN! &StdErr "Wrong format of result expression">; 318 Error! Call = <PrintLN! &StdErr "Wrong argument format in function call">; 319 Error! Pattern = <PrintLN! &StdErr "Wrong format of pattern expression">; 320 Warning! Pattern = <PrintLN! &StdErr "Clash can't be solved">; 321 Error! Var-Re t.var = 322 <PrintLN! &StdErr "Unknown variable '" 323 <AS-To-Ref t.var> "' in result expression">; 324 Error! Var-Hard t.var = 325 <PrintLN! &StdErr "Repeated occurence of the variable '" 326 <AS-To-Ref t.var> "' in hard expression">; 327 Error! Var-Type t.var s.type = 328 <PrintLN! &StdErr "Incorrect type '" <AS-To-Ref s.type> 329 "' of the variable '" <AS-To-Ref t.var> "'">; 330 Error! Cut = <PrintLN! &StdErr "'\\\\!' without corresponding '\\\\?'">; 331 }; 332 333 Print-Pragma s.channel (PRAGMA e.pragmas), 334 e.pragmas : { 335 e (FILE e.file-name) e, <Print! s.channel e.file-name>, $fail; 336 e (LINE s.line s.col) e, <Print! s.channel (s.line ", " s.col)>, $fail; 337 e = <Print! s.channel ":">; 338 }; 339 340 AS-To-Ref { 341 SVAR = 's'; 342 TVAR = 't'; 343 VVAR = 'v'; 344 EVAR = 'e'; 345 (s.tag t (e.name)) = <AS-To-Ref s.tag> '.' <To-Chars e.name>; 346 }; 347 -
to-imperative/trunk/compiler/rfp_compile.rf
r924 r963 4 4 5 5 $use "rfpc"; 6 $use "rfp_err";7 6 $use "rfp_list"; 8 7 $use "rfp_helper"; … … 42 41 43 42 /* 44 * Box for storing names for function input variables45 */46 $box Arg-Vars;47 48 /*49 43 * Box for storing names for function result variables 50 44 */ … … 59 53 $table Labels; 60 54 61 //$box Var-Stack; 62 $table Vars-Tab; 55 /* 56 * Table for storing variables used in place of preprocessor-generated ones. 57 */ 58 $table Prep-Vars; 63 59 64 60 $box Greater-Ineqs; … … 69 65 $func Compile (e.targets) (e.headers) e.Items = e.Compiled-Items (INTERFACE e.headers); 70 66 71 $func Print-Pragma s.channel t.Pragma = ;72 73 $func AS-To-Ref e.AS-Expr = e.Refal-Expr;74 75 67 $func Length-of e.Re = e.length; 76 68 … … 137 129 $func Comp-Calls e.Re = e.calls; 138 130 139 $func Comp-Static-Exprs e.Reult-exprs = e.Result-exprs; 131 $func Prepare-Vars e.vars = e.vars; 132 133 $func Prepare-Res e.Reult-exprs = e.Result-exprs; 140 134 141 135 $func Comp-Assigns e.assignments = e.asail-assignments; … … 233 227 <Store &Greater-Ineqs /*empty*/>, 234 228 <Store &Less-Ineqs /*empty*/>, 235 //! <RFP-Clear-Table &Vars-Tab>,229 <RFP-Clear-Table &Prep-Vars>, 236 230 <Init-Vars>, 237 231 //! <Ref-To-Var e.Sentence> :: e.Sentence, 238 //! <Store-Vars <Vars e.out>> :: e.res-vars,239 232 <Vars <Gener-Vars (e.out) "res">> :: e.res-vars, 240 233 <Vars-Decl e.res-vars> : e, 241 234 <Store &Res-Vars e.res-vars>, 242 235 <Store &Out-Format <Format-Exp e.out>>, 243 <Gener-Vars (e.in) "arg"> :: e.in, 244 <Vars e.in> :: e.arg-vars, 245 <Vars-Decl e.arg-vars> : e, // ??? 236 <Prepare-Res (e.in)> : (e.arg), 237 <Vars e.arg> :: e.arg-vars, 246 238 <Map &Set-Var- (Instantiated? True) (e.arg-vars)> : e, 247 <Store &Arg-Vars e.arg-vars>,248 239 s.tag : { 249 240 FUNC = FATAL; … … 251 242 } :: t.retfail, 252 243 (FUNC t.name (<Vars-Print e.arg-vars>) (<Vars-Print e.res-vars>) 253 <Comp-Sentence Tail ((t.retfail)) (e. in) e.Sentence>244 <Comp-Sentence Tail ((t.retfail)) (e.arg) e.Sentence> 254 245 ) :: e.comp-func, 255 246 * <Set-Drops () <Gener-Var-Names e.comp-func>> :: t e.comp-func, … … 363 354 <Subformat? (e.Fout) (<? &Out-Format>)> = 364 355 <Extract-Calls e.arg> :: (e.last-Re) e.calls, 365 < Comp-Static-Exprs <Split-Re (e.Fin) e.last-Re>> :: e.splited-Re,356 <Prepare-Res <Split-Re (e.Fin) e.last-Re>> :: e.splited-Re, 366 357 <Comp-Calls <R 0 v.fails> e.calls> 367 358 (TAILCALL t.name (e.splited-Re) (<? &Res-Vars>)); … … 372 363 e.Snt : /*empty*/, s.tail? : Tail = 373 364 <Split-Re (<? &Out-Format>) e.last-Re> :: e.splited-Re, 374 < Comp-Static-Exprs e.splited-Re> :: e.splited-Re,365 <Prepare-Res e.splited-Re> :: e.splited-Re, 375 366 e.comp-calls <Comp-Assigns <Zip (<? &Res-Vars>) (e.splited-Re)>>; 376 367 … … 437 428 (FORMAT e.format) = e.format; 438 429 } :: e.expr = 439 < Vars e.expr> :: e.vars,430 <Prepare-Vars <Vars e.expr>> :: e.vars, 440 431 * <New-Vars e.vars>, 441 432 (<Vars-Decl e.vars>) ((Comp If-not-error) t.first) … … 454 445 */ 455 446 { 456 \{ e.source? : v; e.Snt : v; } = ((Comp Source) ) Notail;447 \{ e.source? : v; e.Snt : v; } = ((Comp Source) <R 0 v.fails>) Notail; 457 448 s.tail? : Tail = () Tail; 458 449 () Notail; … … 627 618 628 619 (Comp Error) e.Snt = 629 < Comp-Static-Exprs (e.last-Re)> : (e.Re),620 <Prepare-Res (e.last-Re)> : (e.Re), 630 621 (ERROR e.Re); 631 622 … … 685 676 <Lookup-Func t.name> :: s.linkage s.tag t.pragma (e.Fin) (e.Fout), 686 677 <Extract-Calls e.arg> :: (e.last-Re) e.calls, 687 < Comp-Static-Exprs <Split-Re (e.Fin) e.last-Re>> :: e.splited-Re,678 <Prepare-Res <Split-Re (e.Fin) e.last-Re>> :: e.splited-Re, 688 679 <RFP-Extract-Qualifiers t.name> :: t e.prefix, 689 680 * <Del-Pragmas <Gener-Vars 0 (e.Fout) e.prefix>> : e.Re s, … … 722 713 723 714 715 ********** Preparation of vars and REs for following processing ********** 724 716 *********** Compilation of static parts of result expressions ************ 725 717 … … 731 723 /* 732 724 * Extract static parts from each Re. 733 * Also get the right names of arg-variables, if those are in the expr. 734 * FIXME: the function should be renamed. In something reflecting expression 735 * preparing for following doings. 736 */ 737 Comp-Static-Exprs { 738 (e.Re) e.rest = <Static-Expr? Create e.Re> :: s e.Re, (e.Re) <Comp-Static-Exprs e.rest>; 725 * Also get the right names for variables generated during the preprocessing 726 * stage, if those are in the expr. 727 */ 728 Prepare-Res { 729 (e.Re) e.rest = <Static-Expr? Create e.Re> :: s e.Re, (e.Re) <Prepare-Res e.rest>; 739 730 /*empty*/ = /*empty*/; 740 731 }; 741 742 732 743 733 /* … … 776 766 (PAREN e.Re) = <Static-Expr? Not-Create e.Re> :: static? e.Re, static? (PAREN e.Re); 777 767 (REF t.name) = Static (REF t.name); 778 (s.var-tag ("arg" s.n)) = Dynamic <L <"-" s.n 1> <? &Arg-Vars>>; 779 t.var = Dynamic t.var; 768 t.var = <Prepare-Vars t.var> : t.prep-var, Dynamic t.prep-var; 769 }; 770 771 772 Prepare-Vars { 773 (s.var-tag (e.prefix s.n)) e.rest, <Int? s.n> = 774 { 775 <Lookup &Prep-Vars e.prefix s.n>; 776 <Gener-Vars ((s.var-tag)) e.prefix> :: e.var, 777 // <WriteLN Prep-Var (s.var-tag (e.prefix s.n)) e.var>, 778 <Bind &Prep-Vars (e.prefix s.n) (e.var)>, 779 e.var; 780 } :: e.var, 781 e.var <Prepare-Vars e.rest>; 782 t.var e.rest = t.var <Prepare-Vars e.rest>; 783 /*empty*/ = /*empty*/; 780 784 }; 781 785 … … 787 791 788 792 Comp-Assign-to-Var (t.var (e.Re)) = 789 <Set-Var (Instantiated? True) t.var>,790 793 { 791 794 t.var : e.Re = /*empty*/; 792 <Generated-Var? e.Re> = <Gener-Var-Assign t.var e.Re>; 795 <Generated-Var? e.Re>, # \{ <Get-Var Instantiated? t.var> : True; } = 796 <Gener-Var-Assign t.var e.Re>; 797 <Set-Var (Instantiated? True) t.var>, $fail; 793 798 <Get-Var Decl t.var> : s = (ASSIGN <Vars-Print t.var> e.Re); 794 799 <Vars-Decl t.var> : e, (EXPR <Vars-Print t.var> e.Re); … … 815 820 816 821 Comp-Format (e.last-Re) e.He = 817 < Vars e.He> :: e.vars,818 < Comp-Static-Exprs <Split-Re (<Format-Exp e.He>) e.last-Re>> :: e.splited-Re,822 <Prepare-Vars <Vars e.He>> :: e.vars, 823 <Prepare-Res <Split-Re (<Format-Exp e.He>) e.last-Re>> :: e.splited-Re, 819 824 <Store &Aux-Index 1>, 820 825 <Create-Aux-Vars (e.vars) e.splited-Re> :: e.assigns, … … 1055 1060 * на предмет клешей, в которых они раньше использовались. 1056 1061 */ 1057 < Comp-Static-Exprs (e.Re) (e.Pe)> : (e.R1) (e.P1),1062 <Prepare-Res (e.Re) (e.Pe)> : (e.R1) (e.P1), 1058 1063 <Map &Set-Var- (Clashes /*empty*/) (<Vars e.R1 e.P1>)> : e, 1059 1064 (e.clashes (e.R1) (s.dir e.P1)) e.rest; … … 1944 1949 1945 1950 1946 Print-Error s.WE e.Descrip t.Pragma =1947 <? &Error-Counter> : s.n,1948 <Store &Error-Counter <"+" s.n 1>>,1949 <Print-Pragma &StdErr t.Pragma>,1950 <Print! &StdErr " " s.WE " ">,1951 s.WE e.Descrip : {1952 Error! Re = <PrintLN! &StdErr "Wrong format of result expression">;1953 Error! Call = <PrintLN! &StdErr "Wrong argument format in function call">;1954 Error! Pattern = <PrintLN! &StdErr "Wrong format of pattern expression">;1955 Warning! Pattern = <PrintLN! &StdErr "Clash can't be solved">;1956 Error! Var-Re t.var =1957 <PrintLN! &StdErr "Unknown variable '"1958 <AS-To-Ref t.var> "' in result expression">;1959 Error! Var-Hard t.var =1960 <PrintLN! &StdErr "Repeated occurence of the variable '"1961 <AS-To-Ref t.var> "' in hard expression">;1962 Error! Var-Type t.var s.type =1963 <PrintLN! &StdErr "Incorrect type '" <AS-To-Ref s.type>1964 "' of the variable '" <AS-To-Ref t.var> "'">;1965 Error! Cut = <PrintLN! &StdErr "'\\\\!' without corresponding '\\\\?'">;1966 };1967 1968 Print-Pragma s.channel (PRAGMA e.pragmas),1969 e.pragmas : {1970 e (FILE e.file-name) e, <Print! s.channel e.file-name>, $fail;1971 e (LINE s.line s.col) e, <Print! s.channel (s.line ", " s.col)>, $fail;1972 e = <Print! s.channel ":">;1973 };1974 1975 AS-To-Ref {1976 SVAR = 's';1977 TVAR = 't';1978 VVAR = 'v';1979 EVAR = 'e';1980 (s.tag t (e.name)) = <AS-To-Ref s.tag> '.' <To-Chars e.name>;1981 };1982 1983 1951 Lookup-Func t.Fname, \{ 1984 1952 <Lookup &Fun t.Fname>; -
to-imperative/trunk/compiler/rfp_compile.rfi
r881 r963 18 18 $table Object; 19 19 20 // Print error or warning message21 $func Print-Error s.warning-or-error? e.description t.pragma = ;22 23 20 24 21 -
to-imperative/trunk/compiler/rfp_format.rf
r901 r963 48 48 // (BLOCK e.Branches) = ... 49 49 (PAREN e.Expression) = (PAREN <Format-Exp e.Expression>); 50 (VAR t.name) = <?? t.name Format>;50 (VAR t.name) = $fail; 51 51 (s.VariableTag e) = (s.VariableTag); // s.VariableTag ::= SVAR | TVAR 52 52 } :: e.first-format = // | VVAR | EVAR … … 91 91 <Split-Re (v.Fe <Middle 3 0 <Lookup &Const t.name>>) e.Re>; 92 92 }; 93 ((VVAR)) e.Re = (e.Re); 94 ((EVAR)) e.Re = (e.Re); 93 95 (e.Fe) t.Rt e.Re, <Format-Exp t.Rt> : (REF t.name) = 94 96 <Split-Re (e.Fe) <Middle 3 0 <Lookup &Const t.name>> e.Re>; 95 97 (e.Fe) v.Re t.Rt, <Format-Exp t.Rt> : (REF t.name) = 96 98 <Split-Re (e.Fe) v.Re <Middle 3 0 <Lookup &Const t.name>>>; 97 ((VVAR)) e.Re = (e.Re);98 ((EVAR)) e.Re = (e.Re);99 99 () /*empty*/ = /*empty*/; 100 100 }; -
to-imperative/trunk/compiler/rfp_vars.rf
r924 r963 46 46 47 47 48 49 //! $func Create-Var e = e;50 51 //! New-Vars e.vars = <Map &Create-Var (e.vars)> : e;52 53 //! Create-Var t.var, t.var : {54 //! (SVAR t.name) = <Put &State (t.var (SVAR) (1) (1) Non-Declared Non-Instantiated)>;55 //! (TVAR t.name) = <Put &State (t.var (TVAR) (1) (1) Non-Declared Non-Instantiated)>;56 //! (VVAR t.name) = <Put &State (t.var (VVAR) (1) ( ) Non-Declared Non-Instantiated)>;57 //! (EVAR t.name) = <Put &State (t.var (EVAR) (0) ( ) Non-Declared Non-Instantiated)>;58 //! ( VAR t.name) = <Put &State (t.var (VAR) (0) ( ) Non-Declared Non-Instantiated)>;59 //! };60 48 61 49 $func Normalize-Info e.info t.var = ; … … 216 204 217 205 /* 218 * Convert FORMAT to RESULT expression by giving a name to each format219 * variable. In FORMAT may meet normal variables, they are not changed.220 * Resulting expression is generated without pragmas, so it can't be used in221 * the abstract syntax.222 * Return all variables from generated expression and the expression.223 206 */ 224 207 Gener-Vars (e.format) e.prefix = 225 * <Gener-Var-Indices <Free-Index e.prefix> (e.format) e.prefix> :: e.Re s.max-index,226 * <Set-Index (e.prefix) s.max-index>,227 * <Del-Pragmas e.Re> :: e.Re,228 208 { 229 209 e.format : (s.tag) e.Fe, { … … 238 218 /*empty*/; 239 219 }; 240 * <Vars e.Re> :: e.vars,241 * <New-Vars e.vars>,242 * (e.vars) e.Re;243 220 244 221 Gener-Err-Var = (EVAR <Box 2>); … … 248 225 249 226 227 /* 228 * (s.tag s.box) -- сгенерированная ранее переменная. 229 * Вместо того, чтобы присвоить её значение переменной t.var, мы подставляем 230 * t.var во все места, гда была использована (s.tag s.box). Таким образом, 231 * t.var получит нужное значение в тот момент, когда выполняется присваивание в 232 * (s.tag s.box). 233 * Если переменная t.var уже была ранее декларирована, чтобы избежать повторной 234 * декларации, делаем декларацию для (s.tag s.box) пустой. 235 * Если же переменная t.var -- новая, то её декларацией становится декларация 236 * (s.tag s.box). 237 */ 250 238 Gener-Var-Assign t.var (s.tag s.box) = 251 239 <Store s.box <Print-Var t.var>>, … … 253 241 <Get-Var Decl t.var> : s = 254 242 <Get-Var Decl (s.tag s.box)> : s.decl-box, 255 <Store s.decl-box /*empty*/>;; 243 <Store s.decl-box /*empty*/>; 244 <Set-Var (Decl <Get-Var Decl (s.tag s.box)>) t.var>; 256 245 }; 257 246 … … 330 319 (PAREN expr) <Gener-Var-Indices s.num (e.rest) e.prefix>; 331 320 (s.VariableTag) = 332 ( VAR(PRAGMA) (e.prefix s.num)) :: t.var,321 (s.VariableTag (PRAGMA) (e.prefix s.num)) :: t.var, 333 322 <"+" s.num 1> :: s.num, 334 323 t.var <Gener-Var-Indices s.num (e.rest) e.prefix>;
Note: See TracChangeset
for help on using the changeset viewer.