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

Last change on this file since 1010 was 1010, checked in by pooh, 18 years ago
  • More work on long arithmetic.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 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: 1010 $
20// $Date: 2003-07-15 12:12:14 +0000 (Tue, 15 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#include <gmp.h>
31
32namespace pxx {
33  extern void terminate_handler () ;
34}
35
36namespace rfrt
37{
38
39using namespace rftype;
40
41void terminate_handler ()
42{
43  try {
44    throw;
45  } catch (Expr& _expr) {
46    _expr.writeln(stderr);
47  } catch (...) {
48    pxx::terminate_handler();
49  }
50}
51
52class Init
53{
54
55public:
56
57  pxx::HeapAllocator allocator ;
58  pxx::ChunkAllocator<mpz_t> *mpz_allocator;
59
60  Init () :
61    allocator (pxx::page_size, default_heap_size, heap_start)
62  {
63    default_allocator.set(allocator);
64    char* s = getenv("LANG");
65    if (s != null) setlocale(LC_ALL, s);
66    s = getenv("LC_CTYPE");
67    if (s != null) setlocale(LC_CTYPE, s);
68    s = getenv("LC_ALL");
69    if (s != null) setlocale(LC_ALL, s);
70    std::set_terminate(terminate_handler);
71    mpz_allocator = new pxx::ChunkAllocator<mpz_t>(allocator);
72  }
73
74  ~Init ()
75  {
76    #if DEBUG
77    printf("Concatenation statistics:\n");
78    printf("- no copy:       %"PRIuPTR"\n", empty_copy);
79    printf("- left copy:     %"PRIuPTR"\n", lt_copy);
80    printf("- right copy:    %"PRIuPTR"\n", rt_copy);
81    printf("- both copy:     %"PRIuPTR"\n", both_copy);
82    printf("- unifications:  %"PRIuPTR"\n", unifications);
83    printf("- identical:     %"PRIuPTR"\n", identical);
84    #if PARANOIA
85    delete mpz_allocator;
86    allocator.memory_dump();
87    #endif // PARANOIA
88    #endif // DEBUG
89  }
90
91};
92
93Init init /* __attribute__ ((init_priority (600))) */ ;
94
95pxx::HeapAllocator& allocator = init.allocator ;
96pxx::ChunkAllocator<mpz_t>& mpz_allocator = *init.mpz_allocator;
97
98TypeRegister rftype::Term::ref_reg(&Term::ref_funcs, type_ref) ;
99TypeRegister rftype::ObjectRef::reg(&ObjectRef::funcs, type_object) ;
100TypeRegister rftype::Char::reg(&Char::funcs, type_char) ;
101TypeRegister rftype::ShortInt::reg(&ShortInt::funcs, type_short_int) ;
102TypeRegister rftype::Integer::reg(&Integer::funcs, type_int) ;
103TypeRegister rftype::Word::reg(&Word::funcs, type_word) ;
104
105ObjectRegister rftype::Box::reg(type_box) ;
106ObjectRegister rftype::Vector::reg(type_vector) ;
107ObjectRegister rftype::Channel::reg(type_channel) ;
108ObjectRegister rftype::String::reg(type_string) ;
109ObjectRegister rftype::Table::reg(type_table) ;
110
111const Expr empty;
112
113RetVal (*entry) () = null ;
114
115}
116
117using namespace rfrt;
118
119int main ()
120{
121  double start = clock ();
122  Expr res;
123  RF_CALL ((*rfrt::entry), (), (res));
124  printf ("Time elapsed: %.2fs\n", (clock () - start) / CLOCKS_PER_SEC);
125  return 0;
126}
127
Note: See TracBrowser for help on using the repository browser.