e364ec21c5d53246947b9b5919cf85f29196c932
[sbcl.git] / src / runtime / funcall.c
1 /* funcall0 -- funcall3: we can get by with just two sets of these:
2  * for platforms where the control stack is the C-stack, and all others.
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
9  * This software is derived from the CMU CL system, which was
10  * written at Carnegie Mellon University and released into the
11  * public domain. The software is in the public domain and is
12  * provided with absolutely no warranty. See the COPYING and CREDITS
13  * files for more information.
14  */
15
16 #include <stdio.h>
17
18 #include "sbcl.h"
19 #include "runtime.h"
20 #include "globals.h"
21
22 /* This is implemented in assembly language and called from C: */
23 extern lispobj call_into_lisp(lispobj fun, lispobj *args, int nargs);
24
25 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
26 /* These functions are an interface to the Lisp call-in facility.
27  * Since this is C we can know nothing about the calling environment.
28  * The control stack might be the C stack if called from the monitor
29  * or the Lisp stack if called as a result of an interrupt or maybe
30  * even a separate stack. The args are most likely on that stack but
31  * could be in registers depending on what the compiler likes. So we
32  * copy the args into a portable vector and let the assembly language
33  * call-in function figure it out. */
34
35 lispobj
36 funcall0(lispobj function)
37 {
38     lispobj *args = NULL;
39
40     FSHOW((stderr, "/entering funcall0(0x%lx)\n", (long)function));
41     return call_into_lisp(function, args, 0);
42 }
43 lispobj
44 funcall1(lispobj function, lispobj arg0)
45 {
46     lispobj args[1];
47     args[0] = arg0;
48     return call_into_lisp(function, args, 1);
49 }
50
51 lispobj
52 funcall2(lispobj function, lispobj arg0, lispobj arg1)
53 {
54     lispobj args[2];
55     args[0] = arg0;
56     args[1] = arg1;
57     return call_into_lisp(function, args, 2);
58 }
59
60 lispobj
61 funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
62 {
63     lispobj args[3];
64     args[0] = arg0;
65     args[1] = arg1;
66     args[2] = arg2;
67     return call_into_lisp(function, args, 3);
68 }
69
70 #else
71
72 lispobj
73 funcall0(lispobj function)
74 {
75     lispobj *args = current_control_stack_pointer;
76
77     return call_into_lisp(function, args, 0);
78 }
79
80 lispobj
81 funcall1(lispobj function, lispobj arg0)
82 {
83     lispobj *args = current_control_stack_pointer;
84
85     current_control_stack_pointer += 1;
86     args[0] = arg0;
87
88     return call_into_lisp(function, args, 1);
89 }
90
91 lispobj
92 funcall2(lispobj function, lispobj arg0, lispobj arg1)
93 {
94     lispobj *args = current_control_stack_pointer;
95
96     current_control_stack_pointer += 2;
97     args[0] = arg0;
98     args[1] = arg1;
99
100     return call_into_lisp(function, args, 2);
101 }
102
103 lispobj
104 funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
105 {
106     lispobj *args = current_control_stack_pointer;
107
108     current_control_stack_pointer += 3;
109     args[0] = arg0;
110     args[1] = arg1;
111     args[2] = arg2;
112
113     return call_into_lisp(function, args, 3);
114 }
115 #endif