001: package sisc.modules.io;
002:
003: import sisc.interpreter.*;
004: import sisc.nativefun.*;
005: import sisc.data.*;
006:
007: import sisc.io.custom.CustomPort;
008:
009: public class CustomIO extends IndexedFixableProcedure {
010:
011: protected static Symbol IOB = Symbol
012: .intern("sisc.modules.io.Messages");
013:
014: protected static final int PORTLOCAL = 1, SETPORTLOCAL = 2,
015: CUSTOMPORTPROCS = 3, CUSTOMPORTQ = 4;
016:
017: public static class Index extends IndexedLibraryAdapter {
018:
019: public Value construct(Object context, int id) {
020: return new CustomIO(id);
021: }
022:
023: public Index() {
024: define("custom-port?", CUSTOMPORTQ);
025: define("custom-port-procedures", CUSTOMPORTPROCS);
026: define("port-local", PORTLOCAL);
027: define("set-port-local!", SETPORTLOCAL);
028: }
029: }
030:
031: public static final CustomPort customport(Value o) {
032: if (o instanceof CustomPort) {
033: return (CustomPort) o;
034: } else {
035: typeError(IOB, "custom-port", o);
036: return null;
037: }
038: }
039:
040: public CustomIO(int id) {
041: super (id);
042: }
043:
044: public CustomIO() {
045: }
046:
047: public Value apply(Value v1) throws ContinuationException {
048: switch (id) {
049: case PORTLOCAL:
050: return customport(v1).getPortLocal();
051: case CUSTOMPORTPROCS:
052: return customport(v1).getProxy().getProcs();
053: case CUSTOMPORTQ:
054: return truth(v1 instanceof CustomPort);
055: default:
056: throwArgSizeException();
057: }
058: return VOID;
059: }
060:
061: public Value apply(Value v1, Value v2) throws ContinuationException {
062: switch (id) {
063: case SETPORTLOCAL:
064: customport(v1).setPortLocal(v2);
065: return VOID;
066: default:
067: throwArgSizeException();
068: }
069: return VOID;
070: }
071: }
072:
073: /*
074: * The contents of this file are subject to the Mozilla Public
075: * License Version 1.1 (the "License"); you may not use this file
076: * except in compliance with the License. You may obtain a copy of
077: * the License at http://www.mozilla.org/MPL/
078: *
079: * Software distributed under the License is distributed on an "AS
080: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
081: * implied. See the License for the specific language governing
082: * rights and limitations under the License.
083: *
084: * The Original Code is the Second Interpreter of Scheme Code (SISC).
085: *
086: * The Initial Developer of the Original Code is Scott G. Miller.
087: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
088: * Scott G. Miller. All Rights Reserved.
089: *
090: * Contributor(s):
091: * Matthias Radestock
092: *
093: * Alternatively, the contents of this file may be used under the
094: * terms of the GNU General Public License Version 2 or later (the
095: * "GPL"), in which case the provisions of the GPL are applicable
096: * instead of those above. If you wish to allow use of your
097: * version of this file only under the terms of the GPL and not to
098: * allow others to use your version of this file under the MPL,
099: * indicate your decision by deleting the provisions above and
100: * replace them with the notice and other provisions required by
101: * the GPL. If you do not delete the provisions above, a recipient
102: * may use your version of this file under either the MPL or the
103: * GPL.
104: */
|