Skip to content

Commit

Permalink
Рефакторинг после удаления FClose (#58)
Browse files Browse the repository at this point in the history
Функция cookie_ns::close(), которая вызывалась и из Close, и из FClose,
больше не нужна — её тело упрощено и встроено в Close.

Коммит удобно смотреть с игнорированием пробелов.
  • Loading branch information
Mazdaywik committed Apr 9, 2020
1 parent c7cdaca commit 314d465
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions src/lib/Library.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2363,32 +2363,8 @@ $ENTRY Exit {
54. <Close s.FileNo> == []
If file not opened function never does.
*/
%%
namespace cookie_ns {

enum CloseMode { cCloseMode_Silent, cCloseMode_Fail };

extern refalrts::FnResult close(
refalrts::VM *vm, const refalrts::RefalIdentifier *identifiers,
refalrts::Iter arg_begin, refalrts::Iter arg_end, CloseMode mode
);

} // namespace cookie_ns
%%

$ENTRY Close {
%%
return cookie_ns::close(
vm, identifiers, arg_begin, arg_end, cookie_ns::cCloseMode_Silent
);
%%
}

%%
refalrts::FnResult cookie_ns::close(
refalrts::VM *vm, const refalrts::RefalIdentifier *identifiers,
refalrts::Iter arg_begin, refalrts::Iter arg_end, CloseMode mode
) {
refalrts::Iter content_b = 0;
refalrts::Iter content_e = 0;
refalrts::call_left(content_b, content_e, arg_begin, arg_end);
Expand All @@ -2402,33 +2378,16 @@ refalrts::FnResult cookie_ns::close(
}

FILE *handle = extract_file_handle(vm, identifiers, pfile_handle);
switch (mode) {
case cookie_ns::cCloseMode_Silent:
if (handle) {
if (! release_file_handle(vm, pfile_handle)) {
return refalrts::cRecognitionImpossible;
}
}
break;

case cookie_ns::cCloseMode_Fail:
if (! handle) {
return refalrts::cRecognitionImpossible;
}

if (handle) {
if (! release_file_handle(vm, pfile_handle)) {
return refalrts::cRecognitionImpossible;
}
break;

default:
refalrts_switch_default_violation(mode);
}

refalrts::splice_to_freelist(vm, arg_begin, arg_end);
return refalrts::cSuccess;
}
%%
}


/**
Expand Down

0 comments on commit 314d465

Please sign in to comment.