# HG changeset patch # User Anders Halager # Date 1216755293 -7200 # Node ID 9cfa335175263838086a7cfbb67704fe71790289 # Parent 7606387b2f0a4b3df56c8d450a7da1d36000326f Codegen support for new expressions (very lame so far) Calls the correct constructor, but it doesn't get a this pointer Objects are simply malloced, no GC diff -r 7606387b2f0a -r 9cfa33517526 gen/CodeGen.d --- a/gen/CodeGen.d Tue Jul 22 18:24:15 2008 +0200 +++ b/gen/CodeGen.d Tue Jul 22 21:34:53 2008 +0200 @@ -320,6 +320,17 @@ case ExpType.Index: auto indexExp = cast(IndexExp)exp; return loadLValue(genLValue(exp)); + case ExpType.NewExp: + auto newExp = cast(NewExp)exp; + DClass type = newExp.newType.type().asClass(); + auto llvm_type = cast(PointerType)llvm(type); + auto pointer = b.buildMalloc(llvm_type.elementType(), "new"); + scope args = new Value[newExp.c_args.length]; + foreach (i, arg; newExp.c_args) + args[i] = genExpression(arg).value; + auto f = m.getNamedFunction(newExp.callSym.getMangledFQN()); + b.buildCall(f, args, ""); + return RValue(pointer); case ExpType.CallExp: auto callExp = cast(CallExp)exp; // BUG: Might not be a simple identifier, a.foo(x) is also a @@ -356,7 +367,8 @@ auto id = cast(Identifier)exp; if (id.type.isStruct() || id.type.isArray() - || id.type.isStaticArray()) + || id.type.isStaticArray() + || id.type.isClass()) return RValue(table.find(id.get)); else return RValue(b.buildLoad(table.find(id.get), id.get)); @@ -839,7 +851,29 @@ Type res = StructType.Get(members.unsafe()); type_map[t] = res; - m.addTypeName(s.name, res); + m.addTypeName("struct." ~ s.name, res); + return res; + } + else if (auto c = t.asClass) + { + SmallArray!(Type) members; + if (c.members.length > 0 && false) + { + DType[] array; + array.length = c.members.length; + + foreach (m; c.members) + array[m.index] = m.type; + + foreach (m; array) + members ~= llvm(m); + } + else members ~= Type.Int32; + + Type res = StructType.Get(members.unsafe()); + res = PointerType.Get(res); + type_map[t] = res; + m.addTypeName("class." ~ c.name, res); return res; } else if (auto f = t.asFunction) @@ -860,29 +894,6 @@ Type res = FunctionType.Get(ret_t, params.unsafe()); type_map[t] = res; - /* - //TODO: create own DType -> FunctionType mapping without names - auto id = new Identifier(f.name); - id.setType(f); - - auto f_name = symbolName(id); - auto f_t = m.getNamedFunction(f_name); - if(f_t is null) - { - Stdout("oh noes").newline; - auto llfunc = m.addFunction(res, f_name); - - foreach (i, param; f.params) - if (param.isStruct) - llfunc.addParamAttr(i, ParamAttr.ByVal); - - if (f.firstParamIsReturnValue) - { - llfunc.removeParamAttr(0, ParamAttr.ByVal); - llfunc.addParamAttr(0, ParamAttr.StructRet); - } - } - */ return res; } else if (auto f = t.asPointer)