Skip to content

Commit

Permalink
Fixed a bug in the generated code for setting a field inside a sequen…
Browse files Browse the repository at this point in the history
…ce. (#681)

* Fixed a bug in the generated code for setting a field inside a sequence.

* Added back the mutator function
  • Loading branch information
ankushdesai authored Nov 14, 2023
1 parent ed6f19c commit 44b9f4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Src/PCompiler/CompilerCore/Backend/Java/MachineGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,11 @@ private void WriteStmt(IPStmt stmt)
WriteExpr(insertStmt.Variable);
if (PLanguageType.TypeIsOfKind(insertStmt.Variable.Type, TypeKind.Sequence))
{
Write($".{t.MutatorMethodName}((int)(");
Write($".{t.InsertMethodName}((int)(");
}
else
{
Write($".{t.MutatorMethodName}((");
Write($".{t.InsertMethodName}((");
}
WriteExpr(insertStmt.Index);
Write("), ");
Expand Down
8 changes: 7 additions & 1 deletion Src/PCompiler/CompilerCore/Backend/Java/TypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ internal string ReferenceTypeName
/// </summary>
internal virtual string MutatorMethodName =>
throw new Exception($"MutatorMethodName not implemented for {TypeName}");


internal virtual string InsertMethodName =>
throw new Exception($"MutatorMethodName not implemented for {TypeName}");

/// <summary>
/// The name of the method K -> void that removes key K from the collection. Throws for
/// non-collection types!
Expand Down Expand Up @@ -201,6 +204,7 @@ internal JList(JType t)
internal override string AccessorMethodName => "get";
internal override string ContainsMethodName => "contains";
internal override string MutatorMethodName => "set";
internal override string InsertMethodName => "add";
internal override string RemoveMethodName => "remove";
}
internal class JMap : JType
Expand All @@ -218,6 +222,7 @@ internal JMap(JType k, JType v)
internal override string AccessorMethodName => "get";
internal override string ContainsMethodName => "containsKey";
internal override string MutatorMethodName => "put";
internal override string InsertMethodName => "put";
internal override string RemoveMethodName => "remove";

/// <summary>
Expand Down Expand Up @@ -252,6 +257,7 @@ internal JSet(JType t)
// the Java PRT runtime.

internal override string ContainsMethodName => "contains";
internal override string InsertMethodName => "add";
internal override string MutatorMethodName => "add";
internal override string RemoveMethodName => "remove";
}
Expand Down

0 comments on commit 44b9f4f

Please sign in to comment.