|
|
이전 주제 보기 :: 다음 주제 보기 |
글쓴이 |
메시지 |
김현식
가입: 2017년 9월 5일 올린 글: 24
|
올려짐: 2017년11월17일 14:50 주제: 5-2 테스트케이스 |
|
|
15년도 게시판에 올라온 테스트 케이스를 모아서 올려봅니다.
main.ml에 있는 코드를 뒤덮어서 복붙하셔도 되고 gc_test.ml을 따로
만드셔서 작업하셔도 됩니다^^
실행결과는 주석처리로 표현하였습니다.
코드: |
open Sm5.Sm5
let _ = gc_mode := true
let check_exception cmd =
try let _ = run cmd in false with GC_Failure -> true
(* concat command n times *)
let append (n: int) (f: int -> command) (cmd: command) : command =
let rec iter i =
if i = n then []
else (f i) @ iter (i + 1) in cmd @ (iter 0)
(* 1. Simple malloc & use : trigger gc and success *)
let cmds1 =
(* To be collected *)
let cmds = [
PUSH (Val (Z 1));
MALLOC;
STORE;
] in
let cmds = append 127 (fun i ->
let v = Printf.sprintf "x%d" i in [
MALLOC;
BIND v;
PUSH (Val (Z 1));
PUSH (Id v);
STORE;
]) cmds in
(* Trigger GC *)
let cmds = cmds @ [
MALLOC;
BIND "x_new";
PUSH (Val (Z 10));
PUSH (Id "x_new");
STORE;
PUSH (Id "x_new");
LOAD;
] in
(* Check if allocated memory location's values are not affected by GC() *)
let cmds = append 127 (fun i ->
let v = Printf.sprintf "x%d" i in [
PUSH (Id v);
LOAD;
ADD;
]) cmds in
let cmds = cmds @ [PUT] in
cmds
(* 2. Simple malloc & use : gc fails *)
let cmds2 =
let cmds = append 128 (fun _ -> [
MALLOC;
BIND "x";
PUSH (Val (Z 200));
PUSH (Id "x");
STORE;
]
) [] in
let cmds = cmds @ [
(* Trigger GC *)
PUSH (Val (Z 400));
MALLOC;
STORE;
] in
(* Access all the allocated memory locations, ensuring they must not have been collected *)
let cmds = append 128 (fun _ -> [
PUSH (Id "x");
LOAD;
POP;
UNBIND;
POP;
]
) cmds in
cmds
(* 3. Gc must be able to track record : gc fail *)
let cmds3 =
let cmds = append 126 (fun i ->
let v = Printf.sprintf "x%d" i in [
MALLOC;
BIND v;
PUSH (Val (Z i));
PUSH (Id v);
STORE;
])
[] in
let cmds = cmds @ [
MALLOC;
BIND "loc";
PUSH (Val (Z 1));
PUSH (Id "loc");
STORE;
UNBIND;
BOX 1
]
in
let cmds = cmds @ [
MALLOC;
BIND "box";
PUSH (Id "box");
STORE;
(* Trigger GC *)
PUSH (Val (Z 1));
MALLOC;
STORE;
] in
(* Access all the allocated memory locations, ensuring they must not have been collected *)
let cmds = append 126 (fun i ->
let v = Printf.sprintf "x%d" i in [
PUSH (Id v);
LOAD;
POP;
]) cmds @ [PUSH (Id "box"); LOAD; UNBOX "loc"; LOAD] in
cmds
(* 4. GC must be able to track locations in the 'Continuation' : gc fails *)
let cmds4 =
let cmds = [
PUSH (Fn ("x", [
(* Trigger GC *)
PUSH (Val (Z 1));
MALLOC;
STORE;
(* Access argument location, ensuring it must not have been collected *)
PUSH (Id "x");
LOAD;
POP;
]));
BIND "f";
] in
let cmds = append 127 (fun i ->
let v = Printf.sprintf "x%d" i in [
MALLOC;
BIND v;
PUSH (Val (Z i));
PUSH (Id v);
STORE
]) cmds in
let cmds = cmds @ [
PUSH (Id "f");
PUSH (Val (Z 1));
MALLOC;
CALL;
] in
(* Access all the allocated memory locations, ensuring they must not have been collected *)
let cmds = append 127 (fun i ->
let v = Printf.sprintf "x%d" i in [
PUSH (Id v);
LOAD;
POP;
]) cmds in
cmds
(* 5. Location allocated in function can be collected after return : gc success *)
let cmds5 =
let cmds = [
PUSH (Fn ("x", [
(* To be collected *)
MALLOC;
BIND "local";
PUSH (Val (Z 1));
PUSH (Id "local");
STORE;
(* Access argument location, ensuring it must not have been collected *)
PUSH (Id "x");
LOAD;
POP;
]));
BIND "f";
] in
let cmds = append 126 (fun i ->
let v = Printf.sprintf "x%d" i in [
MALLOC;
BIND v;
PUSH (Val (Z 5));
PUSH (Id v);
STORE;
]) cmds in
let cmds = cmds @ [
PUSH (Id "f");
PUSH (Val (Z 1));
MALLOC;
CALL;
(* Trigger GC *)
PUSH (Val (Z 10));
MALLOC;
STORE;
] in
(* Check if allocated memory location's values are not affected by GC() *)
let cmds =
append 126
(fun i ->
let v = Printf.sprintf "x%d" i in
[PUSH (Id v);
LOAD;
ADD]
) (cmds @ [PUSH (Val (Z 0));]) in
let cmds = cmds @ [PUT] in
cmds
(* 6. GC must not miss a location with different offset *)
let cmds6 =
(* Location to be collected *)
let cmds = [PUSH (Val (Z 1)); MALLOC; STORE] in
(* Allocate, bind and store 126 times *)
let cmds = append 126 (fun i ->
let v = Printf.sprintf "x%d" i in [
MALLOC;
BIND v;
PUSH (Val (Z 1));
PUSH (Id v);
STORE;
]) cmds
in
(* Another location with same base, different offset *)
let cmds = cmds @
[PUSH (Val (Z 500));
PUSH (Id "x0");
PUSH (Val (Z 10));
ADD;
STORE; (* Env : "x0" ==> (a, 0) / Mem : (a, 10) ==> 500 *)
]
in
(* Trigger GC *)
let cmds = cmds @ [
MALLOC;
BIND "foo";
PUSH (Val (Z 1));
PUSH (Id "foo");
STORE
]
in
cmds @ [PUSH (Id "x0"); PUSH (Val (Z 10)); ADD; LOAD; PUT]
(*test case 7*)
let cmds7 =
let cmds = [] in
let cmds = append 126 (fun i ->
let v = Printf.sprintf "x%d" i in [
MALLOC;
BIND v;
PUSH (Val (Z 5));
PUSH (Id v);
STORE;
]) cmds in
let cmds = cmds @ [
MALLOC;
BIND "TARGET";
PUSH (Val (Z 1234));
PUSH (Id "TARGET");
STORE;
UNBIND;
PUSH (Val (Z 10));
MALLOC;
STORE;
(* Trigger GC *)
PUSH (Val (Z 10));
MALLOC;
STORE;
BOX 1;
UNBOX "TARGET";
LOAD;
] in
(* Check if allocated memory location's values are not affected by GC() *)
let cmds =
append 126
(fun i ->
let v = Printf.sprintf "x%d" i in
[PUSH (Id v);
LOAD;
POP]
) (cmds) in
let cmds = cmds @ [PUT] in
cmds
(*test case 8*)
let cmds8 =
let cmds = [
MALLOC;
BIND "val";
PUSH (Val (Z 1234));
PUSH (Id "val");
STORE;
UNBIND;
] in
let cmds = append 126 (fun i ->
let v = Printf.sprintf "x%d" i in [
BOX 1;
MALLOC;
BIND v;
PUSH (Id v);
STORE;
UNBIND;
]) cmds in
let cmds = cmds @ [
BOX 1;
MALLOC;
POP;
(* Trigger GC *)
MALLOC;
POP;
] in
(* Check if allocated memory location's values are not affected by GC() *)
let cmds =
append 126
(fun i ->
let v = Printf.sprintf "x%d" (125 - i) in
[UNBOX v;
LOAD;]
) (cmds) in
let cmds = cmds @ [UNBOX "val"; LOAD; PUT] in
cmds
let _ = run cmds1 (* 137 *)
let _ = print_endline (string_of_bool (check_exception cmds2)) (* true *)
let _ = print_endline (string_of_bool (check_exception cmds3)) (* true *)
let _ = print_endline (string_of_bool (check_exception cmds4)) (* true *)
let _ = run cmds5 (* 630 *)
let _ = run cmds6 (* 500 *)
let _ = run cmds7 (* 1234 *)
let _ = run cmds8 (* 1234 *) |
|
|
위로 |
|
|
김수
가입: 2017년 9월 5일 올린 글: 16
|
올려짐: 2017년11월17일 17:45 주제: |
|
|
감사합니다. |
|
위로 |
|
|
장필식
가입: 2017년 9월 12일 올린 글: 2
|
올려짐: 2017년11월18일 17:09 주제: |
|
|
정리해주셔서 감사합니다.
다만 올해 과제에는 Record의 구현이 K--에서 빠지는 바람에 테스트케이스 몇개는 잘 안 돌아갈 수 있을것 같습니다. (특히 3, 6, 7, 8번) |
|
위로 |
|
|
문동영
가입: 2017년 9월 11일 올린 글: 2
|
|
위로 |
|
|
|
|
새로운 주제를 올릴 수 없습니다 답글을 올릴 수 없습니다 주제를 수정할 수 없습니다 올린 글을 삭제할 수 없습니다 투표를 할 수 없습니다
|
Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group Translated by kss & drssay
|