aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2011-06-01 19:19:55 -0700
committerShawn O. Pearce <sop@google.com>2011-06-02 07:48:01 -0700
commitfb5925a8700180736b7db2430546390a5e5959e9 (patch)
treebbfc0fccae24b264c6b2cfe411701b8f054ec36a
parentd2e3b5bfd31c5d9031dd1a15e18fa38d8f87be58 (diff)
downloadprolog-cafe-fb5925a8700180736b7db2430546390a5e5959e9.tar.gz
Remove $INSERT and $INSERT_AM magic
These allow direct insertion of Java statements within Prolog code, similar to GCC's asm() directive. Since this would permit script writers to invoke non-Predicate code we want to forbid that.
-rw-r--r--src/builtin/PRED_$compare0_3.java24
-rw-r--r--src/builtin/PRED_$compiled_predicate_3.java26
-rw-r--r--src/builtin/PRED_$compiled_predicate_or_builtin_3.java27
-rw-r--r--src/builtin/builtins.pl17
-rw-r--r--src/compiler/am2j.pl3
-rw-r--r--src/compiler/pl2am.pl14
6 files changed, 77 insertions, 34 deletions
diff --git a/src/builtin/PRED_$compare0_3.java b/src/builtin/PRED_$compare0_3.java
new file mode 100644
index 0000000..60873a0
--- /dev/null
+++ b/src/builtin/PRED_$compare0_3.java
@@ -0,0 +1,24 @@
+package jp.ac.kobe_u.cs.prolog.builtin;
+import jp.ac.kobe_u.cs.prolog.lang.IntegerTerm;
+import jp.ac.kobe_u.cs.prolog.lang.Operation;
+import jp.ac.kobe_u.cs.prolog.lang.Predicate;
+import jp.ac.kobe_u.cs.prolog.lang.Prolog;
+import jp.ac.kobe_u.cs.prolog.lang.Term;
+
+public final class PRED_$compare0_3 extends Predicate.P3 {
+ public PRED_$compare0_3(Term a1, Term a2, Term a3, Operation cont) {
+ this.arg1 = a1;
+ this.arg2 = a2;
+ this.arg3 = a3;
+ this.cont = cont;
+ }
+
+ public Operation exec(Prolog engine) {
+ engine.setB0();
+ Term a2 = arg2.dereference();
+ Term a3 = arg3.dereference();
+ if(! arg1.unify(new IntegerTerm(a2.compareTo(a3)), engine.trail))
+ return engine.fail();
+ return cont;
+ }
+}
diff --git a/src/builtin/PRED_$compiled_predicate_3.java b/src/builtin/PRED_$compiled_predicate_3.java
new file mode 100644
index 0000000..8eb71fb
--- /dev/null
+++ b/src/builtin/PRED_$compiled_predicate_3.java
@@ -0,0 +1,26 @@
+package jp.ac.kobe_u.cs.prolog.builtin;
+import jp.ac.kobe_u.cs.prolog.lang.IntegerTerm;
+import jp.ac.kobe_u.cs.prolog.lang.Operation;
+import jp.ac.kobe_u.cs.prolog.lang.Predicate;
+import jp.ac.kobe_u.cs.prolog.lang.Prolog;
+import jp.ac.kobe_u.cs.prolog.lang.SymbolTerm;
+import jp.ac.kobe_u.cs.prolog.lang.Term;
+
+public final class PRED_$compiled_predicate_3 extends Predicate.P3 {
+ public PRED_$compiled_predicate_3(Term a1, Term a2, Term a3, Operation cont) {
+ this.arg1 = a1;
+ this.arg2 = a2;
+ this.arg3 = a3;
+ this.cont = cont;
+ }
+
+ public Operation exec(Prolog engine) {
+ engine.setB0();
+ Term a1 = arg1.dereference();
+ Term a2 = arg2.dereference();
+ Term a3 = arg3.dereference();
+ if(! engine.pcl.definedPredicate(((SymbolTerm)a1).name(), ((SymbolTerm)a2).name(), ((IntegerTerm)a3).intValue()))
+ return engine.fail();
+ return cont;
+ }
+}
diff --git a/src/builtin/PRED_$compiled_predicate_or_builtin_3.java b/src/builtin/PRED_$compiled_predicate_or_builtin_3.java
new file mode 100644
index 0000000..0b5ab50
--- /dev/null
+++ b/src/builtin/PRED_$compiled_predicate_or_builtin_3.java
@@ -0,0 +1,27 @@
+package jp.ac.kobe_u.cs.prolog.builtin;
+import jp.ac.kobe_u.cs.prolog.lang.IntegerTerm;
+import jp.ac.kobe_u.cs.prolog.lang.Operation;
+import jp.ac.kobe_u.cs.prolog.lang.Predicate;
+import jp.ac.kobe_u.cs.prolog.lang.Prolog;
+import jp.ac.kobe_u.cs.prolog.lang.SymbolTerm;
+import jp.ac.kobe_u.cs.prolog.lang.Term;
+
+public final class PRED_$compiled_predicate_or_builtin_3 extends Predicate.P3 {
+ public PRED_$compiled_predicate_or_builtin_3(Term a1, Term a2, Term a3, Operation cont) {
+ this.arg1 = a1;
+ this.arg2 = a2;
+ this.arg3 = a3;
+ this.cont = cont;
+ }
+
+ public Operation exec(Prolog engine) {
+ engine.setB0();
+ Term a1 = arg1.dereference();
+ Term a2 = arg2.dereference();
+ Term a3 = arg3.dereference();
+ if(! engine.pcl.definedPredicate(((SymbolTerm)a1).name(), ((SymbolTerm)a2).name(), ((IntegerTerm)a3).intValue())
+ && ! engine.pcl.definedPredicate("jp.ac.kobe_u.cs.prolog.builtin", ((SymbolTerm)a2).name(), ((IntegerTerm)a3).intValue()))
+ return engine.fail();
+ return cont;
+ }
+}
diff --git a/src/builtin/builtins.pl b/src/builtin/builtins.pl
index 5d40189..30a788f 100644
--- a/src/builtin/builtins.pl
+++ b/src/builtin/builtins.pl
@@ -244,11 +244,6 @@ X @>= Y :- X @>= Y.
compare(Op, X, Y) :- '$compare0'(Op0, X, Y), '$map_compare_op'(Op0, Op).
-'$compare0'(Op0, X, Y) :-
- '$INSERT_AM'([deref(a(2),a(2)),deref(a(3),a(3))]),
- '$INSERT'(['\tif(! a1.unify(new IntegerTerm(a2.compareTo(a3)), engine.trail))',
- '\t\treturn engine.fail();']).
-
'$map_compare_op'(Op0, Op) :- Op0 =:= 0, !, Op = (=).
'$map_compare_op'(Op0, Op) :- Op0 < 0, !, Op = (<).
'$map_compare_op'(Op0, Op) :- Op0 > 0, !, Op = (>).
@@ -461,19 +456,7 @@ clause(Head, B) :-
illarg(permission(Operation,ObjType,P:F/A,_), Goal, _).
'$check_procedure_permission'(_, _, _, _).
-% checks if predicate P:F/A is compiled or not.
-'$compiled_predicate'(P, F, A) :-
- '$INSERT_AM'([deref(a(1),a(1)),deref(a(2),a(2)),deref(a(3),a(3))]),
- '$INSERT'(['\tif(! engine.pcl.definedPredicate(((SymbolTerm)a1).name(), ((SymbolTerm)a2).name(), ((IntegerTerm)a3).intValue()))',
- '\t\treturn engine.fail();']).
-
-'$compiled_predicate_or_builtin'(P, F, A) :-
- '$INSERT_AM'([deref(a(1),a(1)),deref(a(2),a(2)),deref(a(3),a(3))]),
- '$INSERT'(['\tif(! engine.pcl.definedPredicate(((SymbolTerm)a1).name(), ((SymbolTerm)a2).name(), ((IntegerTerm)a3).intValue()) && ! engine.pcl.definedPredicate("jp.ac.kobe_u.cs.prolog.builtin", ((SymbolTerm)a2).name(), ((IntegerTerm)a3).intValue()))',
- '\t\treturn engine.fail();']).
-
% initialize internal databases of given packages.
-%initialization([], Goal) :- !, call(Goal).
initialization([], Goal) :- !, once(Goal).
initialization([P|Ps], Goal) :-
'$new_internal_database'(P),
diff --git a/src/compiler/am2j.pl b/src/compiler/am2j.pl
index ddd5dfc..6329cac 100644
--- a/src/compiler/am2j.pl
+++ b/src/compiler/am2j.pl
@@ -223,9 +223,6 @@ write_java0(execute(BinG), _, Out) :- !,
write_java0(inline(G), In, Out) :-
write_inline(G, In, Out),
!.
-write_java0('$INSERT'(X), In, Out) :-
- write_insert(X, In, Out),
- !.
write_java0(new_hash(Tag,I), _, Out) :- !,
tab(Out, 4),
write(Out, 'static final java.util.HashMap<Term, Operation> '),
diff --git a/src/compiler/pl2am.pl b/src/compiler/pl2am.pl
index 24dc866..c7c013d 100644
--- a/src/compiler/pl2am.pl
+++ b/src/compiler/pl2am.pl
@@ -89,7 +89,6 @@ Control Instructions
execute(p:BinG)
execute(BinG)
inline(G)
- '$INSERT'(ListOfAtom)
Other Instructions
==================
@@ -1073,12 +1072,6 @@ precompile_body(Goals) -->
precomp_body(Goals).
precomp_body([]) --> !, [execute(cont)].
-precomp_body(['$INSERT_AM'(Code)|_]) --> !,
- {pl2am_error([invalid,instruction,'$INSERT_AM'(Code)])},
- {fail}.
-precomp_body(['$INSERT'(Code)|_]) --> !,
- {pl2am_error([invalid,instruction,'$INSERT'(Code)])},
- {fail}.
precomp_body([M:G|Cont]) --> !,
binarize_body(G, Cont, G1),
[execute(M:G1)].
@@ -1118,10 +1111,6 @@ precomp_cont([G|Cont], V) -->
precomp_inline([], Gs1) --> !, precomp_body(Gs1).
precomp_inline([fail|_], _) --> !, [inline(fail)].
-precomp_inline(['$INSERT_AM'(Code)|Gs], Gs1) --> !,
- [Code], precomp_inline(Gs, Gs1).
-precomp_inline(['$INSERT'(Code)|Gs], Gs1) --> !,
- ['$INSERT'(Code)], precomp_inline(Gs, Gs1).
precomp_inline([G|Gs], Gs1) -->
{G =.. [F|Args]},
{functor(G, F, A)},
@@ -1626,9 +1615,6 @@ builtin_inline_predicates('$greater_or_equal'(_,_)).
builtin_inline_predicates('$greater_than'(_,_)).
builtin_inline_predicates('$less_or_equal'(_,_)).
builtin_inline_predicates('$less_than'(_,_)).
-% Prolog Cafe Specific
-builtin_inline_predicates('$INSERT_AM'(_)).
-builtin_inline_predicates('$INSERT'(_)).
builtin_arith_constant(random).
builtin_arith_constant(pi).