Skip to content

Commit

Permalink
refactor: remove redundant names from ir
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspots committed Jun 25, 2024
1 parent d675bc2 commit f24638f
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 49 deletions.
7 changes: 3 additions & 4 deletions proto/intermediate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ enum IRParameterCount {
}

message IRParameter {
string name = 1;
IRParameterType type = 2;
IRParameterPresence presence = 3;
IRParameterCount count = 4;
IRParameterType type = 1;
IRParameterPresence presence = 2;
IRParameterCount count = 3;
}

message IRProcessor {
Expand Down
30 changes: 7 additions & 23 deletions runners/nodejs/src/proto/intermediate.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions runners/nodejs/src/runtime/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export class Runner {

/** Parse the stage's arguments. */
const args: Map<String, unknown> = new Map();
Object.entries(stage.arguments).map(([key, arg]) => {
Object.entries(stage.arguments).map(([name, arg]) => {
if (arg.parameter!.type == IRParameterType.READER) {
const subject = new Subject<Uint8Array>();
const reader = new Reader(subject);
this.readers.set(arg.value[0], subject);
args.set(arg.parameter!.name, reader);
args.set(name, reader);
} else if (arg.parameter!.type == IRParameterType.WRITER) {
const subject = new Subject<Uint8Array>();
subject.subscribe((data) => {
Expand All @@ -51,7 +51,7 @@ export class Runner {
});
});
const writer = new Writer(subject);
args.set(arg.parameter!.name, writer);
args.set(name, writer);
} else {
console.error(
new Error(`Unsupported parameter type ${arg.parameter!.type}`),
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/parser/impl/RDFParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RDFParser(file: File) : Parser() {
else -> Log.shared.fatal("Unknown datatype: $datatype")
}

val parameter = IRParameter(path, type, presence, count)
val parameter = IRParameter(type, presence, count)
parameters[path] = parameter
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/kotlin/parser/impl/TomlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import technology.idlab.parser.intermediate.IRStage
import technology.idlab.util.Log

private fun TomlTable.toIRParameter(): IRParameter {
val name = this.getString("name") ?: Log.shared.fatal("No name found for parameter.")
val typeString = this.getString("type") ?: Log.shared.fatal("No type found for parameter.")
val presenceString =
this.getString("presence") ?: Log.shared.fatal("No presence found for parameter.")
Expand Down Expand Up @@ -48,11 +47,11 @@ private fun TomlTable.toIRParameter(): IRParameter {
else -> Log.shared.fatal("Unknown count: $countString")
}

return IRParameter(name, type, presence, count)
return IRParameter(type, presence, count)
}

private fun TomlTable.toIRArguments(parameters: Map<String, IRParameter>): List<IRArgument> {
val results = mutableListOf<IRArgument>()
private fun TomlTable.toIRArguments(parameters: Map<String, IRParameter>): Map<String, IRArgument> {
val results = mutableMapOf<String, IRArgument>()

this.keySet().forEach { name ->
if (this.isArray(name)) {
Expand All @@ -64,10 +63,10 @@ private fun TomlTable.toIRArguments(parameters: Map<String, IRParameter>): List<
values.add(value)
}

results.add(IRArgument(parameters[name]!!, values))
results[name] = IRArgument(parameters[name]!!, values)
} else {
val value = this.get(name).toString()
results.add(IRArgument(parameters[name]!!, listOf(value)))
results[name] = IRArgument(parameters[name]!!, listOf(value))
}
}

Expand All @@ -94,8 +93,10 @@ private fun TomlTable.toIRProcessor(uri: String): IRProcessor {
val parametersArray = this.getArray("parameters")!!
val result = mutableMapOf<String, IRParameter>()
for (i in 0 until parametersArray.size()) {
val table = parametersArray.getTable(i)
val name = table.getString("name") ?: Log.shared.fatal("No name found for parameter.")
val parameter = parametersArray.getTable(i).toIRParameter()
result[parameter.name] = parameter
result[name] = parameter
}

// Parse metadata.
Expand All @@ -116,8 +117,8 @@ private fun TomlTable.toIRStage(processors: Map<String, IRProcessor>, uri: Strin
val processor = processors[processorURI] ?: Log.shared.fatal("Unknown processor: $processorURI")

// Parse arguments.
val arguments = this.getTable("arguments")?.toIRArguments(processor.parameters) ?: emptyList()
return IRStage(uri, processor, arguments.associateBy { it.parameter.name })
val arguments = this.getTable("arguments")?.toIRArguments(processor.parameters) ?: emptyMap()
return IRStage(uri, processor, arguments)
}

class TomlParser(file: File) : Parser() {
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/parser/intermediate/IRParameter.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package technology.idlab.parser.intermediate

data class IRParameter(
// Argument name.
val name: String,
// The type of the argument.
val type: Type,
// Whether the argument is required.
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/runner/impl/GRPCRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private fun IRParameter.Count.toGRPC(): GRPC.IRParameterCount {

private fun IRParameter.toGRPC(): GRPC.IRParameter {
val builder = GRPC.IRParameter.newBuilder()
builder.setName(name)
builder.setType(type.toGRPC())
builder.setPresence(presence.toGRPC())
builder.setCount(count.toGRPC())
Expand Down
2 changes: 0 additions & 2 deletions src/test/kotlin/processors/NodeTransparent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ class NodeTransparent {
mapOf(
"input" to
IRParameter(
"input",
IRParameter.Type.READER,
IRParameter.Presence.REQUIRED,
IRParameter.Count.SINGLE,
),
"output" to
IRParameter(
"output",
IRParameter.Type.WRITER,
IRParameter.Presence.REQUIRED,
IRParameter.Count.SINGLE,
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/processors/TappedReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class TappedReader(args: Map<String, Any>) : Processor(args) {
mapOf(
"input" to
IRParameter(
"input",
IRParameter.Type.READER,
IRParameter.Presence.REQUIRED,
IRParameter.Count.SINGLE,
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/processors/TappedWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class TappedWriter(args: Map<String, Any>) : Processor(args) {
mapOf(
"output" to
IRParameter(
"output",
IRParameter.Type.WRITER,
IRParameter.Presence.REQUIRED,
IRParameter.Count.SINGLE,
Expand Down
2 changes: 0 additions & 2 deletions src/test/kotlin/runner/RunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ abstract class RunnerTest {

private val paramInput =
IRParameter(
"input",
IRParameter.Type.READER,
IRParameter.Presence.REQUIRED,
IRParameter.Count.SINGLE,
)

private val paramOutput =
IRParameter(
"output",
IRParameter.Type.WRITER,
IRParameter.Presence.REQUIRED,
IRParameter.Count.SINGLE,
Expand Down

0 comments on commit f24638f

Please sign in to comment.