Merge changes I40e7f7c1,I6542c6eb * changes: Return to jtry1..jtry10 to save space Statically import fail/0 instead of defining new fields
diff --git a/examples/plcafe/Makefile b/examples/plcafe/Makefile deleted file mode 100644 index 3dd0348..0000000 --- a/examples/plcafe/Makefile +++ /dev/null
@@ -1,29 +0,0 @@ -################################################################ -# Makefile for Prolog Cafe -################################################################ - -################################################################ -PLJAVAC = pljavac -PLJAVACOPTS = -v - -PLJAR = pljar -PLJAROPTS = -v -################################################################ -.SUFFIXES: -.SUFFIXES: .jar .pl $(SUFFIXES) - -jar_objects := $(patsubst %.pl,%.jar,$(wildcard *.pl)) - -.pl.jar: - $(PLJAR) $(PLJAROPTS) $@ $< - -rm -f -r $* - -all: $(jar_objects) - $(PLJAVAC) $(PLJAVACOPTS) -cp queens.jar T.java - -clean: - -rm -f core *~ - -realclean: clean - -rm -f *.jar *.class -
diff --git a/examples/plcafe/T.java b/examples/plcafe/T.java deleted file mode 100644 index 42ff7e2..0000000 --- a/examples/plcafe/T.java +++ /dev/null
@@ -1,62 +0,0 @@ -import com.googlecode.prolog_cafe.lang.*; -/** - * A sample program for multi-thread execution.<br> - * Usage: <br> - * <pre> - * % plcafe -cp queens.jar T - * </pre> - * - * @author Naoyuki Tamura (tamura@kobe-u.ac.jp) - * @author Mutsunori Banbara (banbara@kobe-u.ac.jp) - */ -public class T { - public static void main(String args[]) { - long t = System.currentTimeMillis(); - boolean r1 = true; - boolean r2 = true; - Term a1[] = {new IntegerTerm(10), new VariableTerm()}; - Term a2[] = {new IntegerTerm(8), new VariableTerm()}; - - PrologControl e1 = new PrologControl(); - PrologControl e2 = new PrologControl(); - Term v1 = new VariableTerm(); - Term v2 = new VariableTerm(); - e1.setPredicate(new PRED_queens_2(), a1); - e2.setPredicate(new PRED_queens_2(), a2); - System.out.println("Start"); - e1.start(); - e2.start(); - while (r1 || r2) { - try { - Thread.sleep(10); - } catch (InterruptedException e) {} - if (r1 && e1.ready()) { - r1 = e1.next(); - if (r1) { - System.out.println("Success1 = " + a1[1]); - e1.cont(); - } else { - System.out.println("Fail1"); - } - } else if (r2 && e2.ready()) { - r2 = e2.next(); - if (r2) { - System.out.println("Success2 = " + a2[1]); - e2.cont(); - } else { - System.out.println("Fail2"); - } - } else { - System.out.println("Waiting"); - try { - Thread.sleep(100); - } catch (InterruptedException e) {} - } - } - System.out.println("End"); - long t1 = System.currentTimeMillis(); - long t2 = t1 - t; - System.out.println("time = " + t2 + "msec."); - - } -}
diff --git a/examples/plcafe/border_layout.pl b/examples/plcafe/border_layout.pl deleted file mode 100644 index 80a7dc1..0000000 --- a/examples/plcafe/border_layout.pl +++ /dev/null
@@ -1,36 +0,0 @@ -% File : border_layout.pl -% Authors: Mutsunori Banbara (banbara@kobe-u.ac.jp) -% Updated: 15 May 2008 -% Purpose: java.awt.BorderLayout -% Usage : -% % plcafe -cp border_layout.jar -% ?- main. - -main :- - java_constructor('java.awt.Frame', X), - java_get_field('java.awt.Color', blue, Blue), - java_get_field('java.awt.Color', white, White), - java_method(X, setSize(300,200), _), - java_method(X, setBackground(Blue), _), - java_method(X, setForeground(White), _), - java_method(X, setTitle('Prolog Cafe'), _), - java_constructor('java.awt.BorderLayout', Border), - java_method(X, setLayout(Border), _), - java_get_field('java.awt.Font', 'BOLD', Bold), - java_constructor('java.awt.Font'('Helvetica', Bold, 12), F1), - java_method(X, setFont(F1), _), - java_constructor('java.awt.Button'('A Prolog to Java Translator'), B1), - java_constructor('java.awt.Button'('Prolog Cafe'), B2), - java_constructor('java.awt.Button'('Prolog'), B3), - java_constructor('java.awt.Button'('Java'), B4), - java_constructor('java.awt.Button'('produced by M.Banbara and N.Tamura'), B5), - java_method(X, add('North', B1),_), - java_method(X, add('Center', B2),_), - java_method(X, add('West', B3),_), - java_method(X, add('East', B4),_), - java_method(X, add('South', B5),_), - java_get_field('java.lang.Boolean', 'TRUE', True), - java_method(X, setVisible(True), _). - - -
diff --git a/examples/plcafe/frame.pl b/examples/plcafe/frame.pl deleted file mode 100644 index a77e87a..0000000 --- a/examples/plcafe/frame.pl +++ /dev/null
@@ -1,16 +0,0 @@ -% File : frame.pl -% Authors: Mutsunori Banbara (banbara@kobe-u.ac.jp) -% Updated: 14 February 2008 -% Purpose: java.awt.Frame -% Usage : -% % plcafe -cp frame.jar -% ?- main. - -main :- - java_constructor('java.awt.Frame', X), - java_method(X, setSize(200,200), _), - java_get_field('java.lang.Boolean', 'TRUE', True), - java_method(X, setVisible(True), _). - - -
diff --git a/examples/plcafe/paint.pl b/examples/plcafe/paint.pl deleted file mode 100644 index a5e88ec..0000000 --- a/examples/plcafe/paint.pl +++ /dev/null
@@ -1,325 +0,0 @@ -% File : paint.pl -% Authors: Mutsunori Banbara (banbara@kobe-u.ac.jp) -% Updated: 15 May 2008 -% Purpose: Graphics -% Usage : -% % plcafe -cp paint.jar -% ?- main. -% or -% % plcafe -cp paint.jar -t main - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -main :- - start, - repeat, - write('Simple Graphical Examples (bye. to quit)'), nl, - tab(4), write('Example: ex1.'), nl, - tab(4), write('Example: ex2.'), nl, - tab(4), write('Example: ex3.'), nl, nl, - write('|: '), flush_output, - read(Cmd), - do(Cmd), - !. - -do(X) :- var(X), !, fail. -do(bye) :- !, stop. -do(quit) :- !, stop. -do(end_of_file) :- !, stop. -do(Cmd) :- - statistics(runtime, _), - call(Cmd), - statistics(runtime, [_,T]), - tab(3), write('Time = '), write(T), write(' msec'), nl, nl, - fail. - -%%% Example 1 -ex1 :- init, ex1(30). - -ex1(N) :- - integer(N), - R is random*255, - G is random*255, - B is random*255, - setColor(rgb(R,G,B)), - getCenter(Cx, Cy), - for(I, -N, N), - X1 is Cx+I*5, - Y1 is Cy+N*5, - X2 is Cx+N*5, - Y2 is Cy-I*5, - drawLine(X1, Y1, X2, Y2), - A1 is Cx-I*5, - B1 is Cy-N*5, - A2 is Cx-N*5, - B2 is Cy+I*5, - drawLine(A1, B1, A2, B2), - fail. -ex1(_). - -%%% Example 2 -ex2 :- init, ex2(6). - -ex2(N) :- - integer(N), - for(I, 1, N), - M is I*5, - ex1(M), - fail. -ex2(_). - -%%% Example 3 -ex3 :- init, ex3(100). - -ex3(N) :- - integer(N), - getCenter(Cx, Cy), - R is random*255, - G is random*255, - B is random*255, - setColor(rgb(R,G,B)), - for(I, 1, N), - X is round(Cx-I*3/2), - Y is round(Cy-I*3/2), - W is I*3, - H is I*3, - drawOval(X, Y, W, H), - fail. -ex3(X). - -%%% Utilities -for(I, I, N) :- I =< N. -for(I, J, N) :- J < N, J1 is J+1, for(I, J1, N). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Start, Init, and Stop -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -:- dynamic current_image/1, current_canvas/1, current_frame/1. -:- dynamic current_color/2, current_font/3. - -start :- start(350, 350), init. - -start(Width, Height) :- - integer(Width), - integer(Height), - retractall(current_frame(_)), - retractall(current_canvas(_)), - retractall(current_image(_)), - retractall(current_color(_,_)), - retractall(current_font(_,_,_)), - java_constructor('java.awt.Frame', Frame), - java_constructor('java.awt.BorderLayout', Border), - java_method(Frame, setLayout(Border), _), - java_method(Frame, setSize(Width,Height), _), - java_method(Frame, setTitle('Simple Graphical Examples'), _), - java_constructor('java.awt.Canvas', Canvas), - java_method(Frame, add('Center', Canvas), _), - java_get_field('java.lang.Boolean', 'TRUE', True), - java_method(Frame, setVisible(True), _), - java_method(Canvas, getWidth, CW), - java_method(Canvas, getHeight, CH), - java_method(Canvas, createImage(CW,CH), Image), - assertz(current_frame(Frame)), - assertz(current_canvas(Canvas)), - assertz(current_image(Image)). - -init :- - setColor(black), - setBackground(white), - setFont(dialog, italic, 12), - getSize(W, H), - clearRect(0, 0, W, H). - -stop :- - current_frame(Frame), - java_get_field('java.lang.Boolean', 'FALSE', F), - java_method(Frame, setVisible(F), _). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Size -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -getHeight(X) :- - current_canvas(C), - java_method(C, getHeight, X). - -getWidth(X) :- - current_canvas(C), - java_method(C, getWidth, X). - -getCenter(X, Y) :- - getWidth(W), - getHeight(H), - X is (W+1)//2, - Y is (H+1)//2. - -getSize(X, Y) :- - getWidth(X), - getHeight(Y). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Graphics -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -get_graphics(Gra, Canvas) :- - current_canvas(Canvas), - java_method(Canvas, getGraphics, Gra). - -get_image_graphics(ImgGra, Image) :- - current_image(Image), - java_method(Image, getGraphics, ImgGra). - -paint(Function) :- - get_graphics(Gra, Canvas), - get_image_graphics(ImgGra, Image), - java_method(Gra, Function, _), - java_method(ImgGra, Function, _), - java_method(Gra, drawImage(Image,0,0,Canvas), _). - -repaint :- - get_graphics(Gra, Canvas), - get_image_graphics(_, Image), - java_method(Gra, drawImage(Image,0,0,Canvas), _). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Drawing Functions -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -clearRect(X, Y, Width, Height) :- - integer(X), integer(Y), integer(Width), integer(Height), - paint(clearRect(X,Y,Width,Height)). - -drawLine(X1, Y1, X2, Y2) :- - integer(X1), integer(Y1), integer(X2), integer(Y2), - paint(drawLine(X1,Y1,X2,Y2)). - -drawString(Str, X, Y) :- - atom(Str), integer(X), integer(Y), - paint(drawString(Str,X,Y)). - -drawOval(X, Y, Width, Height) :- - integer(X), integer(Y), integer(Width), integer(Height), - paint(drawOval(X,Y,Width,Height)). - -fill3DRect(X, Y, Width, Height, Raise) :- - integer(X), integer(Y), integer(Width), integer(Height), - boolean_map(Raise, Bool), - paint(fill3DRect(X,Y,Width,Height,Bool)). - -drawRect(X, Y, Width, Height) :- - integer(X), integer(Y), integer(Width), integer(Height), - paint(drawRect(X,Y,Width,Height)). - -fillRect(X, Y, Width, Height) :- - integer(X), integer(Y), integer(Width), integer(Height), - paint(fillRect(X,Y,Width,Height)). - -draw3DRect(X, Y, Width, Height, Raise) :- - integer(X), integer(Y), integer(Width), integer(Height), - boolean_map(Raise, Bool), - paint(draw3DRect(X,Y,Width,Height,Bool)). - -fillOval(X, Y, Width, Height) :- - integer(X), integer(Y), integer(Width), integer(Height), - paint(fillOval(X,Y,Width,Height)). - -drawArc(X, Y, Width, Height, StartAngle, ArcAngle) :- - integer(X), integer(Y), integer(Width), integer(Height), - integer(StartAngle), integer(ArcAngle), - paint(drawArc(X,Y,Width,Height,StartAngle,ArcAngle)). - -fillArc(X, Y, Width, Height, StartAngle, ArcAngle) :- - integer(X), integer(Y), integer(Width), integer(Height), - integer(StartAngle), integer(ArcAngle), - paint(fillArc(X,Y,Width,Height,StartAngle,ArcAngle)). - -drawRoundRect(X, Y, Width, Height, ArcWidth, ArcHeight) :- - integer(X), integer(Y), integer(Width), integer(Height), - integer(ArcWidth), integer(ArcHeight), - paint(drawRoundRect(X,Y,Width,Height,ArcWidth,ArcHeight)). - -fillRoundRect(X, Y, Width, Height, ArcWidth, ArcHeight) :- - integer(X), integer(Y), integer(Width), integer(Height), - integer(ArcWidth), integer(ArcHeight), - paint(fillRoundRect(X,Y,Width,Height,ArcWidth,ArcHeight)). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Color -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -setColor(Co) :- color_map(Co, Obj), !, - current_canvas(Canvas), - java_method(Canvas, setForeground(Obj), _), - retractall(current_color(_,_)), - assertz(current_color(Co, Obj)). -setColor(Co) :- - findall(Co, color(Co), Domain), - throw(domain_error(setColor(Co),1,['rgb(R,G,B)'|Domain],Co)). - -setBackground(Co) :- color_map(Co, Obj), !, - current_canvas(Canvas), - java_method(Canvas, setBackground(Obj), _). -setBackground(Co) :- - findall(Co, color(Co), Domain), - throw(domain_error(setBackground(Co),1,['rgb(R,G,B)'|Domain],Co)). - -color_map(Co, Obj) :- color(Co), !, - java_get_field('java.awt.Color', Co, Obj). -color_map(Co, Obj) :- - Co = rgb(X,Y,Z), - R is round(X), 0 =< R, R =< 255, - G is round(Y), 0 =< G, G =< 255, - B is round(Z), 0 =< B, B =< 255, - !, - java_constructor('java.awt.Color'(R,G,B), Obj). - -color(black). -color(blue). -color(cyan). -color(darkGray). -color(gray). -color(green). -color(lightGray). -color(magenta). -color(orange). -color(pink). -color(red). -color(white). -color(yellow). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Font -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -setFont(Font, Style, Size) :- font_map(Font, Style, Size, Obj), !, - current_canvas(Canvas), - java_method(Canvas, setFont(Obj), _), - retractall(current_font(_,_,_)), - assertz(current_font(Font,Style,Size)). -setFont(Font, Style, Size) :- - findall(F, font(F), Domain), - throw(domain_error(setFont(Font, Style, Size),1,Domain,Font)). - -font_map(Font, Style, Size, Obj) :- - integer(Size), - font(Font, F), - font_style(Style, St), - java_constructor('java.awt.Font'(F, St, Size), Obj). - -font(helvetica, 'Helvetica'). -font(times_roman, 'TimesRoman'). -font(courier, 'Courier'). -font(dialog, 'Dialog'). -font(dialog_input, 'DialogInput'). - -font_style(plain, 0). -font_style(bold, 1). -font_style(italic, 2). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Boolean -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -boolean_map(Bool, Obj) :- - boolean(Bool, B), - java_get_field('java.lang.Boolean', B, Obj). - -boolean(true, 'TRUE'). -boolean(false, 'FALSE'). - -%%% END
diff --git a/examples/plcafe/queens.pl b/examples/plcafe/queens.pl deleted file mode 100644 index 8b21eb1..0000000 --- a/examples/plcafe/queens.pl +++ /dev/null
@@ -1,31 +0,0 @@ -% File : queens.pl -% Updated: 14 February 2008 -% Purpose: N-Queen Puzzle (posed by Franz Nauch, 1850) - -queens(N,Qs) :- - range(1,N,Ns), - queens(Ns,[],Qs). - -queens([],Qs,Qs). -queens(UnplacedQs,SafeQs,Qs) :- - select(UnplacedQs,UnplacedQs1,Q), - not_attack(SafeQs,Q), - queens(UnplacedQs1,[Q|SafeQs],Qs). - -not_attack(Xs,X) :- - not_attack(Xs,X,1). - -not_attack([],_,_) :- !. -not_attack([Y|Ys],X,N) :- - X =\= Y+N, X =\= Y-N, - N1 is N+1, - not_attack(Ys,X,N1). - -select([X|Xs],Xs,X). -select([Y|Ys],[Y|Zs],X) :- select(Ys,Zs,X). - -range(N,N,[N]) :- !. -range(M,N,[M|Ns]) :- - M < N, - M1 is M+1, - range(M1,N,Ns).
diff --git a/examples/plcafe/thread.pl b/examples/plcafe/thread.pl deleted file mode 100644 index 0c15dd1..0000000 --- a/examples/plcafe/thread.pl +++ /dev/null
@@ -1,84 +0,0 @@ -% File : thread.pl -% Authors: Naoyuki Tamura (tamura@kobe-u.ac.jp) -% Mutsunori Banbara (banbara@kobe-u.ac.jp) -% Updated: 26 May 2008 -% Purpose: Multi-thread execution -% Usage : -% % plcafe -cp queens.jar -% ?- [thread]. -% ?- main. -% or -% % plcafe -cp thread.jar:queens.jar -% ?- main. - -main :- - statistics(runtime, _), - start, - statistics(runtime, [_,T]), - write('Time = '), write(T), - write(' msec.'), nl. - -start :- - G1 = (queens(10, X), write(X), nl), - msg(start1 = G1), - start(G1, E1), - G2 = (queens(8, Y), write(Y), nl), - msg(start2 = G2), - start(G2, E2), - loop(G1, E1, G2, E2), - stop(E1), - stop(E2), - msg(end). - -loop(G1, E1, G2, E2) :- - in_failure(E1), - in_failure(E2), - !. -loop(G1, E1, G2, E2) :- - in_success(E1), - !, - cont(E1), - loop(G1, E1, G2, E2). -loop(G1, E1, G2, E2) :- - in_success(E2), - !, - cont(E2), - loop(G1, E1, G2, E2). -loop(G1, E1, G2, E2) :- - msg(waiting), - sleep(5), - loop(G1, E1, G2, E2). - -msg(Msg) :- - write(Msg), nl, flush_output. - -%% -%% Utilities -%% -start(G, Engine) :- - java_constructor0('com.googlecode.prolog_cafe.lang.PrologControl', Engine), - java_method0(Engine, setPredicate(G), _), - java_method0(Engine, start, _). - -in_success(Engine) :- - java_get_field0('java.lang.Boolean', 'TRUE', T), - java_method(Engine, in_success, T). - -in_failure(Engine) :- - java_get_field0('java.lang.Boolean', 'TRUE', T), - java_method(Engine, in_failure, T). - -ready(Engine) :- - java_get_field0('java.lang.Boolean', 'TRUE', T), - java_method(Engine, ready, T). - -cont(Engine) :- java_method0(Engine, cont, _). - -join(Engine) :- java_method0(Engine, join, _). - -stop(Engine) :- java_method0(Engine, stop, _). - -sleep(N) :- java_method('java.lang.Thread', sleep(N), _). - -%result(Engine, Result) :- java_method0(Engine, next, Result). -
diff --git a/examples/plcafe/thread2.pl b/examples/plcafe/thread2.pl deleted file mode 100644 index 01280f4..0000000 --- a/examples/plcafe/thread2.pl +++ /dev/null
@@ -1,66 +0,0 @@ -% File : thread2.pl -% Authors: Mutsunori Banbara (banbara@kobe-u.ac.jp) -% Naoyuki Tamura (tamura@kobe-u.ac.jp) -% Updated: 26 May 2008 -% Purpose: Multi-thread execution -% Usage : -% % plcafe -cp queens.jar -% ?- [thread2]. -% ?- main. -% or -% % plcafe -cp thread2.jar:queens.jar -% ?- main. - -main :- - statistics(runtime, _), - start, - statistics(runtime, [_,T]), - write('Time = '), write(T), - write(' msec.'), nl. - -start :- - G1 = (queens(10, X), write(X), nl, fail), - msg(start1 = G1), - start(G1, E1), - G2 = (queens(8, Y), write(Y), nl, fail), - msg(start2 = G2), - start(G2, E2), - join(E1), - join(E2), - stop(E1), - stop(E2), - msg(end). - -msg(Msg) :- - write(Msg), nl, flush_output. - -%% -%% Utilities -%% -start(G, Engine) :- - java_constructor0('com.googlecode.prolog_cafe.lang.PrologControl', Engine), - java_method0(Engine, setPredicate(G), _), - java_method0(Engine, start, _). - -in_success(Engine) :- - java_get_field0('java.lang.Boolean', 'TRUE', T), - java_method(Engine, in_success, T). - -in_failure(Engine) :- - java_get_field0('java.lang.Boolean', 'TRUE', T), - java_method(Engine, in_failure, T). - -ready(Engine) :- - java_get_field0('java.lang.Boolean', 'TRUE', T), - java_method(Engine, ready, T). - -cont(Engine) :- java_method0(Engine, cont, _). - -join(Engine) :- java_method0(Engine, join, _). - -stop(Engine) :- java_method0(Engine, stop, _). - -sleep(N) :- java_method('java.lang.Thread', sleep(N), _). - -%result(Engine, Result) :- java_method0(Engine, next, Result). -