blob: 132207639d71fd8cca3f316889db3ab8be02b8de [file] [log] [blame]
package jp.ac.kobe_u.cs.prolog.builtin;
import jp.ac.kobe_u.cs.prolog.lang.*;
import java.io.PushbackReader;
/**
<code>set_input/1</code><br>
@author Mutsunori Banbara (banbara@kobe-u.ac.jp)
@author Naoyuki Tamura (tamura@kobe-u.ac.jp)
@version 1.0
*/
public class PRED_set_input_1 extends Predicate.P1 {
public PRED_set_input_1(Term a1, Operation cont) {
arg1 = a1;
this.cont = cont;
}
public Operation exec(Prolog engine) {
engine.setB0();
Term a1;
a1 = arg1;
Object stream = null;
a1 = a1.dereference();
if (a1.isVariable()) {
throw new PInstantiationException(this, 1);
} else if (a1.isSymbol()) {
if (! engine.getStreamManager().containsKey(a1))
throw new ExistenceException(this, 1, "stream", a1, "");
stream = ((JavaObjectTerm) engine.getStreamManager().get(a1)).object();
} else if (a1.isJavaObject()) {
stream = ((JavaObjectTerm) a1).object();
} else {
throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
}
if (! (stream instanceof PushbackReader))
throw new PermissionException(this, "input", "stream", a1, "");
engine.setCurrentInput((PushbackReader)stream);
return cont;
}
}