Scroll down for important stuff .. first:
The latest code can do this:

//////////////////
var a: int ^ 6 = (1,2,3,4,5,6);
println$ (case 1 of 6) a;

var k = case 1 of 6;
println$ k a;

var pa = &a;
var pb = C_hack::cast[&(int ^ (3 * 2))] pa;
var b = *pb;
println$ b . (case 0 of 3, case 0 of 2);
println$ b . (case 0 of 3, case 1 of 2);
println$ b . (case 1 of 3, case 0 of 2);
println$ b . (case 1 of 3, case 1 of 2);
println$ b . (case 2 of 3, case 0 of 2);
println$ b . (case 2 of 3, case 1 of 2);
////////////////////////

The cast above is a hack to get a suitable array to index. BTW: I'm not sure if 
the
column/row order is right :)

The generated C++ looks like this:

_a8610t_64393 _tmp64411 = ::flx::rtl::strutil::str<int>(PTF b.data[(_tt64398(2, 
0).mem_0*2+_tt64398(2, 0).mem_1)]) + ::std::string("\n") ;

Not very optimal, but it works.  The Ocaml code to make this work is special 
cased
just to see what happens:


  | BEXPR_get_n ( (_,BTYP_tuple [BTYP_unitsum j1;BTYP_unitsum k1]) as idx,
    (e',(BTYP_array (_,BTYP_tuple [BTYP_unitsum j2; BTYP_unitsum k2])) as e2)) 
->
    print_endline "Detected array indexed by unitsum * unitsum";
    assert (j1 = j2);
    assert (k1 = k2);
    let n = Flx_vgen.gen_get_case_index ge' bsym_table idx in
    let n1 = ce_dot n "mem_0" in
    let n2 = ce_dot n  "mem_1" in
    let lidx = ce_infix"+" (ce_infix "*" n1 (ce_atom (string_of_int k1)))  n2 in
    ce_array (ce_dot (ge' e2) "data") lidx
 
Ok, so clearly, this is easily generalised to a tuple of arbitrary length each
component of which is a unitsum. This means indexes like

        (1,2,3)

for a 3 dimensional array, and so on for higher rank. But what about a more
general combination of tuples and sums? Just with more tuples and unitsums,
think about index of type

        3 * ( 2 * 2) * 4

with values like:

        (1, (1,0), 3)

What's that all mean? My brain can't work in so many dimensions so
lets reduce it:

        100 * (2 * 2)

Clearly this is a vector of little 2 x 2 matrices. On the hand this

        2 * 2 * (25 *25)

appears to be a 2 x 2 matrix with each component a 25 * 25 matrix.
in other words a "block matrix".


--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to