Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
runtime.h
Go to the documentation of this file.
1 //
2 // Project: Lhogho
3 // File: runtime.c
4 //
5 // Copyright (C) 2007 P.Boytchev
6 //
7 // Revision history:
8 // 2007-06-19 - file created
9 // 2007-06-25 - added rt_plus()
10 // 2007-06-26 - rt_minus(), rt_mul(), rt_div()
11 // 2007-07-04 - rt_cmdchk(), rt_funchk()
12 // 2007-07-31 - rt_make()
13 // 2007-08-01 - rt_local()
14 // 2007-08-05 - rt_makechk()
15 // 2007-08-08 - Added arithmetical and trigonometric primitives
16 // 2007-09-03 - Fixed bug #1787023 ARCTAN and RADARCTAN
17 // 2007-09-14 - Added comparison primitives
18 // 2007-09-17 - Added AND, OR, NOT
19 // 2007-09-18 - rt_output(), rt_stop(), rt_dump()
20 // 2007-09-19 - rt_ignore()
21 // 2007-09-19 - rt_first(), rt_butfirst()
22 // 2007-09-19 - rt_last(), rt_butlast(), rt_item()
23 // 2007-09-23 - rt_parse(), rt_runparse()
24 // 2007-09-26 - rt_wordp(), rt_listp(), rt_numberp(), rt_empty()
25 // 2007-09-27 - rt_memberp()
26 // 2007-09-29 - rt_repeat()
27 // 2007-10-06 - rt_word(), rt_list(), rt_sent(), rt_fput(), rt_lput()
28 // 2007-10-13 - rt_count(), rt_char(), rt_ascii(), rt_upper(), rt_lower(), rt_member()
29 // 2007-10-28 - rt_random(), rt_rerandom(), rt_iseq(), rt_rseq()
30 // 2007-10-28 - rt_type(), rt_show(), rt_form(), rt_format()
31 // 2007-11-04 - rt_while(), rt_until()
32 // 2007-11-05 - support for PRINTDEPTHLIMIT, PRINTWIDTHLIMIT and
33 // FULLPRINTP
34 // 2007-11-06 - rt_dowhile(), rt_dountil()
35 // - rt_definedp(), rt_primitivep(), namep(), procedurep()
36 // - rt_thing()
37 // 2007-11-09 - rt_reference
38 // 2007-11-11 - rt_bye(), rt_wait()
39 // - rt_name()
40 // 2007-11-12 - rt_throw()
41 // 2007-11-16 - rt_catch()
42 // 2007-11-21 - rt_test(), rt_iftrue(), rt_ifelse()
43 // 2007-12-02 - rt_backslashedp()
44 // 2007-12-02 - rt_ashift(), rt_lshift()
45 // - rt_bitand(), rt_bitor(), rt_bitxor(), rt_bitnot()
46 // 2007-12-03 - rt_text()
47 // 2007-12-14 - rt_fulltext()
48 // 2007-12-16 - rt_pick(), rt_remdup(), rt_remove(), rt_reverse(),
49 // - rt_rawascii(), rt_gensym(), rt_substrp()
50 // 2007-12-22 - rt_run()
51 // 2007-12-30 - rt_combine()
52 // 2007-01-05 - rt_runresult()
53 // 2008-03-22 - rt_quoted()
54 // 2008-05-16 - rt_define()
55 // 2008-08-14 - rt_for()
56 // 2008-08-17 - rt_firsts(), rt_butfirsts()
57 // 2008-09-05 - rt_dllload(), rt_libfree()
58 // - rt_packsize(), rt_pack(), rt_unpack()
59 // 2008-09-06 - rt_packaddr(), rt_packto()
60 // 2008-09-09 - rt_external()
61 // 2008-09-18 - rt_internal()
62 // 2008-10-27 - rt_load()
63 // 2008-11-21 - rt_openfile(), rt_closefile(), rt_readpack(), rt_writepack()
64 // 2009-06-03 - rt_readchar(), rt_readchars(), rt_getenv(), rt_getenvs()
65 // 2009-08-03 - rt_readrawline()
66 // 2009-08-04 - rt_readword(), rt_readlist()
67 // 2010-06-25 - rt_eofp()
68 // 2011-10-14 - rt_runmacro()
69 // 2011-12-26 - rt_substring()
70 // 2012-01-19 - rt_currentfolder(), rt_makefolder()
71 // 2012-01-20 - rt_erasefolder(), rt_folderp(), rt_renamefolder()
72 // 2012-01-21 - rt_folders(), rt_changefolder()
73 // 2012-01-23 - rt_files(), rt_erasefile(), rt_file(), rt_renamefile()
74 // rt_filesize(), rt_filetimes(), rt_formattime()
75 // 2012-01-24 - rt_openread(), rt_openwrite(), rt_openappend(),
76 // rt_openupdate(), rt_setread(), rt_setwrite()
77 // 2012-01-25 - init_runtime(), finit_runtime, rt_reader(), rt_writer()
78 // rt_allopen()
79 // 2012-01-27 - rt_closeall(), rt_readpos(), rt_setreadpos(), rt_writepos(),
80 // rt_setwritepos()
81 // 2012-01-31 - rt_timezone()
82 // 2012-02-04 - adding mode to file open functions
83 // 2012-02-05 - rt_readinblock()
84 // 2012-02-09 - rt_dribble(), rt_nodribble()
85 //
86 //
87 // This program is free software; you can redistribute it and/or modify
88 // it under the terms of the GNU General Public License as published by
89 // the Free Software Foundation; either version 2 of the License, or
90 // (at your option) any later version.
91 //
92 // This program is distributed in the hope that it will be useful,
93 // but WITHOUT ANY WARRANTY; without even the implied warranty of
94 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95 // GNU General Public License for more details.
96 //
97 // You should have received a copy of the GNU General Public License
98 // along with this program; if not, write to the Free Software
99 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
100 //
101 
102 
103 #ifndef LHOGHO_RUNTIME_H
104 #define LHOGHO_RUNTIME_H
105 
106 #include "globals.h"
107 #include "atoms.h"
108 
109 
110 #define RETURN(a) \
111  { atom_t _res_ = (a); \
112  __asm__( " " ); \
113  return (_res_); \
114  }
115 
116 #define GET_FLOAT(a,b) \
117 { \
118  if( IS_ERROR(a) ) \
119  RETURN( use(a) ); \
120  if( !atom_to_float( a, &b ) ) \
121  RETURN( new_error( ERROR_NOT_A_NUMBER, unbound ) ) \
122 }
123 
124 
125 
126 #define GET_INT(a,b) \
127 { \
128  if (IS_ERROR(a)) \
129  RETURN(use(a)); \
130  if (IS_INTEGER(a)) \
131  b = INTEGER(a); \
132  else \
133  if (!atom_to_int(a, &b)) \
134  RETURN(new_error(ERROR_NOT_AN_INTEGER, unbound)) \
135 }
137 
138 #define GET_BOOLEAN(a, b) \
139 { \
140  if (IS_ERROR(a)) RETURN(use(a)); \
141  if (a == false_true[0]) b = 0; \
142  else if (a == false_true[0]) b = 1; \
143  if (!atom_to_boolean(a, &b)) \
144  RETURN(new_error(ERROR_BOOLEAN_EXPECTED, unbound)) \
145 }
146 
147 
148 
149 #define FASTRUNTIME(X) extern atom_t X __attribute__((used,noinline,regparm(0),stdcall))
150 
151 FASTRUNTIME( rt_cmdchk ( atom_t source, atom_t data ) );
152 FASTRUNTIME( rt_funchk ( atom_t source, atom_t data ) );
153 FASTRUNTIME( rt_exprchk ( atom_t source, atom_t data ) );
154 FASTRUNTIME( rt_repchk ( atom_t source, atom_t data ) );
155 FASTRUNTIME( rt_whlchk ( atom_t source, atom_t data ) );
156 FASTRUNTIME( rt_makechk ( atom_t source, atom_t data ) );
157 FASTRUNTIME( rt_boolchk ( atom_t source, atom_t data ) );
158 FASTRUNTIME( rt_dump ( atom_t source ) );
159 FASTRUNTIME( rt_predump ( atom_t source ) );
160 FASTRUNTIME( rt_catchchk ( int status, atom_t tag, atom_t data ) );
161 //FASTRUNTIME( rt_catchchk ( atom_t tag, atom_t data ) );
162 FASTRUNTIME( rt_forchk ( atom_t source, atom_t* step_var, atom_t step, atom_t to, atom_t from ) );
163 FASTRUNTIME( rt_check_inputs( int stack_frame ) );
164 
165 
166 
167 #define RUNTIME(X) extern atom_t X __attribute__((used,noinline,regparm(0),cdecl))
168 
169 RUNTIME( rt_print (atom_t pdl, atom_t pwl, atom_t fpp, int data));
170 RUNTIME( rt_plus (int count, atom_t data2, atom_t data1));
171 RUNTIME( rt_minus (int count, atom_t data2, atom_t data1));
172 RUNTIME( rt_div (atom_t data2, atom_t data1));
173 RUNTIME( rt_mul (atom_t data2, atom_t data1));
174 RUNTIME( rt_sum (int data));
176 RUNTIME( rt_unminus (atom_t data));
177 RUNTIME( rt_product (int data));
178 RUNTIME( rt_remainder (atom_t data2, atom_t data1));
179 RUNTIME( rt_int (atom_t data));
180 RUNTIME( rt_round (atom_t data));
181 RUNTIME( rt_sqrt (atom_t data));
182 RUNTIME( rt_power (atom_t power, atom_t base));
183 RUNTIME( rt_exp (atom_t power));
184 RUNTIME( rt_log10 (atom_t data));
185 RUNTIME( rt_ln (atom_t data));
186 RUNTIME( rt_abs (atom_t data));
187 RUNTIME( rt_pi (void));
188 RUNTIME( rt_sin (atom_t data));
189 RUNTIME( rt_radsin (atom_t data));
190 RUNTIME( rt_cos (atom_t data));
191 RUNTIME( rt_radcos (atom_t data));
192 RUNTIME( rt_arctan (int count, atom_t data2, atom_t data1));
193 RUNTIME( rt_radarctan (int count, atom_t data2, atom_t data1));
194 RUNTIME( rt_equal (atom_t cip, atom_t data2, atom_t data1));
195 RUNTIME( rt_nequal (atom_t cip, atom_t data2, atom_t data1));
196 RUNTIME( rt_less (atom_t data2, atom_t data1));
197 RUNTIME( rt_more (atom_t data2, atom_t data1));
198 RUNTIME( rt_lesseq (atom_t data2, atom_t data1));
199 RUNTIME( rt_moreeq (atom_t data2, atom_t data1));
200 RUNTIME( rt_before (atom_t cip, atom_t data2, atom_t data1));
201 RUNTIME( rt_and (int count));
202 RUNTIME( rt_or (int count));
203 RUNTIME( rt_not (atom_t data));
204 RUNTIME( rt_first (atom_t data));
205 RUNTIME( rt_butfirst (atom_t data));
206 RUNTIME( rt_firsts (atom_t data));
207 RUNTIME( rt_butfirsts (atom_t data));
208 RUNTIME( rt_last (atom_t data));
209 RUNTIME( rt_butlast (atom_t data));
210 RUNTIME( rt_item (atom_t data, atom_t index));
211 RUNTIME( rt_wordp (atom_t data));
212 RUNTIME( rt_listp (atom_t data));
213 RUNTIME( rt_numberp (atom_t data));
214 RUNTIME( rt_empty (atom_t data));
215 RUNTIME( rt_memberp (atom_t cip, atom_t data, atom_t elem));
216 RUNTIME( rt_word (int data));
217 RUNTIME( rt_list (int data));
218 RUNTIME( rt_sent (int data));
219 RUNTIME( rt_fput (atom_t data2, atom_t data1));
220 RUNTIME( rt_lput (atom_t data2, atom_t data1));
221 RUNTIME( rt_count (atom_t data));
222 RUNTIME( rt_char (atom_t data));
223 RUNTIME( rt_ascii (atom_t data));
224 RUNTIME( rt_lower (atom_t data));
225 RUNTIME( rt_upper (atom_t data));
226 RUNTIME( rt_member (atom_t cip, atom_t elem, atom_t data));
227 RUNTIME( rt_iseq (atom_t to, atom_t from));
228 RUNTIME( rt_rseq (atom_t count, atom_t to, atom_t from));
229 RUNTIME( rt_random (int count, atom_t data2, atom_t data1));
230 RUNTIME( rt_rerandom(int count, atom_t seed));
231 RUNTIME( rt_show (atom_t pdl, atom_t pwl, atom_t fpp, int data));
232 RUNTIME( rt_type (atom_t pdl, atom_t pwl, atom_t fpp, int data));
233 RUNTIME( rt_form (atom_t precision, atom_t width, atom_t num));
234 RUNTIME( rt_format (atom_t format, atom_t data));
235 RUNTIME( rt_formattime (atom_t format, atom_t data));
236 RUNTIME( rt_timezone ( ));
237 RUNTIME( rt_bye (void));
238 RUNTIME( rt_wait (atom_t time));
239 RUNTIME( rt_ashift (atom_t bits, atom_t num));
240 RUNTIME( rt_lshift (atom_t bits, atom_t num));
241 RUNTIME( rt_bitand (int data));
242 RUNTIME( rt_bitor (int data));
243 RUNTIME( rt_bitxor (int data));
244 RUNTIME( rt_bitnot (atom_t data));
245 
246 
247 
248 RUNTIME( rt_if ( int count ) );
249 RUNTIME( rt_repeat ( atom_t repcount, atom_t commands ) );
250 RUNTIME( rt_while ( atom_t condition, atom_t commands ) );
251 RUNTIME( rt_until ( atom_t condition, atom_t commands ) );
252 RUNTIME( rt_dowhile ( atom_t commands, atom_t condition ) );
253 RUNTIME( rt_dountil ( atom_t commands, atom_t condition ) );
254 RUNTIME( rt_repcount ( int repcount ) );
255 RUNTIME( rt_forever ( atom_t commands ) );
256 RUNTIME( rt_make ( int static_link, atom_t parent, atom_t value, atom_t name ) );
257 RUNTIME( rt_name ( int static_link, atom_t parent, atom_t value, atom_t name ) );
258 RUNTIME( rt_local ( int static_link, atom_t parent, int data ) );
259 RUNTIME( rt_output ( atom_t data ) );
260 RUNTIME( rt_maybeoutput ( atom_t data ) );
261 RUNTIME( rt_stop ( ) );
262 RUNTIME( rt_ignore ( atom_t data ) );
263 RUNTIME( rt_for ( atom_t body, atom_t limits, atom_t var ) );
264 
265 RUNTIME( rt_parse (atom_t data) );
266 RUNTIME( rt_runparse (atom_t data) );
267 
268 RUNTIME( rt_definedp ( int static_link, atom_t parent, atom_t data ) );
269 RUNTIME( rt_primitivep ( int static_link, atom_t parent, atom_t data ) );
270 RUNTIME( rt_namep ( int static_link, atom_t parent, atom_t data ) );
271 RUNTIME( rt_procedurep ( int static_link, atom_t parent, atom_t data ) );
272 RUNTIME( rt_thing ( int static_link, atom_t parent, atom_t data ) );
273 RUNTIME( rt_reference ( int static_link, atom_t parent, atom_t data ) );
274 RUNTIME( rt_text ( int static_link, atom_t parent, atom_t data ) );
275 RUNTIME( rt_fulltext ( int static_link, atom_t parent, atom_t data ) );
276 RUNTIME( rt_run ( int static_link, atom_t parent, atom_t data, int mode ) );
277 RUNTIME( rt_runresult ( int static_link, atom_t parent, atom_t data ) );
278 RUNTIME( rt_runmacro ( int static_link, atom_t parent, atom_t data, int mode ) );
279 RUNTIME( rt_define ( int static_link, atom_t parent, atom_t value, atom_t name ) );
280 RUNTIME( rt_load ( atom_t data ) );
281 RUNTIME( rt_commandline ( ) );
282 
283 RUNTIME( rt_throw ( int count, atom_t value, atom_t tag ) );
284 RUNTIME( rt_catch ( atom_t commands, atom_t tag ) );
285 RUNTIME( rt_error ( ) );
286 
287 RUNTIME( rt_tag ( ) );
288 RUNTIME( rt_goto ( int static_link, atom_t parent, atom_t data, atom_t source ) );
289 
290 RUNTIME( rt_test ( atom_t condition, int frame ) );
291 RUNTIME( rt_iftrue ( atom_t commands ) );
292 RUNTIME( rt_iffalse ( atom_t commands ) );
293 
294 RUNTIME( rt_backslashedp ( atom_t data ) );
295 
296 RUNTIME( rt_pick (atom_t list) );
297 RUNTIME( rt_remdup (atom_t cip, atom_t list) );
298 RUNTIME( rt_remove (atom_t cip, atom_t data, atom_t elem) );
299 RUNTIME( rt_reverse (atom_t list) );
300 RUNTIME( rt_rawascii (atom_t data) );
301 RUNTIME( rt_gensym() );
302 RUNTIME( rt_combine (atom_t data2, atom_t data1));
303 RUNTIME( rt_quoted (atom_t data));
304 RUNTIME( rt_substringp (atom_t cip, atom_t data2, atom_t data1));
305 RUNTIME( rt_substring (atom_t cip, atom_t data2, atom_t data1));
306 
307 RUNTIME( rt_libload (atom_t data));
308 RUNTIME( rt_libfree (atom_t data));
309 RUNTIME( rt_blocksize (int static_link, atom_t parent, atom_t prototype));
310 RUNTIME( rt_listtoblock (int static_link, atom_t parent, atom_t prototype, atom_t data));
311 RUNTIME( rt_blocktolist (int static_link, atom_t parent, atom_t prototype, atom_t data));
312 RUNTIME( rt_dataaddr (atom_t data));
313 RUNTIME( rt_listintoblock (int static_link, atom_t parent, atom_t prototype, atom_t dest, atom_t data));
314 RUNTIME( rt_funcaddr( int static_link, atom_t parent, atom_t data ));
315 
316 RUNTIME( rt_openfile (atom_t mode, atom_t filename, int call_mode));
317 RUNTIME( rt_closefile (atom_t handle));
318 RUNTIME( rt_readblock (int static_link, atom_t parent, atom_t size));
319 RUNTIME( rt_readinblock (atom_t block, int call_mode));
320 RUNTIME( rt_writeblock (atom_t data));
321 
322 RUNTIME( rt_external (int static_link, atom_t parent, atom_t handle, atom_t prototype, atom_t name));
323 RUNTIME( rt_internal (int static_link, atom_t parent, atom_t prototype, atom_t name));
324 RUNTIME( rt_int3 ());
325 RUNTIME( rt_stackframe (int static_link, atom_t parent, atom_t offset, atom_t frame));
326 RUNTIME( rt_stackframeatom (int static_link, atom_t parent, atom_t offset, atom_t frame));
327 
328 RUNTIME( rt_readchar (void));
329 RUNTIME( rt_readchars (atom_t data));
330 RUNTIME( rt_readrawline (void));
331 RUNTIME( rt_readword (void));
332 RUNTIME( rt_readlist (void));
333 
334 RUNTIME( rt_getenv (atom_t data));
335 RUNTIME( rt_getenvs ( ));
336 RUNTIME( rt_eofp ( ));
337 
339 RUNTIME( rt_makefolder (atom_t name));
340 RUNTIME( rt_erasefolder (atom_t name));
341 RUNTIME( rt_folderp (atom_t name));
342 RUNTIME( rt_renamefolder (atom_t toname, atom_t fromname));
343 RUNTIME( rt_folders (atom_t name));
345 RUNTIME( rt_files (atom_t name));
346 RUNTIME( rt_erasefile (atom_t name));
347 RUNTIME( rt_filep (atom_t name));
348 RUNTIME( rt_renamefile (atom_t toname, atom_t fromname));
349 RUNTIME( rt_filesize (atom_t name));
350 RUNTIME( rt_filetimes (atom_t name));
351 RUNTIME( rt_openread (atom_t name, int call_mode));
352 RUNTIME( rt_openwrite (atom_t name, int call_mode));
353 RUNTIME( rt_openappend (atom_t name, int call_mode));
354 RUNTIME( rt_openupdate (atom_t name, int call_mode));
355 RUNTIME( rt_setread (atom_t file));
356 RUNTIME( rt_setwrite (atom_t file));
357 RUNTIME( rt_reader ( ));
358 RUNTIME( rt_writer ( ));
359 RUNTIME( rt_allopen ( ));
360 RUNTIME( rt_closeall ( ));
361 RUNTIME( rt_readpos ( ));
363 RUNTIME( rt_writepos ( ));
365 RUNTIME( rt_dribble (atom_t file));
366 RUNTIME( rt_nodribble ( ));
367 
368 
369 extern atom_t __attribute__((used,noinline,regparm(0),stdcall)) rt_use_var( atom_t source, atom_t value );
370 extern atom_t rt_var_value( int static_link, atom_t parent, atom_t var );
371 
372 extern void __attribute__ ((used,noinline,regparm(0),stdcall)) rt_repeat_enter( int frame, int count );
373 extern atom_t __attribute__ ((used,noinline,regparm(0),stdcall)) rt_repeat_exit( int frame );
374 extern void __attribute__ ((used,noinline,regparm(0),stdcall)) rt_forever_enter( int frame );
375 extern atom_t __attribute__ ((used,noinline,regparm(0),stdcall)) rt_runresult_fix( atom_t data );
376 
377 extern void init_runtime( );
378 extern void finit_runtime( );
379 
380 #endif //LHOGHO_RUNTIME_H

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013