How to type the core language
Closed this issue · 0 comments
The core AST returned by the type-checker does not differ from the one returned by the parser. This isn't right, because we will have to carry type information to the codegen, for example to choose between using a imm8
or a imm16
(or any other really). While this does not cause any problem at the moment (we only have 8-bytes big data), this will at some point, and can generate some poor machine code (for example, generating two times more opcodes than really necessary).
We really should add a way to type instructions, for example from their input type. Like, mov a, b
could have a type mov [[typeof(a), typeof(b)]] a, b
attached to it after type-checking. This implies to create a new core for the type-checker though. So for example, assuming we have the instruction mov 0, %eax
, the typechecker would return the typed instruction mov [[u32, r32]] 0, %eax
. This will, in turn, imply on the codegen step that we want to generate the instruction MOV r32, imm32
(notice that the order is reversed in intel notation; we are using the AT&T notation) which then is translated to B8+ rd id
(instead of the 64 bits version REX.W + B8+ rd io
─ we saved a few opcodes doing so).