created mirror
This commit is contained in:
55
Java/clang/thales/syntaxforms/Abstraction.java
Normal file
55
Java/clang/thales/syntaxforms/Abstraction.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Primitive.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.clang.thales.syntaxform;
|
||||
|
||||
import org.gzigzag.*;
|
||||
import org.gzigzag.clang.thales.*;
|
||||
|
||||
public class Abstraction extends SyntaxForm {
|
||||
public static final String rcsid = "$Id: Abstraction.java,v 1.4 2000/10/18 14:35:31 tjl Exp $";
|
||||
|
||||
// Runtime representation basecell -> rvcc -> bodyc -> envc posward on d.1
|
||||
private final class Rep {
|
||||
public ZZCell rvcc;
|
||||
public ZZCell rvc;
|
||||
public ZZCell bodyc;
|
||||
public ZZCell body;
|
||||
public ZZCell envc; // pointer to inherited environment
|
||||
public Environment env; // dereferenced envc
|
||||
|
||||
/** Create from existing structure. */
|
||||
public Rep() {
|
||||
rvcc = getBaseCell().s("d.1", 1);
|
||||
rvc = ZZCursorReal.get(rvcc);
|
||||
bodyc = rvcc.s("d.1", 1);
|
||||
body = ZZCursorReal.get(bodyc);
|
||||
envc = bodyc.s("d.1", 1);
|
||||
env = new Environment(ZZCursorReal.get(envc));
|
||||
}
|
||||
|
||||
public Rep(ZZCell body, Environment env, ZZCell rvc
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
82
Java/clang/thales/syntaxforms/CellDenoter.java
Normal file
82
Java/clang/thales/syntaxforms/CellDenoter.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
CellDenoter.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.clang.thales.syntaxform;
|
||||
|
||||
import org.gzigzag.*;
|
||||
import org.gzigzag.clang.thales.*;
|
||||
|
||||
class CellDenoter extends SyntaxForm {
|
||||
// Runtime representation: basecell -> rvcc -> instc on d.1 posward
|
||||
private final class Rep {
|
||||
public ZZCell rvcc; // pointer to return value pointer
|
||||
public ZZCell rvc; // dereferenced rvcc
|
||||
public ZZCell instc; // Pointer to runtime instance of the denoter
|
||||
public ZZCell inst; // dereferenced instc
|
||||
|
||||
/** Create from existing structure. */
|
||||
public Rep() {
|
||||
rvcc = getBaseCell().s("d.1", 1);
|
||||
rvc = ZZCursorReal.get(rvcc);
|
||||
instc = rvcc.s("d.1", 1);
|
||||
inst = ZZCursorReal.get(instc);
|
||||
}
|
||||
|
||||
public Rep(ZZCell inst, ZZCell rvc) {
|
||||
this.rvc = rvc;
|
||||
this.inst = inst;
|
||||
rvcc = getBaseCell().N("d.1", 1);
|
||||
instc = rvcc.N("d.1", 1);
|
||||
ZZCursorReal.set(rvcc, rvc);
|
||||
ZZCursorReal.set(instc, inst);
|
||||
Environment env = new Environment(inst);
|
||||
env.registerReference();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
rvcc.delete();
|
||||
instc.delete();
|
||||
Environment env = new Environment(inst);
|
||||
env.unregisterReference();
|
||||
}
|
||||
}
|
||||
|
||||
public CellDenoter(ZZCell c, Evaluator etor) { super(c, etor); }
|
||||
|
||||
public CellDenoter(ZZCell expr, ZZCell rvc, Evaluator etor) {
|
||||
super(SyntaxForm.newRT(rvc.getSpace(), this.getClass()), etor);
|
||||
Environment env = getCurrentEnvironment();
|
||||
ZZCell instance = env.getDenoterInstance(expr);
|
||||
Rep rep(instance, rvc);
|
||||
}
|
||||
|
||||
public void evalIteration() {
|
||||
Rep rep;
|
||||
ZZCursorReal.set(rep.rvc, ZZCursorReal.get(rep.inst));
|
||||
finishEval();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
Rep rep;
|
||||
rep.delete();
|
||||
}
|
||||
|
||||
}
|
||||
75
Java/clang/thales/syntaxforms/CellLiteral.java
Normal file
75
Java/clang/thales/syntaxforms/CellLiteral.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
CellLiteral.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.clang.thales.syntaxform;
|
||||
|
||||
import org.gzigzag.*;
|
||||
import org.gzigzag.clang.thales.*;
|
||||
|
||||
class CellLiteral extends SyntaxForm {
|
||||
// Runtime representation: basecell -> rvcc -> litc on d.1 posward
|
||||
private final class Rep {
|
||||
public ZZCell rvcc; // pointer to the return value pointer
|
||||
public ZZCell rvc; // dereferenced rvcc
|
||||
public ZZCell litc; // pointer to literal value
|
||||
|
||||
/** Create from existing structure. */
|
||||
public Rep() {
|
||||
rvcc = getBaseCell().s("d.1", 1);
|
||||
rvc = ZZCursorReal.get(rvcc);
|
||||
litc = rvcc.s("d.1", 1);
|
||||
}
|
||||
|
||||
/** Create also a new structure. */
|
||||
public Rep(ZZCell lit, ZZCell rvc) {
|
||||
this.rvc = rvc;
|
||||
rvcc = getBaseCell().N("d.1", 1);
|
||||
ZZCursorReal.set(rvcc, rvc);
|
||||
litc = rvcc.N("d.1", 1);
|
||||
ZZCursorReal.set(litc, lit);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
rvcc.delete();
|
||||
litc.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public CellLiteral(ZZCell c, Evaluator etor) {
|
||||
super(c, etor);
|
||||
}
|
||||
|
||||
public CellLiteral(ZZCell expr, ZZCell rvc, Evaluator etor) {
|
||||
super(SyntaxForm.newRT(rvc.getSpace(), this.getClass()), etor);
|
||||
Rep rep(ZZCursorReal.get(expr), rvc);
|
||||
}
|
||||
|
||||
public void evalIteration() {
|
||||
Rep rep;
|
||||
ZZCursorReal.set(rep.rvc, ZZCursorReal.get(rep.litc));
|
||||
finishEval();
|
||||
}
|
||||
|
||||
protected void delete() {
|
||||
Rep rep;
|
||||
rep.delete();
|
||||
}
|
||||
}
|
||||
191
Java/clang/thales/syntaxforms/Primitive.java
Normal file
191
Java/clang/thales/syntaxforms/Primitive.java
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
Primitive.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.clang.thales.syntaxform;
|
||||
|
||||
import org.gzigzag.*;
|
||||
import org.gzigzag.clang.thales.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Primitive extends SyntaxForm {
|
||||
public static final String rcsid = "$Id: Primitive.java,v 1.7 2000/10/18 14:35:31 tjl Exp $";
|
||||
public static boolean dbg = false;
|
||||
final static void p(String s) { if(dbg) System.out.println(s); }
|
||||
final static void pa(String s) { System.out.println(s); }
|
||||
|
||||
// Runtime representation basecell -> rvcc -> primc posward on d.1
|
||||
private final class Rep {
|
||||
public ZZCell rvcc; // pointer to return value pointer
|
||||
public ZZCell rvc; // dereferenced rvcc
|
||||
public ZZCell primc; // pointer to the primitive cell
|
||||
public ZZCell prim; // the primitive cell
|
||||
|
||||
/** Create from existing structure. */
|
||||
public Rep() {
|
||||
rvcc = getBaseCell().s("d.1", 1);
|
||||
rvc = ZZCursorReal.get(rvcc);
|
||||
primc = rvcc.s("d.1", 1);
|
||||
prim = ZZCursorReal.get(rvc);
|
||||
}
|
||||
|
||||
/** Create also a new structure. */
|
||||
public Rep(ZZCell prim, ZZCell rvc) {
|
||||
this.rvc = rvc;
|
||||
rvcc = getBaseCell().N("d.1", 1);
|
||||
ZZCursorReal.set(rvcc, rvc);
|
||||
this.prim = prim;
|
||||
primc = rvcc.N("d.1", 1);
|
||||
ZZCursorReal.set(primc, prim);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
rvcc.delete();
|
||||
primc.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public Primitive(ZZCell c) { super(c); }
|
||||
public Primitive(ZZCell expr, ZZCell rvc) {
|
||||
super(rvc.getSpace());
|
||||
Rep rep(expr.h("d.clone", -1), rvc);
|
||||
}
|
||||
|
||||
public void evalIteration() {
|
||||
Rep rep;
|
||||
|
||||
ZZCell rv = rep.rvc.N();
|
||||
rv.connect(DimensionNames.applicable, 1, rep.prim);
|
||||
ZZCursorReal.set(rep.rvc, rv);
|
||||
finishEval();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
Rep rep;
|
||||
rep.delete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static private Hashtable prims = new Hashtable();
|
||||
static private Hashtable optocell = new Hashtable();
|
||||
|
||||
static public PrimitiveOperation get(ZZCell c) {
|
||||
ZZCell id = c.h("d.clone", -1);
|
||||
synchronized (prims) {
|
||||
return (PrimitiveOperation) prims.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
static public class PrimitiveProblemException extends ZZError {
|
||||
public PrimitiveProblemException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
static public class DuplicateException extends PrimitiveProblemException {
|
||||
public DuplicateException() {
|
||||
this("duplicate Thales Clang primitive cell");
|
||||
}
|
||||
public DuplicateException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
static public class InvalidException extends PrimitiveProblemException {
|
||||
public InvalidException() {
|
||||
this("invalid Thales Clang primitive cell");
|
||||
}
|
||||
public InvalidException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
static private void readAPrimitive(ZZCell c) {
|
||||
ZZCell op = c.s(DimensionNames.primbinding, 1);
|
||||
|
||||
if (op == null) throw new InvalidException();
|
||||
|
||||
Object o;
|
||||
|
||||
try {
|
||||
Class cl = Class.forName("org.gzigzag.clang.thales.primitive." + op.getText());
|
||||
o = cl.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new InvalidException("primitive not found (" + e + ")");
|
||||
} catch (InstantiationException e) {
|
||||
throw new InvalidException("problems instantiating primitive: " + e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new InvalidException("" + e);
|
||||
}
|
||||
|
||||
if (!(o instanceof PrimitiveOperation)) throw new InvalidException();
|
||||
|
||||
// XXX: is this necessary or desirable?
|
||||
if (optocell.containsKey(o)) throw new DuplicateException();
|
||||
|
||||
synchronized (prims) {
|
||||
prims.put(c, o);
|
||||
optocell.put(o, c);
|
||||
}
|
||||
}
|
||||
|
||||
static public void readPrimitivesFromStructure(ZZSpace space) {
|
||||
ZZCell home = space.getHomeCell();
|
||||
|
||||
synchronized (prims) {
|
||||
for (ZZCell c = home.s(DimensionNames.primitives, 1);
|
||||
c != null;
|
||||
c = c.s(DimensionNames.primitives, 1)) {
|
||||
try {
|
||||
readAPrimitive(c);
|
||||
} catch (PrimitiveProblemException e) {
|
||||
pa("" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void register(ZZSpace space, String mc) {
|
||||
ZZCell home = space.getHomeCell();
|
||||
|
||||
synchronized (prims) {
|
||||
ZZCell id = home.N();
|
||||
ZZCell name = id.N(DimensionNames.primbinding, 1);
|
||||
|
||||
name.setText(mc);
|
||||
|
||||
try {
|
||||
readAPrimitive(id);
|
||||
} catch (ZZError e) {
|
||||
id.delete();
|
||||
name.delete();
|
||||
throw e;
|
||||
}
|
||||
|
||||
home.insert(DimensionNames.primitives, 1, id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
95
Java/clang/thales/syntaxforms/Sequence.java
Normal file
95
Java/clang/thales/syntaxforms/Sequence.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Sequence.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.clang.thales.syntaxform;
|
||||
|
||||
import org.gzigzag.*;
|
||||
import org.gzigzag.clang.thales.*;
|
||||
|
||||
class Sequence extends SyntaxForm {
|
||||
// Runtime representation: basecell -> rvcc -> tmprc -> csec on
|
||||
// d.1 posward
|
||||
private final class Rep {
|
||||
public ZZCell rvcc; // pointer to return value pointer
|
||||
public ZZCell rvc; // dereferenced rvcc
|
||||
public ZZCell tmprc; // temporary holder of component expression results
|
||||
public ZZCell tmpr; // dereferenced tmprc
|
||||
public ZZCell csec; // pointer to the current subexpression in code
|
||||
public ZZCell cse; // current subexpression in code
|
||||
|
||||
/** Create from existing structure. */
|
||||
public Rep() {
|
||||
rvcc = getBaseCell().s("d.1", 1);
|
||||
rvc = ZZCursorReal.get(rvcc);
|
||||
tmprc = rvcc.s("d.1", 1);
|
||||
tmpr = ZZCursorReal.get(tmprc);
|
||||
csec = tmprc.s("d.1", 1);
|
||||
cse = ZZCursorReal.get(csec);
|
||||
}
|
||||
|
||||
/** Create also a new structure. */
|
||||
public Rep(ZZCell fse, ZZCell rvc) {
|
||||
rvcc = getBaseCell().N("d.1", 1);
|
||||
ZZCursorReal.set(rvcc, rvc);
|
||||
this.rvc = rvc;
|
||||
tmprc = rvcc.N("d.1", 1);
|
||||
tmpr = null;
|
||||
csec = tmprc.N("d.1", 1);
|
||||
ZZCursorReal.set(csec, fse);
|
||||
cse = fse;
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
rvcc.delete();
|
||||
tmprc.delete();
|
||||
csec.delete();
|
||||
}
|
||||
|
||||
public Sequence(ZZCell c) { super(c); }
|
||||
|
||||
public Sequence(ZZCell expr, ZZCell rvc) {
|
||||
super(rvc.getSpace());
|
||||
ZZCell fse = expr.s(DimensionNames.sequence, 1);
|
||||
if (fse == null) {
|
||||
throw new SyntaxError("sequence must have at least one element");
|
||||
}
|
||||
Rep rep(fse, rvc);
|
||||
}
|
||||
|
||||
public void evalIteration() {
|
||||
Rep rep;
|
||||
|
||||
if (rep.cse == null) {
|
||||
ZZCursorReal.set(rvc, tmpr);
|
||||
finishEval();
|
||||
}
|
||||
|
||||
SyntaxForm sf = code_instantiate(rep.cse, tmprc);
|
||||
|
||||
requestEval(sf);
|
||||
|
||||
ZZCursorReal.set(rep.csec,
|
||||
rep.cse.s(DimensionNames.sequence, 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user