게시판 인덱스

 
 FAQFAQ   검색검색   멤버리스트멤버리스트   사용자 그룹사용자 그룹   사용자 등록하기사용자 등록하기 
 개인 정보개인 정보   비공개 메시지를 확인하려면 로그인하십시오비공개 메시지를 확인하려면 로그인하십시오   로그인로그인 

5-2 테스트케이스

 
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.310 Programming Languages (Fall 2017)
이전 주제 보기 :: 다음 주제 보기  
글쓴이 메시지
김현식



가입: 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

올리기올려짐: 2017년11월18일 19:05    주제: Record의 구현도 고려해야 할 것 같습니다 인용과 함께 답변

장필식 씀:
정리해주셔서 감사합니다.

다만 올해 과제에는 Record의 구현이 K--에서 빠지는 바람에 테스트케이스 몇개는 잘 안 돌아갈 수 있을것 같습니다. (특히 3, 6, 7, 8번)


https://ropas.snu.ac.kr/phpbb/viewtopic.php?t=4540
2014년도 게시판에 올라온 글입니다.
조교님의 답변을 보면 5-1과 5-2는 독립적으로 생각해야 할 것 같습니다.

https://ropas.snu.ac.kr/phpbb/viewtopic.php?t=6028
올해 게시판에도 비슷한 질문이 있습니다.
조교님께서 답변을 달아주지 않으셔서 확실하진 않지만, 별다른 언급이 없다면 14년도와 같게 해야 할 것 같습니다.
위로
사용자 정보 보기 비밀 메시지 보내기
이전 글 표시:   
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.310 Programming Languages (Fall 2017) 시간대: GMT + 9 시간(한국)
페이지 11

 
건너뛰기:  
새로운 주제를 올릴 수 없습니다
답글을 올릴 수 없습니다
주제를 수정할 수 없습니다
올린 글을 삭제할 수 없습니다
투표를 할 수 없습니다


Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group
Translated by kss & drssay