pvdrz / pijama_legacy

A functional programming language
MIT License
47 stars 4 forks source link

Proposal: Remove tagging for literals during evaluation #85

Closed pvdrz closed 4 years ago

pvdrz commented 4 years ago

We use the ast::Literal type to represent "primitive values" in every representation. In particular, evaluation of binary and unary operations are done checking which Literal variant is being used in the operands.

However, when the code is lowered to the LIR we no longer need to differentiate integers and booleans. We could have a simple newtype struct Literal(i64) to represent all literals. This would simplify our bin_op and un_op functions in Machine to something like

match bin_op => {
    BinOp::Add => l1 + l2,
    BinOp::And => l1 && l2,
   ...
}

Advantages

Disadvantages

DarkDrek commented 4 years ago

In this system what would true and false be in terms of integers? 1 and 0?

A program like print(1 > 2) would print 0

It prints (1 > 2) because it doesn't evaluate its arguments. The problem is print(true > true) it would then print (1 > 1)

pvdrz commented 4 years ago

yes true and false would be 1 and 0.

We don't have polymorphism yet (I'm working on type inference so this will happen soonish). But when we do, we could dispatch each Print to a PrintInt, PrintBool and so on.

I think we should change Prints behavior to force evaluation.

Edit: I'll take care of that, I think I have an idea

DarkDrek commented 4 years ago

Edit: I'll take care of that, I think I have an idea

Ok but do I hear some evil laughter somewhere 😈