ohua-dev / ohuac

A standalone compiler for ohua algorithms
Eclipse Public License 1.0
1 stars 0 forks source link

Generated JSON Map is inconsistent #1

Closed Feliix42 closed 6 years ago

Feliix42 commented 6 years ago

The JSON file that is generated from the test file (test-resources/some_ns.ohuac) is not consistent. For an arc source value, it either yields 0 or another JSON object. An example is shown below.

{
    "target": {
        "operator": 5,
        "index": 1
    },
    "source": {
        "type": "env",
        "val": 0
    }
},
{
    "target": {
        "operator": 6,
        "index": 0
    },
    "source": {
        "type": "local",
        "val": {
            "operator": 5,
            "index": -1
        }
    }
},

If I see this correctly, this behaviour is intended to function as the JSON equivalent of an Optional or a Maybe. If this is the case, I suggest to replace the 0 fields with the JSON null value.

This would enable me to natively deserialise the val field as an Option<T> type in Rust. 🙃 But if this is intended behaviour and val can be an integer value != 0 or this cannot be changed, I have to come up with a workaround to parse the file.

JustusAdam commented 6 years ago

No it is not intended as such.

In fact the "source" field is in habited by the Source type which is an algebraic data type and can have two representations. Either it is a local source ("type" field has value "local") or a value from the environment ("type" field has value "env"). In case of a local source the "val" field contains a value of type Target and in case it is an environment argument "val" contains the numeric reference to that environment arg.

Feliix42 commented 6 years ago

Ok, it's my fault then. Thanks for the explanation!