Skip to content

Tidy up and add primitives to source AST op #1271

@myreen

Description

@myreen

I recently made a PR (#1270) that added Test to source op datatype. This issue is about doing more of these kinds of rearranging and additions to source op.

My PR added:

   | Test test prim_type

where

Datatype:
  test = Equal | Less | Less_alt | LessEq | LessEq_alt
End

and

Datatype:
  prim_type = BoolT
            | IntT
            | CharT
            | StrT
            | WordT word_size
            | Float64T
End

The plan is to also add a primitive that collects all direct conversions between primitive types:

   | FromTo prim_type prim_type

and also:

   | Arith arith_op prim_type

where arith will collect +, -, *, div, mod, and, or, xor, neg, not, fma.

It would also be good to structure test better. Something like:

  test = Equal | Cmp cmp | AltCmp cmp

where cmp is <, <=, >=, > and AltCmp is signed compare for words and fast string comparison for strings (#1160).

The intention is not to give every possible combination meanings (e.g. what's mod of two strings?). The structure of the definition is partly motivated by streamlining type inference and also it makes it obvious which combinations exist (rather than the ad hoc naming and duplication we have currently, e.g. Less, Lt, Less_alt and Plus, Add, FP_Add).

This redesign is consistent with slightly more exotic operations, e.g. doing bitwise-operations on arbitrary precision integers (#1074) or doing bitwise operations on two strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions