1 /* Mocklisp compatibility functions for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1995 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* Compatibility for mocklisp */
28 /* Now in lisp code ("macrocode...")
29 * DEFUN ("ml-defun", Fml_defun, Sml_defun, 0, UNEVALLED, 0,
30 * "Define mocklisp functions")
36 * while (!NILP (args))
39 * Ffset (Fcar (elt), Fcons (Qmocklisp, Fcdr (elt)));
46 DEFUN ("ml-if", Fml_if
, Sml_if
, 0, UNEVALLED
, 0,
47 "Mocklisp version of `if'.\n\
48 usage: (ml-if COND THEN ELSE...)")
52 register Lisp_Object val
;
59 val
= Feval (Fcar (args
));
61 if (NILP (args
)) break;
64 val
= Feval (Fcar (args
));
73 #if 0 /* Now converted to regular "while" by hairier conversion code. */
74 /**/DEFUN ("ml-while", Fml_while
, Sml_while
, 1, UNEVALLED
, 0, "while for mocklisp programs")
78 Lisp_Object test
, body
, tem
;
79 struct gcpro gcpro1
, gcpro2
;
85 while (tem
= Feval (test
), XINT (tem
))
96 /* This is the main entry point to mocklisp execution.
97 When eval sees a mocklisp function being called, it calls here
98 with the unevaluated argument list */
101 ml_apply (function
, args
)
102 Lisp_Object function
, args
;
104 register int count
= specpdl_ptr
- specpdl
;
105 register Lisp_Object val
;
107 specbind (Qmocklisp_arguments
, args
);
108 val
= Fprogn (Fcdr (function
));
109 return unbind_to (count
, val
);
112 DEFUN ("ml-nargs", Fml_nargs
, Sml_nargs
, 0, 0, 0,
113 "Number of arguments to currently executing mocklisp function.")
116 if (EQ (Vmocklisp_arguments
, Qinteractive
))
117 return make_number (0);
118 return Flength (Vmocklisp_arguments
);
121 DEFUN ("ml-arg", Fml_arg
, Sml_arg
, 1, 2, 0,
122 "Argument number N to currently executing mocklisp function.")
124 Lisp_Object n
, prompt
;
126 if (EQ (Vmocklisp_arguments
, Qinteractive
))
127 return Fread_string (prompt
, Qnil
, Qnil
, Qnil
, Qnil
);
129 XSETINT (n
, XINT (n
) - 1); /* Mocklisp likes to be origin-1 */
130 return Fcar (Fnthcdr (n
, Vmocklisp_arguments
));
133 DEFUN ("ml-interactive", Fml_interactive
, Sml_interactive
, 0, 0, 0,
134 "True if currently executing mocklisp function was called interactively.")
137 return (EQ (Vmocklisp_arguments
, Qinteractive
)) ? Qt
: Qnil
;
140 DEFUN ("ml-provide-prefix-argument", Fml_provide_prefix_argument
, Sml_provide_prefix_argument
,
142 "Evaluate second argument, using first argument as prefix arg value.\n\
143 usage: (ml-provide-prefix-argument ARG1 ARG2)")
149 Vcurrent_prefix_arg
= Feval (Fcar (args
));
151 return Feval (Fcar (Fcdr (args
)));
154 DEFUN ("ml-prefix-argument-loop", Fml_prefix_argument_loop
, Sml_prefix_argument_loop
,
156 "usage: (ml-prefix-argument-loop ...)")
160 register Lisp_Object tem
;
164 /* Set `arg' in case we call a built-in function that looks at it. Still are a few. */
165 if (NILP (Vcurrent_prefix_arg
))
169 tem
= Vcurrent_prefix_arg
;
172 if (EQ (tem
, Qminus
))
184 #if 0 /* Now in mlsupport.el */
186 DEFUN ("ml-substr", Fml_substr
, Sml_substr
, 3, 3, 0,
187 "Return a substring of STRING, starting at index FROM and of length LENGTH.\n\
188 If either FROM or LENGTH is negative, the length of STRING is added to it.")
190 Lisp_Object string
, from
, to
;
192 CHECK_STRING (string
, 0);
193 CHECK_NUMBER (from
, 1);
194 CHECK_NUMBER (to
, 2);
197 XSETINT (from
, XINT (from
) + XSTRING (string
)->size
);
199 XSETINT (to
, XINT (to
) + XSTRING (string
)->size
);
200 XSETINT (to
, XINT (to
) + XINT (from
));
201 return Fsubstring (string
, from
, to
);
204 DEFUN ("insert-string", Finsert_string
, Sinsert_string
, 0, MANY
, 0,
205 "Mocklisp-compatibility insert function.\n\
206 Like the function `insert' except that any argument that is a number\n\
207 is converted into a string by expressing it in decimal.\n\
208 usage: (insert-string &rest ARGS)")
214 register Lisp_Object tem
;
216 for (argnum
= 0; argnum
< nargs
; argnum
++)
221 tem
= Fnumber_to_string (tem
);
226 tem
= wrong_type_argument (Qstringp
, tem
);
238 Qmocklisp
= intern ("mocklisp");
239 staticpro (&Qmocklisp
);
241 /*defsubr (&Sml_defun);*/
243 /*defsubr (&Sml_while);*/
245 defsubr (&Sml_nargs
);
246 defsubr (&Sml_interactive
);
247 defsubr (&Sml_provide_prefix_argument
);
248 defsubr (&Sml_prefix_argument_loop
);
249 /*defsubr (&Sml_substr);*/
250 defsubr (&Sinsert_string
);