Fixes defined variables, fixes live variables, implements reduces registers, fixes risc semantic
This commit is contained in:
@ -52,6 +52,7 @@ let rec fromIntToString (alphabet: string) (x: int) : string =
|
||||
|> String.make 1)
|
||||
|
||||
|
||||
(* true if every element of la is in lb *)
|
||||
let inclusion la lb =
|
||||
let rec aux la =
|
||||
function
|
||||
@ -63,6 +64,11 @@ let inclusion la lb =
|
||||
in
|
||||
aux lb la
|
||||
|
||||
(* true if lb includes la and la includes lb *)
|
||||
let equality la lb =
|
||||
inclusion la lb && inclusion lb la
|
||||
|
||||
(* computes the result of la \setminus lb *)
|
||||
let subtraction la lb =
|
||||
let rec aux la =
|
||||
function
|
||||
@ -89,23 +95,40 @@ let unique l =
|
||||
let unique_union la lb =
|
||||
unique (la @ lb)
|
||||
|
||||
(* returns all elements both in la and in lb *)
|
||||
let unique_intersection la lb =
|
||||
let rec aux la lb acc =
|
||||
let rec aux la acc =
|
||||
match la with
|
||||
[] -> acc
|
||||
| a::la ->
|
||||
if List.mem a lb
|
||||
then aux la lb (a::acc)
|
||||
else aux la lb acc
|
||||
then aux la (a::acc)
|
||||
else aux la acc
|
||||
in
|
||||
aux la lb [] |> unique
|
||||
aux la [] |> unique
|
||||
|
||||
(* returns a list with at most n items and the rest in the second *)
|
||||
let rec take (n: int) (l: 'a list) : ('a list * 'a list) =
|
||||
match n with
|
||||
| 0 -> ([], l)
|
||||
| n ->
|
||||
match l with
|
||||
| [] -> ([], [])
|
||||
| i::ls ->
|
||||
let (t1, t2) = (take (n - 1) ls) in
|
||||
((i :: t1), (t2))
|
||||
|
||||
(* returns the list without the last element *)
|
||||
let drop_last_element_list =
|
||||
function
|
||||
| [] -> []
|
||||
| l -> l |> List.rev |> List.tl |> List.rev
|
||||
|
||||
let drop_first_element_list =
|
||||
function
|
||||
| [] -> []
|
||||
| _::l -> l
|
||||
|
||||
(* Complicated way to drop the last element and add a new option element to the
|
||||
beginning *)
|
||||
let prev l a =
|
||||
@ -152,6 +175,13 @@ let add_to_last_list (la: 'a list list) (a: 'a) : 'a list list =
|
||||
in
|
||||
aux la a
|
||||
|
||||
let rec combine_twice la lb =
|
||||
match (la, lb) with
|
||||
| [], [] -> []
|
||||
| [a], [b] -> [a, b]
|
||||
| a::la, b::lb -> (a, b) :: (combine_twice la lb)
|
||||
| _ -> []
|
||||
|
||||
let rec combine_thrice la lb lc =
|
||||
match (la, lb, lc) with
|
||||
| [], [], [] -> []
|
||||
|
||||
Reference in New Issue
Block a user