source: to-imperative/trunk/runtime/rf_core.cc @ 994

Last change on this file since 994 was 994, checked in by pooh, 18 years ago
  • Fixed includes problems.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1//
2// Copyright (C) 2000 Refal+ Development Group
3//
4// Refal+ is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// Refal+ is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Refal+; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17//
18// $Source$
19// $Revision: 994 $
20// $Date: 2003-07-09 16:11:22 +0000 (Wed, 09 Jul 2003) $
21// Author: Andrey Slepuhin <pooh@msu.ru>
22
23#include "rf_core.hh"
24#include "rf_types.ih"
25#include "pxx_default_allocator.ih"
26
27#include <time.h>
28#include <stdlib.h>
29#include <locale.h>
30
31namespace pxx {
32  extern void terminate_handler () ;
33}
34
35namespace rfrt
36{
37
38using namespace rftype;
39
40void terminate_handler ()
41{
42  try {
43    throw;
44  } catch (Expr& _expr) {
45    _expr.writeln(stderr);
46  } catch (...) {
47    pxx::terminate_handler();
48  }
49}
50
51class Init
52{
53
54public:
55
56  pxx::HeapAllocator allocator ;
57
58  Init () :
59    allocator (pxx::page_size, default_heap_size, heap_start)
60  {
61    default_allocator.set(allocator);
62    char* s = getenv("LANG");
63    if (s != null) setlocale(LC_ALL, s);
64    s = getenv("LC_CTYPE");
65    if (s != null) setlocale(LC_CTYPE, s);
66    s = getenv("LC_ALL");
67    if (s != null) setlocale(LC_ALL, s);
68    std::set_terminate(terminate_handler);
69  }
70
71  ~Init ()
72  {
73    #if DEBUG
74    printf("Concatenation statistics:\n");
75    printf("- no copy:       %"PRIuPTR"\n", empty_copy);
76    printf("- left copy:     %"PRIuPTR"\n", lt_copy);
77    printf("- right copy:    %"PRIuPTR"\n", rt_copy);
78    printf("- both copy:     %"PRIuPTR"\n", both_copy);
79    printf("- unifications:  %"PRIuPTR"\n", unifications);
80    printf("- identical:     %"PRIuPTR"\n", identical);
81    #if PARANOIA
82    allocator.memory_dump();
83    #endif // PARANOIA
84    #endif // DEBUG
85  }
86
87};
88
89Init init /* __attribute__ ((init_priority (600))) */ ;
90
91pxx::HeapAllocator& allocator = init.allocator ;
92
93TypeRegister rftype::Term::ref_reg(&Term::ref_funcs, type_ref) ;
94TypeRegister rftype::ObjectRef::reg(&ObjectRef::funcs, type_object) ;
95TypeRegister rftype::Char::reg(&Char::funcs, type_char) ;
96TypeRegister rftype::ShortInt::reg(&ShortInt::funcs, type_short_int) ;
97TypeRegister rftype::Integer::reg(&Integer::funcs, type_integer) ;
98TypeRegister rftype::Word::reg(&Word::funcs, type_word) ;
99
100ObjectRegister rftype::Box::reg(type_box) ;
101ObjectRegister rftype::Vector::reg(type_vector) ;
102ObjectRegister rftype::Channel::reg(type_channel) ;
103ObjectRegister rftype::String::reg(type_string) ;
104ObjectRegister rftype::Table::reg(type_table) ;
105
106const Expr empty;
107
108RetVal (*entry) () = null ;
109
110}
111
112using namespace rfrt;
113
114int main ()
115{
116  double start = clock ();
117  Expr res;
118  RF_CALL ((*rfrt::entry), (), (res));
119  printf ("Time elapsed: %.2fs\n", (clock () - start) / CLOCKS_PER_SEC);
120  return 0;
121}
122
Note: See TracBrowser for help on using the repository browser.