TmpFile→I8Arr
This commit is contained in:
parent
1d43e72a16
commit
d8d56bbdd4
@ -500,9 +500,9 @@ B fchars_c2(B d, B w, B x) {
|
|||||||
}
|
}
|
||||||
static NFnDesc* fBytesDesc;
|
static NFnDesc* fBytesDesc;
|
||||||
B fbytes_c1(B d, B x) {
|
B fbytes_c1(B d, B x) {
|
||||||
TmpFile* tf = file_bytes(path_resolve(nfn_objU(d), x));
|
I8Arr* tf = file_bytes(path_resolve(nfn_objU(d), x));
|
||||||
usz ia = tf->ia; u8* p = (u8*)tf->a;
|
usz ia = tf->ia; u8* p = (u8*)tf->a;
|
||||||
u32* rp; B r = m_c32arrv(&rp, ia);
|
u8* rp; B r = m_c8arrv(&rp, ia);
|
||||||
for (i64 i = 0; i < ia; i++) rp[i] = p[i];
|
for (i64 i = 0; i < ia; i++) rp[i] = p[i];
|
||||||
ptr_dec(tf);
|
ptr_dec(tf);
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@ -197,13 +197,13 @@ static void* nvm_alloc(u64 sz) {
|
|||||||
// void* r = mmap(NULL, sz, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON|MAP_32BIT, -1, 0);
|
// void* r = mmap(NULL, sz, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON|MAP_32BIT, -1, 0);
|
||||||
// if (r==MAP_FAILED) thrM("JIT: Failed to allocate executable memory");
|
// if (r==MAP_FAILED) thrM("JIT: Failed to allocate executable memory");
|
||||||
// return r;
|
// return r;
|
||||||
TmpFile* src = mmX_allocN(fsizeof(TmpFile,a,u8,sz), t_i8arr);
|
I8Arr* src = mmX_allocN(fsizeof(I8Arr,a,u8,sz), t_i8arr);
|
||||||
src->ia = sz;
|
src->ia = sz;
|
||||||
arr_shVec((Arr*)src);
|
arr_shVec((Arr*)src);
|
||||||
return src->a;
|
return src->a;
|
||||||
}
|
}
|
||||||
void nvm_free(u8* ptr) {
|
void nvm_free(u8* ptr) {
|
||||||
if (!USE_PERF) mmX_free((Value*)RFLD(ptr, TmpFile, a));
|
if (!USE_PERF) mmX_free((Value*)RFLD(ptr, I8Arr, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,25 +25,25 @@ static DIR* dir_open(B path) { // doesn't consume
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
TmpFile* file_bytes(B path) { // consumes
|
I8Arr* file_bytes(B path) { // consumes
|
||||||
FILE* f = file_open(path, "read", "r");
|
FILE* f = file_open(path, "read", "r");
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
u64 len = ftell(f);
|
u64 len = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
TmpFile* src = m_arr(fsizeof(TmpFile,a,u8,len), t_i8arr, len); arr_shVec((Arr*)src);
|
I8Arr* src = m_arr(fsizeof(I8Arr,a,u8,len), t_i8arr, len); arr_shVec((Arr*)src);
|
||||||
if (fread((char*)src->a, 1, len, f)!=len) thrF("Error reading file \"%R\"", path);
|
if (fread((char*)src->a, 1, len, f)!=len) thrF("Error reading file \"%R\"", path);
|
||||||
dec(path);
|
dec(path);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
B file_chars(B path) { // consumes
|
B file_chars(B path) { // consumes
|
||||||
TmpFile* c = file_bytes(path);
|
I8Arr* c = file_bytes(path);
|
||||||
B r = fromUTF8((char*)c->a, c->ia);
|
B r = fromUTF8((char*)c->a, c->ia);
|
||||||
ptr_dec(c);
|
ptr_dec(c);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
B file_lines(B path) { // consumes
|
B file_lines(B path) { // consumes
|
||||||
TmpFile* tf = file_bytes(path);
|
I8Arr* tf = file_bytes(path);
|
||||||
usz ia = tf->ia; u8* p = (u8*)tf->a;
|
usz ia = tf->ia; u8* p = (u8*)tf->a;
|
||||||
usz lineCount = 0;
|
usz lineCount = 0;
|
||||||
for (usz i = 0; i < ia; i++) {
|
for (usz i = 0; i < ia; i++) {
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "utf.h"
|
#include "utf.h"
|
||||||
|
|
||||||
typedef struct TmpFile { // to be turned into a proper I8Arr
|
|
||||||
struct Arr;
|
|
||||||
i8 a[];
|
|
||||||
} TmpFile;
|
|
||||||
|
|
||||||
B path_resolve(B base, B rel); // consumes rel; assumes base is a char vector or bi_N
|
B path_resolve(B base, B rel); // consumes rel; assumes base is a char vector or bi_N
|
||||||
B path_dir(B path); // consumes; returns directory part of file path, with trailing slash
|
B path_dir(B path); // consumes; returns directory part of file path, with trailing slash
|
||||||
B path_abs(B path); // consumes; returns absolute version of the path; propagates bi_N
|
B path_abs(B path); // consumes; returns absolute version of the path; propagates bi_N
|
||||||
|
|
||||||
FILE* file_open(B path, char* desc, char* mode); // doesn't consume path
|
FILE* file_open(B path, char* desc, char* mode); // doesn't consume path
|
||||||
TmpFile* file_bytes(B path); // consumes
|
I8Arr* file_bytes(B path); // consumes
|
||||||
B file_chars(B path); // consumes
|
B file_chars(B path); // consumes
|
||||||
B file_lines(B path); // consumes
|
B file_lines(B path); // consumes
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user