update script-to-C++ compilation for new record constructor internals

This commit is contained in:
Vern Paxson 2021-12-06 09:39:58 -05:00
parent e7412e257f
commit a1324a882d
3 changed files with 39 additions and 2 deletions

View file

@ -670,8 +670,30 @@ string CPPCompile::GenRecordConstructorExpr(const Expr* e)
vals += ", "; vals += ", ";
} }
return string("record_constructor__CPP({") + vals + "}, " + "cast_intrusive<RecordType>(" + vals = string("{") + vals + "}";
GenTypeName(t) + "))";
const auto& map = rc->Map();
if ( map )
{
string map_vals;
for ( auto m : *map )
{
if ( ! map_vals.empty() )
map_vals += ", ";
map_vals += to_string(m);
}
map_vals = string("{") + map_vals + "}";
return string("record_constructor_map__CPP(") + vals + ", " + map_vals +
", cast_intrusive<RecordType>(" + GenTypeName(t) + "))";
}
else
return string("record_constructor__CPP(") + vals + ", cast_intrusive<RecordType>(" +
GenTypeName(t) + "))";
} }
string CPPCompile::GenSetConstructorExpr(const Expr* e) string CPPCompile::GenSetConstructorExpr(const Expr* e)

View file

@ -224,6 +224,17 @@ RecordValPtr record_constructor__CPP(vector<ValPtr> vals, RecordTypePtr t)
return rv; return rv;
} }
RecordValPtr record_constructor_map__CPP(vector<ValPtr> vals, vector<int> map, RecordTypePtr t)
{
auto rv = make_intrusive<RecordVal>(move(t));
auto n = vals.size();
for ( auto i = 0u; i < n; ++i )
rv->Assign(map[i], vals[i]);
return rv;
}
VectorValPtr vector_constructor__CPP(vector<ValPtr> vals, VectorTypePtr t) VectorValPtr vector_constructor__CPP(vector<ValPtr> vals, VectorTypePtr t)
{ {
auto vv = make_intrusive<VectorVal>(move(t)); auto vv = make_intrusive<VectorVal>(move(t));

View file

@ -140,6 +140,10 @@ extern TableValPtr table_constructor__CPP(std::vector<ValPtr> indices, std::vect
// assigned to the corresponding elements of the given vector of values. // assigned to the corresponding elements of the given vector of values.
extern RecordValPtr record_constructor__CPP(std::vector<ValPtr> vals, RecordTypePtr t); extern RecordValPtr record_constructor__CPP(std::vector<ValPtr> vals, RecordTypePtr t);
// Same, but with a map when using a named constructor.
extern RecordValPtr record_constructor_map__CPP(std::vector<ValPtr> vals, std::vector<int> map,
RecordTypePtr t);
// Constructs a vector of the given type, populated with the given values. // Constructs a vector of the given type, populated with the given values.
extern VectorValPtr vector_constructor__CPP(std::vector<ValPtr> vals, VectorTypePtr t); extern VectorValPtr vector_constructor__CPP(std::vector<ValPtr> vals, VectorTypePtr t);