lower: 소유 값을 스코프 끝에서 자동으로 해제한다
defer 목록을 '스코프가 아직 갚아야 할 것' 목록으로 일반화했다. defer 블록과 소유 값 해제가 같은 목록에 쓰인 순서대로 들어가고, 모든 이탈 경로가 역순으로 갚는다. 해제에는 값 옆에 플래그를 둔다. 값이 저장될 때 세우고 넘겨줄 때 지운다. 값이 아직 여기 있는 경로에서만 해제되는데, 그건 코드의 모양만 봐서는 알 수 없는 것이다. 검사기가 소유권을 넘기는 사용을 이미 표시해두므로 그것을 읽는다. !void 함수의 빈 return 은 성공이다. 줄 값도 없고 오류도 없다는 뜻인데 프론트엔드가 타입 불일치로 거부하고 있었다. 런타임이 할당/해제 횟수를 센다. owndrop 프로그램이 그 둘이 일치함을 실행으로 증명한다 -- 이른 반환, 이미 넘긴 값, 스코프 끝 전부.
This commit is contained in:
@@ -28,6 +28,8 @@ colon db ':',0
|
||||
newline db 13,10,0
|
||||
numbuf db 16 dup(0)
|
||||
written dd 0
|
||||
allocs dd 0
|
||||
frees dd 0
|
||||
|
||||
_DATA ends
|
||||
|
||||
@@ -168,6 +170,7 @@ fe_rt_alloc proc near
|
||||
push 8 ; HEAP_ZERO_MEMORY
|
||||
push eax
|
||||
call _HeapAlloc@12
|
||||
inc dword ptr [allocs]
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
@@ -186,12 +189,27 @@ fe_rt_free proc near
|
||||
push 0
|
||||
push eax
|
||||
call _HeapFree@12
|
||||
inc dword ptr [frees]
|
||||
free_done:
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
fe_rt_free endp
|
||||
|
||||
; fe_rt_allocs() / fe_rt_frees() -- what the allocator has been asked to do,
|
||||
; so that a test can insist every allocation was released.
|
||||
public fe_rt_allocs
|
||||
fe_rt_allocs proc near
|
||||
mov eax, [allocs]
|
||||
ret
|
||||
fe_rt_allocs endp
|
||||
|
||||
public fe_rt_frees
|
||||
fe_rt_frees proc near
|
||||
mov eax, [frees]
|
||||
ret
|
||||
fe_rt_frees endp
|
||||
|
||||
; fe_rt_exit(code) -- never returns
|
||||
public fe_rt_exit
|
||||
fe_rt_exit proc near
|
||||
|
||||
Reference in New Issue
Block a user