let resolve_variable name env =
        let rec find scopes =
                try
                        let (ind, uid) = StringMap.find name scopes.variable_map
                        in (uid, ind)
                with Not_found ->
                                (match scopes.parent with
                                        | Some parent -> find parent
                                        | None -> raise Not_found)
        in
        let rec find_in_stackframes = function
                | [] -> raise Not_found
                | scope:: tl ->
                                try
                                        let (uid, ind) = find scope
                                        in (LocalVar(uid, List.length tl, ind))
                                with
                                | Not_found -> find_in_stackframes tl
        in
        try
                match env.locals with
                | [] -> let (uid, ind) = find env.globals in (GlobalVar(uid, ind))
                | _ -> (try
                                        find_in_stackframes env.locals
                                with Not_found ->
                                                let (uid, ind) = find env.globals in (GlobalVar(uid, ind)))
        with Not_found -> raise (Variable_not_found name)