module Ast:sig..end
This is the output of the parser and the input of the type checker.
typelocation =Stdlib.Lexing.position * Stdlib.Lexing.position
type ident = {
|
loc : |
|
id : |
}
type unop =
| |
Uneg |
(* | -e | *) |
| |
Unot |
(* | not e | *) |
type binop =
| |
Badd |
|||
| |
Bsub |
|||
| |
Bmul |
|||
| |
Bdiv |
|||
| |
Bmod |
(* | + - * // % | *) |
| |
Beq |
|||
| |
Bneq |
|||
| |
Blt |
|||
| |
Ble |
|||
| |
Bgt |
|||
| |
Bge |
(* | == != < <= > >= | *) |
| |
Band |
|||
| |
Bor |
(* | and or | *) |
type constant =
| |
Cnone |
| |
Cbool of |
| |
Cstring of |
| |
Cint of |
type expr =
| |
Ecst of |
|||
| |
Eident of |
|||
| |
Ebinop of |
|||
| |
Eunop of |
|||
| |
Ecall of |
|||
| |
Elist of |
(* | | *) |
| |
Eget of |
(* | | *) |
type stmt =
| |
Sif of |
|||
| |
Sreturn of |
|||
| |
Sassign of |
|||
| |
Sprint of |
|||
| |
Sblock of |
|||
| |
Sfor of |
|||
| |
Seval of |
|||
| |
Sset of |
(* | | *) |
typedef =ident * ident list * stmt
typefile =def list * stmt
This is the output of the type checker and the input of the code generation.
type var = {
|
v_name : |
|||
|
mutable v_ofs : |
(* | position wrt %rbp | *) |
}
In the typed trees, all the occurrences of the same variable point to a single record of the following type.
type fn = {
|
fn_name : |
|
fn_params : |
}
Similarly, all the occurrences of a given function all point to a single record of the following type.
type texpr =
| |
TEcst of |
|||
| |
TEvar of |
|||
| |
TEbinop of |
|||
| |
TEunop of |
|||
| |
TEcall of |
|||
| |
TElist of |
|||
| |
TErange of |
(* | list(range(e1)) | *) |
| |
TEget of |
(* | | *) |
type tstmt =
| |
TSif of |
|||
| |
TSreturn of |
|||
| |
TSassign of |
|||
| |
TSprint of |
|||
| |
TSblock of |
|||
| |
TSfor of |
|||
| |
TSeval of |
|||
| |
TSset of |
(* | | *) |
typetdef =fn * tstmt
typetfile =tdef list
the block of global statements is now a `main` function