Skip to content

Commit

Permalink
Реализована библиотечная функция Write (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed Nov 19, 2019
1 parent 3cc3ea6 commit 36d7833
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions autotests/write.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ENTRY Go {
= <Open 'w' 10 'write.tmp'>
<Eq () <Write 10 'Hello, '>>
<Eq () <Write 10 'World!'>>
<Eq () <Close 10>>
<Open 'r' 10 'write.tmp'>
<Eq ('Hello, World!' 0) <Get 10>>
<Close 10>
}

Eq { (e.X) e.X = }
18 changes: 14 additions & 4 deletions lib/Library.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ R05_DEFINE_ENTRY_FUNCTION(Ord, "Ord") {


enum output_func_type {
PROUT, PUTOUT,
PROUT, PUTOUT, WRITE
};

static void output_func(
Expand All @@ -510,7 +510,7 @@ static void output_func(
if (type == PROUT) {
before_expr = callee;
output = stdout;
} else if (type == PUTOUT) {
} else if (type == PUTOUT || type == WRITE) {
struct r05_node *pfile_no = callee->next;

if (R05_DATATAG_NUMBER != pfile_no->tag) {
Expand Down Expand Up @@ -554,7 +554,9 @@ static void output_func(
}
}

CHECK_PRINTF(fprintf(output, "\n"));
if (type != WRITE) {
CHECK_PRINTF(fprintf(output, "\n"));
}

#undef CHECK_PRINTF

Expand Down Expand Up @@ -937,6 +939,14 @@ R05_DEFINE_ENTRY_FUNCTION(Compare, "Compare") {
}


/**
66. <Write e.Expr> == []
*/
R05_DEFINE_ENTRY_FUNCTION(Write, "Write") {
output_func(arg_begin, arg_end, WRITE);
}


/**
67. <ListOfBuiltin> == (s.No s.Name s.Type)*
Expand Down Expand Up @@ -1042,7 +1052,7 @@ R05_DEFINE_ENTRY_FUNCTION(ListOfBuiltin, "ListOfBuiltin") {
/* ALLOC_BUILTIN(63, XMLParse, regular) */
/* ALLOC_BUILTIN(64, Random, regular) */
/* ALLOC_BUILTIN(65, RandomDigit, regular) */
/* ALLOC_BUILTIN(66, Write, regular) */
ALLOC_BUILTIN(66, Write, regular)
ALLOC_BUILTIN(67, ListOfBuiltin, regular)
/* ALLOC_BUILTIN(68, SizeOf, regular) */
/* ALLOC_BUILTIN(69, GetPID, regular) */
Expand Down

0 comments on commit 36d7833

Please sign in to comment.