Jatha Software

org.jatha.compile
Class ApplyPrimitive

java.lang.Object
  extended by org.jatha.dynatype.StandardLispValue
      extended by org.jatha.compile.LispPrimitive
          extended by org.jatha.compile.ApplyPrimitive
All Implemented Interfaces:
Comparable, LispValue

public class ApplyPrimitive
extends LispPrimitive

(APPLY fn args...)

See Also:
SECDMachine, LispCompiler, LispPrimitive

Field Summary
 
Fields inherited from class org.jatha.compile.LispPrimitive
functionName, functionNameSymbol, inlineP, maxNumberOfArgs, minNumberOfArgs
 
Fields inherited from class org.jatha.dynatype.StandardLispValue
f_lisp
 
Constructor Summary
ApplyPrimitive(Jatha lisp)
           
 
Method Summary
 LispValue CompileArgs(LispCompiler compiler, SECDMachine machine, LispValue args, LispValue valueList, LispValue code)
          The CompileArgs method turns the arguments of the function call into SECD abstract machine code.
(package private)  LispValue constructArgList(LispValue args)
           
 void Execute(SECDMachine machine)
          Execute performs the operation using the abstract machine registers.
 boolean validArgumentList(LispValue args)
          This method returns true if the list of arguments satisfies the length and format restrictions posed by the function, and false otherwise.
 
Methods inherited from class org.jatha.compile.LispPrimitive
basic_functionp, BuiltinFunctionCode, CompileArgs, grindef, indent, internal_prin1, internal_princ, internal_print, LispFunctionNameString, LispFunctionNameSymbol, parameterCountString, printCode, printCode, toString, validArgumentLength
 
Methods inherited from class org.jatha.dynatype.StandardLispValue
abs, acos, add, adjustSpecialCount, append, apply, apropos_print, asin, assoc, atan, atan2, atom, basic_atom, basic_bignump, basic_consp, basic_constantp, basic_floatp, basic_foreignp, basic_integerp, basic_keywordp, basic_length, basic_listp, basic_macrop, basic_null, basic_numberp, basic_stringp, basic_symbolp, bignump, boundp, butlast, car, cdr, ceiling, characterp, clrhash, compareTo, concatenate, consp, constantp, contains, copy_list, copy, cos, cot, csc, degreesToRadians, divide, documentation, eighth, elt, elt, eq, eql, equal, equalNumeric, factorial, fboundp, fifth, first, floatp, floor, fourth, funcall, functionp, get_specialCount, gethash, gethash, getLisp, greaterThan, greaterThanOrEqual, hash_table_count, hash_table_rehash_size, hash_table_rehash_threshold, hash_table_size, hash_table_test, hashtablep, integerp, internal_getName, internal_prin1_as_cdr, internal_princ_as_cdr, internal_print_as_cdr, iterator, keywordp, last, length, lessThan, lessThanOrEqual, lisp_null, list, listp, max, member, min, multiply, nconc, negate, neql, ninth, nreverse, nstringCapitalize, nstringDowncase, nstringUpcase, numberp, pop, position, prin1, princ, print, push, radiansToDegrees, rassoc, readFromString, reciprocal, remhash, remove, rest, reverse, rplaca, rplacd, sec, second, set_special, setf_documentation, setf_gethash, setf_symbol_function, setf_symbol_plist, setf_symbol_value, setLisp, setPackage, setq, seventh, showStackTrace, sin, sixth, specialP, sqrt, string, stringCapitalize, stringDowncase, stringEndsWith, stringEq, stringEqual, stringGreaterP, stringGreaterThan, stringGreaterThanOrEqual, stringLeftTrim, stringLeftTrim, stringLessP, stringLessThan, stringLessThanOrEqual, stringNeq, stringNotGreaterP, stringNotLessP, stringp, stringRightTrim, stringRightTrim, stringStartsWith, stringTrim, stringTrim, stringUpcase, subst, substring, substring, subtract, symbol_function, symbol_name, symbol_package, symbol_plist, symbol_value, symbolp, tan, tenth, third, toCollection, toJava, toJava, toString, toStringAsCdr_internal, toStringAsCdr, toStringShort, toStringShort, toStringSimple, type_of, typep, uses, zerop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ApplyPrimitive

public ApplyPrimitive(Jatha lisp)
Method Detail

Execute

public void Execute(SECDMachine machine)
             throws CompilerException
Description copied from class: LispPrimitive
Execute performs the operation using the abstract machine registers. Arguments are found on the S register stack, in reverse order. UNLIMITED argument lists are collected into a list which is the top element on the stack. The implementation should pop an appropriate number of arguments from the stack, perform a computation, then push a result back on the S stack. The instruction should then be popped from the C (code) register. A LispValueFactory objects is available in the static variable LispValueFactory. Example implementations:
   FIRST
   class FirstPrimitive extends LispPrimitive
   {
     public First()
     {
       super("FIRST", 1);   // 1 argument
     }

     public void Execute(SECDMachine machine)
     {
       LispValue arg = machine.S.pop();

       machine.S.push(my_first(arg));
       machine.C.pop();
     }
   }
 
A multi-argument function must pop the arguments in reverse order.
     public void Execute(SECDMachine machine)
     {
       LispValue arg2 = machine.S.pop();
       LispValue arg1 = machine.S.pop();

       machine.S.push(my_new_function(arg1, arg2));
       machine.C.pop();
     }
   }
 
To register the new primitive, call:
    Jatha.COMPILER.Register(new FirstPrimitive());
 

Specified by:
Execute in class LispPrimitive
Parameters:
machine - The abstract machine instance.
Throws:
CompilerException
See Also:
LispCompiler

CompileArgs

public LispValue CompileArgs(LispCompiler compiler,
                             SECDMachine machine,
                             LispValue args,
                             LispValue valueList,
                             LispValue code)
                      throws CompilerException
Description copied from class: LispPrimitive
The CompileArgs method turns the arguments of the function call into SECD abstract machine code. Most functions won't need to override the default code generation, but ones that do funny things with argument lists will need to.

Overrides:
CompileArgs in class LispPrimitive
Returns:
LispValue The code generated and cons'ed onto the front of the incoming code.
Throws:
CompilerException
See Also:
LispCompiler

constructArgList

LispValue constructArgList(LispValue args)

validArgumentList

public boolean validArgumentList(LispValue args)
Description copied from class: LispPrimitive
This method returns true if the list of arguments satisfies the length and format restrictions posed by the function, and false otherwise. It calls validArgumentLength, so the programmer doesn't need to call it.

This method is called by the compiler.

Overrides:
validArgumentList in class LispPrimitive
Parameters:
args - the list of arguments.
Returns:
boolean
See Also:
LispPrimitive, LispCompiler

Jatha Software