created mirror

This commit is contained in:
whatever
2026-09-14 20:19:29 -04:00
commit 6764738d92
600 changed files with 87187 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
/*
HeraclitusClang.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
*/
package org.gzigzag.heraclitus;
import org.gzigzag.*;
import java.util.*;
/** A simple execution-based clang.
* Based on a cascading interpreter model, like #! in unix.
* Executables are given as parameters the cell they were referred
* to in (for structural params) and another cell, the parameter.
*/
public class HeraclitusClang {
public static final String rcsid = "$Id$";
public static boolean dbg = true;
static final void p(String s) { if(dbg) ZZLogger.log(s); }
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.heraclitus."+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(ZZCell c) {
String s = c.getText();
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;
}
/** Execute a heraclitus operation.
* @param op This cell gives the operation, either by
* being the clone of a Heraclitus primitive
* or by having its root clone have an "exe-type".
* @param param The parameter to be given for the
* execution.
*/
public static ZZCell execute(ZZCell op, ZZCell param) {
Primitive p = findPrimitive(op);
p("Heraclitus exec: "+p);
if(p == null) {
ZZCell n = op.h("d.clone", -1);
p = findPrimitive(n);
if(p == null) {
ZZCell nx = op.h("d.exe-type", -1, true);
if(nx == null) {
throw new ZZError("No executable primitive");
}
// The core: create the new langcache level
ZZCell curs1 = op.getHomeCell().N();
ZZCell curs2 = curs1.N("d.1", 1);
ZZCursorReal.set(curs1, op);
ZZCursorReal.set(curs2, param);
try {
p("Heraclitus recurse: "+nx);
return execute(nx, curs1);
} finally {
// XXX ZZCursorReal -delete as well?!?!
ZZCursorReal.delete(curs1);
ZZCursorReal.delete(curs2);
curs1.delete();
curs2.delete();
}
}
}
return p.execute(op, param);
}
}

View File

@@ -0,0 +1,79 @@
/*
HeraclitusCommand.java
*
* 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 Antti-Juhani Kaijanaho
*/
package org.gzigzag;
import java.awt.*;
/** ZZCommand interface to Heraclitus Clang.
*/
class HeraclitusCommand extends ZZCommand implements ZOb {
public static boolean dbg = false;
static final void p(String s) { if(dbg) ZZLogger.log(s); }
static final void pa(String s) { ZZLogger.log(s); }
STRUCTPARAMS {
/** Heraclitus operation cell. */
ZZCell op
= null;
}
INITIALIZE {
if(op == null)
throw new ZZError("Must specify Heraclitus Clang operation!");
}
public void exec(ZZCell param) {
throw new ZZError("exec not implemented yet");
}
public void execCallback(
ZZCell target,
ZZView view,
ZZView cview,
String key,
Point pt,
ZZScene xi
) {
ZZCell curspar = op.N();
ZZCell curs1 = op.N();
ZZCell curs2 = curs1.N("d.1", 1);
ZZCursorReal.set(curs1, cview.getViewcell());
ZZCursorReal.set(curs2, view.getViewcell());
ZZCursorReal.set(curspar, curs1);
try {
p("Enter heraclitus: ");
org.gzigzag.heraclitus.HeraclitusClang.execute(op, curspar);
p("Exit heraclitus");
} finally {
ZZCursorReal.delete(curs1);
ZZCursorReal.delete(curs2);
ZZCursorReal.delete(curspar);
curs1.delete();
curs2.delete();
curspar.delete();
}
}
}
// vim: set syntax=java :

View File

@@ -0,0 +1,85 @@
/*
PS1.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
*/
package org.gzigzag.heraclitus;
import org.gzigzag.*;
import java.util.*;
/**
* The first primitive set for Heraclitus clang.
*/
public class PS1 implements PrimitiveSet {
public static final String rcsid = "$Id$";
public static boolean dbg = true;
static final void p(String s) { if(dbg) ZZLogger.log(s); }
public Primitive get(String id) {
if(id.equals("Move1Test"))
return new Move1Test();
return null;
}
/** First test: move a HERA1 (see ZZPrimitiveActions) datacursor one
* step pos on d.1.
*/
static public class Move1Test implements Primitive {
public ZZCell execute(ZZCell primitive, ZZCell cursorparam) {
p("Move1test");
ZZCell c0 = ZZCursorReal.get(cursorparam);
ZZCell c = c0.s("d.1", 1);
ZZCell v = ZZCursorReal.get(c);
ZZCell t0 = ZZCursorReal.get(v);
ZZCell t = t0.s("d.1", 1);
p("M1T: "+cursorparam+" "+c0+" "+c+" "+t0+" "+t);
ZZCursorReal.set(v, t);
return cursorparam;
}
}
/** A text translator: translates fixed strings into other fixed
* strings.
*/
/** Dereference the cursorparameter: expects the cursorparameter
* to point to another cursor, and makes it point to the place
* the other cursor pointed to.
*/
static public class Deref1 implements Primitive {
public ZZCell execute(ZZCell primitive, ZZCell cursorparam) {
ZZCell c = ZZCursorReal.get(cursorparam);
if(c == null) return null;
ZZCursorReal.set(cursorparam, ZZCursorReal.get(c));
return cursorparam;
}
}
/** Execute a sequence of cells with the same cursorparam.
*/
static public class Seq1 implements Primitive {
public ZZCell execute(ZZCell primitive, ZZCell cursorparam) {
// ZZCell root = cursorParam.
return cursorparam;
}
}
}

View File

@@ -0,0 +1,41 @@
/*
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 Tuomas Lukka
*/
package org.gzigzag.heraclitus;
import org.gzigzag.*;
/** An Heraclitus Clang primitive.
* A primitive, just like a subroutine, executes one cell with another
* as a parameter, and returns another cell.
*/
public interface Primitive {
String rcsid = "$Id$";
/** Execute this primitive.
* @param instance The cell instance (clone) that was originally
* requested to be executed.
* @param param The parameter given to the execution.
*/
ZZCell execute(ZZCell instance, ZZCell param);
}

View 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
*/
package org.gzigzag.heraclitus;
import org.gzigzag.*;
/** A set of Heraclitus Clang primitives.
*/
public interface PrimitiveSet {
String rcsid = "$Id$";
Primitive get(String id);
}