created mirror
This commit is contained in:
99
Java/clang/flowing/B.java
Normal file
99
Java/clang/flowing/B.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
B.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* The "B" (Binary Logic) primitive set for Flowing clang.
|
||||
*/
|
||||
|
||||
public class B extends PrimitiveSet {
|
||||
public static final String rcsid = "$Id: B.java,v 1.2 2000/10/13 13:52:24 bfallenstein Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
public Primitive get(String id) {
|
||||
if(id.equals("AND") || id.equals("&"))
|
||||
return new And();
|
||||
if(id.equals("OR") || id.equals("|"))
|
||||
return new Or();
|
||||
if(id.equals("NOT") || id.equals("!"))
|
||||
return new Not();
|
||||
if(id.equals("XOR"))
|
||||
return new Xor();
|
||||
if(id.equals("NOTNULL"))
|
||||
return new NotNull();
|
||||
return null;
|
||||
}
|
||||
|
||||
static public class And extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
boolean res = params.b(0);
|
||||
for(int i=1; i<params.len(); i++) {
|
||||
res = res && params.b(i);
|
||||
}
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Or extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
boolean res = params.b(0);
|
||||
for(int i=1; i<params.len(); i++) {
|
||||
res = res || params.b(i);
|
||||
}
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Not extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
boolean res = !params.b(0);
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Xor extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
boolean res = params.b(0);
|
||||
for(int i=1; i<params.len(); i++) {
|
||||
boolean b = params.b(i);
|
||||
res = (!res && b) || (res && !b);
|
||||
}
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class NotNull extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
boolean res = params.o(0) != null;
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
115
Java/clang/flowing/C.java
Normal file
115
Java/clang/flowing/C.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
C.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* The "C" (Number Crunching) primitive set for Flowing clang.
|
||||
*/
|
||||
|
||||
public class C extends PrimitiveSet {
|
||||
public static final String rcsid = "$Id: C.java,v 1.2 2000/10/13 13:52:24 bfallenstein Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
public Primitive get(String id) {
|
||||
if(id.equals("+"))
|
||||
return new Plus();
|
||||
if(id.equals("-"))
|
||||
return new Minus();
|
||||
if(id.equals("*"))
|
||||
return new Mul();
|
||||
if(id.equals("/"))
|
||||
return new Div();
|
||||
if(id.equals("="))
|
||||
return new Compare(0);
|
||||
if(id.equals(">"))
|
||||
return new Compare(-2);
|
||||
if(id.equals("<"))
|
||||
return new Compare(+2);
|
||||
if(id.equals(">="))
|
||||
return new Compare(-1);
|
||||
if(id.equals("<="))
|
||||
return new Compare(+1);
|
||||
return null;
|
||||
}
|
||||
|
||||
static public class Plus extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
int res = params.i(0);
|
||||
for(int i=1; i<params.len(); i++) {
|
||||
res += params.i(i);
|
||||
}
|
||||
return new Data(new Integer(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Minus extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
int res = params.i(0);
|
||||
for(int i=1; i<params.len(); i++) {
|
||||
res -= params.i(i);
|
||||
}
|
||||
return new Data(new Integer(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Mul extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
int res = params.i(0);
|
||||
for(int i=1; i<params.len(); i++) {
|
||||
res *= params.i(i);
|
||||
}
|
||||
return new Data(new Integer(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Div extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 2);
|
||||
return new Data(new Integer(params.i(0) / params.i(1)));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Compare extends Primitive {
|
||||
int weight;
|
||||
public Compare(int weight) { this.weight = weight; }
|
||||
|
||||
protected Data execute(Data params) {
|
||||
count(params, 2);
|
||||
int i0, i1;
|
||||
if(weight > 0) { i0 = params.i(0); i1 = params.i(1); }
|
||||
else { i0 = params.i(1); i1 = params.i(0); }
|
||||
|
||||
boolean res;
|
||||
if(weight==0) res = i0 == i1;
|
||||
else if(weight*weight == 4) res = i0 < i1;
|
||||
else res = i0 <= i1;
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
260
Java/clang/flowing/Flowing.java
Normal file
260
Java/clang/flowing/Flowing.java
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
Flowing.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.module;
|
||||
import org.gzigzag.*;
|
||||
import org.gzigzag.flowing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/** A module interface to Flowing Clang.
|
||||
*/
|
||||
|
||||
public class Flowing {
|
||||
public static final String rcsid = "$Id: Flowing.java,v 1.7.8.1 2001/08/16 13:40:44 bfallenstein Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
static final void createdebugger(ZZCell debug) {
|
||||
debug.getSpace().getHomeCell().h("d.2", 1).insert("d.2", 1, debug);
|
||||
ZZCell normal = debug.N("d.1", 1);
|
||||
normal.setText("Debug mode");
|
||||
ZZCell edit = normal.N("d.1", 1);
|
||||
edit.setText("Text edit mode");
|
||||
ZZCell dim0 = edit.N("d.1", 1);
|
||||
dim0.setText("d..flowing-frame");
|
||||
dim0.N("d.2", 1).setText("d.2");
|
||||
dim0.N("d.2", 1).setText("d..flowing-data");
|
||||
ZZCell dim1 = dim0.N("d.1", 1);
|
||||
dim1.setText("d.1");
|
||||
dim1.N("d.2", 1).setText("d.clone");
|
||||
dim1.N("d.2", 1).setText("d.xeq");
|
||||
|
||||
// EDIT MODE
|
||||
|
||||
ZZCell c = edit.N("d.2", 1);
|
||||
c.setText("Tab");
|
||||
c.N("d.1", 1).setText("SWITCHOFFCURSMODE");
|
||||
normal.insert("d.3", 1, c.s("d.1"));
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Esc");
|
||||
c.N("d.1", 1).setText("SWITCHOFFCURSMODE");
|
||||
normal.insert("d.3", 1, c.s("d.1"));
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
ZZDefaultSpace.findOnSystemlist(c.getSpace(), "Bindings", false)
|
||||
.s("d.1", 2).s("d.2", 1).insert("d.3", -1, c);
|
||||
|
||||
// NORMAL MODE
|
||||
|
||||
c = normal.N("d.2", 1);
|
||||
c.setText(" ");
|
||||
c.N("d.1", 1).setText("Flowing.D-STEP");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Enter");
|
||||
c.N("d.1", 1).setText("Flowing.D-JUMP");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Backspace");
|
||||
c.N("d.1", 1).setText("UNDO");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Alt-Backspace");
|
||||
c.N("d.1", 1).setText("REDO");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("q");
|
||||
c.N("d.1", 1).setText("QUIT");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Tab");
|
||||
c.N("d.1", 1).setText("SWITCHCURSMODE");
|
||||
edit.insert("d.3", 1, c.s("d.1"));
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Left");
|
||||
c.N("d.1", 1).setText("CRSR X-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Right");
|
||||
c.N("d.1", 1).setText("CRSR X+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Up");
|
||||
c.N("d.1", 1).setText("CRSR Y-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("Down");
|
||||
c.N("d.1", 1).setText("CRSR Y+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("j");
|
||||
c.N("d.1", 1).setText("CRSR X-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("l");
|
||||
c.N("d.1", 1).setText("CRSR X+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("i");
|
||||
c.N("d.1", 1).setText("CRSR Y-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText(",");
|
||||
c.N("d.1", 1).setText("CRSR Y+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("K");
|
||||
c.N("d.1", 1).setText("CRSR Z-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("k");
|
||||
c.N("d.1", 1).setText("CRSR Z+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("s");
|
||||
c.N("d.1", 1).setText("CRSR CX-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("f");
|
||||
c.N("d.1", 1).setText("CRSR CX+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("e");
|
||||
c.N("d.1", 1).setText("CRSR CY-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("c");
|
||||
c.N("d.1", 1).setText("CRSR CY+");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("D");
|
||||
c.N("d.1", 1).setText("CRSR CZ-");
|
||||
|
||||
c = c.N("d.2", 1);
|
||||
c.setText("d");
|
||||
c.N("d.1", 1).setText("CRSR CZ+");
|
||||
}
|
||||
|
||||
static public ZZModule module = new ZZModule() {
|
||||
public void action(String id,
|
||||
ZZCell code,
|
||||
ZZCell target,
|
||||
ZZView view, ZZView cview, String key, Point pt, ZZScene xi) {
|
||||
if(id.equals("BIND") || id.equals("BINDREAL") ||
|
||||
id.equals("RUN") || id.equals("RUNREAL")) {
|
||||
ZZCell prog;
|
||||
if(id.indexOf("BIND") > -1) {
|
||||
prog = code.s("d.2");
|
||||
if(prog == null)
|
||||
throw new ZZError("Flowing.BIND without program");
|
||||
prog = prog.h("d.clone", -1, true);
|
||||
if(prog == null)
|
||||
throw new ZZError("Flowing.BIND prog must be cloned");
|
||||
} else {
|
||||
prog = target;
|
||||
if(prog == null)
|
||||
prog = ZZCursorReal.get(view.getViewcell());
|
||||
}
|
||||
boolean real = id.indexOf("REAL") > 0;
|
||||
FlowingClang.run(prog, new Data(cview.getViewcell(),
|
||||
view.getViewcell(),
|
||||
key), real);
|
||||
} else if(id.equals("DEBUG")) {
|
||||
p("Create debugger:");
|
||||
ZZCell prog =
|
||||
ZZCursorReal.get(view.getViewcell()).getRootclone();
|
||||
ZZCell debug = ZZDefaultSpace.findOnSystemlist(
|
||||
view.getViewcell().getSpace(), "Flowing.Debugger", true);
|
||||
if(debug.s("d.1") == null) createdebugger(debug);
|
||||
ZZCell views = ZZDefaultSpace.findOnSystemlist(
|
||||
view.getViewcell().getSpace(), "Views", false).s("d.1");
|
||||
|
||||
p("Start program.");
|
||||
Data d = new Data(cview.getViewcell(),
|
||||
view.getViewcell(), key);
|
||||
ZZCell frame = FlowingClang.start(prog, d);
|
||||
|
||||
p("Create windows.");
|
||||
ZZCell frameview = ZZDefaultSpace.newToplevelView(
|
||||
prog.getSpace(), "Flowing stack frame",
|
||||
20, 20, 400, 500,
|
||||
views, debug.s("d.1"),
|
||||
frame, null,
|
||||
debug.s("d.1", 3).readRank("d.2", 1, true),
|
||||
ZZUtil.perturb(Color.blue.brighter()));
|
||||
ZZCursorReal.setColor(frameview, Color.blue.darker());
|
||||
|
||||
ZZCell progview = ZZDefaultSpace.newToplevelView(
|
||||
prog.getSpace(), "Flowing program",
|
||||
440, 20, 400, 500,
|
||||
views, debug.s("d.1"),
|
||||
ZZCursorReal.get(frame), null,
|
||||
debug.s("d.1", 4).readRank("d.2", 1, true),
|
||||
ZZUtil.perturb(Color.red.brighter()));
|
||||
ZZCursorReal.setColor(progview, Color.red.darker());
|
||||
|
||||
p("Connecting windows.");
|
||||
frameview.connect("d.ctrlview", 1, progview);
|
||||
ZZCell framecur = progview.N("d.2", 1);
|
||||
framecur.setText("Flowing.StackFrame");
|
||||
ZZCursorReal.set(framecur, frame);
|
||||
|
||||
p("Update windows.");
|
||||
ZZWindows.update();
|
||||
} else if(id.indexOf("D-") > -1) {
|
||||
ZZCell framecur = ZZDefaultSpace.findInheritableParam(
|
||||
view.getViewcell(), "Flowing.StackFrame");
|
||||
if(framecur == null)
|
||||
throw new ZZError("Flowing Clang debugging command on a "
|
||||
+ "non-debug view");
|
||||
ZZCell frame = ZZCursorReal.get(framecur);
|
||||
StackFrameReal sf = new StackFrameReal(frame), nsf;
|
||||
|
||||
if(id.equals("D-STEP"))
|
||||
nsf = (StackFrameReal)FlowingClang.step(sf, true);
|
||||
else if(id.equals("D-JUMP")) {
|
||||
nsf = (StackFrameReal)FlowingClang.jump(sf);
|
||||
} else
|
||||
throw new ZZError("Unknown Flowing.XXX code");
|
||||
|
||||
if(nsf != null) {
|
||||
if(nsf != sf) {
|
||||
ZZCursorReal.set(framecur, nsf.main);
|
||||
ZZCursorReal.set(cview.getViewcell(), nsf.main);
|
||||
}
|
||||
ZZCursorReal.set(view.getViewcell(), nsf.getPos());
|
||||
} else {
|
||||
view.getViewcell().h("d.1").delete();
|
||||
cview.getViewcell().h("d.1").delete();
|
||||
ZZWindows.update();
|
||||
ZZCursorReal.delete(view.getViewcell());
|
||||
ZZCursorReal.delete(cview.getViewcell());
|
||||
}
|
||||
} else
|
||||
throw new ZZError("Unknown Flowing.XXX code");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
219
Java/clang/flowing/FlowingClang.java
Normal file
219
Java/clang/flowing/FlowingClang.java
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
FlowingClang.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written for Heraclitus Clang by Tuomas Lukka
|
||||
* Adaption for Flowing Clang by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
|
||||
/** A simple (imperative) clang passing values dataflow-like.
|
||||
* Kind of a cross between a dataflow ("graphical") programming language and
|
||||
* an assembler. On the one hand we have sequences of instructions, each with
|
||||
* zero or more in- and output variables; variables are set and read;
|
||||
* jmp-style branching.
|
||||
* <p>
|
||||
* However, variables can only be set in one place
|
||||
* * XXX not any more -- explain XXX
|
||||
* (they can be set more than
|
||||
* once by executing the same instruction multiple times). All references to
|
||||
* the variable are clones; the original (rootclone) is the place where the
|
||||
* variable is set. This means when you view d.clone, you can see how the
|
||||
* data "flows" through the program (hence the language's name).
|
||||
* <p>
|
||||
* Execution strictly proceeds on d.xeq. There are no blocks: when there's
|
||||
* nothing more on d.xeq, the call returns. Until then, the return values
|
||||
* (if any) have to be set. Primitives are called by putting their ID into
|
||||
* a cell, putting the input values negwards and the variables to take the
|
||||
* output poswards on d.1 from it. (XXX use a less string-based behavior?)
|
||||
* Subroutines are called by cloning their maincell. Parameter passing and
|
||||
* results work the same as with primitives.
|
||||
* <p>
|
||||
* Primitives and subroutines are passed cells, and return cells. If in
|
||||
* the "input zone" of for a cell or subroutine (neg on d.1) there's a
|
||||
* cell which isn't cloned (and thus cannot be read as a variable, because
|
||||
* it cannot have a value assigned), it is taken as literal and passed to
|
||||
* the subroutine. Cloned cells (variables) are dereferenced in the stack frame
|
||||
* for the current routine, which means they have to be set. What's passed to
|
||||
* the subroutine or primitive is the cell which was formerly assigned to the
|
||||
* variable, not the variable cell itself.
|
||||
* <p>
|
||||
* To create a subroutine, create a non-clone cell with the routine's name.
|
||||
* (Later, you clone this into other code.) Put its input variables
|
||||
* negwards on d.1. Then put the subroutine on d.xeq. When you're done,
|
||||
* clone the result variable(s) from the point where you set them in the
|
||||
* routine to the right of the routine's maincell.
|
||||
* <p>
|
||||
* To branch, create a cell with a question mark ("?") in a strip, put a value
|
||||
* (variable or literal, but the latter doesn't make too much sense) in its
|
||||
* "input zone" (neg on d.1), which contains a boolean value ("true" or "false"
|
||||
* -- everything else is an error), and put a cell in what would usually be
|
||||
* its "output zone" (pos on d.1). From there, hang a new strip. If the
|
||||
* condition is true, execution proceeds on the new strip; if the condition
|
||||
* is false, execution proceeds on the old strip.
|
||||
* <p>
|
||||
* Blank cells in a strip are usually just ignored. However, a blank cell at
|
||||
* the end of a strip works like a goto statement: if there's something
|
||||
* poswards on d.1, the execution pointer jumps to the endcell on d.1
|
||||
* and proceeds execution on d.xeq. This is used when, after branching
|
||||
* because of some condition, you want to unify your strips (i.e., you
|
||||
* make a blank cell on the end of each one, connect them on d.1, and
|
||||
* proceed programming on the posmost cell on d.1).
|
||||
* <p>
|
||||
* Loops can be constructed by looping ZZ cells. You should take care to
|
||||
* have a condition somewhere in the loop which can turn true. (XXX break
|
||||
* infinite loops somehow!)
|
||||
* <p>
|
||||
* The language only uses the d.1, d.xeq, and d.clone dimensions. The
|
||||
* combinations d.1/d.xeq, d.1/d.clone, d.1/d.xeq/d.clone, d.1/d.clone/d.xeq
|
||||
* all make sense to view, especially in the row and column views.
|
||||
*/
|
||||
|
||||
public class FlowingClang {
|
||||
public static final String rcsid = "$Id: FlowingClang.java,v 1.7 2000/11/16 20:33:13 bfallenstein Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
public static final String dim = "d.xeq";
|
||||
|
||||
static Hashtable pss = new Hashtable();
|
||||
static PrimitiveSet findPrimitiveSet(String set) {
|
||||
Object o = pss.get(set);
|
||||
if(o != null) return (PrimitiveSet)o;
|
||||
try {
|
||||
o = Class.forName("org.gzigzag.flowing."+set).newInstance();
|
||||
} catch(Exception e) {
|
||||
ZZLogger.exc(e);
|
||||
return null;
|
||||
}
|
||||
if(!(o instanceof PrimitiveSet)) return null;
|
||||
pss.put(set, o);
|
||||
return (PrimitiveSet)o;
|
||||
}
|
||||
|
||||
static Hashtable prims = new Hashtable();
|
||||
static Primitive findPrimitive(String s) {
|
||||
Object o = prims.get(s);
|
||||
if(o != null) return (Primitive)o;
|
||||
|
||||
int ind = s.indexOf(".");
|
||||
if(ind < 0) return null;
|
||||
String set = s.substring(0, ind);
|
||||
String id = s.substring(ind+1);
|
||||
PrimitiveSet ps = findPrimitiveSet(set);
|
||||
Primitive prim = ps.get(id);
|
||||
if(prim != null)
|
||||
prims.put(id, prim);
|
||||
return prim;
|
||||
}
|
||||
|
||||
public static Data run(ZZCell c, Data d) { return run(c, d, false); }
|
||||
|
||||
public static Data run(ZZCell c0, Data d, boolean real) {
|
||||
p("Flowing Clang run: "+c0.getText());
|
||||
ZZCell c = c0.getRootclone();
|
||||
StackFrame frame;
|
||||
if(real) frame = new StackFrameReal(c.getSpace());
|
||||
else frame = new StackFrameVirtual();
|
||||
frame.setPos(c);
|
||||
frame.put(c, d, -1);
|
||||
StackFrame f = frame;
|
||||
try {
|
||||
while(f != null) f = step(f, true);
|
||||
} catch(Throwable t) {
|
||||
ZZLogger.exc(t, "Exception in Flowing Clang run. ");
|
||||
return null;
|
||||
}
|
||||
return frame.get(c, +1);
|
||||
}
|
||||
|
||||
public static ZZCell start(ZZCell c0, Data d) {
|
||||
StackFrameReal frame = new StackFrameReal(c0.getSpace());
|
||||
frame.setPos(c0);
|
||||
frame.put(c0, d, -1);
|
||||
return frame.main;
|
||||
}
|
||||
|
||||
public static StackFrame jump(StackFrame frame) {
|
||||
StackFrame f = frame;
|
||||
do {
|
||||
f = step(f, true);
|
||||
} while(frame.parentof(f));
|
||||
return f;
|
||||
}
|
||||
|
||||
public static StackFrame step(StackFrame frame, boolean throwerrs) {
|
||||
ZZCell cur = frame.getPos().s(dim);
|
||||
if(cur == null) { // RETURN
|
||||
p("Flowing clang return step");
|
||||
StackFrame ret = frame.ret();
|
||||
if(ret == null) return null;
|
||||
ZZCell rpos = ret.getPos();
|
||||
ret.put(rpos, frame.get(rpos.getRootclone(), +1), +1);
|
||||
frame.delete();
|
||||
return ret;
|
||||
}
|
||||
|
||||
p("Flowing Clang step: "+cur.getText()+" ("+cur.getID()+")");
|
||||
ZZCell root = cur.h("d.clone", -1, true);
|
||||
String s = cur.getText();
|
||||
if(s.equals("") && root==null) { // GOTO
|
||||
frame.setPos(cur.h("d.1", 1));
|
||||
return frame;
|
||||
}
|
||||
|
||||
Data d = frame.get(cur, -1); // IF
|
||||
if(s.equals("?")) {
|
||||
Primitive.count(d, 1);
|
||||
if(d.b(0)) cur = cur.h("d.1", 1);
|
||||
frame.setPos(cur);
|
||||
return frame;
|
||||
}
|
||||
|
||||
Primitive p = findPrimitive(s);
|
||||
if(p != null) { // PRIMITIVE
|
||||
try {
|
||||
d = p.execute(d, cur.getSpace());
|
||||
} catch(ZZError e) {
|
||||
if(throwerrs) throw e;
|
||||
ZZLogger.exc(e, "Exception in Flowing Clang step. ");
|
||||
return frame;
|
||||
}
|
||||
frame.put(cur, d, +1);
|
||||
frame.setPos(cur);
|
||||
return frame;
|
||||
} else if(root != null) { // FUNCTION CALL
|
||||
frame.setPos(cur);
|
||||
StackFrame called = frame.call();
|
||||
called.put(root, d, -1);
|
||||
called.setPos(root);
|
||||
return called;
|
||||
} else { // UNKNOWN
|
||||
if(throwerrs)
|
||||
throw new ZZError("Not a primitive at " + cur.getID() + ": " +
|
||||
cur.getText());
|
||||
ZZLogger.log("Flowing Clang step cannot be executed: Not a " +
|
||||
"primitive at " + cur.getID() + ": " + cur.getText());
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
64
Java/clang/flowing/Primitive.java
Normal file
64
Java/clang/flowing/Primitive.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Primitive.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
|
||||
/** An Flowing Clang primitive.
|
||||
*/
|
||||
|
||||
public abstract class Primitive {
|
||||
String rcsid = "$Id: Primitive.java,v 1.3 2000/10/13 13:52:24 bfallenstein Exp $";
|
||||
|
||||
// In subclasses, override one of the following two:
|
||||
protected Data execute(Data params) { return null; }
|
||||
public Data execute(Data params, ZZSpace space) {
|
||||
return execute(params);
|
||||
}
|
||||
|
||||
static public void count(Data pars, int n) {
|
||||
if(n != pars.len()) miscount();
|
||||
}
|
||||
static public void miscount() { throw new ZZError("Wrong parameter count"); }
|
||||
|
||||
/** Read a direction or step count from a parameter array.
|
||||
* If the pos is out of the bounds of the array, +1 is assumed, so that
|
||||
* the dir can optionally be left out.
|
||||
* <p>
|
||||
* (This, obviously, is just a convenience function.)
|
||||
*/
|
||||
static int readsteps(Data pars, int pos) {
|
||||
if(pos < pars.len()) {
|
||||
String stepstr = pars.s(pos);
|
||||
if(stepstr.equals("+"))
|
||||
return 1;
|
||||
else if(stepstr.equals("-"))
|
||||
return -1;
|
||||
else
|
||||
return pars.i(pos);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
Java/clang/flowing/PrimitiveSet.java
Normal file
34
Java/clang/flowing/PrimitiveSet.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
PrimitiveSet.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Tuomas Lukka (for Heraclitus Clang)
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
|
||||
/** A set of Flowing Clang primitives.
|
||||
*/
|
||||
|
||||
public abstract class PrimitiveSet {
|
||||
String rcsid = "$Id: PrimitiveSet.java,v 1.3 2000/10/13 13:52:24 bfallenstein Exp $";
|
||||
public abstract Primitive get(String id);
|
||||
}
|
||||
|
||||
|
||||
117
Java/clang/flowing/StackFrame.java
Normal file
117
Java/clang/flowing/StackFrame.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
StackFrame.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
|
||||
/** A stack frame for Flowing Clang.
|
||||
*/
|
||||
|
||||
public abstract class StackFrame {
|
||||
String rcsid = "$Id: StackFrame.java,v 1.5 2000/11/16 20:33:13 bfallenstein Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
// METHODS TO BE IMPLEMENTED BY SUBCLASSES
|
||||
|
||||
/** Get the value associated with a cell. */
|
||||
public abstract Object getSingle(ZZCell c);
|
||||
|
||||
/** Set the value associated with a cell.
|
||||
* @param d The Data object in which the value to be set is found.
|
||||
* @param at The value's position in the Data object.
|
||||
*/
|
||||
public abstract void setSingle(ZZCell c, Data d, int at);
|
||||
|
||||
/** Get position of instruction pointer. */
|
||||
public abstract ZZCell getPos();
|
||||
/** Set position of instruction pointer. */
|
||||
public abstract void setPos(ZZCell c);
|
||||
|
||||
/** Create a lower-level stackframe. */
|
||||
public abstract StackFrame call();
|
||||
|
||||
/** Return true if this stack frame is parent of given stack frame. */
|
||||
public abstract boolean parentof(StackFrame sf);
|
||||
|
||||
/** Return to the next higher stackframe (disconnects this (lower) frame).
|
||||
* Also sets instruction pointer to null, but keeps the values associated
|
||||
* with cells, so that the returned data can be read. Call delete() when
|
||||
* you're done with the values.
|
||||
*/
|
||||
public abstract StackFrame ret();
|
||||
|
||||
/** Delete the cells associated with the stackframe, if any.
|
||||
* This renders the values of a structural stackframe inaccessible.
|
||||
*/
|
||||
public void delete() {}
|
||||
|
||||
// METHODS StackFrame PROVIDES
|
||||
|
||||
private static final ZZCell[] reverse(ZZCell[] arr) {
|
||||
ZZCell[] res = new ZZCell[arr.length];
|
||||
for(int i=0; i<arr.length; i++) res[arr.length-i-1] = arr[i];
|
||||
return res;
|
||||
}
|
||||
|
||||
public Data get(ZZCell c, int dir) {
|
||||
p("Start getting for "+c.getText()+" ("+c.getID()+")");
|
||||
ZZCell[] cells = c.readRank("d.1", dir, false);
|
||||
if(dir<0) cells = reverse(cells);
|
||||
Object[] result = new Object[cells.length];
|
||||
p("Getting "+cells.length+" values");
|
||||
for(int i=0; i<cells.length; i++) {
|
||||
if(cells[i].s("d.clone", -1) != null) {
|
||||
p("Getting: " + cells[i].getText());
|
||||
result[i] = getSingle(cells[i].getRootclone());
|
||||
if(result[i] == null)
|
||||
throw new ZZError("Value for " + cells[i].getText() +
|
||||
" not yet set");
|
||||
} else {
|
||||
p("Getting literal");
|
||||
result[i] = cells[i];
|
||||
}
|
||||
p("Got "+result[i]);
|
||||
}
|
||||
p("Finish getting");
|
||||
return new Data(result);
|
||||
}
|
||||
|
||||
public void put(ZZCell c, Data params, int dir) {
|
||||
p("Start putting for "+c.getText()+" ("+c.getID()+")");
|
||||
Data pars = params != null ? params : new Data();
|
||||
ZZCell[] cells = c.readRank("d.1", dir, false);
|
||||
if(dir<0) cells = reverse(cells);
|
||||
p("Putting "+cells.length+" values");
|
||||
if(pars.len() < cells.length)
|
||||
throw new ZZError("Pars: " + pars.len() +
|
||||
" < cells: " + cells.length);
|
||||
for(int i=0; i<cells.length; i++) {
|
||||
p("Putting: "+pars.s(i)+" into: "+cells[i].getText());
|
||||
setSingle(cells[i].getRootclone(), pars, i);
|
||||
}
|
||||
p("Finish putting");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
97
Java/clang/flowing/StackFrameReal.java
Normal file
97
Java/clang/flowing/StackFrameReal.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
StackFrameReal.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
|
||||
/** A structural implementation for Flowing Clang stack frames.
|
||||
*/
|
||||
|
||||
public class StackFrameReal extends StackFrame {
|
||||
String rcsid = "$Id: StackFrameReal.java,v 1.6 2000/11/16 20:33:13 bfallenstein Exp $";
|
||||
|
||||
public ZZCell main;
|
||||
|
||||
public StackFrameReal(ZZSpace sp) { main = sp.getHomeCell().N(); }
|
||||
public StackFrameReal(ZZCell main) { this.main = main; }
|
||||
public StackFrameReal(StackFrameReal caller) {
|
||||
this(caller.main.N("d.2", 1));
|
||||
}
|
||||
|
||||
public Object getSingle(ZZCell c) {
|
||||
ZZCell where = main.intersect("d..flowing-frame", 1,
|
||||
c, "d..flowing-data", 1);
|
||||
if(where == null) return null;
|
||||
ZZCell acc = ZZCursorReal.get(where);
|
||||
if(acc != null) return acc;
|
||||
else return where;
|
||||
}
|
||||
public void setSingle(ZZCell c, Data d, int at) {
|
||||
ZZCell where = main.intersect("d..flowing-frame", 1,
|
||||
c, "d..flowing-data", 1);
|
||||
if(where == null) {
|
||||
where = main.N("d..flowing-frame", 1);
|
||||
c.insert("d..flowing-data", 1, where);
|
||||
}
|
||||
if(d.o(at) instanceof ZZCell)
|
||||
ZZCursorReal.setcursor(where, d.c(at));
|
||||
else {
|
||||
ZZCursorReal.setcursor(where, null);
|
||||
where.setText(d.s(at));
|
||||
}
|
||||
}
|
||||
|
||||
public ZZCell getPos() { return ZZCursorReal.get(main.h("d.2")); }
|
||||
public void setPos(ZZCell c) { ZZCursorReal.setcursor(main, c); }
|
||||
|
||||
public StackFrame call() { return new StackFrameReal(this); }
|
||||
public boolean parentof(StackFrame sf) {
|
||||
if(!(sf instanceof StackFrameReal)) return false;
|
||||
ZZCell find = ((StackFrameReal)sf).main;
|
||||
for(ZZCell c = main; c != null && c != main; c = c.s("d.2")) {
|
||||
if(c.equals(find)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public StackFrame ret() {
|
||||
ZZCell caller = main.s("d.2", -1);
|
||||
setPos(null);
|
||||
if(caller != null) {
|
||||
caller.disconnect("d.2", +1);
|
||||
return new StackFrameReal(caller);
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
public void delete() {
|
||||
ZZCell pos = main;
|
||||
while(pos != null) {
|
||||
ZZCell nextrow = pos.s("d.2");
|
||||
while(pos != null) {
|
||||
ZZCell next = pos.s("d..flowing-frame");
|
||||
pos.delete();
|
||||
pos = next;
|
||||
}
|
||||
pos = nextrow;
|
||||
}
|
||||
}
|
||||
public boolean equals(StackFrameReal f) { return main.equals(f.main); }
|
||||
}
|
||||
63
Java/clang/flowing/StackFrameVirtual.java
Normal file
63
Java/clang/flowing/StackFrameVirtual.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
StackFrameVirtual.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
|
||||
/** A virtual implementation for Flowing Clang stack frames.
|
||||
*/
|
||||
|
||||
public class StackFrameVirtual extends StackFrame {
|
||||
String rcsid = "$Id: StackFrameVirtual.java,v 1.5 2000/11/16 20:33:13 bfallenstein Exp $";
|
||||
|
||||
Hashtable values = new Hashtable();
|
||||
static final Object NULL = new Object();
|
||||
StackFrameVirtual caller = null, called = null;
|
||||
ZZCell pos;
|
||||
|
||||
public StackFrameVirtual() {}
|
||||
public StackFrameVirtual(StackFrameVirtual frame) { caller = frame; }
|
||||
|
||||
public Object getSingle(ZZCell c) {
|
||||
Object res = values.get(c);
|
||||
return res == NULL ? null : res;
|
||||
}
|
||||
public void setSingle(ZZCell c, Data d, int at) {
|
||||
values.put(c, d.o(at) == null ? NULL : d.o(at));
|
||||
}
|
||||
public ZZCell getPos() { return called == null ? pos : called.getPos(); }
|
||||
public void setPos(ZZCell c) { pos = c; }
|
||||
public StackFrame call() { return called = new StackFrameVirtual(this); }
|
||||
public boolean parentof(StackFrame sf) {
|
||||
if(called == null) return false;
|
||||
return (sf == called) || (called.parentof(sf));
|
||||
}
|
||||
public StackFrame ret() {
|
||||
pos = null;
|
||||
if(caller != null) caller.called = null;
|
||||
return caller;
|
||||
}
|
||||
public boolean equals(StackFrameVirtual frame) { return this == frame; }
|
||||
}
|
||||
|
||||
|
||||
229
Java/clang/flowing/T.java
Normal file
229
Java/clang/flowing/T.java
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
T.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* The "T" (Space Transformation) primitive set for Flowing clang.
|
||||
*/
|
||||
|
||||
public class T extends PrimitiveSet {
|
||||
public static final String rcsid = "$Id: T.java,v 1.4 2000/10/18 14:35:31 tjl Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
public Primitive get(String id) {
|
||||
if(id.equals("GET"))
|
||||
return new Get();
|
||||
if(id.equals("SET"))
|
||||
return new Set();
|
||||
if(id.equals("STEP") || id.equals("s"))
|
||||
return new Step();
|
||||
if(id.equals("END") || id.equals("h"))
|
||||
return new End();
|
||||
if(id.equals("FIND"))
|
||||
return new Find();
|
||||
if(id.equals("ORIGINAL"))
|
||||
return new Original();
|
||||
if(id.equals("CROSS")) // == intersect
|
||||
return new Cross();
|
||||
if(id.equals("HOMECELL"))
|
||||
return new HomeCell();
|
||||
if(id.equals("CONNECT"))
|
||||
return new Connect();
|
||||
if(id.equals("INSERT"))
|
||||
return new Insert();
|
||||
if(id.equals("DISCONNECT"))
|
||||
return new Disconnect();
|
||||
if(id.equals("HOP"))
|
||||
return new Hop();
|
||||
if(id.equals("NEW") || id.equals("N"))
|
||||
return new New();
|
||||
if(id.equals("CLONE"))
|
||||
return new Clone();
|
||||
if(id.equals("DELETE"))
|
||||
return new Delete();
|
||||
if(id.equals("SAME"))
|
||||
return new Same();
|
||||
return null;
|
||||
}
|
||||
|
||||
static public class Get extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
return new Data(ZZCursorReal.get(params.c(0)));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Set extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 2);
|
||||
ZZCursorReal.set(params.c(0), params.c(1));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class Step extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2 || params.len() > 3) miscount();
|
||||
int steps = readsteps(params, 2);
|
||||
String dim = params.s(1);
|
||||
return new Data(params.c(0).s(dim, steps));
|
||||
}
|
||||
}
|
||||
|
||||
static public class End extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2 || params.len() > 3) miscount();
|
||||
String dim = params.s(1);
|
||||
return new Data(params.c(0).h(dim, readsteps(params, 2)));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Find extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 3 || params.len() > 4) miscount();
|
||||
String dim = params.s(1), txt; int dir;
|
||||
if(params.len() == 3) {
|
||||
dir = 1;
|
||||
txt = params.s(2);
|
||||
} else {
|
||||
dir = readsteps(params, 2);
|
||||
txt = params.s(3);
|
||||
}
|
||||
ZZCell c = params.c(0).findText(dim, dir, txt);
|
||||
return new Data(c);
|
||||
}
|
||||
}
|
||||
|
||||
static public class Original extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
return new Data(params.c(0).getRootclone());
|
||||
}
|
||||
}
|
||||
|
||||
static public class Cross extends Primitive { // i.e., intersect
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() != 4 && params.len() != 6) miscount();
|
||||
ZZCell c0, c1;
|
||||
String dim0, dim1;
|
||||
int dir0, dir1;
|
||||
|
||||
if(params.len() == 4) {
|
||||
c0 = params.c(0); c1 = params.c(2);
|
||||
dim0 = params.s(1); dim1 = params.s(3);
|
||||
dir0 = 1; dir1 = 1;
|
||||
} else {
|
||||
c0 = params.c(0); c1 = params.c(3);
|
||||
dim0 = params.s(1); dim1 = params.s(4);
|
||||
dir0 = readsteps(params, 2); dir1 = readsteps(params, 5);
|
||||
}
|
||||
p("CROSS: "+c0.getText()+" "+dim0+" "+dir0+" "+
|
||||
c1.getText()+" "+dim1+" "+dir1);
|
||||
return new Data(c0.intersect(dim0, dir0, c1, dim1, dir1));
|
||||
}
|
||||
}
|
||||
|
||||
static public class HomeCell extends Primitive {
|
||||
public Data execute(Data params, ZZSpace space) {
|
||||
count(params, 0);
|
||||
return new Data(space.getHomeCell());
|
||||
}
|
||||
}
|
||||
|
||||
static public class Connect extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 3 || params.len() > 4) miscount();
|
||||
if(params.len() == 3)
|
||||
params.c(0).connect(params.s(1), params.c(2));
|
||||
else
|
||||
params.c(0).connect(params.s(1), readsteps(params, 2),
|
||||
params.c(3));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class Insert extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 3 || params.len() > 4) miscount();
|
||||
if(params.len() == 3)
|
||||
params.c(0).insert(params.s(1), 1, params.c(2));
|
||||
else
|
||||
params.c(0).insert(params.s(1), readsteps(params, 2),
|
||||
params.c(3));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class Disconnect extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2 || params.len() > 3) miscount();
|
||||
params.c(0).disconnect(params.s(1), readsteps(params, 2));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class Hop extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2 || params.len() > 3) miscount();
|
||||
params.c(0).hop(params.s(1), readsteps(params, 2));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class New extends Primitive {
|
||||
public Data execute(Data params, ZZSpace space) {
|
||||
if(params.len() == 1 || params.len() > 3) miscount();
|
||||
if(params.len() == 0)
|
||||
return new Data(space.getHomeCell().N());
|
||||
else {
|
||||
String dim = params.s(1);
|
||||
return new Data(params.c(0).N(dim,readsteps(params, 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public class Clone extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
return new Data(params.c(0).zzclone());
|
||||
}
|
||||
}
|
||||
|
||||
static public class Delete extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
params.c(0).delete();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class Same extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
return params;
|
||||
}
|
||||
}
|
||||
}
|
||||
138
Java/clang/flowing/X.java
Normal file
138
Java/clang/flowing/X.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
X.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benjamin Fallenstein
|
||||
*/
|
||||
package org.gzigzag.flowing;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* The "X" (Cell Text) primitive set for Flowing clang.
|
||||
*/
|
||||
|
||||
public class X extends PrimitiveSet {
|
||||
public static final String rcsid = "$Id: X.java,v 1.4 2000/10/20 15:16:54 bfallenstein Exp $";
|
||||
public static boolean dbg = true;
|
||||
static final void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
|
||||
public Primitive get(String id) {
|
||||
if(id.equals("SET"))
|
||||
return new Set();
|
||||
if(id.equals("+"))
|
||||
return new Concat();
|
||||
if(id.equals("="))
|
||||
return new Equals();
|
||||
if(id.equals("LEN"))
|
||||
return new Len();
|
||||
if(id.equals("PART"))
|
||||
return new Part();
|
||||
if(id.equals("FIND"))
|
||||
return new Find();
|
||||
if(id.equals("PUICOPY"))
|
||||
return new PUICopy();
|
||||
if(id.equals("PUIPASTE"))
|
||||
return new PUIPaste();
|
||||
if(id.equals("LOG"))
|
||||
return new Log();
|
||||
return null;
|
||||
}
|
||||
|
||||
static public class Set extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 2);
|
||||
params.c(0).setText(params.s(1));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class Concat extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2) miscount();
|
||||
String s = "";
|
||||
for(int i=0; i<params.len(); i++) {
|
||||
s = s + params.s(i);
|
||||
}
|
||||
return new Data(s);
|
||||
}
|
||||
}
|
||||
|
||||
static public class Equals extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 2);
|
||||
boolean res = params.s(0).equals(params.s(1));
|
||||
return new Data(new Boolean(res));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Len extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
return new Data(new Integer(params.s(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
static public class Part extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2 || params.len() > 3) miscount();
|
||||
String txt = params.s(0); int start = params.i(1);
|
||||
if(params.len() == 2) {
|
||||
txt = txt.substring(start);
|
||||
} else {
|
||||
txt = txt.substring(start, params.i(2));
|
||||
}
|
||||
return new Data(txt);
|
||||
}
|
||||
}
|
||||
|
||||
static public class Find extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
if(params.len() < 2 || params.len() > 3) miscount();
|
||||
String txt = params.s(0), sub = params.s(1);
|
||||
int start;
|
||||
if(params.len() == 3) start = params.i(2);
|
||||
else start = 0;
|
||||
return new Data(new Integer(txt.indexOf(sub, start)));
|
||||
}
|
||||
}
|
||||
|
||||
static public class PUICopy extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
ZZUtil.puiCopy(params.s(0));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class PUIPaste extends Primitive {
|
||||
public Data execute(Data params, ZZSpace space) {
|
||||
count(params, 0);
|
||||
return new Data(ZZUtil.puiGetClipText());
|
||||
}
|
||||
}
|
||||
|
||||
static public class Log extends Primitive {
|
||||
protected Data execute(Data params) {
|
||||
count(params, 1);
|
||||
ZZLogger.log(params.s(0));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user