Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Jul 9, 2023
1 parent a5e2f78 commit 542397e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ struct parser_ {
bool no_fp:1;
bool symbol:1;
bool reuse:1;
bool interactive:1;
};

typedef struct loaded_file_ loaded_file;
Expand Down
3 changes: 3 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,9 @@ unsigned tokenize(parser *p, bool args, bool consing)
p->end_of_term = true;
last_op = true;

if (p->interactive)
p->fp = NULL;

if (p->one_shot)
break;

Expand Down
7 changes: 4 additions & 3 deletions src/prolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,19 @@ void set_opt(prolog *pl, int level) { pl->opt = level; }
bool pl_isatty(prolog* pl) { return isatty(fileno(pl->streams[0].fp)); }
FILE *pl_stdin(prolog *pl) { return pl->streams[0].fp; }

bool pl_eval(prolog *pl, const char *s)
bool pl_eval(prolog *pl, const char *s, bool interactive)
{
if (!*s)
return false;

pl->p = parser_create(pl->curr_m);
if (!pl->p) return false;

if (isatty(fileno(stdin)))
if (interactive && isatty(fileno(stdin)))
pl->p->fp = stdin;
else pl->p->command = true;

pl->p->interactive = interactive;
pl->p->command = true;
bool ok = run(pl->p, s, true, NULL, 0);
if (get_status(pl)) pl->curr_m = pl->p->m;
parser_destroy(pl->p);
Expand Down
2 changes: 1 addition & 1 deletion src/trealla.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern void pl_destroy(prolog*);

extern bool pl_consult(prolog*, const char *filename);
extern bool pl_consult_fp(prolog*, FILE *fp, const char *filename);
extern bool pl_eval(prolog*, const char *expr);
extern bool pl_eval(prolog*, const char *expr, bool interactive);
extern bool pl_isatty(prolog*);
extern FILE *pl_stdin(prolog*);

Expand Down
4 changes: 2 additions & 2 deletions tpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int main(int ac, char *av[], char * envp[])
#endif

if (goal) {
if (!pl_eval(pl, goal)) {
if (!pl_eval(pl, goal, false)) {
int halt_code = get_halt_code(pl);
pl_destroy(pl);
return halt_code;
Expand Down Expand Up @@ -349,7 +349,7 @@ int main(int ac, char *av[], char * envp[])
g_tpl_interrupt = 0;

#if 1
pl_eval(pl, src);
pl_eval(pl, src, true);
#else
pl_sub_query *subq;
pl_query(pl, src, &subq, 0);
Expand Down

0 comments on commit 542397e

Please sign in to comment.