@@ -32,7 +32,8 @@ namespace mlir::rlc
3232 return (
3333 type and
3434 (mlir::isa<mlir::rlc::ClassType>(decayCtxFrmType (type)) or
35- mlir::isa<mlir::rlc::AlternativeType>(decayCtxFrmType (type))));
35+ mlir::isa<mlir::rlc::AlternativeType>(decayCtxFrmType (type)) or
36+ mlir::isa<mlir::rlc::ArrayType>(decayCtxFrmType (type))));
3637 }
3738 static void printCFunDecl (
3839 StreamWriter& writer, mlir::FunctionType type, llvm::StringRef name)
@@ -210,11 +211,6 @@ namespace mlir::rlc
210211 static void printArg (
211212 mlir::Type type, llvm::StringRef name, StreamWriter& writer)
212213 {
213- bool isUserDefined = false ;
214- if (type and (mlir::isa<mlir::rlc::ClassType>(decayCtxFrmType (type)) or
215- mlir::isa<mlir::rlc::AlternativeType>(decayCtxFrmType (type))))
216- isUserDefined = true ;
217-
218214 bool isStringArg =
219215 mlir::isa_and_nonnull<mlir::rlc::StringLiteralType>(type);
220216 if (type.isa_and_nonnull <mlir::rlc::StringLiteralType>())
@@ -237,7 +233,7 @@ namespace mlir::rlc
237233 {
238234 writer.write (" )" );
239235 }
240- if (isUserDefined)
236+ if (isUserDefined (type) )
241237 writer.write (" .__rlc_data" );
242238 writer.write (" " );
243239 }
@@ -300,6 +296,7 @@ namespace mlir::rlc
300296 .Case ([&](mlir::rlc::StringLiteralType t) {
301297 w.write (" Fiddle::SIZEOF_VOIDP" );
302298 })
299+ .Case ([&](mlir::rlc::FloatType t) { w.write (" Fiddle::SIZEOF_DOUBLE" ); })
303300 .Case (
304301 [&](mlir::rlc::ClassType t) { w.write (t.mangledName (), " .size" ); })
305302 .Case ([&](mlir::rlc::AliasType t) {
@@ -327,12 +324,10 @@ namespace mlir::rlc
327324
328325 {
329326 auto _ = w.indent ();
330- bool isUserDefined = resultType.isa <mlir::rlc::ClassType>() or
331- resultType.isa <mlir::rlc::AlternativeType>();
332327
333328 if (returnsVoid (type).failed ())
334329 {
335- if (isUserDefined)
330+ if (isUserDefined (resultType) )
336331 {
337332 w.write (" __to_return = " );
338333 w.writeType (resultType);
@@ -357,7 +352,7 @@ namespace mlir::rlc
357352 // extract to convert it to a python builtin type instead
358353 if (returnsVoid (type).failed ())
359354 {
360- if (isUserDefined)
355+ if (isUserDefined (resultType) )
361356 {
362357 w.writenl (" __to_return" );
363358 }
@@ -578,32 +573,23 @@ namespace mlir::rlc
578573 }
579574
580575 static void emitMemberType (
581- mlir::rlc::StreamWriter& w, mlir::Type type, llvm::StringRef name)
576+ mlir::rlc::StreamWriter& w,
577+ mlir::Type type,
578+ llvm::StringRef name,
579+ mlir::Type size = nullptr )
582580 {
583- if (auto casted = type.dyn_cast <mlir::rlc::ClassType>())
581+ bool needs_rlc_introducer =
582+ isUserDefined (type) and not type.isa <mlir::rlc::ArrayType>();
583+ if (size != nullptr )
584584 {
585- w.write (" {" , name, " : RLC_" , casted.mangledName (), " }" );
586- return ;
587- }
588- if (auto casted = type.dyn_cast <mlir::rlc::AlternativeType>())
589- {
590- w.write (" {" , name, " : " );
591- w.write (" RLC_" );
592- w.writeType (casted);
585+ w.write (" {\" " , name, " [" );
586+ w.writeType (size);
587+ w.write (" ]\" : " , (needs_rlc_introducer ? " RLC_" : " " ));
588+ w.writeType (type, 1 );
593589 w.write (" }" );
594590 return ;
595591 }
596- if (auto casted = type.dyn_cast <mlir::rlc::ArrayType>())
597- {
598- w.write (" '" );
599- w.writeType (casted.getUnderlying (), 1 );
600- w.write (" " , name);
601- w.write (" [" );
602- w.write (casted.getSize (), " ]" );
603- w.write (" '" );
604- return ;
605- }
606- w.write (" {" , name, " :" );
592+ w.write (" {" , name, " :" , (needs_rlc_introducer ? " RLC_" : " " ));
607593 w.writeType (type, 1 );
608594 w.write (" }" );
609595 }
@@ -812,6 +798,19 @@ namespace mlir::rlc
812798 }
813799 }
814800
801+ static void emitFiddleDeclaration (
802+ mlir::rlc::ArrayType type,
803+ mlir::rlc::StreamWriter& w,
804+ MemberFunctionsTable& table,
805+ mlir::rlc::ModuleBuilder& builder,
806+ mlir::rlc::EnumDeclarationOp enumDeclaration = nullptr )
807+ {
808+ w.writeType (type);
809+ w.writenl (" = struct([" );
810+ emitMemberType (w, type.getUnderlying (), " content" , type.getSize ());
811+ w.writenl (" ])" );
812+ }
813+
815814 static void emitFiddleDeclaration (
816815 mlir::rlc::AlternativeType type,
817816 mlir::rlc::StreamWriter& w,
@@ -874,6 +873,10 @@ namespace mlir::rlc
874873 {
875874 emitFiddleDeclaration (casted, w, table, builder);
876875 }
876+ if (auto casted = mlir::dyn_cast<mlir::rlc::ArrayType>(t))
877+ {
878+ emitFiddleDeclaration (casted, w, table, builder);
879+ }
877880 }
878881 }
879882
@@ -974,6 +977,43 @@ namespace mlir::rlc
974977 writer.writenl (" end" );
975978 }
976979
980+ static void emitDeclaration (
981+ mlir::rlc::ArrayType type,
982+ mlir::rlc::StreamWriter& w,
983+ MemberFunctionsTable& table,
984+ mlir::rlc::ModuleBuilder& builder)
985+ {
986+ w.write (" class " );
987+ w.writeType (type);
988+ w.endLine ();
989+ {
990+ auto _ = w.indent ();
991+ w.writenl (" def __rlc_data" );
992+ {
993+ auto _ = w.indent ();
994+ w.write (" return @content" );
995+ w.endLine ();
996+ }
997+ w.writenl (" end" );
998+ emitSpecialFunctions (type, w, table, builder);
999+
1000+ w.writenl (" def [](index)" );
1001+ {
1002+ auto _2 = w.indent ();
1003+ w.write (" return " );
1004+ if (not isUserDefined (type.getUnderlying ()))
1005+ w.writenl (" @content[index].content" );
1006+ else
1007+ {
1008+ w.writeType (type.getUnderlying ());
1009+ w.writenl (" .new(@content[index])" );
1010+ }
1011+ }
1012+ w.writenl (" end" );
1013+ }
1014+ w.writenl (" end" );
1015+ }
1016+
9771017 static void emitDeclaration (
9781018 mlir::rlc::AlternativeType type,
9791019 mlir::rlc::StreamWriter& w,
@@ -1006,14 +1046,8 @@ namespace mlir::rlc
10061046 {
10071047 auto _ = w.indent ();
10081048 w.write (" return " );
1009- bool isUserDefined = false ;
1010- if (type and (mlir::isa<mlir::rlc::ClassType>(
1011- decayCtxFrmType (enumeration.value ())) or
1012- mlir::isa<mlir::rlc::AlternativeType>(
1013- decayCtxFrmType (enumeration.value ()))))
1014- isUserDefined = true ;
1015-
1016- if (not isUserDefined)
1049+
1050+ if (not isUserDefined (enumeration.value ()))
10171051 w.writenl (
10181052 " @content._data._alternative" ,
10191053 enumeration.index (),
@@ -1199,7 +1233,7 @@ namespace mlir::rlc
11991233 OS << " Float" ;
12001234 });
12011235 matcher.add ([&](mlir::rlc::ArrayType type, llvm::raw_string_ostream& OS) {
1202- OS << " Array " ;
1236+ OS << " RLC_ " << typeToMangled (type) ;
12031237 });
12041238 matcher.add ([&](mlir::rlc::ClassType type, llvm::raw_string_ostream& OS) {
12051239 OS << type.mangledName ();
@@ -1241,7 +1275,7 @@ namespace mlir::rlc
12411275 OS << " MyLib::RLC_string_lit" ;
12421276 });
12431277 ser.add ([&](mlir::rlc::ArrayType type, llvm::raw_string_ostream& OS) {
1244- OS << " MyLib::RLC_array " ;
1278+ OS << " MyLib::RLC_ " << typeToMangled (type) ;
12451279 });
12461280 ser.add ([&](mlir::rlc::OwningPtrType type, llvm::raw_string_ostream& OS) {
12471281 OS << " MyLib::RLC_voidp" ;
@@ -1477,6 +1511,8 @@ namespace mlir::rlc
14771511 }
14781512 if (auto casted = mlir::dyn_cast<mlir::rlc::AlternativeType>(t))
14791513 emitDeclaration (casted, matcher.getWriter (), table, builder);
1514+ if (auto casted = mlir::dyn_cast<mlir::rlc::ArrayType>(t))
1515+ emitDeclaration (casted, matcher.getWriter (), table, builder);
14801516 }
14811517
14821518 // // emit declarations of free functions
0 commit comments