Skip to content

Commit

Permalink
Java code generation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine Zhou committed Dec 14, 2024
1 parent 545dec4 commit 0a41845
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Src/PCompiler/CompilerCore/Backend/Java/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal static IEnumerable<string> ImportStatements()

#region Event source generation

public static readonly string EventNamespaceName = "Events";
public static readonly string EventNamespaceName = "PEvents";
public static readonly string EventDefnFileName = $"{EventNamespaceName}.java";

#endregion
Expand Down Expand Up @@ -227,9 +227,9 @@ internal static string AsFFIComment(string line)
internal static readonly string PValueClass = "prt.values.PValue";

/// <summary>
/// The fully-qualified class name of the Java P runtime's Event class.
/// The fully-qualified class name of the Java P runtime's PEvent class.
/// </summary>
internal static readonly string EventsClass = "prt.events.Event";
internal static readonly string EventsClass = "prt.events.PEvent";

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ internal void WriteClone(TypeManager.JType t, Action writeTermToBeCloned)
case TypeManager.JType.JSet _:
case TypeManager.JType.JForeign _:
case TypeManager.JType.JNamedTuple _:
case TypeManager.JType.JEvent _:
Write($"{Constants.PrtDeepCloneMethodName}(");
writeTermToBeCloned();
Write(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ private void WriteExpr(IPExpr expr)
// construct a new List from that collection.
Write($"new {mt.ValueCollectionType}(");
WriteExpr(ve.Expr);
Write($".{mt.KeysMethodName}()");
Write($".{mt.ValuesMethodName}()");
Write(")");
break;
}
Expand Down
6 changes: 6 additions & 0 deletions Src/PCompiler/CompilerCore/Backend/Java/TypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ internal JMap(JType k, JType v)
/// The type of a collection containing the keys of this Map.
/// </summary>
internal string KeyCollectionType => $"ArrayList<{_k.ReferenceTypeName}>";

/// <summary>
/// The name of the () -> Set method that produces the values in the map.
/// </summary>
internal string ValuesMethodName => "values";

/// <summary>
/// The type of a collection containing the keys of this Map.
Expand Down Expand Up @@ -307,6 +312,7 @@ internal JEvent()
_unboxedType = $"{Constants.EventsClass}<?>";
}
internal override bool IsPrimitive => false;
internal override string DefaultValue => "null";
}

internal class JVoid : JType
Expand Down

0 comments on commit 0a41845

Please sign in to comment.