Skip to content

How to handle unpackings? #73

Description

@effectfully

An unpacking is the binary representation of an integer. Currently we use Vector Bool for that. However the current evaluator doesn't attempt to track the bidwidth of a variable by analysing constraints of the v < c form and so the evaluator and the compiler do not always agree on what the bitwidth of a variable is and sometimes compilation succeeds while evaluation doesn't (but not vice versa). There's a number of ways to approach this problem:

  1. add a separate type of unpackings instead of using Vector Bool and implement v[i] as "return the i-th bit of the v variable, unless the variable doesn't have enough bits, in which case return 0"
  2. add a lookupDef : Integer -> a -> Vector a -> a primitive, which returns a default value if there aren't enough elements in a vector
  3. add the Maybe type and add the usual lookup : a -> Vector a -> Maybe a primitive
  4. add the length : Vector a -> Integer primitive and define 2 or 3 in terms of it
  5. track bitwidth info in the evaluator like in the compiler

It should be sufficient to implement 5 for current purposes. I kind of like 1, but I don't think it makes much sense from the compilation point of view where you just can't ask for the value of a bit if that bit is outside of the specified bitwidth and we're going to make such specifications mandatory. 3 is too heavyweight of a feature, so out of scope currently. 2 or/and 4 seem useful on their own.

If I don't change my mind about something, then I'll implement 1 at some point.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions