bqn_type
This commit is contained in:
parent
6033c2e90e
commit
5b2d221d0b
@ -15,6 +15,8 @@ uint32_t bqn_toChar(BQNV v); // includes bqn_free(v)
|
|||||||
double bqn_readF64 (BQNV v); // doesn't include bqn_free(v)
|
double bqn_readF64 (BQNV v); // doesn't include bqn_free(v)
|
||||||
uint32_t bqn_readChar(BQNV v); // doesn't include bqn_free(v)
|
uint32_t bqn_readChar(BQNV v); // doesn't include bqn_free(v)
|
||||||
|
|
||||||
|
int bqn_type(BQNV v); // equivalent of BQN •Type
|
||||||
|
|
||||||
// invoke BQN function
|
// invoke BQN function
|
||||||
BQNV bqn_call1(BQNV f, BQNV x);
|
BQNV bqn_call1(BQNV f, BQNV x);
|
||||||
BQNV bqn_call2(BQNV f, BQNV w, BQNV x);
|
BQNV bqn_call2(BQNV f, BQNV w, BQNV x);
|
||||||
@ -73,7 +75,7 @@ BQNV bqn_makeBoundFn2(bqn_boundFn2 f, BQNV obj);
|
|||||||
|
|
||||||
// direct (zero copy) array item access
|
// direct (zero copy) array item access
|
||||||
typedef enum { elt_unk, elt_i8, elt_i16, elt_i32, elt_f64, elt_c8, elt_c16, elt_c32 } BQNElType; // note that more types may be added in the future
|
typedef enum { elt_unk, elt_i8, elt_i16, elt_i32, elt_f64, elt_c8, elt_c16, elt_c32 } BQNElType; // note that more types may be added in the future
|
||||||
BQNElType bqn_directType(BQNV a);
|
BQNElType bqn_directArrType(BQNV a);
|
||||||
// can only use the functions below if bqn_elType returns the corresponding type
|
// can only use the functions below if bqn_elType returns the corresponding type
|
||||||
// a valid implementation of bqn_elType would be to always return elt_unk, thus disallowing the use of direct access entirely
|
// a valid implementation of bqn_elType would be to always return elt_unk, thus disallowing the use of direct access entirely
|
||||||
int8_t* bqn_directI8 (BQNV a);
|
int8_t* bqn_directI8 (BQNV a);
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
bqn_toChar;
|
bqn_toChar;
|
||||||
bqn_readF64;
|
bqn_readF64;
|
||||||
bqn_readChar;
|
bqn_readChar;
|
||||||
|
bqn_type;
|
||||||
bqn_call1;
|
bqn_call1;
|
||||||
bqn_call2;
|
bqn_call2;
|
||||||
bqn_eval;
|
bqn_eval;
|
||||||
@ -41,7 +42,7 @@
|
|||||||
bqn_makeUTF8Str;
|
bqn_makeUTF8Str;
|
||||||
bqn_makeBoundFn1;
|
bqn_makeBoundFn1;
|
||||||
bqn_makeBoundFn2;
|
bqn_makeBoundFn2;
|
||||||
bqn_directType;
|
bqn_directArrType;
|
||||||
bqn_directI8;
|
bqn_directI8;
|
||||||
bqn_directI16;
|
bqn_directI16;
|
||||||
bqn_directI32;
|
bqn_directI32;
|
||||||
|
|||||||
@ -30,6 +30,11 @@ uint32_t bqn_toChar(BQNV v) { uint32_t r = o2cu(getB(v)); freeTagged(v); return
|
|||||||
double bqn_readF64 (BQNV v) { return o2fu(getB(v)); }
|
double bqn_readF64 (BQNV v) { return o2fu(getB(v)); }
|
||||||
uint32_t bqn_readChar(BQNV v) { return o2cu(getB(v)); }
|
uint32_t bqn_readChar(BQNV v) { return o2cu(getB(v)); }
|
||||||
|
|
||||||
|
B type_c1(B t, B x);
|
||||||
|
int bqn_type(BQNV v) {
|
||||||
|
return o2i(type_c1(bi_N, inc(getB(v))));
|
||||||
|
}
|
||||||
|
|
||||||
BQNV bqn_call1(BQNV f, BQNV x) {
|
BQNV bqn_call1(BQNV f, BQNV x) {
|
||||||
return makeX(c1(getB(f), inc(getB(x))));
|
return makeX(c1(getB(f), inc(getB(x))));
|
||||||
}
|
}
|
||||||
@ -159,7 +164,7 @@ const static u8 typeMap[] = {
|
|||||||
[el_i32] = elt_i32, [el_c32] = elt_c32,
|
[el_i32] = elt_i32, [el_c32] = elt_c32,
|
||||||
[el_f64] = elt_f64,
|
[el_f64] = elt_f64,
|
||||||
};
|
};
|
||||||
BQNElType bqn_directType(BQNV a) {
|
BQNElType bqn_directArrType(BQNV a) {
|
||||||
B b = getB(a);
|
B b = getB(a);
|
||||||
if (!isArr(b)) return elt_unk;
|
if (!isArr(b)) return elt_unk;
|
||||||
return typeMap[TI(b,elType)];
|
return typeMap[TI(b,elType)];
|
||||||
|
|||||||
@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
void do_nothing() { }
|
void do_nothing() { }
|
||||||
|
|
||||||
|
int32_t getType(BQNV v) {
|
||||||
|
int32_t i = bqn_type(v);
|
||||||
|
bqn_free(v);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
BQNV timesTen(BQNV v) {
|
BQNV timesTen(BQNV v) {
|
||||||
size_t len = bqn_bound(v);
|
size_t len = bqn_bound(v);
|
||||||
int32_t* buf = malloc(len*4);
|
int32_t* buf = malloc(len*4);
|
||||||
@ -93,7 +99,7 @@ BQNV makeArrays() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t directAccess(BQNV x) {
|
int32_t directAccess(BQNV x) {
|
||||||
BQNElType e = bqn_directType(x);
|
BQNElType e = bqn_directArrType(x);
|
||||||
uint32_t res = 0;
|
uint32_t res = 0;
|
||||||
if (e==elt_i32) {
|
if (e==elt_i32) {
|
||||||
size_t bound = bqn_bound(x);
|
size_t bound = bqn_bound(x);
|
||||||
|
|||||||
@ -4,6 +4,7 @@ Section ← {•Out 𝕩∾˜@+10}
|
|||||||
f ↩ "lib.so" •FFI ""‿"do_nothing" ⋄ •Show F ⟨⟩
|
f ↩ "lib.so" •FFI ""‿"do_nothing" ⋄ •Show F ⟨⟩
|
||||||
|
|
||||||
Section "# ""a"""
|
Section "# ""a"""
|
||||||
|
f ↩ "lib.so" •FFI "i32"‿"getType"‿">a" ⋄ •Show F¨ ⟨⟨⟩, 1, '𝕩', +, ¨, ∘, {⇐}⟩
|
||||||
f ↩ "lib.so" •FFI "a"‿"timesTen"‿"a" ⋄ •Show F ⟨↕10⟩
|
f ↩ "lib.so" •FFI "a"‿"timesTen"‿"a" ⋄ •Show F ⟨↕10⟩
|
||||||
f ↩ "lib.so" •FFI "a"‿"readAtoms"‿"a"‿"a" ⋄ •Show F ⟨÷5 ⋄ '𝕨'⟩
|
f ↩ "lib.so" •FFI "a"‿"readAtoms"‿"a"‿"a" ⋄ •Show F ⟨÷5 ⋄ '𝕨'⟩
|
||||||
f ↩ "lib.so" •FFI "a"‿"readTyped"‿">a" ⋄ •Show F (10×↕7) + (4⥊<↕10)∾3⥊<@+↕10
|
f ↩ "lib.so" •FFI "a"‿"readTyped"‿">a" ⋄ •Show F (10×↕7) + (4⥊<↕10)∾3⥊<@+↕10
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
@
|
@
|
||||||
|
|
||||||
# "a"
|
# "a"
|
||||||
|
⟨ 0 1 2 3 4 5 6 ⟩
|
||||||
⟨ 0 10 20 30 40 50 60 70 80 90 ⟩
|
⟨ 0 10 20 30 40 50 60 70 80 90 ⟩
|
||||||
120168 120168 0.200000000000000011 0.200000000000000011
|
120168 120168 0.200000000000000011 0.200000000000000011
|
||||||
'𝕩'
|
'𝕩'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user