Module Bmdfc (.ml)


module Bmdfc: sig .. end
Bombs-Must-Detonate: Final Compiler

Bombs-Must-Detonate: Final Compiler Signature
Author(s): : Brian Go, : Brian Go


type instruction = Bmdirc.instruction 

type location =
| StackLoc of int
| GlobalLoc of int
| FunctionLoc of string (*Function types are stored internally as strings. The VM uses a reflection-esque mechanism to call a string. This is safe b/c the typechecker is awesome.*)
Compilation environment location information for variables

type loop_info =
| LoopBreakContinue of string * string
| LoopNoInfo
Loop information for the environment to compile break & continue statements

type environment =
| EnvTopLevel of int * (string * location) list
| EnvFrame of int * loop_info * (string * location) list * environment
Environment keeps track of variables, stack restoration, and loop break/continue labels within different frames
exception Compile_error of string
val raise_compile_error : string list -> 'a
Raises a compiler error from the concatenation of the given string list
val make_env : unit -> environment
Makes a new compilation environment
val get_cur_defs : environment -> (string * location) list
Gets all variable definitions of the current stack frame and its parents
val get_loc : string -> environment -> location
Gets the location of the given variable
val add_loc : string * location -> environment -> environment
Adds the location information of the given variable to the current stack frame
val isdef : string -> environment -> bool
Checks if the given variable is defined in the current scope or one of its parent scopes
val offset_locs : int -> environment -> environment
Offsets every stack location in the environment by i (positive = push, negative = pop
val add_frame : environment -> environment
Adds a frame to the environment
val remove_frame : environment -> environment
Removes a frame from the envrionment. Offsets the parent assuming all remaining elements in the frame were popped (see get_restore_code
val repeat_list : 'a list -> int -> 'a list
Repeats the given list n times and concatenates the repetitions
val get_restore_code : environment -> Bmdirc.instruction list
Gets the number of pops needed to restore the current stack frame to its parent
val set_loop_info : loop_info -> environment -> environment
Sets the break/continue information of the current environment frame
val get_break_label : environment -> string
Gets the relevant break label
val get_breakcontinue_restore : environment -> Bmdirc.instruction list
Gets the restore code needed to exit all frames that have been entered since the loop frame before breaking/continuing
val get_continue_label : environment -> string
Gets the relevant continue label
val make_label : string -> string
See Bmdirc.make_label
val get_stack_offset : Bmdirc.instruction -> int
Gets the change in stack pointer resulting from the given instruction. Note that this from a instruction-by-instruction point of view, not a code flow point of view.
val n_globals : environment -> int
Gets the number of global fields that need to be allocated
val compile_ir_instruction : Bmdirc.ir_instruction ->
environment -> Bmdirc.instruction list * environment
Compiles the given IR instruction
val compile_ir_instruction_list : Bmdirc.ir_buffer ->
environment -> Bmdirc.instruction list * environment
Compiles a list of IR instructions
val compile_buffer : Bmdirc.ir_buffer -> Bmdirc.instruction list
Compiles a complete buffer of IR instructions, including the compiler signal to allocate global fields

Compiles an IR instruction buffer to a final instruction buffer

val string_of_buffer : Bmdirc.instruction list -> string
Produces a string representation of the given instruction buffer
val print_buffer : Pervasives.out_channel -> Bmdirc.instruction list -> unit
Prints the given instruction buffer to the given output channel

Prints the final instruction buffer to the given output channel