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: 1066 $ |
---|
20 | // $Date: 2003-07-30 08:29:01 +0000 (Wed, 30 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 | |
---|
32 | namespace pxx { |
---|
33 | extern void terminate_handler () ; |
---|
34 | } |
---|
35 | |
---|
36 | namespace rfrt |
---|
37 | { |
---|
38 | |
---|
39 | using namespace rftype; |
---|
40 | |
---|
41 | void terminate_handler () |
---|
42 | { |
---|
43 | try { |
---|
44 | throw; |
---|
45 | } catch (Expr& _expr) { |
---|
46 | _expr.writeln(stderr); |
---|
47 | } catch (...) { |
---|
48 | pxx::terminate_handler(); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | class Init |
---|
53 | { |
---|
54 | |
---|
55 | public: |
---|
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 | |
---|
93 | Init init /* __attribute__ ((init_priority (600))) */ ; |
---|
94 | |
---|
95 | pxx::HeapAllocator& allocator = init.allocator ; |
---|
96 | pxx::ChunkAllocator<mpz_t>& mpz_allocator = *init.mpz_allocator; |
---|
97 | |
---|
98 | TypeRegister rftype::Term::ref_reg(&Term::ref_funcs, type_ref) ; |
---|
99 | TypeRegister rftype::ObjectRef::reg(&ObjectRef::funcs, type_object) ; |
---|
100 | TypeRegister rftype::Char::reg(&Char::funcs, type_char) ; |
---|
101 | TypeRegister rftype::ShortInt::reg(&ShortInt::funcs, type_short_int) ; |
---|
102 | TypeRegister rftype::Integer::reg(&Integer::funcs, type_int) ; |
---|
103 | TypeRegister rftype::Word::reg(&Word::funcs, type_word) ; |
---|
104 | TypeRegister rftype::Func::reg(&Func::funcs, type_func) ; |
---|
105 | |
---|
106 | ObjectRegister rftype::Box::reg(type_box) ; |
---|
107 | ObjectRegister rftype::Vector::reg(type_vector) ; |
---|
108 | ObjectRegister rftype::Channel::reg(type_channel) ; |
---|
109 | ObjectRegister rftype::String::reg(type_string) ; |
---|
110 | ObjectRegister rftype::Table::reg(type_table) ; |
---|
111 | |
---|
112 | const Expr empty; |
---|
113 | |
---|
114 | RetVal (*entry) () = null ; |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | using namespace rfrt; |
---|
119 | |
---|
120 | int main () |
---|
121 | { |
---|
122 | double start = clock (); |
---|
123 | Expr res; |
---|
124 | RF_CALL ((*rfrt::entry), (), (res)); |
---|
125 | printf ("Time elapsed: %.2fs\n", (clock () - start) / CLOCKS_PER_SEC); |
---|
126 | return 0; |
---|
127 | } |
---|
128 | |
---|