Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 committed Aug 5, 2024
1 parent bd48f6b commit 400e116
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ trait StagedCompiler {
byteArray(i) = v.readBufferByte(i)
}
val location = LocationDescription.toLocation(LocationDescription.deserialize(byteArray))
Rql2LocationValue(location)
val publicDescription = v.asString()
Rql2LocationValue(location, publicDescription)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,19 @@ trait EntryExtensionHelper extends Rql2TypeUtils {

final protected def getBoolValue(v: Arg): Boolean = { v.asInstanceOf[ValueArg].v.asInstanceOf[Rql2BoolValue].v }

private def getLocation(v: Arg): Location = {
v.asInstanceOf[ValueArg].v.asInstanceOf[Rql2LocationValue].l
}

final protected def getByteStreamLocation(v: Arg): Either[String, ByteStreamLocation] = {
getLocation(v) match {
val locationValue = v.asInstanceOf[ValueArg].v.asInstanceOf[Rql2LocationValue]
locationValue.l match {
case l: ByteStreamLocation => Right(l)
case _ => Left("expected a bytestream")
}
}

final protected def locationValueToExp(v: Arg): Exp = {
val location = getLocation(v)
val locationValue = v.asInstanceOf[ValueArg].v.asInstanceOf[Rql2LocationValue]
val location = locationValue.l
val locationDescription = LocationDescription.toLocationDescription(location)
LocationConst(LocationDescription.serialize(locationDescription))
LocationConst(LocationDescription.serialize(locationDescription), locationValue.publicDescription)
}

final protected def getListStringValue(v: Arg): Seq[String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final case class Rql2IntervalValue(
seconds: Int,
millis: Int
) extends Rql2Value
final case class Rql2LocationValue(l: Location) extends Rql2Value
final case class Rql2LocationValue(l: Location, publicDescription: String) extends Rql2Value
final case class Rql2RecordValue(v: Seq[Rql2RecordAttr]) extends Rql2Value
final case class Rql2RecordAttr(name: String, value: Rql2Value)
final case class Rql2TryValue(v: Either[String, Rql2Value]) extends Rql2Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class CsvInferAndParseEntry extends SugarEntryExtension with CsvEntryExtensionHe
val codeData = getStringValue(mandatoryArgs.head)
for (
inferrerProperties <- getCsvInferrerProperties(
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData)), Rql2LocationType())),
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData), "<value>"), Rql2LocationType())),
optionalArgs
);
inputFormatDescriptor <- programContext.infer(inferrerProperties);
Expand Down Expand Up @@ -636,7 +636,7 @@ class CsvInferAndParseEntry extends SugarEntryExtension with CsvEntryExtensionHe

val r = for (
inferrerProperties <- getCsvInferrerProperties(
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData)), Rql2LocationType())),
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData), "<value>"), Rql2LocationType())),
optionalArgs
);
inputFormatDescriptor <- programContext.infer(inferrerProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class InferAndParseJsonEntry extends SugarEntryExtension with JsonEntryExtension
val codeData = getStringValue(mandatoryArgs.head)
val preferNulls = optionalArgs.collectFirst { case a if a._1 == "preferNulls" => a._2 }.forall(getBoolValue)
val inferenceDiagnostic: Either[Seq[ErrorCompilerMessage], InputFormatDescriptor] = getJsonInferrerProperties(
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData)), Rql2LocationType())),
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData), "<value>"), Rql2LocationType())),
optionalArgs
)
.flatMap(programContext.infer)
Expand Down Expand Up @@ -397,7 +397,7 @@ class InferAndParseJsonEntry extends SugarEntryExtension with JsonEntryExtension

val inputFormatDescriptor = for (
inferrerProperties <- getJsonInferrerProperties(
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData)), Rql2LocationType())),
Seq(ValueArg(Rql2LocationValue(new InMemoryByteStreamLocation(codeData), "<value>"), Rql2LocationType())),
optionalArgs
);
inputFormatDescriptor <- programContext.infer(inferrerProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ final case class BinaryConst(bytes: Array[Byte]) extends Const {
}
}

final case class LocationConst(bytes: Array[Byte]) extends Const
final case class LocationConst(bytes: Array[Byte], publicDescription: String) extends Const

/**
* Number Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ case Exp ignored when tipe(in) instanceof PackageType || tipe(in) instanceof Pac
default -> throw new RawTruffleInternalErrorException();
};
case BinaryConst bc -> new BinaryConstNode(bc.bytes());
case LocationConst lc -> new LocationConstNode(lc.bytes());
case LocationConst lc -> new LocationConstNode(lc.bytes(), lc.publicDescription());
case UnaryExp ue -> switch (ue.unaryOp()) {
case Neg ignored -> NegNodeGen.create(recurseExp(ue.exp()));
case Not ignored -> NotNodeGen.create(recurseExp(ue.exp()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

package raw.runtime.truffle.ast.expressions.literals;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import raw.compiler.rql2.api.LocationDescription$;
import raw.runtime.truffle.ExpressionNode;
Expand All @@ -23,17 +24,23 @@
public class LocationConstNode extends ExpressionNode {

private final byte[] value;
private final String publicDescription;

public LocationConstNode(byte[] value) {
public LocationConstNode(byte[] value, String publicDescription) {
this.value = value;
this.publicDescription = publicDescription;
}

@Override
public final Object executeGeneric(VirtualFrame virtualFrame) {
RawSettings rawSettings = RawContext.get(this).getSettings();
Location location =
LocationDescription$.MODULE$.toLocation(
LocationDescription$.MODULE$.deserialize(value), rawSettings);
return new LocationObject(location, "<value>");
Location location = getLocation(rawSettings);
return new LocationObject(location, publicDescription);
}

@CompilerDirectives.TruffleBoundary
public Location getLocation(RawSettings rawSettings) {
return LocationDescription$.MODULE$.toLocation(
LocationDescription$.MODULE$.deserialize(value), rawSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
import raw.sources.filesystem.api.FileSystemLocation;
import raw.sources.jdbc.api.JdbcServerLocation;

/**
* Truffle object representing a location.
*
* <p>The location is represented in Interop as a serialized byte array. The public description is
* represented in Interop as a string.
*/
@ExportLibrary(InteropLibrary.class)
public final class LocationObject implements TruffleObject {
private final Location location;
Expand Down Expand Up @@ -89,6 +95,16 @@ public byte[] getBytes() {
return byteArray;
}

@ExportMessage
final boolean isString() {
return true;
}

@ExportMessage
final String asString() {
return publicDescription;
}

@ExportMessage
boolean hasArrayElements() {
return true;
Expand Down

0 comments on commit 400e116

Please sign in to comment.