Search in sources :

Example 1 with ABSUnit

use of abs.backend.java.lib.types.ABSUnit in project abstools by abstools.

the class Clazz method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Class");
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            return ABSString.fromString(cls.getName());
        }
    });
    thisClass.addMethod(/*ABSClosure*/
    "getMethod", new ABSClosure() {

        @Override
        public ABSDynamicObject exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            ABSString name = (ABSString) params[0];
            ABSClosure method = cls.getMethod(name.getString());
            return method;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "addMethod", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            ABSString name = (ABSString) params[0];
            ABSClosure method = (ABSClosure) ((ABSDynamicObject) params[1]).getFieldValue_Internal("method");
            cls.addMethod(name.getString(), method);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "removeMethod", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicClass cls = (ABSDynamicClass) t.getFieldValue_Internal("class");
            ABSString name = (ABSString) params[0];
            cls.removeMethod(name.getString());
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(abs.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(abs.backend.java.lib.runtime.ABSClosure) ABSUnit(abs.backend.java.lib.types.ABSUnit) ABSValue(abs.backend.java.lib.types.ABSValue) ABSString(abs.backend.java.lib.types.ABSString) ABSDynamicClass(abs.backend.java.lib.runtime.ABSDynamicClass)

Example 2 with ABSUnit

use of abs.backend.java.lib.types.ABSUnit in project abstools by abstools.

the class Reconfiguration method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Reconfiguration");
    /* 
         * MetaABS Reconfiguration API -- cf. abslang.abs module ABS.Meta 
         */
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return ABSString.fromString(thisR.getName());
        }
    });
    thisClass.addMethod(/*ABSDynamicProduct*/
    "getCurrentProduct", new ABSClosure() {

        @Override
        public ABSDynamicProduct exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return thisR.getCurrentProduct();
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "setCurrentProduct", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            ABSDynamicProduct prod = (ABSDynamicProduct) params[0];
            thisR.setCurrentProduct(prod);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSDynamicProduct*/
    "getTargetProduct", new ABSClosure() {

        @Override
        public ABSDynamicProduct exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return thisR.getTargetProduct();
        }
    });
    thisClass.addMethod(/*ABSUnit*/
    "setTargetProduct", new ABSClosure() {

        @Override
        public ABSUnit exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            ABSDynamicProduct prod = (ABSDynamicProduct) params[0];
            thisR.setTargetProduct(prod);
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*List<ABSDynamicDelta>*/
    "getDeltas", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            List<ABSDynamicDelta> deltas = thisR.getDeltas();
            return ListUtils.toABSList(deltas);
        }
    });
    thisClass.addMethod(/*List<ABSDynamicDelta>*/
    "setDeltas", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            // TODO
            return ABSUnit.UNIT;
        }
    });
    thisClass.addMethod(/*ABSDynamicUpdate*/
    "getStateUpdate", new ABSClosure() {

        @Override
        public ABSDynamicUpdate exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            return thisR.getUpdate();
        }
    });
    thisClass.addMethod(/*List<ABSDynamicDelta>*/
    "setStateUpdate", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicReconfiguration thisR = (ABSDynamicReconfiguration) t;
            ABSDynamicUpdate upd = (ABSDynamicUpdate) params[0];
            thisR.setUpdate(upd);
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(abs.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(abs.backend.java.lib.runtime.ABSClosure) ABSDynamicProduct(abs.backend.java.lib.runtime.ABSDynamicProduct) ABSUnit(abs.backend.java.lib.types.ABSUnit) List(java.util.List) ABSDynamicUpdate(abs.backend.java.lib.runtime.ABSDynamicUpdate) ABSValue(abs.backend.java.lib.types.ABSValue) ABSString(abs.backend.java.lib.types.ABSString) ABSDynamicReconfiguration(abs.backend.java.lib.runtime.ABSDynamicReconfiguration)

Example 3 with ABSUnit

use of abs.backend.java.lib.types.ABSUnit in project abstools by abstools.

the class ServerSocket method fli_bind.

@Override
public Feedback<ABSUnit> fli_bind(ABSInteger port) {
    try {
        socket = new java.net.ServerSocket();
        socket.bind(new InetSocketAddress(port.toInt()));
        return new Feedback_OK<ABSUnit>();
    } catch (Exception e) {
        return new Feedback_Error<ABSUnit>(putil.convert(e.getMessage()));
    }
}
Also used : Feedback_OK(FLI.StreamUtils.Feedback_OK) InetSocketAddress(java.net.InetSocketAddress) ABSUnit(abs.backend.java.lib.types.ABSUnit) IOException(java.io.IOException)

Example 4 with ABSUnit

use of abs.backend.java.lib.types.ABSUnit in project abstools by abstools.

the class Socket method fli_connect.

@Override
public Feedback<ABSUnit> fli_connect(ABSString server, ABSInteger port, ABSInteger timeout) {
    try {
        client_socket = new java.net.Socket();
        SocketAddress serverAddress = new InetSocketAddress(InetAddress.getByName(server.getString()), port.toInt());
        client_socket.connect(serverAddress, timeout.toInt());
        setupStream();
        input.setStream(new DataInputStream(client_socket.getInputStream()));
        output.setStream(new DataOutputStream(client_socket.getOutputStream()));
        return new Feedback_OK<ABSUnit>();
    } catch (Exception e) {
        e.printStackTrace();
        return new Feedback_Error<ABSUnit>(putil.convert(e.getMessage()));
    }
}
Also used : Feedback_OK(FLI.StreamUtils.Feedback_OK) InetSocketAddress(java.net.InetSocketAddress) DataOutputStream(java.io.DataOutputStream) ABSUnit(abs.backend.java.lib.types.ABSUnit) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DataInputStream(java.io.DataInputStream) ABSAssertException(abs.backend.java.lib.runtime.ABSAssertException) IOException(java.io.IOException)

Aggregations

ABSUnit (abs.backend.java.lib.types.ABSUnit)4 Feedback_OK (FLI.StreamUtils.Feedback_OK)2 ABSClosure (abs.backend.java.lib.runtime.ABSClosure)2 ABSDynamicObject (abs.backend.java.lib.runtime.ABSDynamicObject)2 ABSString (abs.backend.java.lib.types.ABSString)2 ABSValue (abs.backend.java.lib.types.ABSValue)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 ABSAssertException (abs.backend.java.lib.runtime.ABSAssertException)1 ABSDynamicClass (abs.backend.java.lib.runtime.ABSDynamicClass)1 ABSDynamicProduct (abs.backend.java.lib.runtime.ABSDynamicProduct)1 ABSDynamicReconfiguration (abs.backend.java.lib.runtime.ABSDynamicReconfiguration)1 ABSDynamicUpdate (abs.backend.java.lib.runtime.ABSDynamicUpdate)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 SocketAddress (java.net.SocketAddress)1 List (java.util.List)1