~crack-team/crack-lang/trunk

« back to all changes in this revision

Viewing changes to runtime/Time.cc

  • Committer: mmuller@enduden.com
  • Date: 2013-10-07 21:07:57 UTC
  • Revision ID: git-v1:97522bbf70b1689242ececf9f33fd2e53f76b8df
Tags: rel-0.8
Fixed getSeconds() test failure on 32-bit systems.
Updated Time.crk with changes that had been manually inserted into Time.cc and
regenerated Time.cc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 Google Inc.
2
 
// Copyright 2011 Conrad Steenberg <conrad.steenberg@gmail.com>
3
 
// 
4
 
//   This Source Code Form is subject to the terms of the Mozilla Public
5
 
//   License, v. 2.0. If a copy of the MPL was not distributed with this
6
 
//   file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
 
// 
8
1
#include <stdlib.h>
9
2
#include <unistd.h>
10
3
#include <time.h>
24
17
   return (InternalDate *)calloc(1, sizeof(InternalDate));
25
18
}
26
19
 
 
20
int64_t crk_getSeconds(InternalDate *d) {
 
21
   // have to wrap this to correctly convert from time_t to int64.
 
22
   return mktime(d);
 
23
}
 
24
 
27
25
InternalDate *crk_localtime(InternalDate *d, int64_t t){
28
26
   const time_t lt = (const time_t)t;
29
27
   return localtime_r(&lt, d);
90
88
    crack::ext::Type *type_bool = mod->getBoolType();
91
89
    crack::ext::Type *type_byteptr = mod->getByteptrType();
92
90
    crack::ext::Type *type_byte = mod->getByteType();
 
91
    crack::ext::Type *type_int16 = mod->getInt16Type();
93
92
    crack::ext::Type *type_int32 = mod->getInt32Type();
94
93
    crack::ext::Type *type_int64 = mod->getInt64Type();
 
94
    crack::ext::Type *type_uint16 = mod->getUint16Type();
95
95
    crack::ext::Type *type_uint32 = mod->getUint32Type();
96
96
    crack::ext::Type *type_uint64 = mod->getUint64Type();
97
97
    crack::ext::Type *type_int = mod->getIntType();
126
126
        type_InternalDate->addInstVar(type_byteptr, "tm_zone",
127
127
                                CRACK_OFFSET(InternalDate, tm_zone));
128
128
        f = type_InternalDate->addConstructor("init",
129
 
                        (void *)crk_create_date
130
 
                );
131
 
 
132
 
        f = type_InternalDate->addMethod(type_int64, "getSeconds",
133
 
                        (void *)mktime
134
 
                );
135
 
 
136
 
        f = type_InternalDate->addMethod(type_void, "setLocalSeconds",
137
 
                        (void *)crk_localtime
138
 
                );
139
 
            f->addArg(type_int64, "t");
140
 
 
141
 
        f = type_InternalDate->addMethod(type_void, "setLocalNow",
142
 
                        (void *)crk_localtime_now
143
 
                );
144
 
 
145
 
        f = type_InternalDate->addMethod(type_void, "setUTCSeconds",
146
 
                        (void *)crk_gmtime
147
 
                );
148
 
            f->addArg(type_int64, "t");
149
 
 
150
 
        f = type_InternalDate->addMethod(type_void, "setUTCNow",
151
 
                        (void *)crk_gmtime_now
152
 
                );
153
 
 
154
 
        f = type_InternalDate->addMethod(type_void, "setEpoch",
155
 
                        (void *)crk_epoch
156
 
                );
157
 
 
158
 
        f = type_InternalDate->addMethod(type_void, "_toBufferRaw",
159
 
                        (void *)asctime_r
160
 
                );
161
 
            f->addArg(type_byteptr, "buf");
 
129
                            (void *)crk_create_date
 
130
                        );
 
131
 
 
132
 
 
133
    f = type_InternalDate->addMethod(
 
134
        type_int64, 
 
135
        "getSeconds",
 
136
        (void *)crk_getSeconds
 
137
    );
 
138
 
 
139
 
 
140
    f = type_InternalDate->addMethod(
 
141
        type_void, 
 
142
        "setLocalSeconds",
 
143
        (void *)crk_localtime
 
144
    );
 
145
    f->addArg(type_int64, 
 
146
              "t"
 
147
              );
 
148
 
 
149
 
 
150
    f = type_InternalDate->addMethod(
 
151
        type_void, 
 
152
        "setLocalNow",
 
153
        (void *)crk_localtime_now
 
154
    );
 
155
 
 
156
 
 
157
    f = type_InternalDate->addMethod(
 
158
        type_void, 
 
159
        "setUTCSeconds",
 
160
        (void *)crk_gmtime
 
161
    );
 
162
    f->addArg(type_int64, 
 
163
              "t"
 
164
              );
 
165
 
 
166
 
 
167
    f = type_InternalDate->addMethod(
 
168
        type_void, 
 
169
        "setUTCNow",
 
170
        (void *)crk_gmtime_now
 
171
    );
 
172
 
 
173
 
 
174
    f = type_InternalDate->addMethod(
 
175
        type_void, 
 
176
        "setEpoch",
 
177
        (void *)crk_epoch
 
178
    );
 
179
 
 
180
 
 
181
    f = type_InternalDate->addMethod(
 
182
        type_void, 
 
183
        "_toBufferRaw",
 
184
        (void *)asctime_r
 
185
    );
 
186
    f->addArg(type_byteptr, 
 
187
              "buf"
 
188
              );
162
189
 
163
190
    type_InternalDate->finish();
164
191