[armedbear-devel] 0.18 and beyond

logicmoo at gmail.com logicmoo at gmail.com
Thu Nov 5 23:57:28 UTC 2009


On Thu, Nov 5, 2009 at 1:45 PM,  <logicmoo at gmail.com> wrote:
>> Other java lisps define each Primitive execute as a single static function
>> in a trampolines file.
>> The Primitive itself just calls the static function in the trampolines (
>> they are named in such a way it is easy to reference the class that holds
>> nothing but static functions).. In compiled code there is never any reason
>> to reference the Primitive or even the Symbol that uses it. The compiled
>> code is simply a series of static functions calling static functions

From: "Alessio Stalla" <alessiostalla at gmail.com>
>This is a useful technique to speed up compiled code. It could also
>speed up startup times as long as you don't invoke such primitives
>from interpreted code during startup (in such a case, you would need
>to load and install the appropriate Primitive subclass to invoke it,
>or use a generic subclass that invokes the appropriate static method
>through reflection).

Indeed

Here is an example of the transition I am working on
----------------------------------------------------------------------------

    // ### char<
    private static final Primitive CHAR_LESS_THAN =
        new Primitive("char<", "&rest characters")
    {
        @Override
        public LispObject execute() throws ConditionThrowable
        {
            return error(new WrongNumberOfArgumentsException(this));
        }
        @Override
        public LispObject execute(LispObject arg) throws ConditionThrowable
        {
            if (arg instanceof LispCharacter)
                return T;
            return type_error(arg, SymbolConstants.CHARACTER);
        }
        @Override
        public LispObject execute(LispObject first, LispObject second)
            throws ConditionThrowable
        {
            return first.charValue() < second.charValue() ? T : NIL;
       }
        @Override
        public LispObject execute(LispObject[] args) throws ConditionThrowable
        {
            final int length = args.length;
            char[] chars = new char[length];
            for (int i = 0; i < length; i++) {
                chars[i] = args[i].charValue();
            }
            for (int i = 1; i < length; i++) {
                if (chars[i-1] >= chars[i])
                    return NIL;
            }
            return T;
        }
    };


Converts to:
--------------------------------------------------------------------------------------------

class CharacterFunctions {
static final String myName= "org.armedbear.lisp.CharacterFunctions";

public final static LispObject primitive_CHAR_LESS_THAN_execute_1_0_false(LispObject req0) {
     req0.charValue(); // throws the type_error in LispObject  (LispCharacter overrides)
     return T;
}


public final static LispObject primitive_CHAR_LESS_THAN_execute_2_0_false(LispObject req0, LispObject req1) {
    return req0.charValue() < req1.charValue() ? T : NIL;
}


public final static LispObject primitive_CHAR_LESS_THAN_execute_0_0_true(LispObject[] args) {
            final int length = args.length;
            if (length==0)   return error(new WrongNumberOfArgumentsException(LispThread.currentMethod()));
            char[] chars = new char[length];
            for (int i = 0; i < length; i++) {
                chars[i] = args[i].charValue();
            }
            for (int i = 1; i < length; i++) {
                if (chars[i-1] >= chars[i])
                    return NIL;
            }
            return T;
}

 static void declare_character_functions() {
      declareFunction(myName,"primitive_CHAR_LESS_THAN_execute_1_0_false","CHAR<",1,0,false);
      declareFunction(myName,"primitive_CHAR_LESS_THAN_execute_2_0_false","CHAR<",2,0,false);
      declareFunction(myName,"primitive_CHAR_LESS_THAN_execute_0_0_true","CHAR<",0,0,true);
 ......
    } 





More information about the armedbear-devel mailing list