Mercurial > projects > ddmd
diff dmd/AssocArrayLiteralExp.d @ 68:ee3a9f34dc48
final bits of codegen implementation to compile Phobos
author | korDen |
---|---|
date | Tue, 24 Aug 2010 16:44:34 +0400 |
parents | 4290d870944a |
children | 2e2a5c3f943a |
line wrap: on
line diff
--- a/dmd/AssocArrayLiteralExp.d Mon Aug 23 21:21:05 2010 +0400 +++ b/dmd/AssocArrayLiteralExp.d Tue Aug 24 16:44:34 2010 +0400 @@ -22,6 +22,11 @@ import dmd.TOK; import dmd.PREC; import dmd.expression.Util; +import dmd.backend.Util; +import dmd.backend.TYM; +import dmd.backend.mTY; +import dmd.backend.OPER; +import dmd.backend.RTLSYM; class AssocArrayLiteralExp : Expression { @@ -112,7 +117,57 @@ elem* toElem(IRState* irs) { - assert(false); + elem* e; + size_t dim; + + //printf("AssocArrayLiteralExp.toElem() %s\n", toChars()); + dim = keys.dim; + e = el_long(TYint, dim); + for (size_t i = 0; i < dim; i++) + { + Expression el = cast(Expression)keys.data[i]; + + for (int j = 0; j < 2; j++) + { + elem* ep = el.toElem(irs); + + if (tybasic(ep.Ety) == TYstruct || tybasic(ep.Ety) == TYarray) + { + ep = el_una(OPstrpar, TYstruct, ep); + ep.Enumbytes = cast(uint)el.type.size(); + } + //printf("[%d] %s\n", i, el.toChars()); + //elem_print(ep); + e = el_param(ep, e); + el = cast(Expression)values.data[i]; + } + } + + Type t = type.toBasetype().mutableOf(); + assert(t.ty == Taarray); + TypeAArray ta = cast(TypeAArray)t; + + /* Unfortunately, the hash function for Aa (array of chars) is custom and + * different from Axa and Aya, which get the generic hash function. + * So, rewrite the type of the AArray so that if it's key type + * is an array of const or invariant, make it an array of mutable. + */ + Type tkey = ta.index.toBasetype(); + if (tkey.ty == Tarray) + { + tkey = tkey.nextOf().mutableOf().arrayOf(); + tkey = tkey.semantic(Loc(0), null); + ta = new TypeAArray(ta.nextOf(), tkey); + ta = cast(TypeAArray)ta.merge(); + } + + e = el_param(e, ta.getTypeInfo(null).toElem(irs)); + + // call _d_assocarrayliteralT(ti, dim, ...) + e = el_bin(OPcall,TYnptr,el_var(rtlsym[RTLSYM_ASSOCARRAYLITERALT]),e); + + el_setLoc(e,loc); + return e; } bool checkSideEffect(int flag)