Closed pvdrz closed 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)
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 Print
s behavior to force evaluation.
Edit: I'll take care of that, I think I have an idea
Edit: I'll take care of that, I think I have an idea
Ok but do I hear some evil laughter somewhere 😈
We use the
ast::Literal
type to represent "primitive values" in every representation. In particular, evaluation of binary and unary operations are done checking whichLiteral
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 newtypestruct Literal(i64)
to represent all literals. This would simplify ourbin_op
andun_op
functions inMachine
to something likeAdvantages
machine
would be simpler.ast::Literal
is128
bits (already taking #82 into account). This new literal would take64
bits only.Disadvantages
print(1 > 2)
would print0
if we don't do some transformations beforehand like adding the type of what's being printed in theMIR
.