Skip to content

Commit

Permalink
Реализованы библиотечные функции Put и Putout (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed Nov 20, 2019
1 parent 74dbfcf commit a908b36
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
13 changes: 13 additions & 0 deletions autotests/print-put.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$EXTERN True;

$ENTRY Go {
= <Eq ('Hello' () 10 Go) <Print 'Hello' () 10 Go>>
<Eq () <Prout 'Hello' () 10 Go>>
<Eq () <Open 'w' 10 'put.tmp'>>
<Eq ('Hello' () 10 Go) <Put 10 'Hello' () 10 Go>>
<Eq () <Putout 10 'Hello' () 10 Go>>
<Eq () <Close 10>>
<Eq (True ()) <RemoveFile 'put.tmp'>>
}

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


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

static void output_func(
Expand All @@ -531,10 +531,10 @@ static void output_func(
struct r05_node *p, *before_expr;
FILE *output;

if (type == PROUT) {
if (type == PRINT || type == PROUT) {
before_expr = callee;
output = stdout;
} else if (type == PUTOUT || type == WRITE) {
} else if (type == PUT || type == PUTOUT || type == WRITE) {
struct r05_node *pfile_no = callee->next;

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

#undef CHECK_PRINTF

r05_splice_to_freelist(arg_begin, arg_end);
if (type == PRINT || type == PUT) {
r05_splice_to_freelist(arg_begin, before_expr);
r05_splice_to_freelist(arg_end, arg_end);
} else if (type == PROUT || type == PUTOUT || type == WRITE) {
r05_splice_to_freelist(arg_begin, arg_end);
} else {
r05_switch_default_violation(type);
}
}


/**
24. <Print e.Expr> == []
*/
R05_DEFINE_ENTRY_FUNCTION(Print, "Print") {
output_func(arg_begin, arg_end, PRINT);
}


Expand All @@ -596,6 +611,14 @@ R05_DEFINE_ENTRY_FUNCTION(Prout, "Prout") {
}


/**
26. <Put s.FileNo e.Expr> == []
*/
R05_DEFINE_ENTRY_FUNCTION(Put, "Put") {
output_func(arg_begin, arg_end, PUT);
}


/**
27. <Putout s.FileNo e.Expr> == []
*/
Expand Down Expand Up @@ -1218,9 +1241,9 @@ R05_DEFINE_ENTRY_FUNCTION(ListOfBuiltin, "ListOfBuiltin") {
ALLOC_BUILTIN(21, Numb, regular)
ALLOC_BUILTIN(22, Open, regular)
ALLOC_BUILTIN(23, Ord, regular)
/* ALLOC_BUILTIN(24, Print, regular) */
ALLOC_BUILTIN(24, Print, regular)
ALLOC_BUILTIN(25, Prout, regular)
/* ALLOC_BUILTIN(26, Put, regular) */
ALLOC_BUILTIN(26, Put, regular)
ALLOC_BUILTIN(27, Putout, regular)
/* ALLOC_BUILTIN(28, Rp, regular) */
/* ALLOC_BUILTIN(29, Step, regular) */
Expand Down

0 comments on commit a908b36

Please sign in to comment.