mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
caching modules: almost there
This commit is contained in:
32
vlib/os2/os2_mac.v
Normal file
32
vlib/os2/os2_mac.v
Normal file
@@ -0,0 +1,32 @@
|
||||
module os2
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
struct File {
|
||||
fd int
|
||||
}
|
||||
|
||||
fn C.open(byteptr, int, int) int
|
||||
fn C.write(voidptr, byteptr, int) int
|
||||
|
||||
pub fn create(path string) ?File {
|
||||
fd := C.creat(path.str, 0644)//511)
|
||||
if fd == -1 {
|
||||
return error('failed to create "$path":')
|
||||
//os.print_c_errno()
|
||||
}
|
||||
return File{fd}
|
||||
}
|
||||
|
||||
pub fn (f File) writeln(s string) {
|
||||
ss := s + '\n'
|
||||
ret := C.write(f.fd, ss.str, s.len + 1)
|
||||
if ret == -1 {
|
||||
C.perror('failed to write')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (f File) close() {
|
||||
C.close(f.fd)
|
||||
}
|
||||
|
||||
9
vlib/os2/os2_test.v
Normal file
9
vlib/os2/os2_test.v
Normal file
@@ -0,0 +1,9 @@
|
||||
import os2
|
||||
|
||||
fn test_open() {
|
||||
$if mac {
|
||||
f := os2.create('os2.test')
|
||||
f.writeln('hello world!')
|
||||
f.close()
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,8 @@ pub fn dice_coefficient(s1, s2 string) f32 {
|
||||
mut first_bigrams := map[string]int
|
||||
for i := 0; i < a.len-1; i++ {
|
||||
bigram := a.substr(i, i+2)
|
||||
first_bigrams[bigram] = if bigram in first_bigrams { first_bigrams[bigram]+1 } else { 1 }
|
||||
q := if bigram in first_bigrams { first_bigrams[bigram]+1 } else { 1 }
|
||||
first_bigrams[bigram] = q
|
||||
}
|
||||
mut intersection_size := 0
|
||||
for i := 0; i < b.len-1; i++ {
|
||||
|
||||
@@ -29,6 +29,8 @@ fn C.localtime(int) &C.tm
|
||||
fn remove_me_when_c_bug_is_fixed() { // TODO
|
||||
}
|
||||
|
||||
struct C.time_t {}
|
||||
|
||||
struct C.tm {
|
||||
tm_year int
|
||||
tm_mon int
|
||||
|
||||
Reference in New Issue
Block a user