In the ASL transpiler, it is common to check the type of a value before acting on it.
For example, when adding two values, we check to see if they are both numbers, both string and then coerce whichever the algorithm says to do.
When we have literal values, we know their type and can act accordingly, but when we have jsonPath (references) we cannot assume their types.
If we add typeHint to the ASLGraph.JsonPath object and then populate it when it we produce JsonPath objects, we could avoid runtime checks.
Example:
TemplateExpr(StirngLiteral("a "), Ident(b)) => Pass(States.Format('a {}', $.b)) => { jsonPath: heap1.str }
BinaryOp({ jsonPath: heap1.str }, NumberLiteral(1), '+')
=> Check if left is a string or number
=> if number => Pass(States.MathAdd($heap1.str, 1)
=> if string => Pass(States.Format('{}1', $heap1.str))
If we the TemplateExpr logic instead returns { jsonPath: "heap1.str", typeHint: "String" }, we can now do
TemplateExpr(StirngLiteral("a "), Ident(b)) => Pass(States.Format('a {}', $.b)) => { jsonPath: "heap1.str", typeHint: "String" }
BinaryOp({ jsonPath: heap1.str, typeHint: "String" }, NumberLiteral(1), '+') => Pass(States.Format('{}1', $heap1.str))
In the ASL transpiler, it is common to check the type of a value before acting on it.
For example, when adding two values, we check to see if they are both numbers, both string and then coerce whichever the algorithm says to do.
When we have literal values, we know their type and can act accordingly, but when we have jsonPath (references) we cannot assume their types.
If we add
typeHintto theASLGraph.JsonPathobject and then populate it when it we produce JsonPath objects, we could avoid runtime checks.Example:
If we the
TemplateExprlogic instead returns{ jsonPath: "heap1.str", typeHint: "String" }, we can now do