/* ZZClang1.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.clang; import org.gzigzag.*; import java.util.*; /** A primitive test version of Clang. * NOT YET FINISHED! *

* XXX - make use stack frames in the structure */ public class ZZClang1 implements ZZClangContext /* , ZZClangOp */ { public static final String rcsid = "$Id: ZZClang1.java,v 1.5 2000/10/18 14:35:31 tjl Exp $"; public static final boolean dbg = true; static final void p(String s) { if(dbg) System.out.println(s); } Hashtable specials; Hashtable symtab; ZZCursor cursor; ZZCell viewspex; /** Execute a script in response to user action. * This means that the language can have special key words to * pass as parameters the key as a cell with a span etc. */ synchronized public void execUserAction(ZZCell code, ZZCell viewspex, ZZCell clicked, String key) { try { specials = new Hashtable(); if(key!=null) specials.put("UserAction.keyString", key); if(clicked!=null) specials.put("UserAction.clickedCell", clicked); execEnv(code, viewspex); } finally { specials = null; } } /** Execute a script in a fresh environment. */ synchronized public void execEnv(ZZCell code, ZZCell viewspex2) { symtab = new Hashtable(); viewspex = viewspex2; ZZCursor realcursor = new ZZCursorReal(viewspex); // Speed & space hack cursor = new ZZCursorVirtual(realcursor.get()); exec(code); realcursor.set(cursor.get()); } /** Execute starting from a cell. * Should not be used from outside except in special cases. */ synchronized public void exec(ZZCell code) { p("CLANG exec "+code); for(ZZCell current = code; current != null; current = current.s("d.2", 1)) { // Find op. ZZClangOp op = (ZZClangOp)funcs.get(current.getText()); p("OP: op"); if(op==null) throw new ZZError("Unknown op '"+current.getText()+ "'"); op.exec(current, cursor, this); } } /* // XXX allow VAR for local variables! public void exec(ZZCell c, ZZCell it, ZZCell[] params) { // First, read the prototype and set the params ZZCell[] p = c.readRank("d.1", 1, false); if(p.length > params.length) throw new ZZError("Insufficient params"); for(int i=0; i