Skip to content

ast, hir, llvm: implement remaining unary and binary operators #53

@coderkalyan

Description

@coderkalyan

A variety of operators are missing support the parser, hir, and/or codegen. For example, negative integers aren't allowed (passes the lexer, but -(expression) is rejected by the parser). Similarly, bitwise logic, shifting, unary bitwise negation, and boolean logic. We should more generally do a pass over all stages of the compiler pipeline and test that everything is working everywhere (write a sample program that tests everything).

Reminder that boolean logic requires short-circuit logic. That is, when emitting a boolean and, the following is incorrect:

  1. emit left operand
  2. emit right operand
  3. emit left && right
    Instead, do the following:
  4. alloca bool
  5. emit left operand
  6. if (!left) bool = false
  7. emit right operand
  8. bool &= right

Similar for or. Whether to do this in HIR or have a special hir instruction and emit this in codegen is up to the author's discretion. It would be nice to not have an alloca, and instead use branch expressions in HIR/phi in llvm. If this ends up being difficult, its not the end of the world since opt's mem2reg pass will probably clean it up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions