# Monet Mil to Mal compiler # Copyright (c) 2001-2004, CWI. All rights reserved. #Predefined code segment #The compiler can not guarantee an accurate compilation, #because MIL unlike MAL is a dynamically typed language. #A few guidelines to maximize usefullness. #- make the type of variables explicit, in particular 'nil' #- upon advice of M2m to remap identifiers, change it in your program directly #use the "mil_schema" for additional support routines # io.print("setoid(oid(20000000));"); aa_a := calc.oid(20000000); ba_a := setoid(aa_a); # io.print("# For distributed processing it should be possible\n"); # io.print("# split and re-distribute BATs.\n"); # io.print("# This is supported by hashsplit, rangesplit, and groupby operations.\n"); # io.print("PROC groupby(bat b, bat rng) : bat {"); function groupby(b:bat[:any$1,:any$2], rng:bat[:any$3,:any$4]):bat[:any$5,:any$6]; # io.print(" VAR r := rng.reverse().number().reverse();"); ca_a := bat.reverse(rng); da_a := number(ca_a); r := bat.reverse(da_a); # io.print(" VAR l := rng.number().reverse();"); ea_a := number(rng); l := bat.reverse(ea_a); # io.print(" RETURN [select](l.project(b),l,r);"); fa_a := project(l,b); return ga_a :=multiplex.tactics("select",fa_a,l,r); end groupby; # io.print("var b:= bat.new(int,int);"); b := bat.new(nil:int,nil:int); # io.print("b.insert(1,15);"); ha_a := bat.insert(b,1,15); # io.print("b.insert(2,4);"); ia_a := bat.insert(b,2,4); # io.print("b.insert(3,int(nil));"); ja_a := calc.int(nil); ka_a := bat.insert(b,3,ja_a); # io.print("b.insert(4,16);"); la_a := bat.insert(b,4,16); # io.print("b.insert(5,25);"); ma_a := bat.insert(b,5,25); # io.print("b.insert(6,36);"); na_a := bat.insert(b,6,36); # io.print("b.insert(7,49);"); oa_a := bat.insert(b,7,49); # io.print("b.insert(8,64);"); pa_a := bat.insert(b,8,64); # io.print("b.insert(9,int(nil));"); qa_a := calc.int(nil); ra_a := bat.insert(b,9,qa_a); # io.print("b.insert(int(nil),int(nil));"); sa_a := calc.int(nil); ta_a := calc.int(nil); ua_a := bat.insert(b,sa_a,ta_a); # io.print("b.insert(int(nil),81);"); va_a := calc.int(nil); wa_a := bat.insert(b,va_a,81); # io.print("b.rename(\"b\");"); xa_a := bat.setName(b,"b"); # io.print("var rng:= bat.new(int,int);"); rng := bat.new(nil:int,nil:int); # io.print("rng.insert(1,1);"); ya_a := bat.insert(rng,1,1); # io.print("rng.insert(1,9);"); ab_a := bat.insert(rng,1,9); # io.print("rng.insert(int(nil),9);"); bb_a := calc.int(nil); cb_a := bat.insert(rng,bb_a,9); # io.print("rng.insert(1,int(nil));"); db_a := calc.int(nil); eb_a := bat.insert(rng,1,db_a); # io.print("rng.insert(9,9);"); fb_a := bat.insert(rng,9,9); # io.print("rng.insert(3,5);"); gb_a := bat.insert(rng,3,5); # io.print("var bb := b.groupby(rng);"); bb := groupby(b,rng); # io.print("bb.print();"); hb_a := bat.print(bb); # io.print("bb@batloop() { $t.print(); }"); barrier (ib_a,ib_aH,ib_aT) := newIterator(bb); jb_a := bat.print(ib_aT); redo (ib_a,ib_aH,ib_aT) := hasMoreElements(bb); exit (ib_a,ib_aH,ib_aT) ; # io.print("# other values;\n"); x := bat.new(nil:int,nil:chr); # io.print("x.insert(1,'a');"); kb_a := bat.insert(x,1,'a'); # io.print("x.insert(2,'a');"); lb_a := bat.insert(x,2,'a'); # io.print("x.insert(3,'b');"); mb_a := bat.insert(x,3,'b'); # io.print("x.insert(4,'b');"); nb_a := bat.insert(x,4,'b'); # io.print("x.insert(5,'b');"); ob_a := bat.insert(x,5,'b'); # io.print("x.insert(6,'b');"); pb_a := bat.insert(x,6,'b'); # io.print("x.insert(7,'c');"); qb_a := bat.insert(x,7,'c'); # io.print("x.insert(8,'c');"); rb_a := bat.insert(x,8,'c'); # io.print("var t := bat.new(chr,chr);"); t := bat.new(nil:chr,nil:chr); # io.print("t.insert('a','b');"); sb_a := bat.insert(t,'a','b'); # io.print("t.insert('c','c');"); tb_a := bat.insert(t,'c','c'); # io.print("t.insert('b','b');"); ub_a := bat.insert(t,'b','b'); # io.print("var xx:= x.groupby(t);"); xx := groupby(x,t); # io.print("xx.print();"); vb_a := bat.print(xx); # io.print("xx@batloop() { $t.print(); }"); barrier (wb_a,wb_aH,wb_aT) := newIterator(xx); xb_a := bat.print(wb_aT); redo (wb_a,wb_aH,wb_aT) := hasMoreElements(xx); exit (wb_a,wb_aH,wb_aT) ; # io.print("# other values;\n"); x := bat.new(nil:int,nil:str); # io.print("x.insert(1,\"a\");"); yb_a := bat.insert(x,1,"a"); # io.print("x.insert(2,\"a\");"); ac_a := bat.insert(x,2,"a"); # io.print("x.insert(3,\"b\");"); bc_a := bat.insert(x,3,"b"); # io.print("x.insert(4,\"b\");"); cc_a := bat.insert(x,4,"b"); # io.print("x.insert(5,\"b\");"); dc_a := bat.insert(x,5,"b"); # io.print("x.insert(6,\"b\");"); ec_a := bat.insert(x,6,"b"); # io.print("x.insert(7,\"c\");"); fc_a := bat.insert(x,7,"c"); # io.print("x.insert(8,\"c\");"); gc_a := bat.insert(x,8,"c"); # io.print("t:= bat.new(str,str);"); t := bat.new(nil:str,nil:str); # io.print("t.rename(\"t\");"); hc_a := bat.setName(t,"t"); # io.print("t.insert(\"a\",\"b\");"); ic_a := bat.insert(t,"a","b"); # io.print("t.insert(\"c\",\"c\");"); jc_a := bat.insert(t,"c","c"); # io.print("t.insert(\"b\",\"b\");"); kc_a := bat.insert(t,"b","b"); # io.print("xx:= x.groupby(t);"); xx := groupby(x,t); # io.print("xx.print();"); lc_a := bat.print(xx); # io.print("xx@batloop() { $t.print(); }"); barrier (mc_a,mc_aH,mc_aT) := newIterator(xx); nc_a := bat.print(mc_aT); redo (mc_a,mc_aH,mc_aT) := hasMoreElements(xx); exit (mc_a,mc_aH,mc_aT) ; # io.print("quit();"); oc_a := clients.quit(); #Identifer 'rename' mapped to 'bat.setName'