-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
Description
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:
`a ${b}` + 1
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))