815268ad33d9bce430c2e5f5eb2c2e76ff5b07e2
[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
21 /* This is implemented in assembly language and called from C: */
22 extern lispobj call_into_lisp(lispobj fun, lispobj *args, int nargs);
23
24 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
25 /* These functions are an interface to the Lisp call-in facility.
26  * Since this is C we can know nothing about the calling environment.
27  * The control stack might be the C stack if called from the monitor
28  * or the Lisp stack if called as a result of an interrupt or maybe
29  * even a separate stack. The args are most likely on that stack but
30  * could be in registers depending on what the compiler likes. So we
31  * copy the args into a portable vector and let the assembly language
32  * call-in function figure it out. */
33
34 lispobj
35 funcall0(lispobj function)
36 {
37     lispobj *args = NULL;
38
39     FSHOW((stderr, "/entering funcall0(0x%lx)\n", (long)function));
40     return call_into_lisp(function, args, 0);
41 }
42 lispobj
43 funcall1(lispobj function, lispobj arg0)
44 {
45     lispobj args[1];
46     args[0] = arg0;
47     return call_into_lisp(function, args, 1);
48 }
49
50 lispobj
51 funcall2(lispobj function, lispobj arg0, lispobj arg1)
52 {
53     lispobj args[2];
54     args[0] = arg0;
55     args[1] = arg1;
56     return call_into_lisp(function, args, 2);
57 }
58
59 lispobj
60 funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
61 {
62     lispobj args[3];
63     args[0] = arg0;
64     args[1] = arg1;
65     args[2] = arg2;
66     return call_into_lisp(function, args, 3);
67 }
68
69 #else
70
71 lispobj
72 funcall0(lispobj function)
73 {
74     lispobj *args = current_control_stack_pointer;
75
76     return call_into_lisp(function, args, 0);
77 }
78
79 lispobj
80 funcall1(lispobj function, lispobj arg0)
81 {
82     lispobj *args = current_control_stack_pointer;
83
84     current_control_stack_pointer += 1;
85     args[0] = arg0;
86
87     return call_into_lisp(function, args, 1);
88 }
89
90 lispobj
91 funcall2(lispobj function, lispobj arg0, lispobj arg1)
92 {
93     lispobj *args = current_control_stack_pointer;
94
95     current_control_stack_pointer += 2;
96     args[0] = arg0;
97     args[1] = arg1;
98
99     return call_into_lisp(function, args, 2);
100 }
101
102 lispobj
103 funcall3(lispobj function, lispobj arg0, lispobj arg1, lispobj arg2)
104 {
105     lispobj *args = current_control_stack_pointer;
106
107     current_control_stack_pointer += 3;
108     args[0] = arg0;
109     args[1] = arg1;
110     args[2] = arg2;
111
112     return call_into_lisp(function, args, 3);
113 }
114 #endif