Skip to content

Commit 45534b5

Browse files
committed
time: move pure V function from time.c.v
1 parent f2cda1a commit 45534b5

File tree

6 files changed

+187
-158
lines changed

6 files changed

+187
-158
lines changed

ROADMAP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [ ] parallel parser
1717
- [ ] parallel checker
1818
- [x] parallel cgen
19+
- [ ] parallel C compilation
1920
- [ ] `recover()` from panics
2021
- [x] IO streams
2122
- [x] struct embedding

thirdparty/sokol/sokol_app.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
31463146
_sapp.framebuffer_height = _sapp.window_height;
31473147
}
31483148
_sapp.dpi_scale = (float)_sapp.framebuffer_width / (float) _sapp.window_width;
3149-
const NSUInteger style =
3149+
const NSUInteger style =
31503150
// __v_ start
31513151
_sapp.desc.fullscreen ? NSWindowStyleMaskBorderless : // __v_
31523152
// __v_ end
@@ -10983,6 +10983,27 @@ SOKOL_API_IMPL void sapp_set_window_title(const char* title) {
1098310983
#endif
1098410984
}
1098510985

10986+
_SOKOL_PRIVATE void _sapp_macos_resize_window(int width, height) {
10987+
[_sapp.macos.window setFrame:NSMakeRect(width, height, width, height) display:YES animate:YES];
10988+
//NSRect frame = [window frame];
10989+
//frame.size = theSizeYouWant;
10990+
//[window setFrame: frame display: YES animate: whetherYouWantAnimation];
10991+
10992+
}
10993+
10994+
SOKOL_API_IMPL void sapp_resize_window(int width, height) {
10995+
/*
10996+
#if defined(_SAPP_MACOS)
10997+
_sapp_macos_resize_window(width, height);
10998+
#elif defined(_SAPP_WIN32)
10999+
_sapp_win32_resize_window();
11000+
#elif defined(_SAPP_LINUX)
11001+
_sapp_x11_resize_window();
11002+
#endif
11003+
*/
11004+
}
11005+
11006+
1098611007
SOKOL_API_IMPL void sapp_set_icon(const sapp_icon_desc* desc) {
1098711008
SOKOL_ASSERT(desc);
1098811009
if (desc->sokol_default) {
@@ -11263,4 +11284,4 @@ SOKOL_API_IMPL void sapp_html5_ask_leave_site(bool ask) {
1126311284
_sapp.html5_ask_leave_site = ask;
1126411285
}
1126511286

11266-
#endif /* SOKOL_APP_IMPL */
11287+
#endif /* SOKOL_APP_IMPL */

vlib/gg/gg.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ pub fn (gg &Context) end() {
432432
pub fn (mut ctx Context) resize(width int, height int) {
433433
ctx.width = width
434434
ctx.height = height
435+
// C.sapp_resize_window(width, height)
435436
}
436437

437438
// draw_line draws a line between the points provided

vlib/sokol/sapp/sapp_funcs.c.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ fn C.sapp_get_num_dropped_files() int
115115

116116
// Get the file path of the droped file
117117
fn C.sapp_get_dropped_file_path(int) &byte
118+
119+
fn C.sapp_resize_window(int, int)

vlib/time/parse.c.v

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,6 @@
33
// that can be found in the LICENSE file.
44
module time
55

6-
pub struct TimeParseError {
7-
msg string
8-
code int
9-
}
10-
11-
fn error_invalid_time(code int) IError {
12-
return TimeParseError{
13-
msg: 'Invalid time format code: $code'
14-
code: code
15-
}
16-
}
17-
18-
// parse returns time from a date string in "YYYY-MM-DD HH:MM:SS" format.
19-
pub fn parse(s string) ?Time {
20-
if s == '' {
21-
return error_invalid_time(0)
22-
}
23-
pos := s.index(' ') or { return error_invalid_time(1) }
24-
symd := s[..pos]
25-
ymd := symd.split('-')
26-
if ymd.len != 3 {
27-
return error_invalid_time(2)
28-
}
29-
shms := s[pos..]
30-
hms := shms.split(':')
31-
hour_ := hms[0][1..]
32-
minute_ := hms[1]
33-
second_ := hms[2]
34-
//
35-
iyear := ymd[0].int()
36-
imonth := ymd[1].int()
37-
iday := ymd[2].int()
38-
ihour := hour_.int()
39-
iminute := minute_.int()
40-
isecond := second_.int()
41-
// eprintln('>> iyear: $iyear | imonth: $imonth | iday: $iday | ihour: $ihour | iminute: $iminute | isecond: $isecond')
42-
if iyear > 9999 || iyear < -9999 {
43-
return error_invalid_time(3)
44-
}
45-
if imonth > 12 || imonth < 1 {
46-
return error_invalid_time(4)
47-
}
48-
if iday > 31 || iday < 1 {
49-
return error_invalid_time(5)
50-
}
51-
if ihour > 23 || ihour < 0 {
52-
return error_invalid_time(6)
53-
}
54-
if iminute > 59 || iminute < 0 {
55-
return error_invalid_time(7)
56-
}
57-
if isecond > 59 || isecond < 0 {
58-
return error_invalid_time(8)
59-
}
60-
res := new_time(Time{
61-
year: iyear
62-
month: imonth
63-
day: iday
64-
hour: ihour
65-
minute: iminute
66-
second: isecond
67-
})
68-
return res
69-
}
70-
716
// parse_rfc2822 returns time from a date string in RFC 2822 datetime format.
727
pub fn parse_rfc2822(s string) ?Time {
738
if s == '' {
@@ -87,56 +22,6 @@ pub fn parse_rfc2822(s string) ?Time {
8722
}
8823
}
8924

90-
// parse_rfc3339 returns time from a date string in RFC 3339 datetime format.
91-
pub fn parse_rfc3339(s string) ?Time {
92-
if s == '' {
93-
return error_invalid_time(0)
94-
}
95-
mut t := parse_iso8601(s) or { Time{} }
96-
// If parse_iso8601 DID NOT result in default values (i.e. date was parsed correctly)
97-
if t != Time{} {
98-
return t
99-
}
100-
101-
t_i := s.index('T') or { -1 }
102-
parts := if t_i != -1 { [s[..t_i], s[t_i + 1..]] } else { s.split(' ') }
103-
104-
// Check if s is date only
105-
if !parts[0].contains_any(' Z') && parts[0].contains('-') {
106-
year, month, day := parse_iso8601_date(s) ?
107-
t = new_time(Time{
108-
year: year
109-
month: month
110-
day: day
111-
})
112-
return t
113-
}
114-
// Check if s is time only
115-
if !parts[0].contains('-') && parts[0].contains(':') {
116-
mut hour_, mut minute_, mut second_, mut microsecond_, mut unix_offset, mut is_local_time := 0, 0, 0, 0, i64(0), true
117-
hour_, minute_, second_, microsecond_, unix_offset, is_local_time = parse_iso8601_time(parts[0]) ?
118-
t = new_time(Time{
119-
hour: hour_
120-
minute: minute_
121-
second: second_
122-
microsecond: microsecond_
123-
})
124-
if is_local_time {
125-
return t // Time is already local time
126-
}
127-
mut unix_time := t.unix
128-
if unix_offset < 0 {
129-
unix_time -= (-unix_offset)
130-
} else if unix_offset > 0 {
131-
unix_time += unix_offset
132-
}
133-
t = unix2(i64(unix_time), t.microsecond)
134-
return t
135-
}
136-
137-
return error_invalid_time(9)
138-
}
139-
14025
// ----- iso8601 -----
14126
fn parse_iso8601_date(s string) ?(int, int, int) {
14227
year, month, day, dummy := 0, 0, 0, byte(0)
@@ -190,44 +75,3 @@ fn parse_iso8601_time(s string) ?(int, int, int, int, i64, bool) {
19075
}
19176
return hour_, minute_, second_, microsecond_, unix_offset, is_local_time
19277
}
193-
194-
// parse_iso8601 parses rfc8601 time format yyyy-MM-ddTHH:mm:ss.dddddd+dd:dd as local time
195-
// the fraction part is difference in milli seconds and the last part is offset
196-
// from UTC time and can be both +/- HH:mm
197-
// remarks: not all iso8601 is supported
198-
// also checks and support for leapseconds should be added in future PR
199-
pub fn parse_iso8601(s string) ?Time {
200-
if s == '' {
201-
return error_invalid_time(0)
202-
}
203-
t_i := s.index('T') or { -1 }
204-
parts := if t_i != -1 { [s[..t_i], s[t_i + 1..]] } else { s.split(' ') }
205-
if !(parts.len == 1 || parts.len == 2) {
206-
return error_invalid_time(12)
207-
}
208-
year, month, day := parse_iso8601_date(parts[0]) ?
209-
mut hour_, mut minute_, mut second_, mut microsecond_, mut unix_offset, mut is_local_time := 0, 0, 0, 0, i64(0), true
210-
if parts.len == 2 {
211-
hour_, minute_, second_, microsecond_, unix_offset, is_local_time = parse_iso8601_time(parts[1]) ?
212-
}
213-
mut t := new_time(Time{
214-
year: year
215-
month: month
216-
day: day
217-
hour: hour_
218-
minute: minute_
219-
second: second_
220-
microsecond: microsecond_
221-
})
222-
if is_local_time {
223-
return t // Time already local time
224-
}
225-
mut unix_time := t.unix
226-
if unix_offset < 0 {
227-
unix_time -= (-unix_offset)
228-
} else if unix_offset > 0 {
229-
unix_time += unix_offset
230-
}
231-
t = unix2(i64(unix_time), t.microsecond)
232-
return t
233-
}

0 commit comments

Comments
 (0)