Remove support for current_input and current_output The current input and output is mostly useful for interactive programs running from the command line, but Prolog Cafe is never used that way by Gerrit Code Review. Change-Id: Id9163384e960f9c39cd9e0169b25b9cf0b9e95a2
diff --git a/BUCK b/BUCK index f170833..03a0c9a 100644 --- a/BUCK +++ b/BUCK
@@ -1,5 +1,18 @@ SRC = 'java/com/googlecode/prolog_cafe/' +REPL = [ + SRC + 'builtin/PRED_$write_toString_2.java', + SRC + 'lang/PrologMain.java', +] + +IO = [ + SRC + 'builtin/PRED_close_2.java', + SRC + 'builtin/PRED_flush_output_1.java', + SRC + 'builtin/PRED_open_4.java', + SRC + 'builtin/PRED_read_line_2.java', + SRC + 'builtin/PRED_tab_2.java', +] + genrule( name = 'all', cmd = ':>all', @@ -21,15 +34,12 @@ java_library( name = 'lang', - srcs = glob( - [SRC + 'lang/*.java'], - excludes = [SRC + 'lang/PrologMain.java'], - ), + srcs = glob([SRC + 'lang/*.java'], excludes = REPL), ) java_library( name = 'builtin', - srcs = glob([SRC + 'builtin/*.java']) + [ + srcs = glob([SRC + 'builtin/*.java'], excludes = REPL + IO) + [ ':builtin_srcs', ':system_srcs', ], @@ -49,6 +59,21 @@ ) java_library( + name = 'io', + srcs = IO + [':io_srcs'], + deps = [ + ':builtin', + ':lang', + ], +) + +pl2j( + name = 'io_srcs', + src = 'src/builtin/io.pl', + out = 'io.src.zip', +) + +java_library( name = 'compiler', srcs = glob([SRC + 'compiler/**/*.java']) + [ ':pl2am_srcs', @@ -56,6 +81,7 @@ ], deps = [ ':builtin', + ':io', ':lang', ], ) @@ -80,12 +106,10 @@ java_library( name = 'cafeteria_lib', - srcs = [ - SRC + 'lang/PrologMain.java', - ':cafeteria_srcs', - ], + srcs = REPL + [':cafeteria_srcs'], deps = [ ':builtin', + ':io', ':lang', ], )
diff --git a/src/builtin/PRED_$fast_write_1.java b/src/builtin/PRED_$fast_write_1.java deleted file mode 100644 index d64aafa..0000000 --- a/src/builtin/PRED_$fast_write_1.java +++ /dev/null
@@ -1,22 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - * <code>'$fast_write'/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_$fast_write_1 extends Predicate.P1 { - public PRED_$fast_write_1(Term a1, Operation cont) { - arg1 = a1; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1; - a1 = arg1.dereference(); - engine.getCurrentOutput().print(a1.toString()); - return cont; - } -}
diff --git a/src/builtin/PRED_$fast_writeq_1.java b/src/builtin/PRED_$fast_writeq_1.java deleted file mode 100644 index 8a47802..0000000 --- a/src/builtin/PRED_$fast_writeq_1.java +++ /dev/null
@@ -1,22 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - * <code>'$fast_writeq'/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_$fast_writeq_1 extends Predicate.P1 { - public PRED_$fast_writeq_1(Term a1, Operation cont) { - arg1 = a1; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1; - a1 = arg1.dereference(); - engine.getCurrentOutput().print(a1.toQuotedString()); - return cont; - } -}
diff --git a/src/builtin/PRED_$get_prolog_impl_flag_2.java b/src/builtin/PRED_$get_prolog_impl_flag_2.java index f8306f2..8b314e9 100644 --- a/src/builtin/PRED_$get_prolog_impl_flag_2.java +++ b/src/builtin/PRED_$get_prolog_impl_flag_2.java
@@ -18,7 +18,6 @@ private static final SymbolTerm MAX_ARITY = SymbolTerm.intern("max_arity"); private static final SymbolTerm UNKNOWN = SymbolTerm.intern("unknown"); private static final SymbolTerm DOUBLE_QUOTES = SymbolTerm.intern("double_quotes"); - private static final SymbolTerm PRINT_STACK_TRACE = SymbolTerm.intern("print_stack_trace"); public PRED_$get_prolog_impl_flag_2(Term a1, Term a2, Operation cont) { arg1 = a1; @@ -66,9 +65,6 @@ } else if (a1.equals(DOUBLE_QUOTES)) { if (! a2.unify(SymbolTerm.intern(engine.getDoubleQuotes()), engine.trail)) return engine.fail(); - } else if (a1.equals(PRINT_STACK_TRACE)) { - if (! a2.unify(SymbolTerm.intern(engine.getPrintStackTrace()), engine.trail)) - return engine.fail(); } else { return engine.fail(); }
diff --git a/src/builtin/PRED_$get_stream_manager_1.java b/src/builtin/PRED_$get_stream_manager_1.java deleted file mode 100644 index 5628b34..0000000 --- a/src/builtin/PRED_$get_stream_manager_1.java +++ /dev/null
@@ -1,27 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - <code>'$get_stream_manager'/1</code><br> - @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - @version 1.0 -*/ -class PRED_$get_stream_manager_1 extends Predicate.P1 { - public PRED_$get_stream_manager_1(Term a1, Operation cont) { - arg1 = a1; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1; - a1 = arg1; - - a1 = a1.dereference(); - if (! a1.isVariable()) - throw new IllegalTypeException(this, 1, "variable", a1); - if (! a1.unify(new JavaObjectTerm(engine.getStreamManager()), engine.trail)) - return engine.fail(); - return cont; - } -}
diff --git a/src/builtin/PRED_$print_stack_trace_1.java b/src/builtin/PRED_$print_stack_trace_1.java deleted file mode 100644 index d91a16e..0000000 --- a/src/builtin/PRED_$print_stack_trace_1.java +++ /dev/null
@@ -1,32 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - * <code>'$print_stack_trace'/1</code> - * @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - * @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - * @version 1.0 -*/ -class PRED_$print_stack_trace_1 extends Predicate.P1 { - public PRED_$print_stack_trace_1(Term a1, Operation cont) { - arg1 = a1; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1; - a1 = arg1; - - a1 = a1.dereference(); - if (a1.isVariable()) - throw new PInstantiationException(this, 1); - if (! a1.isJavaObject()) - throw new IllegalTypeException(this, 1, "java", a1); - Object obj = ((JavaObjectTerm) a1).object(); - if (obj instanceof InterruptedException) - throw new JavaInterruptedException((InterruptedException) obj); - if (engine.getPrintStackTrace().equals("on")) - engine.control.printStackTrace((Throwable) obj); - return cont; - } -}
diff --git a/src/builtin/PRED_$set_prolog_impl_flag_2.java b/src/builtin/PRED_$set_prolog_impl_flag_2.java index b7994b1..222f656 100644 --- a/src/builtin/PRED_$set_prolog_impl_flag_2.java +++ b/src/builtin/PRED_$set_prolog_impl_flag_2.java
@@ -11,7 +11,6 @@ private static final SymbolTerm DEBUG = SymbolTerm.intern("debug"); private static final SymbolTerm UNKNOWN = SymbolTerm.intern("unknown"); private static final SymbolTerm DOUBLE_QUOTES = SymbolTerm.intern("double_quotes"); - private static final SymbolTerm PRINT_STACK_TRACE = SymbolTerm.intern("print_stack_trace"); public PRED_$set_prolog_impl_flag_2(Term a1, Term a2, Operation cont) { arg1 = a1; @@ -43,10 +42,6 @@ if (! a2.isSymbol()) return engine.fail(); engine.setDoubleQuotes(((SymbolTerm)a2).name()); - } else if (a1.equals(PRINT_STACK_TRACE)) { - if (! a2.isSymbol()) - return engine.fail(); - engine.setPrintStackTrace(((SymbolTerm)a2).name()); } else { return engine.fail(); }
diff --git a/src/builtin/PRED_close_2.java b/src/builtin/PRED_close_2.java index 9d9ddbb..855d9e3 100644 --- a/src/builtin/PRED_close_2.java +++ b/src/builtin/PRED_close_2.java
@@ -1,6 +1,23 @@ package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.PushbackReader; + +import com.googlecode.prolog_cafe.lang.ExistenceException; +import com.googlecode.prolog_cafe.lang.HashtableOfTerm; +import com.googlecode.prolog_cafe.lang.IllegalDomainException; +import com.googlecode.prolog_cafe.lang.IllegalTypeException; +import com.googlecode.prolog_cafe.lang.JavaObjectTerm; +import com.googlecode.prolog_cafe.lang.ListTerm; +import com.googlecode.prolog_cafe.lang.Operation; +import com.googlecode.prolog_cafe.lang.PInstantiationException; +import com.googlecode.prolog_cafe.lang.Predicate; +import com.googlecode.prolog_cafe.lang.Prolog; +import com.googlecode.prolog_cafe.lang.StructureTerm; +import com.googlecode.prolog_cafe.lang.SymbolTerm; +import com.googlecode.prolog_cafe.lang.SystemException; +import com.googlecode.prolog_cafe.lang.Term; +import com.googlecode.prolog_cafe.lang.TermException; /** * <code>close/2</code><br> * @author Mutsunori Banbara (banbara@kobe-u.ac.jp) @@ -74,10 +91,6 @@ } if (stream instanceof PushbackReader) { PushbackReader in = (PushbackReader) stream; - if (in.equals(engine.getUserInput())) - return cont; - if (in.equals(engine.getCurrentInput())) - engine.setCurrentInput(engine.getUserInput()); try { in.close(); } catch (IOException e) { @@ -90,10 +103,6 @@ throw new SystemException("output stream error"); } out.flush(); - if (out.equals(engine.getUserOutput()) || out.equals(engine.getUserError())) - return cont; - if (out.equals(engine.getCurrentOutput())) - engine.setCurrentOutput(engine.getUserOutput()); out.close(); } else { throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
diff --git a/src/builtin/PRED_current_input_1.java b/src/builtin/PRED_current_input_1.java deleted file mode 100644 index fc4a0b9..0000000 --- a/src/builtin/PRED_current_input_1.java +++ /dev/null
@@ -1,31 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - * <code>current_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_current_input_1 extends Predicate.P1 { - public PRED_current_input_1(Term a1, Operation cont) { - arg1 = a1; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.requireFeature(Prolog.Feature.IO, this, arg1); - engine.setB0(); - Term a1; - a1 = arg1; - a1 = a1.dereference(); - if (a1.isVariable()) { - ((VariableTerm)a1).bind(new JavaObjectTerm(engine.getCurrentInput()), engine.trail); - } else if (a1.isJavaObject()) { - if (! a1.unify(new JavaObjectTerm(engine.getCurrentInput()), engine.trail)) - return engine.fail(); - } else { - throw new IllegalDomainException(this,1,"stream",a1); - } - return cont; - } -}
diff --git a/src/builtin/PRED_current_output_1.java b/src/builtin/PRED_current_output_1.java deleted file mode 100644 index 4638118..0000000 --- a/src/builtin/PRED_current_output_1.java +++ /dev/null
@@ -1,31 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - * <code>current_output/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_current_output_1 extends Predicate.P1 { - public PRED_current_output_1(Term a1, Operation cont) { - arg1 = a1; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.requireFeature(Prolog.Feature.IO, this, arg1); - engine.setB0(); - Term a1; - a1 = arg1; - a1 = a1.dereference(); - if (a1.isVariable()) { - ((VariableTerm)a1).bind(new JavaObjectTerm(engine.getCurrentOutput()), engine.trail); - } else if (a1.isJavaObject()) { - if (! a1.unify(new JavaObjectTerm(engine.getCurrentOutput()), engine.trail)) - return engine.fail(); - } else { - throw new IllegalDomainException(this,1,"stream",a1); - } - return cont; - } -}
diff --git a/src/builtin/PRED_get_byte_2.java b/src/builtin/PRED_get_byte_2.java deleted file mode 100644 index eab2506..0000000 --- a/src/builtin/PRED_get_byte_2.java +++ /dev/null
@@ -1,68 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - * <code>get_byte/2</code><br> - * @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - * @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - * @version 1.1 - * @since 1.1 -*/ -public class PRED_get_byte_2 extends Predicate.P2 { - private static final IntegerTerm INT_EOF = new IntegerTerm(-1); - - public PRED_get_byte_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - Object stream = null; - - // InByte - a2 = a2.dereference(); - if (! a2.isVariable()) { - if (! a2.isInteger()) - throw new IllegalTypeException(this, 2, "in_byte", a2); - int n = ((IntegerTerm)a2).intValue(); - if (n != -1 && (n < 0 || n > 255)) - throw new RepresentationException(this, 2, "in_byte"); - } - // S_or_a - 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, ""); - // read single byte - try { - int c = ((PushbackReader)stream).read(); - if (c < 0) { // EOF - if (! a2.unify(INT_EOF, engine.trail)) - return engine.fail(); - return cont; - } - if (c > 255) - throw new RepresentationException(this, 0, "byte"); - if (! a2.unify(new IntegerTerm(c), engine.trail)) - return engine.fail(); - return cont; - } catch (IOException e) { - throw new TermException(new JavaObjectTerm(e)); - } - } -}
diff --git a/src/builtin/PRED_get_code_2.java b/src/builtin/PRED_get_code_2.java deleted file mode 100644 index da9f515..0000000 --- a/src/builtin/PRED_get_code_2.java +++ /dev/null
@@ -1,67 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - * <code>get_code/2</code><br> - * @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - * @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - * @version 1.0 -*/ -public class PRED_get_code_2 extends Predicate.P2 { - private static final IntegerTerm INT_EOF = new IntegerTerm(-1); - - public PRED_get_code_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - Object stream = null; - - // Char - a2 = a2.dereference(); - if (! a2.isVariable()) { - if (! a2.isInteger()) - throw new IllegalTypeException(this, 2, "integer", a2); - int n = ((IntegerTerm)a2).intValue(); - if (n != -1 && ! Character.isDefined(n)) - throw new RepresentationException(this, 2, "in_character_code"); - } - // S_or_a - 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, ""); - // read single character - try { - int c = ((PushbackReader)stream).read(); - if (c < 0) { // EOF - if (! a2.unify(INT_EOF, engine.trail)) - return engine.fail(); - return cont; - } - if (! Character.isDefined(c)) - throw new RepresentationException(this, 0, "character"); - if (! a2.unify(new IntegerTerm(c), engine.trail)) - return engine.fail(); - return cont; - } catch (IOException e) { - throw new TermException(new JavaObjectTerm(e)); - } - } -}
diff --git a/src/builtin/PRED_nl_0.java b/src/builtin/PRED_nl_0.java deleted file mode 100644 index 5d58fd8..0000000 --- a/src/builtin/PRED_nl_0.java +++ /dev/null
@@ -1,20 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -/** - * <code>nl/0</code><br> - * @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - * @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - * @version 1.0 - */ -public class PRED_nl_0 extends Predicate { - - public PRED_nl_0(Operation cont) { - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - engine.getCurrentOutput().println(); - return cont; - } -}
diff --git a/src/builtin/PRED_peek_byte_2.java b/src/builtin/PRED_peek_byte_2.java deleted file mode 100644 index b8fcde6..0000000 --- a/src/builtin/PRED_peek_byte_2.java +++ /dev/null
@@ -1,69 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - <code>peek_byte/2</code><br> - @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - @version 1.1 - @since 1.1 -*/ -public class PRED_peek_byte_2 extends Predicate.P2 { - private static final IntegerTerm INT_EOF = new IntegerTerm(-1); - - public PRED_peek_byte_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - Object stream = null; - - // InByte - a2 = a2.dereference(); - if (! a2.isVariable()) { - if (! a2.isInteger()) - throw new IllegalTypeException(this, 2, "in_byte", a2); - int n = ((IntegerTerm)a2).intValue(); - if (n != -1 && (n < 0 || n > 255)) - throw new RepresentationException(this, 2, "in_byte"); - } - // S_or_a - 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, ""); - // read single byte - try { - int c = ((PushbackReader)stream).read(); - if (c < 0) { // EOF - if (! a2.unify(INT_EOF, engine.trail)) - return engine.fail(); - return cont; - } - if (c > 255) - throw new RepresentationException(this, 0, "byte"); - ((PushbackReader)stream).unread(c); - if (! a2.unify(new IntegerTerm(c), engine.trail)) - return engine.fail(); - return cont; - } catch (IOException e) { - throw new TermException(new JavaObjectTerm(e)); - } - } -}
diff --git a/src/builtin/PRED_peek_char_2.java b/src/builtin/PRED_peek_char_2.java deleted file mode 100644 index cb7330c..0000000 --- a/src/builtin/PRED_peek_char_2.java +++ /dev/null
@@ -1,71 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - <code>peek_char/2</code><br> - @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - @version 1.0 -*/ -public class PRED_peek_char_2 extends Predicate.P2 { - private static final SymbolTerm SYM_EOF = SymbolTerm.intern("end_of_file"); - - public PRED_peek_char_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - boolean inCharacter(Term t) { - if (! t.isSymbol()) - return false; - if (t.equals(SYM_EOF)) - return true; - return ((SymbolTerm)t).name().length() == 1; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - Object stream = null; - - // Char - a2 = a2.dereference(); - if (! a2.isVariable() && ! inCharacter(a2)) - throw new IllegalTypeException(this, 2, "in_character", a2); - // S_or_a - 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, ""); - // read single character - try { - int c = ((PushbackReader)stream).read(); - if (c < 0) { // EOF - if (! a2.unify(SYM_EOF, engine.trail)) - return engine.fail(); - return cont; - } - if (! Character.isDefined(c)) - throw new RepresentationException(this, 0, "character"); - ((PushbackReader)stream).unread(c); - if (! a2.unify(SymbolTerm.create((char)c), engine.trail)) - return engine.fail(); - return cont; - } catch (IOException e) { - throw new TermException(new JavaObjectTerm(e)); - } - } -}
diff --git a/src/builtin/PRED_peek_code_2.java b/src/builtin/PRED_peek_code_2.java deleted file mode 100644 index c19676f..0000000 --- a/src/builtin/PRED_peek_code_2.java +++ /dev/null
@@ -1,68 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - <code>peek_code/2</code><br> - @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - @version 1.0 -*/ -public class PRED_peek_code_2 extends Predicate.P2 { - private static final IntegerTerm INT_EOF = new IntegerTerm(-1); - - public PRED_peek_code_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - Object stream = null; - - // Char - a2 = a2.dereference(); - if (! a2.isVariable()) { - if (! a2.isInteger()) - throw new IllegalTypeException(this, 2, "integer", a2); - int n = ((IntegerTerm)a2).intValue(); - if (n != -1 && ! Character.isDefined(n)) - throw new RepresentationException(this, 2, "in_character_code"); - } - // S_or_a - 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, ""); - // read single character - try { - int c = ((PushbackReader)stream).read(); - if (c < 0) { // EOF - if (! a2.unify(INT_EOF, engine.trail)) - return engine.fail(); - return cont; - } - if (! Character.isDefined(c)) - throw new RepresentationException(this, 0, "character"); - ((PushbackReader)stream).unread(c); - if (! a2.unify(new IntegerTerm(c), engine.trail)) - return engine.fail(); - return cont; - } catch (IOException e) { - throw new TermException(new JavaObjectTerm(e)); - } - } -}
diff --git a/src/builtin/PRED_put_byte_2.java b/src/builtin/PRED_put_byte_2.java deleted file mode 100644 index 7b9dee8..0000000 --- a/src/builtin/PRED_put_byte_2.java +++ /dev/null
@@ -1,54 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - <code>put_byte/2</code><br> - @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - @version 1.1 - @since 1.1 -*/ -public class PRED_put_byte_2 extends Predicate.P2 { - public PRED_put_byte_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - int c; - Object stream = null; - - // Byte - a2 = a2.dereference(); - if (a2.isVariable()) - throw new PInstantiationException(this, 2); - if (! a2.isInteger()) - throw new IllegalTypeException(this, 2, "byte", a2); - c = ((IntegerTerm)a2).intValue(); - if (c < 0 || c > 255) - throw new IllegalTypeException(this, 2, "byte", a2); - // S_or_a - 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 PrintWriter)) - throw new PermissionException(this, "output", "stream", a1, ""); - // print single byte - ((PrintWriter) stream).print((char)c); - return cont; - } -}
diff --git a/src/builtin/PRED_set_input_1.java b/src/builtin/PRED_set_input_1.java deleted file mode 100644 index 6a215aa..0000000 --- a/src/builtin/PRED_set_input_1.java +++ /dev/null
@@ -1,39 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.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; - } -}
diff --git a/src/builtin/PRED_set_output_1.java b/src/builtin/PRED_set_output_1.java deleted file mode 100644 index 656861b..0000000 --- a/src/builtin/PRED_set_output_1.java +++ /dev/null
@@ -1,39 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.PrintWriter; -/** - <code>set_output/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_output_1 extends Predicate.P1 { - public PRED_set_output_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 PrintWriter)) - throw new PermissionException(this, "output", "stream", a1, ""); - engine.setCurrentOutput((PrintWriter)stream); - return cont; - } -}
diff --git a/src/builtin/PRED_skip_2.java b/src/builtin/PRED_skip_2.java deleted file mode 100644 index cded854..0000000 --- a/src/builtin/PRED_skip_2.java +++ /dev/null
@@ -1,74 +0,0 @@ -package com.googlecode.prolog_cafe.builtin; -import com.googlecode.prolog_cafe.lang.*; -import java.io.*; -/** - <code>skip/2</code><br> - @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - @version 1.0 -*/ -public class PRED_skip_2 extends Predicate.P2 { - private static final IntegerTerm INT_EOF = new IntegerTerm(-1); - - public PRED_skip_2(Term a1, Term a2, Operation cont) { - arg1 = a1; - arg2 = a2; - this.cont = cont; - } - - public Operation exec(Prolog engine) { - engine.setB0(); - Term a1, a2; - a1 = arg1; - a2 = arg2; - int n; - Object stream = null; - - // Char - a2 = a2.dereference(); - if (a2.isVariable()) - throw new PInstantiationException(this, 2); - if (! a2.isInteger()) { - try { - a2 = Arithmetic.evaluate(a2); - } catch (BuiltinException e) { - e.goal = this; - e.argNo = 2; - throw e; - } - } - n = ((NumberTerm)a2).intValue(); - if (! Character.isDefined(n)) - throw new RepresentationException(this, 2, "character_code"); - // S_or_a - 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, ""); - // skip - try { - PushbackReader in = (PushbackReader) stream; - int c = in.read(); - while(c != n) { - c = in.read(); - if (c == -1) // EOF - return cont; - if (! Character.isDefined(c)) - throw new RepresentationException(this, 0, "character"); - } - return cont; - } catch (IOException e) { - throw new TermException(new JavaObjectTerm(e)); - } - } -}
diff --git a/src/builtin/builtins.pl b/src/builtin/builtins.pl index 3349f93..8e116cb 100644 --- a/src/builtin/builtins.pl +++ b/src/builtin/builtins.pl
@@ -385,10 +385,6 @@ hash_contains_key(P, PI), '$get_indices'(P, PI, H, RevRefs), '$get_instances'(RevRefs, Cls_Refs), - % ??? - %length(Cls_Refs,N), - %'$fast_write'([clause_internal,N,for,P,PI]),nl, - % '$clause_internal0'(Cls_Refs, Cl, Ref). '$clause_internal0'([], _, _) :- fail. @@ -462,7 +458,6 @@ '$check_procedure_permission'(P:PI, modify, static_procedure, assertz(T)), copy_term(Cl, NewCl), '$insert'(NewCl, Ref), - %'$fast_write'([intert,NewCl,Ref]), nl, %??? '$update_indexing'(P, PI, Cl, Ref, 'z'), fail. assertz(_). @@ -473,7 +468,6 @@ '$check_procedure_permission'(P:PI, modify, static_procedure, asserta(T)), copy_term(Cl, NewCl), '$insert'(NewCl, Ref), - %'$fast_write'([insert,NewCl,Ref]), nl, %??? '$update_indexing'(P, PI, Cl, Ref, 'a'), fail. asserta(_). @@ -484,7 +478,6 @@ '$check_procedure_permission'(P:PI, modify, static_procedure, abolish(T)), '$new_indexing_hash'(P, PI, IH), hash_get(IH, all, Refs), - %'$fast_write'([erase_all,Refs]), nl, %??? '$erase_all'(Refs), hash_remove(P, PI), fail. @@ -497,7 +490,6 @@ T = (H :- _), '$clause_internal'(P, PI, H, Cl0, Ref), copy_term(Cl0, T), - %'$fast_write'([erase,Cl0,Ref]), nl, %??? '$erase'(Ref), '$rehash_indexing'(P, PI, Ref). @@ -507,7 +499,6 @@ '$check_procedure_permission'(P:PI, access, static_procedure, retractall(Head)), '$clause_internal'(P, PI, H, Cl, Ref), copy_term(Cl, (H :- _)), - %'$fast_write'([erase,Cl,Ref]), nl, %??? '$erase'(Ref), '$rehash_indexing'(P, PI, Ref), fail. @@ -626,7 +617,6 @@ '$update_indexing'(P, PI, Cl, Ref, A_or_Z) :- '$new_indexing_hash'(P, PI, IH), '$gen_indexing_keys'(Cl, IH, Keys), - %'$fast_write'([update_indexing,P,PI,Cl,Ref,Keys]), nl, %??? '$update_indexing_hash'(A_or_Z, Keys, IH, Ref). '$gen_indexing_keys'((H :- _), _, [all]) :- atom(H), !. @@ -665,7 +655,6 @@ '$rehash_indexing'(P, PI, Ref) :- '$new_indexing_hash'(P, PI, IH), hash_keys(IH, Keys), - %'$fast_write'([rehash_indexing,P,PI,Keys]), nl, %??? '$remove_index_all'(Keys, IH, Ref). '$remove_index_all'([], _, _) :- !. @@ -829,154 +818,23 @@ '$builtin_set_diff0'([X|Xs], Ys, [Y|L]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Stream selection and control -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%:- public current_input/1 (written in Java) -%:- public current_output/1 (written in Java) -%:- public set_input/1, set_output/1. (written in Java) -%:- public open/4 (written in Java) -:- public open/3. -%:- public close/2 (written in Java) -:- public close/1. -%:- public flush_output/1.(written in Java) -:- public flush_output/0. -:- public stream_property/2. - -open(Source_sink, Mode, Stream) :- open(Source_sink, Mode, Stream, []). - -close(S_or_a) :- close(S_or_a, []). - -flush_output :- - current_output(S), - flush_output(S). - -stream_property(Stream, Stream_property) :- - var(Stream_property), - !, - '$stream_property'(Stream, Stream_property). -stream_property(Stream, Stream_property) :- - '$stream_property_specifier'(Stream_property), - !, - '$stream_property'(Stream, Stream_property). -stream_property(Stream, Stream_property) :- - illarg(domain(term,stream_property), stream_property(Stream, Stream_property), 2). - -'$stream_property'(Stream, Stream_property) :- - var(Stream), - !, - '$get_stream_manager'(SM), - hash_map(SM, Map), - '$builtin_member'((Stream,Vs), Map), - java(Stream), - '$builtin_member'(Stream_property, Vs). -'$stream_property'(Stream, Stream_property) :- - java(Stream), - !, - '$get_stream_manager'(SM), - hash_get(SM, Stream, Vs), - '$builtin_member'(Stream_property, Vs). -'$stream_property'(Stream, Stream_property) :- - illarg(domain(stream,stream), stream_property(Stream, Stream_property), 1). - -'$stream_property_specifier'(input). -'$stream_property_specifier'(output). -'$stream_property_specifier'(alias(_)). -'$stream_property_specifier'(mode(_)). -'$stream_property_specifier'(type(_)). -'$stream_property_specifier'(file_name(_)). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Character input/output -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%:- public get_char/2, get_code/2. (written in Java) -%:- public peek_char/2, peek_code/2. (written in Java) -%:- public put_char/2, put_code/2. (written in Java) -%:- public nl/0. (written in Java) - -:- public get_char/1, get_code/1. -:- public peek_char/1, peek_code/1. -:- public put_char/1, put_code/1. -:- public nl/1. - -get_char(Char) :- current_input(S), get_char(S, Char). -get_code(Code) :- current_input(S), get_code(S, Code). - -peek_char(Char) :- current_input(S), peek_char(S, Char). -peek_code(Code) :- current_input(S), peek_code(S, Code). - -put_char(Char) :- current_output(S), put_char(S, Char). -put_code(Code) :- current_output(S), put_code(S, Code). - -nl(S) :- put_char(S, '\n'). - -:- public get0/1, get0/2. -:- public get/1. -%:- public get/2. (written in Java) -:- public put/1, put/2. -:- public tab/1. -%:- public tab/2. (written in Java) -:- public skip/1. -%:- public skip/2. (written in Java) - -get0(Code) :- current_input(S), get_code(S, Code). -get0(S_or_a, Code) :- get_code(S_or_a, Code). - -get(Code) :- current_input(S), get(S, Code). - -put(Exp) :- current_output(S), put(S, Exp). -put(S_or_a, Exp) :- Code is Exp, put_code(S_or_a, Code). - -tab(N) :- current_output(S), tab(S, N). - -skip(N) :- current_input(S), skip(S, N). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Byte input/output -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- public get_byte/1, peek_byte/1, put_byte/1. -%:- public get_byte/2. % written in java -%:- public peek_byte/2. % written in java -%:- public put_byte/2. % written in java - -get_byte(Byte) :- - current_input(S), - get_byte(S, Byte). - -peek_byte(Byte) :- - current_input(S), - peek_byte(S, Byte). - -put_byte(Byte) :- - current_output(S), - put_byte(S, Byte). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Term input/output (read) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- public read/1, read/2. -:- public read_with_variables/2, read_with_variables/3. -:- public read_line/1. +:- public read/2. +:- public read_with_variables/3. %:- public read_line/2. (written in Java) :- dynamic '$tokens'/1. -read(X) :- current_input(S), read(S, X). - read(S_or_a, X) :- read_tokens(S_or_a, Tokens, _), parse_tokens(X, Tokens), !. -read_with_variables(X, Vs) :- - current_input(S), - read_with_variables(S, X, Vs). - read_with_variables(S_or_a, X, Vs) :- read_tokens(S_or_a, Tokens, Vs), parse_tokens(X, Tokens), !. -read_line(X) :- current_input(S), read_line(S, X). - % read_token(S_or_a, Token) reads one token from the input, % and unifies Token with: % error(Atom), @@ -987,8 +845,6 @@ % var(Atom), % string(CharCodeList) -%read_token(Token) :- current_input(S), read_token(S, Token). - read_token(S_or_a, Token) :- '$read_token0'(S_or_a, Type, Token0), '$read_token1'([Type], Token0, Token). @@ -1007,11 +863,6 @@ % Token for a variable has a form of var(Name,Variable). % Vs is a list of Name=Variable pairs. -%read_tokens(Tokens, Vs) :- -% current_input(Stream), -% '$read_tokens'(Stream, Tokens, Vs, []), -% !. - read_tokens(Stream, Tokens, Vs) :- '$read_tokens'(Stream, Tokens, Vs, []), !. @@ -1021,9 +872,8 @@ '$read_tokens1'(Stream, Token, Tokens, Vs, VI). '$read_tokens1'(Stream, error(Message), [], _, _) :- !, - write('{SYNTAX ERROR}'), nl, - write('** '), write(Message), write(' **'), nl, '$read_tokens_until_fullstop'(Stream), + raise_exception(syntax_error(Message)), fail. '$read_tokens1'(_Stream, end_of_file, [end_of_file,'.'], [], _) :- !. '$read_tokens1'(_Stream, '.', ['.'], [], _) :- !. @@ -1267,71 +1117,27 @@ '$parse_tokens_peep_next'(Next, S, S) :- S = [Next|_]. '$parse_tokens_error'(Message, S0, _S) :- - write('{SYNTAX ERROR}'), nl, write('** '), - '$parse_tokens_write_message'(Message), write(' **'), nl, - '$parse_tokens_error1'([], S0), clause('$tokens'(Tokens), _), - '$parse_tokens_error1'(Tokens, S0), + raise_exception(syntax_error(Message, at(Tokens))), fail. -'$parse_tokens_error1'([], _) :- !. -'$parse_tokens_error1'(Tokens, S0) :- Tokens == S0, !, - nl, write('** here **'), nl, - '$parse_tokens_error1'(Tokens, []), nl. -'$parse_tokens_error1'([Token|Tokens], S0) :- - '$parse_tokens_error2'(Token), - '$parse_tokens_error1'(Tokens, S0). - -'$parse_tokens_error2'(number(X)) :- !, write(X). -'$parse_tokens_error2'(atom(X)) :- !, writeq(X). -'$parse_tokens_error2'(var(X,_)) :- !, write(X). -'$parse_tokens_error2'(string(X)) :- !, - write('"'), '$parse_tokens_write_string'(X), write('"'). -'$parse_tokens_error2'(X) :- write(X). - -'$parse_tokens_write_string'([]). -'$parse_tokens_write_string'([C|Cs]) :- [C] = """", !, - put_code(C), put_code(C), '$parse_tokens_write_string'(Cs). -'$parse_tokens_write_string'([C|Cs]) :- - put_code(C), '$parse_tokens_write_string'(Cs). - -'$parse_tokens_write_message'([]). -'$parse_tokens_write_message'([X|Xs]) :- - write(X), write(' '), '$parse_tokens_write_message'(Xs). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Term input/output (write) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- public write/1, write/2. -:- public writeq/1, writeq/2. -:- public write_canonical/1, write_canonical/2. -:- public write_term/2, write_term/3. - -write(Term) :- - current_output(S), - write_term(S, Term, [numbervars(true)]). +:- public write/2. +:- public writeq/2. +:- public write_canonical/2. +:- public write_term/3. write(S_or_a, Term) :- write_term(S_or_a, Term, [numbervars(true)]). -writeq(Term) :- - current_output(S), - write_term(S, Term, [quoted(true),numbervars(true)]). - writeq(S_or_a, Term) :- write_term(S_or_a, Term, [quoted(true),numbervars(true)]). -write_canonical(Term) :- - current_output(S), - write_term(S, Term, [quoted(true),ignore_ops(true)]). - write_canonical(S_or_a, Term) :- write_term(S_or_a, Term, [quoted(true),ignore_ops(true)]). -write_term(Term, Options) :- - current_output(S), - write_term(S, Term, Options). - write_term(S_or_a, Term, Options) :- '$write_term'(S_or_a, Term, Options), fail. @@ -1763,16 +1569,12 @@ current_prolog_flag(Flag, Term) :- illarg(type(atom), current_prolog_flag(Flag,Term), 1). -% '$prolog_impl_flag'(bounded, _, changeable(no)). '$prolog_impl_flag'(max_integer, _, changeable(no)). '$prolog_impl_flag'(min_integer, _, changeable(no)). -% '$prolog_impl_flag'(integer_rounding_function, [down,toward_zero], changeable(no)). -% '$prolog_impl_flag'(char_conversion, [on,off], changeable(no)). '$prolog_impl_flag'(debug, [on,off], changeable(yes)). '$prolog_impl_flag'(max_arity, _, changeable(no)). '$prolog_impl_flag'(unknown, [error,fail,warning], changeable(yes)). '$prolog_impl_flag'(double_quotes, [chars,codes,atom], changeable(no)). -'$prolog_impl_flag'(print_stack_trace, [on,off], changeable(yes)). :- public halt/0. :- public abort/0. @@ -2018,97 +1820,6 @@ '$statistics_mode'(trail). '$statistics_mode'(choice). -print_message(Type, Message) :- var(Type), !, - illarg(var, print_message(Type,Message), 1). -print_message(error, Message) :- !, - '$error_message'(Message). -print_message(info, Message) :- !, - '$fast_write'('{'), - '$builtin_message'(Message), - '$fast_write'('}'), nl. -print_message(warning, Message) :- !, - '$fast_write'('{WARNING: '), - '$builtin_message'(Message), - '$fast_write'('}'), nl. - -'$error_message'(instantiation_error(Goal,0)) :- !, - '$fast_write'('{INSTANTIATION ERROR: '), - '$write_goal'(Goal), - '$fast_write'('}'), nl. -'$error_message'(instantiation_error(Goal,ArgNo)) :- !, - '$fast_write'('{INSTANTIATION ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'('}'), nl. -'$error_message'(type_error(Goal,ArgNo,Type,Culprit)) :- !, - '$fast_write'('{TYPE ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(': expected '), '$fast_write'(Type), - '$fast_write'(', found '), write(Culprit), - '$fast_write'('}'), nl. -'$error_message'(domain_error(Goal,ArgNo,Domain,Culprit)) :- !, - '$fast_write'('{DOMAIN ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(': expected '), '$fast_write'(Domain), - '$fast_write'(', found '), write(Culprit), - '$fast_write'('}'), nl. -'$error_message'(existence_error(_Goal,0,ObjType,Culprit,_Message)) :- !, - '$fast_write'('{EXISTENCE ERROR: '), - '$fast_write'(ObjType), '$fast_write'(' '), write(Culprit), '$fast_write'(' does not exist'), - '$fast_write'('}'), nl. -'$error_message'(existence_error(Goal,ArgNo,ObjType,Culprit,_Message)) :- !, - '$fast_write'('{EXISTENCE ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(': '), - '$fast_write'(ObjType), '$fast_write'(' '), write(Culprit), '$fast_write'(' does not exist'), - '$fast_write'('}'), nl. -'$error_message'(permission_error(Goal,Operation,ObjType,Culprit,Message)) :- !, - '$fast_write'('{PERMISSION ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - can not '), '$fast_write'(Operation), '$fast_write'(' '), - '$fast_write'(ObjType), '$fast_write'(' '), write(Culprit), - '$fast_write'(': '), '$fast_write'(Message), - '$fast_write'('}'), nl. -'$error_message'(representation_error(Goal,ArgNo,Flag)) :- !, - '$fast_write'('{REPRESENTATION ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(': limit of '), '$fast_write'(Flag), '$fast_write'(' is breached'), - '$fast_write'('}'), nl. -'$error_message'(evaluation_error(Goal,ArgNo,Type)) :- !, - '$fast_write'('{EVALUATION ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(', found '), '$fast_write'(Type), - '$fast_write'('}'), nl. -'$error_message'(syntax_error(Goal,ArgNo,Type,Culprit,_Message)) :- !, - '$fast_write'('{SYNTAX ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(': expected '), '$fast_write'(Type), - '$fast_write'(', found '), write(Culprit), - '$fast_write'('}'), nl. -'$error_message'(system_error(Message)) :- !, - '$fast_write'('{SYSTEM ERROR: '), write(Message), '$fast_write'('}'), nl. -'$error_message'(internal_error(Message)) :- !, - '$fast_write'('{INTERNAL ERROR: '), write(Message), '$fast_write'('}'), nl. -'$error_message'(java_error(Goal,ArgNo,Exception)) :- !, - '$fast_write'('{JAVA ERROR: '), - '$write_goal'(Goal), - '$fast_write'(' - arg '), '$fast_write'(ArgNo), - '$fast_write'(', found '), '$write_goal'(Exception), - '$fast_write'('}'), nl, - '$print_stack_trace'(Exception). -'$error_message'(Message) :- - '$fast_write'('{'), write(Message), '$fast_write'('}'), nl. - -'$write_goal'(Goal) :- java(Goal), !, - current_output(S), '$write_toString'(S, Goal). -'$write_goal'(Goal) :- write(Goal). - illarg(Msg, Goal, ArgNo) :- var(Msg), !, illarg(var, Goal, ArgNo). illarg(var, Goal, ArgNo) :- @@ -2183,10 +1894,6 @@ '$builtin_member'(X, [X|_]). '$builtin_member'(X, [_|L]) :- '$builtin_member'(X, L). -'$builtin_message'([]) :- !. -'$builtin_message'([M]) :- !, write(M). -'$builtin_message'([M|Ms]) :- write(M), '$fast_write'(' '), '$builtin_message'(Ms). - '$member_in_reverse'(X, [_|L]) :- '$member_in_reverse'(X, L). '$member_in_reverse'(X, [X|_]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/builtin/cafeteria.pl b/src/builtin/cafeteria.pl index cb63123..7bb5f33 100644 --- a/src/builtin/cafeteria.pl +++ b/src/builtin/cafeteria.pl
@@ -43,7 +43,7 @@ flush_output. '$cafeteria'(Goal) :- - read_with_variables(Goal, Vars), + read_with_variables('user_input', Goal, Vars), '$process_order'(Goal, Vars). '$process_order'(G, _) :- var(G), !, illarg(var, (?- G), 1). @@ -68,7 +68,7 @@ '$give_answers_with_prompt'(Vs) :- '$give_an_answer'(Vs), '$fast_write'(' ? '), flush_output, - read_line(Str), + read_line('user_input', Str), Str \== ";", nl. @@ -92,7 +92,6 @@ '$consult'(F) :- '$prolog_file_name'(F, PF), open(PF, read, In), - stream_property(In, file_name(File)), print_message(info, [consulting,File,'...']), statistics(runtime, _), consult_stream(File, In), @@ -176,7 +175,7 @@ '$read_blocked'(G) :- '$fast_write'(' ? '), flush_output, - read_line(C), + read_line('user_input', C), (C == [] -> DOP = 99 ; C = [DOP|_]), '$debug_option'(DOP, G). @@ -339,3 +338,108 @@ tab(N), write(')'). '$write_dynamic_body'(B, N) :- tab(N), writeq(B). + + +print_message(Type, Message) :- var(Type), !, + illarg(var, print_message(Type,Message), 1). +print_message(error, Message) :- !, + '$error_message'(Message). +print_message(info, Message) :- !, + '$fast_write'('{'), + '$builtin_message'(Message), + '$fast_write'('}'), nl. +print_message(warning, Message) :- !, + '$fast_write'('{WARNING: '), + '$builtin_message'(Message), + '$fast_write'('}'), nl. + +write(M) :- write('user_output', M). +writeq(M) :- writeq('user_output', M). +tab(S) :- tab('user_output', S). +nl :- nl('user_output'). +flush_output :- flush_output('user_output'). +'$fast_write'(M) :- '$fast_write'('user_output', M). + +'$builtin_message'([]) :- !. +'$builtin_message'([M]) :- !, write(M). +'$builtin_message'([M|Ms]) :- + write(M), + '$fast_write'(' '), + '$builtin_message'(Ms). + +'$error_message'(instantiation_error(Goal,0)) :- !, + '$fast_write'('{INSTANTIATION ERROR: '), + '$write_goal'(Goal), + '$fast_write'('}'), nl. +'$error_message'(instantiation_error(Goal,ArgNo)) :- !, + '$fast_write'('{INSTANTIATION ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'('}'), nl. +'$error_message'(type_error(Goal,ArgNo,Type,Culprit)) :- !, + '$fast_write'('{TYPE ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(': expected '), '$fast_write'(Type), + '$fast_write'(', found '), write(Culprit), + '$fast_write'('}'), nl. +'$error_message'(domain_error(Goal,ArgNo,Domain,Culprit)) :- !, + '$fast_write'('{DOMAIN ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(': expected '), '$fast_write'(Domain), + '$fast_write'(', found '), write(Culprit), + '$fast_write'('}'), nl. +'$error_message'(existence_error(_Goal,0,ObjType,Culprit,_Message)) :- !, + '$fast_write'('{EXISTENCE ERROR: '), + '$fast_write'(ObjType), '$fast_write'(' '), write(Culprit), '$fast_write'(' does not exist'), + '$fast_write'('}'), nl. +'$error_message'(existence_error(Goal,ArgNo,ObjType,Culprit,_Message)) :- !, + '$fast_write'('{EXISTENCE ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(': '), + '$fast_write'(ObjType), '$fast_write'(' '), write(Culprit), '$fast_write'(' does not exist'), + '$fast_write'('}'), nl. +'$error_message'(permission_error(Goal,Operation,ObjType,Culprit,Message)) :- !, + '$fast_write'('{PERMISSION ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - can not '), '$fast_write'(Operation), '$fast_write'(' '), + '$fast_write'(ObjType), '$fast_write'(' '), write(Culprit), + '$fast_write'(': '), '$fast_write'(Message), + '$fast_write'('}'), nl. +'$error_message'(representation_error(Goal,ArgNo,Flag)) :- !, + '$fast_write'('{REPRESENTATION ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(': limit of '), '$fast_write'(Flag), '$fast_write'(' is breached'), + '$fast_write'('}'), nl. +'$error_message'(evaluation_error(Goal,ArgNo,Type)) :- !, + '$fast_write'('{EVALUATION ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(', found '), '$fast_write'(Type), + '$fast_write'('}'), nl. +'$error_message'(syntax_error(Goal,ArgNo,Type,Culprit,_Message)) :- !, + '$fast_write'('{SYNTAX ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(': expected '), '$fast_write'(Type), + '$fast_write'(', found '), write(Culprit), + '$fast_write'('}'), nl. +'$error_message'(system_error(Message)) :- !, + '$fast_write'('{SYSTEM ERROR: '), write(Message), '$fast_write'('}'), nl. +'$error_message'(internal_error(Message)) :- !, + '$fast_write'('{INTERNAL ERROR: '), write(Message), '$fast_write'('}'), nl. +'$error_message'(java_error(Goal,ArgNo,Exception)) :- !, + '$fast_write'('{JAVA ERROR: '), + '$write_goal'(Goal), + '$fast_write'(' - arg '), '$fast_write'(ArgNo), + '$fast_write'(', found '), '$write_goal'(Exception), + '$fast_write'('}'), nl. +'$error_message'(Message) :- + '$fast_write'('{'), write(Message), '$fast_write'('}'), nl. + +'$write_goal'(Goal) :- java(Goal), !, + '$write_toString'('user_error', Goal). +'$write_goal'(Goal) :- write(Goal).
diff --git a/src/builtin/io.pl b/src/builtin/io.pl new file mode 100644 index 0000000..16a1220 --- /dev/null +++ b/src/builtin/io.pl
@@ -0,0 +1,26 @@ +:- package 'com.googlecode.prolog_cafe.builtin'. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Stream selection and control +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%:- public open/4 (written in Java) +:- public open/3. +%:- public close/2 (written in Java) +:- public close/1. + +open(Source_sink, Mode, Stream) :- open(Source_sink, Mode, Stream, []). + +close(S_or_a) :- close(S_or_a, []). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Character input/output +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%:- public get_char/2. (written in Java) +%:- public put_char/2, put_code/2. (written in Java) +:- public nl/1. + +nl(S) :- put_char(S, '\n'). + +%:- public get/2. (written in Java) +%:- public tab/2. (written in Java) +%:- public skip/2. (written in Java)
diff --git a/src/builtin/system.pl b/src/builtin/system.pl index 2d80aff..101ff35 100644 --- a/src/builtin/system.pl +++ b/src/builtin/system.pl
@@ -133,61 +133,27 @@ system_predicate(bagof(_,_,_)). system_predicate(setof(_,_,_)). % Stream selection and control -system_predicate(current_input(_)). -system_predicate(current_output(_)). -system_predicate(set_input(_)). -system_predicate(set_output(_)). system_predicate(open(_,_,_)). system_predicate(open(_,_,_,_)). system_predicate(close(_)). system_predicate(close(_,_)). system_predicate(flush_output(_)). -system_predicate(flush_output). -system_predicate(stream_property(_,_)). % Character input/output -system_predicate(get_char(_)). system_predicate(get_char(_,_)). -system_predicate(get_code(_)). system_predicate(get_code(_,_)). -system_predicate(peek_char(_)). -system_predicate(peek_char(_,_)). -system_predicate(peek_code(_)). -system_predicate(peek_code(_,_)). -system_predicate(put_char(_)). system_predicate(put_char(_,_)). -system_predicate(put_code(_)). system_predicate(put_code(_,_)). -system_predicate(nl). system_predicate(nl(_)). -system_predicate(get0(_)). -system_predicate(get0(_,_)). -system_predicate(get(_)). system_predicate(get(_,_)). -system_predicate(put(_)). system_predicate(put(_,_)). -system_predicate(tab(_)). system_predicate(tab(_,_)). -system_predicate(skip(_)). system_predicate(skip(_,_)). -% Byte input/output -system_predicate(get_byte(_)). -system_predicate(get_byte(_,_)). -system_predicate(peek_byte(_)). -system_predicate(peek_byte(_,_)). -system_predicate(put_byte(_)). -system_predicate(put_byte(_,_)). % Term input/output -system_predicate(read(_)). system_predicate(read(_,_)). -system_predicate(read_with_variables(_,_)). system_predicate(read_with_variables(_,_,_)). -system_predicate(read_line(_)). system_predicate(read_line(_,_)). -system_predicate(write(_)). system_predicate(write(_,_)). -system_predicate(writeq(_)). system_predicate(writeq(_,_)). -system_predicate(write_canonical(_)). system_predicate(write_canonical(_,_)). system_predicate(write_term(_,_)). system_predicate(write_term(_,_,_)).
diff --git a/src/compiler/am2j.pl b/src/compiler/am2j.pl index 96354be..8da39a3 100644 --- a/src/compiler/am2j.pl +++ b/src/compiler/am2j.pl
@@ -49,14 +49,10 @@ % :- module('com.googlecode.prolog_cafe.compiler.am2j', [main/0,am2j/1]). package(_). :- package 'com.googlecode.prolog_cafe.compiler.am2j'. -:- public main/0, am2j/1. +:- public am2j/1. /***************************************************************** Main *****************************************************************/ -main :- - read(X), - am2j(X). - am2j([File]) :- !, am2j([File, '.']). am2j([File,Dir]) :- retractall(dest_dir(_)), @@ -1228,11 +1224,7 @@ for(M, M, N) :- M =< N. for(I, M, N) :- M =< N, M1 is M + 1, for(I, M1, N). -%%% print -am2j_error(M) :- am2j_message(['***','AM2JAVA','ERROR'|M]). - -am2j_message([]) :- nl, flush_output(user_output). -am2j_message([M|Ms]) :- write(M), write(' '), am2j_message(Ms). +am2j_error(M) :- raise_exception(am2j_error(M)). %%% list am2j_append([], Zs, Zs).
diff --git a/src/compiler/pl2am.pl b/src/compiler/pl2am.pl index 96cac36..f588822 100644 --- a/src/compiler/pl2am.pl +++ b/src/compiler/pl2am.pl
@@ -171,14 +171,10 @@ % :- module('com.googlecode.prolog_cafe.compiler.pl2am', [main/0,pl2am/1]). :- package 'com.googlecode.prolog_cafe.compiler.pl2am'. -:- public main/0, pl2am/1. +:- public pl2am/1. /***************************************************************** Main *****************************************************************/ -main :- - read(X), - pl2am(X). - pl2am([PrologFile, AsmFile, Opts]) :- read_in_program(PrologFile, Opts), open(AsmFile, write, Out), @@ -287,11 +283,11 @@ assert_clause((:- import G)) :- !, assert_import(G). assert_clause((:- mode _G)) :- !, - pl2am_message(['*** WARNING',mode,declaration,is,not,supported,yet]). + pl2am_error([mode,declaration,is,not,supported,yet]). assert_clause((:- multifile _G)) :- !, - pl2am_message(['*** WARNING',multifile,declaration,is,not,supported,yet]). + pl2am_error([multifile,declaration,is,not,supported,yet]). assert_clause((:- block _G)) :- !, - pl2am_message(['*** WARNING',block,declaration,is,not,supported,yet]). + pl2am_error([block,declaration,is,not,supported,yet]). assert_clause((:- G)) :- !, call(G), assert_declarations(G). @@ -1683,11 +1679,7 @@ /***************************************************************** Utilities *****************************************************************/ -%%% print -pl2am_error(M) :- pl2am_message(['***','PL2ASM','ERROR'|M]). - -pl2am_message([]) :- nl, flush_output(user_output). -pl2am_message([M|Ms]) :- write(M), write(' '), pl2am_message(Ms). +pl2am_error(M) :- raise_exception(pl2am_error(M)). %%% format mode_expr([]).
diff --git a/src/lang/BlockingPrologControl.java b/src/lang/BlockingPrologControl.java index 33e9219..907997d 100644 --- a/src/lang/BlockingPrologControl.java +++ b/src/lang/BlockingPrologControl.java
@@ -371,9 +371,6 @@ } catch (JavaInterruptedException e) { System.exit(1); } catch (PrologException e){ - if (engine.getPrintStackTrace().equals("on")) - printStackTrace(e); - else System.out.println(e.toString()); } catch (Exception e){ printStackTrace(e);
diff --git a/src/lang/Prolog.java b/src/lang/Prolog.java index c939c7e..5b62ee8 100644 --- a/src/lang/Prolog.java +++ b/src/lang/Prolog.java
@@ -73,8 +73,6 @@ protected String unknown; /** <font color="red">Not supported yet</font>. Prolog implementation flag: <code>double_quotes</code>. */ protected String doubleQuotes; - /** Prolog implementation flag: <code>print_stack_trace</code>. */ - protected String printStackTrace; /** Holds an exception term for <code>catch/3</code> and <code>throw/1</code>. */ protected Term exception; @@ -90,16 +88,6 @@ /** The size of the pushback buffer used for creating input streams. */ public static final int PUSHBACK_SIZE = 3; - /** Standard input stream. */ - protected transient PushbackReader userInput; - /** Standard output stream. */ - protected transient PrintWriter userOutput; - /** Standard error stream. */ - protected transient PrintWriter userError; - /** Current input stream. */ - protected transient PushbackReader currentInput; - /** Current output stream. */ - protected transient PrintWriter currentOutput; /** Hashtable for managing input and output streams. */ protected HashtableOfTerm streamManager; @@ -121,35 +109,6 @@ static final SymbolTerm SYM_INPUT = SymbolTerm.intern("input"); static final SymbolTerm SYM_OUTPUT = SymbolTerm.intern("output"); static final SymbolTerm SYM_TEXT = SymbolTerm.intern("text"); - static final SymbolTerm SYM_USERINPUT = SymbolTerm.intern("user_input"); - static final SymbolTerm SYM_USEROUTPUT = SymbolTerm.intern("user_output"); - static final SymbolTerm SYM_USERERROR = SymbolTerm.intern("user_error"); - - private static final PrintWriter NO_OUTPUT = new PrintWriter(new Writer() { - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - throw new IOException("Prolog.Feature.IO disabled"); - } - - @Override - public void flush() throws IOException { - } - - @Override - public void close() throws IOException { - } - }); - - private static final PushbackReader NO_INPUT = new PushbackReader(new Reader() { - @Override - public int read(char[] cbuf, int off, int len) throws IOException { - return -1; - } - - @Override - public void close() throws IOException { - } - }); public static enum Feature { /** Access to the local filesystem and console. */ @@ -186,9 +145,6 @@ * This <code>initOnce</code> method is invoked in the constructor * and initializes the following instances: * <ul> - * <li><code>userInput</code> - * <li><code>userOutput</code> - * <li><code>userError</code> * <li><code>copyHash</code> * <li><code>streamManager</code> * </ul> @@ -203,28 +159,6 @@ if (internalDB == null) internalDB = new InternalDatabase(); streamManager = new HashtableOfTerm(); - - if (features.contains(Feature.IO)) { - userInput = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), PUSHBACK_SIZE); - userOutput = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); - userError = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err)), true); - - streamManager.put(SYM_USERINPUT, new JavaObjectTerm(userInput)); - streamManager.put(new JavaObjectTerm(userInput), - makeStreamProperty(SYM_READ, SYM_INPUT, SYM_USERINPUT, SYM_TEXT)); - - streamManager.put(SYM_USEROUTPUT, new JavaObjectTerm(userOutput)); - streamManager.put(new JavaObjectTerm(userOutput), - makeStreamProperty(SYM_APPEND, SYM_OUTPUT, SYM_USEROUTPUT, SYM_TEXT)); - - streamManager.put(SYM_USERERROR, new JavaObjectTerm(userError)); - streamManager.put(new JavaObjectTerm(userError), - makeStreamProperty(SYM_APPEND, SYM_OUTPUT, SYM_USERERROR, SYM_TEXT)); - } else { - userInput = NO_INPUT; - userOutput = NO_OUTPUT; - userError = userOutput; - } } /** Initializes this Prolog engine. */ @@ -250,16 +184,12 @@ debug = "off"; unknown = "error"; doubleQuotes = "codes"; - printStackTrace = "off"; exception = NONE; startRuntime = features.contains(Feature.STATISTICS_RUNTIME) ? System.currentTimeMillis() : 0; previousRuntime = 0; - - currentInput = userInput; - currentOutput = userOutput; } /** Ensure a feature is enabled, throwing if not. */ @@ -415,19 +345,6 @@ return p; } - Term makeStreamProperty(SymbolTerm _mode, SymbolTerm io, SymbolTerm _alias, SymbolTerm _type) { - Term[] mode = {_mode}; - Term[] alias = {_alias}; - Term[] type = {_type}; - - Term t = Nil; - t = new ListTerm(new StructureTerm(SYM_MODE_1, mode ), t); - t = new ListTerm(io, t); - t = new ListTerm(new StructureTerm(SYM_ALIAS_1, alias), t); - t = new ListTerm(new StructureTerm(SYM_TYPE_1, type ), t); - return t; - } - /** Returns the current time stamp of choice point frame. */ public long getCPFTimeStamp() { return CPFTimeStamp; } @@ -466,11 +383,6 @@ /** Sets the value of Prolog implementation flag: <code>double_quotes</code>. */ public void setDoubleQuotes(String mode) { doubleQuotes = mode;} - /** Returns the value of Prolog implementation flag: <code>print_stack_trace</code>. */ - public String getPrintStackTrace() { return printStackTrace; } - /** Sets the value of Prolog implementation flag: <code>print_stack_trace</code>. */ - public void setPrintStackTrace(String mode) { printStackTrace = mode;} - /** Returns the value of <code>exception</code>. This is used in <code>catch/3</code>. */ public Term getException() { return exception; } /** Sets the value of <code>exception</code>. This is used in <code>throw/1</code>. */ @@ -484,23 +396,6 @@ /** Sets the value of <code>previousRuntime</code>. This is used in <code>statistics/2</code>. */ public void setPreviousRuntime(long t) { previousRuntime = t; } - /** Returns the standard input stream. */ - public PushbackReader getUserInput() { return userInput; } - /** Returns the standard output stream. */ - public PrintWriter getUserOutput() { return userOutput; } - /** Returns the standard error stream. */ - public PrintWriter getUserError() { return userError; } - - /** Returns the current input stream. */ - public PushbackReader getCurrentInput() { return currentInput; } - /** Sets the current input stream to <code>in</code>. */ - public void setCurrentInput(PushbackReader in) { currentInput = in; } - - /** Returns the current output stream. */ - public PrintWriter getCurrentOutput() { return currentOutput; } - /** Sets the current output stream to <code>out</code>. */ - public void setCurrentOutput(PrintWriter out) { currentOutput = out; } - /** Returns the stream manager. */ public HashtableOfTerm getStreamManager() { return streamManager; }
diff --git a/src/lang/PrologMain.java b/src/lang/PrologMain.java index 1e41c38..956248e 100644 --- a/src/lang/PrologMain.java +++ b/src/lang/PrologMain.java
@@ -1,4 +1,10 @@ package com.googlecode.prolog_cafe.lang; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.PushbackReader; import java.util.StringTokenizer; /** * Prolog Cafe launcher. @@ -47,7 +53,23 @@ usage(); System.exit(1); } + p = new BlockingPrologControl(); + p.engine.init(); + p.engine.getStreamManager().put( + SymbolTerm.intern("user_input"), + new JavaObjectTerm(new PushbackReader(new BufferedReader( + new InputStreamReader(System.in)), + Prolog.PUSHBACK_SIZE))); + p.engine.getStreamManager().put( + SymbolTerm.intern("user_output"), + new JavaObjectTerm(new PrintWriter(new BufferedWriter( + new OutputStreamWriter(System.out)), true))); + p.engine.getStreamManager().put( + SymbolTerm.intern("user_error"), + new JavaObjectTerm(new PrintWriter(new BufferedWriter( + new OutputStreamWriter(System.err)), true))); + p.setPredicate(Prolog.BUILTIN, "initialization", arg1, arg2); for (boolean r = p.call(); r; r = p.redo()) {} System.exit(0);