home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / gcl-1.000 / gcl-1 / gcl-1.0 / c / reference.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  4.1 KB  |  198 lines

  1. /*
  2.  Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
  3.  
  4. This file is part of GNU Common Lisp, herein referred to as GCL
  5.  
  6. GCL is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GCL is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
  14. License for more details.
  15.  
  16. You should have received a copy of the GNU Library General Public License 
  17. along with GCL; see the file COPYING.  If not, write to the Free Software
  18. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. */
  21.  
  22. /*
  23.  
  24.     reference.c
  25.  
  26.     Reference in Constants and Variables
  27. */
  28.  
  29. #include "include.h"
  30.  
  31. Lfboundp()
  32. {
  33.     object sym;
  34.  
  35.     check_arg(1);
  36.     sym = vs_base[0];
  37.     if (type_of(sym) != t_symbol)
  38.         not_a_symbol(sym);
  39.     if (sym->s.s_sfdef != NOT_SPECIAL)
  40.         vs_base[0] = Ct;
  41.     else if (sym->s.s_gfdef == OBJNULL)
  42.         vs_base[0]= Cnil;
  43.     else
  44.         vs_base[0]= Ct;
  45. }
  46.  
  47. object
  48. symbol_function(sym)
  49. object sym;
  50. {
  51. /*
  52.     if (type_of(sym) != t_symbol)
  53.         not_a_symbol(sym);
  54. */
  55.     if (sym->s.s_sfdef != NOT_SPECIAL || sym->s.s_mflag)
  56.         FEinvalid_function(sym);
  57.     if (sym->s.s_gfdef == OBJNULL)
  58.         FEundefined_function(sym);
  59.     return(sym->s.s_gfdef);
  60. }
  61.  
  62. /*
  63.     Symbol-function returns
  64.                 function-closure        for function
  65.         (macro . function-closure)    for macros
  66.         (special . address)        for special forms.
  67. */
  68. Lsymbol_function()
  69. {
  70.     object sym;
  71.  
  72.     check_arg(1);
  73.     sym = vs_base[0];
  74.     if (type_of(sym) != t_symbol)
  75.         not_a_symbol(sym);
  76.     if (sym->s.s_sfdef != NOT_SPECIAL) {
  77.         vs_push(make_fixnum((int)(sym->s.s_sfdef)));
  78.         vs_base[0] = Sspecial;
  79.         stack_cons();
  80.         return;
  81.     }
  82.     if (sym->s.s_gfdef==OBJNULL)
  83.         FEundefined_function(sym);
  84.     if (sym->s.s_mflag) {
  85.         vs_push(sym->s.s_gfdef);
  86.         vs_base[0] = Smacro;
  87.         stack_cons();
  88.         return;
  89.     }
  90.     vs_base[0] = sym->s.s_gfdef;
  91. }
  92.  
  93. Fquote(form)
  94. object form;
  95. {
  96.     if (endp(form))
  97.         FEtoo_few_argumentsF(form);
  98.     if (!endp(MMcdr(form)))
  99.         FEtoo_many_argumentsF(form);
  100.     vs_base = vs_top;
  101.     vs_push(MMcar(form));
  102. }
  103.  
  104. Ffunction(form)
  105. object form;
  106. {
  107.     object fun;
  108.     object fd;
  109.     if (endp(form))
  110.         FEtoo_few_argumentsF(form);
  111.     if (!endp(MMcdr(form)))
  112.         FEtoo_many_argumentsF(form);
  113.     fun = MMcar(form);
  114.     if (type_of(fun) == t_symbol) {
  115.         fd = lex_fd_sch(fun);
  116.         if (MMnull(fd) || MMcadr(fd) != Sfunction)
  117.             if (fun->s.s_gfdef == OBJNULL || fun->s.s_mflag)
  118.                 FEundefined_function(fun);
  119.             else {
  120.                 vs_base = vs_top;
  121.                 vs_push(fun->s.s_gfdef);
  122.             }
  123.         else {
  124.             vs_base = vs_top;
  125.             vs_push(MMcaddr(fd));
  126.         }
  127.     } else if (type_of(fun) == t_cons && MMcar(fun) == Slambda) {
  128.         vs_base = vs_top;
  129.         vs_push(MMcdr(fun));
  130.         vs_base[0] = MMcons(lex_env[2], vs_base[0]);
  131.         vs_base[0] = MMcons(lex_env[1], vs_base[0]);
  132.         vs_base[0] = MMcons(lex_env[0], vs_base[0]);
  133.         vs_base[0] = MMcons(Slambda_closure, vs_base[0]);
  134.     } else
  135.         FEinvalid_function(fun);
  136. }
  137.  
  138. Lsymbol_value()
  139. {
  140.     object sym;
  141.     check_arg(1);
  142.     sym = vs_base[0];
  143.     if (type_of(sym) != t_symbol)
  144.         not_a_symbol(sym);
  145.     if (sym->s.s_dbind == OBJNULL)
  146.         FEunbound_variable(sym);
  147.     else
  148.         vs_base[0] = sym->s.s_dbind;
  149. }
  150.  
  151. Lboundp()
  152. {
  153.     object sym;
  154.     check_arg(1);
  155.     sym=vs_base[0];
  156.     if (type_of(sym) != t_symbol)
  157.         not_a_symbol(sym);
  158.     if (sym->s.s_dbind == OBJNULL)
  159.         vs_base[0] = Cnil;
  160.     else
  161.         vs_base[0] = Ct;
  162. }
  163.  
  164. Lmacro_function()
  165. {
  166.     check_arg(1);
  167.     if (type_of(vs_base[0]) != t_symbol)
  168.         not_a_symbol(vs_base[0]);
  169.     if (vs_base[0]->s.s_gfdef != OBJNULL && vs_base[0]->s.s_mflag)
  170.         vs_base[0] = vs_base[0]->s.s_gfdef;
  171.     else
  172.         vs_base[0] = Cnil;
  173. }
  174.  
  175. Lspecial_form_p()
  176. {
  177.     check_arg(1);
  178.     if (type_of(vs_base[0]) != t_symbol)
  179.         not_a_symbol(vs_base[0]);
  180.     if (vs_base[0]->s.s_sfdef != NOT_SPECIAL)
  181.         vs_base[0] = Ct;
  182.     else
  183.         vs_base[0] = Cnil;
  184. }
  185.  
  186. init_reference()
  187. {
  188.     make_function("SYMBOL-FUNCTION", Lsymbol_function);
  189.     make_function("FBOUNDP", Lfboundp);
  190.     make_special_form("QUOTE", Fquote);
  191.     Sfunction = make_special_form("FUNCTION", Ffunction);
  192.     make_function("SYMBOL-VALUE", Lsymbol_value);
  193.     make_function("BOUNDP", Lboundp);
  194.     make_function("MACRO-FUNCTION", Lmacro_function);
  195.     make_function("SPECIAL-FORM-P", Lspecial_form_p);
  196. }
  197.  
  198.