source: to-imperative/trunk/compiler/src/org/refal/plus/compiler/rfp_src.rf @ 3589

Last change on this file since 3589 was 3589, checked in by yura, 13 years ago
  • Compiler files are moved into package org.refal.plus.compiler.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1$use Apply Arithm Box Class Convert Dir File Java List StdIO Table ;
2
3$use "org.refal.plus.compiler.rfpc";
4$use "org.refal.plus.compiler.rfp_helper";
5
6//$use "org.refal.plus.wrappers.java.io.BufferedReader";
7//$use "org.refal.plus.wrappers.java.io.InputStreamReader";
8//$use "org.refal.plus.wrappers.java.lang.ClassLoader";
9//$use "org.refal.plus.wrappers.org.refal.plus.comp.CompilerEnvironment";
10//$use "org.refal.plus.wrappers.org.refal.plus.comp.FormatReader";
11
12$func BRclose s = ;
13$native BRclose = "void java.io.BufferedReader.close ()";
14
15$func BRreadLine s = s;
16$native BRreadLine = "java.lang.String java.io.BufferedReader.readLine ()";
17
18$func BufferedReader s = s;
19$native BufferedReader = "java.io.BufferedReader (java.io.Reader)";
20
21$func InputStreamReader s = s;
22$native InputStreamReader = "java.io.InputStreamReader (java.io.InputStream)";
23
24$func GetSystemResourceAsStream s = s;
25$native GetSystemResourceAsStream = "static java.io.InputStream java.lang.ClassLoader.getSystemResourceAsStream (java.lang.String)";
26
27$func  Arg_GetImplementationReader t.fileId = (e.qname) (e.inter_reader) (e.implem_reader) ;
28$func? Arg_GetInterfaceReader e.qname = e.reader ;
29//$func  Env_GetImplementationReader t.fileId = (e.qname) (e.inter_reader) (e.implem_reader) ;
30//$func? Env_GetInterfaceReader e.qname = e.reader ;
31
32$box Env Package ;
33
34Reader_GetLine s.srctype s.getline_func (e.name) (e.src) =
35  <Apply s.getline_func e.src>;
36
37Reader_Close s.srctype s.getline_func (e.name) (e.src) =
38  s.srctype :
39  {
40    FILE = e.src : {
41      s.channel, {
42        <IsChannel s.channel> = <CloseChannel s.channel>;
43        <BRclose s.channel>;
44      };
45      /*empty*/;
46    };
47    STDIN = ;
48  };
49
50GetImplementationReader t.fileId =
51//  {
52//    <Get &Env> : s = <Env_GetImplementationReader t.fileId>;
53    = <Arg_GetImplementationReader t.fileId>;
54//  };
55
56GetInterfaceReader e.name =
57//  {
58//    <Get &Env> : s = <Env_GetInterfaceReader e.name>;
59    = <Arg_GetInterfaceReader e.name>;
60//  };
61
62
63$func? Try_Open e.filename = e.source;
64$func? Get_Line_From_File e.source = e.line ;
65$func? Get_Line_From_Reader s.reader = e.line;
66$func? ReadFormatsFromBox e = e.line;
67
68RFP_Src_InitFromArgs e.files =
69  {
70    <Store &Package <Make_Name <Lookup &RFP_Options PACKAGE>>>;
71    <Store &Package>;
72  };
73
74Arg_GetImplementationReader (e.file) =
75  <Get &DirSeparator> : s.dir_separator,
76  e.file : {
77    $r e s.dir_separator e.name '.' e = e.name;
78    $r e.name '.' e = e.name;
79  } :: e.name,
80  <Get &Package> <ToWord e.name> :: e.qname,
81  e.file : $r e.head '.' e,
82  {
83    <Try_Open e.head '.rfi'>;
84    /*empty*/;
85  } :: e.inter_reader,
86  {
87    <Try_Open e.file>;
88    /*empty*/;
89  } :: e.implem_reader,
90  //<WriteLn "Arg_GetImplementationReader: " (e.qname) (e.inter_reader) (e.implem_reader)>,
91  (e.qname) (e.inter_reader) (e.implem_reader);
92
93$box FormatsFromClass;
94
95$func ReadFormatsFromClass s = s;
96$native ReadFormatsFromClass = "static java.lang.String org.refal.plus.comp.FormatReader.ReadFormatsFromClass (java.lang.String)";
97
98$func ReadFormatsFromFile s = s;
99$native ReadFormatsFromFile = "static java.lang.String org.refal.plus.comp.FormatReader.ReadFormatsFromFile (java.lang.String)";
100
101Arg_GetInterfaceReader e.qname =
102  <Store &FormatsFromClass>,
103  <Get &DirSeparator> : s.dir_separator,
104  \{
105    <Intersperse (s.dir_separator) e.qname> :: e.fname,
106      <Get &RFP_Include_Path> : e (e.dirname) e,
107      <Try_Open e.dirname e.fname '.rfi'>;
108    $trap \{
109      <Intersperse ('/') e.qname> '.rfi' :: e.fname \?
110        <GetSystemResourceAsStream <ToWord e.fname>> <Null> : {
111          s.null s.null \! $fail;
112          s.is   s.null = FILE &Get_Line_From_Reader (e.fname) (<BufferedReader <InputStreamReader s.is>>);
113        };
114      <Intersperse (s.dir_separator) e.qname> :: e.fname,
115        <Get &RFP_Include_Path> : e (e.dirname) e \?
116        <ReadFormatsFromFile <ToWord e.dirname e.fname '.class'>> <Null> : {
117          s.null s.null \! $fail;
118          s.str  s.null = <Store &FormatsFromClass <ToChars s.str>>,
119            FILE &ReadFormatsFromBox (e.dirname e.fname '.class') ();
120        };
121      <Intersperse ('/') e.qname> :: e.fname \?
122        <ReadFormatsFromClass <ToWord e.fname>> <Null> : {
123          s.null s.null \! $fail;
124          s.str  s.null = <Store &FormatsFromClass <ToChars s.str>>,
125            FILE &ReadFormatsFromBox (e.fname '.class') ();
126        };
127    }
128    $with \{
129      e "Not available",
130        e.qname : "refal" "plus" e.lib,
131        <Intersperse (s.dir_separator) e.lib> :: e.lib,
132        <Get &RFP_Boot_Path> : e (e.dirname) e,
133        <Try_Open e.dirname e.lib '.rfi'>;
134    };
135  };
136
137Try_Open e.filename =
138  {
139    <IsRFP_Debug>, <PrintLn "Trying to open \'" e.filename "\'">;;
140  },
141  {
142    <IsCaseInsensitive> \?
143      <Get &DirSeparator> : s.dir_separator,
144      {
145        e.filename : $r e.dirname s.dir_separator e.fname = (e.dirname) e.fname;
146        ('.') e.filename;
147      } :: (e.dirname) e.fname,
148      <ToUpper <ToChars e.fname>> :: e.fname,
149      <OpenDir e.dirname> :: s.dir,
150      $iter,
151      {
152        <ReadDir s.dir>;
153        \! $fail;
154      } :: e.filename,
155      <ToUpper e.filename> : e.fname,
156      <Channel> :: s.chl,
157      <OpenFile s.chl e.dirname s.dir_separator e.filename "r">,
158      e.dirname s.dir_separator e.filename s.chl;
159    = <Channel> :: s.chl,
160      <OpenFile s.chl e.filename "r">,
161      e.filename s.chl;
162  } :: e.filename s.chl,
163  {
164    <IsRFP_Debug>, <PrintLn "\'" e.filename "\' successfully opened">;;
165  },
166  FILE &Get_Line_From_File (e.filename) (s.chl);
167
168Get_Line_From_File s.channel =
169  <ReadLineCh s.channel>;
170
171ReadFormatsFromBox e,
172  <Get &FormatsFromClass> : v.formats,
173  <Store &FormatsFromClass>,
174  v.formats;
175
176
177// No more used
178//RFP_Src_InitFromEnv s.env =
179//  <Store &Env s.env>;
180//
181//Env_GetImplementationReader t =
182//  <Get &Env> : s.env,
183//  <GetModuleName s.env> :: s.name,
184//  <Make_Name <ToChars s.name>> :: e.qname,
185//  <GetInterfReader s.env s.name> :: s.reader,
186//  {
187//    <Null> : s.reader = /*empty*/;
188//    FILE &Get_Line_From_Reader (s.name) (<BufferedReader s.reader>);
189//  } :: e.inter_reader,
190//  <GetImplemReader s.env> :: s.reader,
191//  {
192//    <Null> : s.reader = /*empty*/;
193//    FILE &Get_Line_From_Reader (s.name) (<BufferedReader s.reader>);
194//  } :: e.implem_reader,
195//  (e.qname) (e.inter_reader) (e.implem_reader);
196//
197//Env_GetInterfaceReader e.qname =
198//  <Get &Env> : s.env,
199//  <ToWord <Intersperse ('/') e.qname>> :: s.fname,
200//  <GetInterfReader s.env s.fname> :: s.reader,
201//  {
202//    <Null> : s.reader = $fail;
203//    FILE &Get_Line_From_Reader (e.qname) (<BufferedReader s.reader>);
204//  };
205
206Get_Line_From_Reader s.reader =
207  <BRreadLine s.reader> :: s.string,
208  {
209    <Null> : s.string = $fail;
210    <ToChars s.string>;
211  };
212
213
214IsCaseInsensitive = <IsInTable &RFP_Options "CASE-INSENSITIVE">;
215
216WordFirstSymbol = {
217  <IsInTable &RFP_Options "IDENT-COMPATIBILITY"> = '?!';
218  '_';
219};
220
221WordSymbol = {
222  <IsInTable &RFP_Options "IDENT-COMPATIBILITY"> = '?!-';
223  '_.';
224};
225
226VarSymbol = {
227  <IsInTable &RFP_Options "IDENT-COMPATIBILITY"> = '?!-';
228  '_';
229};
230
231
232InitPosition = 0 1;
233
234NextRow s.row s.col =
235  <Arithm.Add s.row 1> 1;
236
237NextColumn s.row s.col =
238  s.row <Arithm.Add s.col 1>;
239
240PositionToChars s.row s.col = <ToChars s.row '-' s.col>;
Note: See TracBrowser for help on using the repository browser.