From ed850f25321d379d5eced0ccfe1903302c290a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ibrahim=20Numanagic=CC=81?= Date: Mon, 20 Feb 2023 09:03:35 -0800 Subject: [PATCH] GetSet support (fixes) --- codon/parser/cache.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/codon/parser/cache.cpp b/codon/parser/cache.cpp index e80474de..b44f0ec6 100644 --- a/codon/parser/cache.cpp +++ b/codon/parser/cache.cpp @@ -621,12 +621,14 @@ void Cache::populatePythonModule() { auto &r = c.realizations.begin()->second; py.type = realizeType(r->type); for (auto &[mn, mt] : r->fields) { - py.members.push_back(ir::PyMember{mn, "", - mt->is("int") ? ir::PyMember::Type::LONGLONG - : mt->is("float") - ? ir::PyMember::Type::DOUBLE - : ir::PyMember::Type::OBJECT, - true}); + // This will be handled later + // py.members.push_back(ir::PyMember{mn, "", + // mt->is("int") ? + // ir::PyMember::Type::LONGLONG : + // mt->is("float") + // ? ir::PyMember::Type::DOUBLE + // : ir::PyMember::Type::OBJECT, + // true}); // Generate getters & setters std::vector params{ @@ -646,13 +648,15 @@ void Cache::populatePythonModule() { params = {Param{sctx->generateCanonicalName("self"), N("cobj")}, Param{sctx->generateCanonicalName("what"), N("cobj")}, Param{sctx->generateCanonicalName("closure"), N("cobj")}}; - retType = N("NoneType"); - ret = N( - N(N(N(cn), "__from_py__"), - N(params[0].name)), - mn, - N(N(N(mt->realizedName()), "__from_py__"), - N(params[1].name))); + retType = N("i32"); + ret = N( + N( + N(N(N(cn), "__from_py__"), + N(params[0].name)), + mn, + N(N(N(mt->realizedName()), "__from_py__"), + N(params[1].name))), + N(N(N("i32"), N(0)))); auto sstub = sctx->generateCanonicalName(fmt::format("_py._set_{}", mn)); auto snode = N(sstub, retType, params, N(ret), Attr({Attr::ForceRealize})); @@ -674,8 +678,7 @@ void Cache::populatePythonModule() { py.getset.push_back({mn, "", functions[gstub].realizations.begin()->second->ir, functions[sstub].realizations.begin()->second->ir}); - LOG("[py] {}: {}.{} => {}: {}, {}", "member", cn, mn, py.members.back().type, - gstub, sstub); + LOG("[py] {}: {}.{} => {}, {}", "member", cn, mn, gstub, sstub); } pyModule->types.push_back(py); }