(*
 Oukseh Lee

 Copyright(c) 2000-2004 KAIST/SNU Research On Program Analysis System
 (National Creative Research Initiative Center 1998-2003)
 http://ropas.snu.ac.kr/n

 All rights reserved. This file is distributed under the terms of
 an Open Source License.
*)

module Gc = struct
  open Gc

  type stat = int * int * int * int * int * int * int * int *
              int * int * float * int * float * float
  type control = int * int * int * int * int * int

  let stat() = 
    let x = Gc.stat()
    in  x.compactions, x.fragments, x.free_blocks, x.free_words,
        x.heap_chunks, x.heap_words, x.largest_free, x.live_blocks,
        x.live_words, x.major_collections, x.major_words,
        x.minor_collections, x.minor_words, x.promoted_words
  let print_stat = Gc.print_stat

  let get () = 
    let x = Gc.get()
    in  x.major_heap_increment, x.max_overhead, x.minor_heap_size,
        x.space_overhead, x.stack_limit, x.verbose

  let set (x1,x2,x3,x4,x5,x6) = 
        Gc.set {major_heap_increment = x1; max_overhead = x2; minor_heap_size = x3;
                space_overhead = x4; stack_limit = x5; verbose = x6}

  let minor = Gc.minor
  let major = Gc.major
  let full_major = Gc.full_major
  let compact = Gc.compact
end

module Lexing = struct
  type lexbuf = Lexing.lexbuf
  let from_channel = Lexing.from_channel
  let from_string = Lexing.from_string
  let from_function = Lexing.from_function
  let lexeme = Lexing.lexeme
  let lexeme_char = Lexing.lexeme_char
  let lexeme_start = Lexing.lexeme_start
  let lexeme_end = Lexing.lexeme_end
  type lex_tables = string * string * string * string * string
  let engine (x1,x2,x3,x4,x5) = 
    Lexing.engine {Lexing.lex_backtrk = x1;
                   Lexing.lex_base = x2;
                   Lexing.lex_check = x3;
                   Lexing.lex_default = x4;
                   Lexing.lex_trans = x5}
end

module Parsing = struct
  let symbol_start = Parsing.symbol_start
  let symbol_end = Parsing.symbol_end
  let rhs_start = Parsing.rhs_start
  let rhs_end = Parsing.rhs_end
  let clear_parser = Parsing.clear_parser
  exception Parse_error = Parsing.Parse_error
  type parser_env = Parsing.parser_env
  type parse_tables = 
    (parser_env -> Obj.t) array * string * string * string *
    (string -> unit) * string * string * string * string * string * string *
    int * int array * int array
  exception YYexit = Parsing.YYexit
 let yyparse (a, c, de, dg, e, g, le, lh, nb, nc, r, s, t, ts, tb, tc) =
      Parsing.yyparse 
        {Parsing.actions = a; Parsing.check = c; Parsing.defred = de; Parsing.dgoto = dg;
         Parsing.error_function = e;
         Parsing.gindex = g; Parsing.len = le; Parsing.lhs = lh; 
		 Parsing.names_block = nb;
		 Parsing.names_const = nc; 
         Parsing.rindex = r; Parsing.sindex = s;
         Parsing.table = t; Parsing.tablesize = ts; 
         Parsing.transl_block = tb; Parsing.transl_const = tc}
 let peek_val = Parsing.peek_val
 let is_current_lookahead = Parsing.is_current_lookahead
 let parse_error = Parsing.parse_error
end

module Interop = struct
  let lexing_to_lex_tables (s1,s2,s3,s4,s5) = (s2,s1,s5,s3,s4)
  let lexing_field_refill_buff = Interop.lexing_field_refill_buff
  let lexing_field_lex_buffer = Interop.lexing_field_lex_buffer
  let lexing_field_lex_buffer_len = Interop.lexing_field_lex_buffer_len 
  let lexing_field_lex_abs_pos = Interop.lexing_field_lex_abs_pos 
  let lexing_field_lex_start_pos = Interop.lexing_field_lex_start_pos 
  let lexing_field_lex_curr_pos = Interop.lexing_field_lex_curr_pos 
  let lexing_field_lex_last_pos = Interop.lexing_field_lex_last_pos 
  let lexing_field_lex_last_action = Interop.lexing_field_lex_last_action
  let lexing_field_lex_eof_reached = Interop.lexing_field_lex_eof_reached 

  let lexing_field_update_lex_buffer = Interop.lexing_field_update_lex_buffer 
  let lexing_field_update_lex_buffer_len = Interop.lexing_field_update_lex_buffer_len
  let lexing_field_update_lex_abs_pos = Interop.lexing_field_update_lex_abs_pos 
  let lexing_field_update_lex_start_pos = Interop.lexing_field_update_lex_start_pos 
  let lexing_field_update_lex_curr_pos = Interop.lexing_field_update_lex_curr_pos 
  let lexing_field_update_lex_last_pos = Interop.lexing_field_update_lex_last_pos 
  let lexing_field_update_lex_last_action = Interop.lexing_field_update_lex_last_action 
  let lexing_field_update_lex_eof_reached = Interop.lexing_field_update_lex_eof_reached
end
