1 /* platform.h                                     -*- mode:c; coding:utf-8; -*-
2  *
3  *   Copyright (c) 2010-2021  Takashi Kato <ktakashi@ymail.com>
4  *
5  *   Redistribution and use in source and binary forms, with or without
6  *   modification, are permitted provided that the following conditions
7  *   are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright
10  *      notice, this list of conditions and the following disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above copyright
13  *      notice, this list of conditions and the following disclaimer in the
14  *      documentation and/or other materials provided with the distribution.
15  *
16  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef SAGITTARIUS_PLATFORM_H_
29 #define SAGITTARIUS_PLATFORM_H_
30 
31 /* Platform specific C macro */
32 /*
33   Macro Definitions and typedefs
34  */
35 #if defined(__MINGW32__) || defined(_MSC_VER) || defined(_SG_WIN_SUPPORT)
36 #define SAGITTARIUS_WINDOWS 1
37 #endif
38 
39 #undef SG_EXTERN
40 #if defined(__CYGWIN__) || defined(SAGITTARIUS_WINDOWS)
41 # if defined(LIBSAGITTARIUS_BODY)
42 #  define SG_EXPORT __declspec(dllexport)
43 # else
44 #  define SG_EXPORT __declspec(dllimport)
45 # endif
46 # define SG_EXTERN extern SG_EXPORT
47 #else
48 # define SG_EXPORT
49 # define SG_EXTERN extern
50 #endif
51 
52 #ifdef __cplusplus
53 # define __STDC_LIMIT_MACROS
54 # define SG_CDECL_BEGIN extern "C" {
55 # define SG_CDECL_END }
56 #else
57 # define SG_CDECL_BEGIN
58 # define SG_CDECL_END
59 #endif
60 
61 #include <stdint.h>
62 
63 /* Types */
64 typedef unsigned char SgByte;
65 typedef int32_t       SgChar;	/** UCS32 character */
66 typedef void*         SgObject;	/** Generic object */
67 
68 SG_CDECL_BEGIN
69 
70 /* Boolean */
71 /**
72    Make boolean object.
73 
74    @param value to be boolean. 0 = #f, otherwise #t
75    @return boolean object
76  */
77 SG_EXTERN SgObject Sg_MakeBoolean(int value);
78 /**
79    Check if the given object is boolean object.
80 
81    @param obj an object
82    @return 1 obj is a boolean, 0 obj is not a boolean
83  */
84 SG_EXTERN int      Sg_IsBoolean(SgObject obj);
85 /**
86    Returns boolean value.
87    This function handles object like in Scheme world.
88    This means as long as an object is not #f, then it's
89    a true value.
90    @param obj an object
91    @return 0 obj is #f, 1 obj is not #f
92  */
93 SG_EXTERN int      Sg_BooleanValue(SgObject obj);
94 /**
95    Returns #f object
96    @return #f scheme object
97  */
98 SG_EXTERN SgObject Sg_False();
99 /**
100    Check is the given object is #f.
101    @param obj an object
102    @return 1 obj is #f, 0 obj is not #f
103  */
104 SG_EXTERN int      Sg_IsFalse(SgObject obj);
105 /**
106    Returns #t object
107    @return #t scheme object
108  */
109 SG_EXTERN SgObject Sg_True();
110 /**
111    Check is the given object is #t.
112    @param obj an object
113    @return 1 obj is #t, 0 obj is not #t
114  */
115 SG_EXTERN int      Sg_IsTrue(SgObject obj);
116 
117 /* char */
118 /**
119    Make a character object.
120 
121    @param c to be a character.
122    @return character object
123  */
124 SG_EXTERN SgObject Sg_MakeChar(SgChar c);
125 /**
126    Check is the given object is a char.
127    @param obj an object
128    @return 1 obj is a char, 0 obj is not a char
129  */
130 SG_EXTERN int      Sg_IsChar(SgObject c);
131 /**
132    Returns character value.
133    @param c a character
134    @return UCS32 character value
135  */
136 SG_EXTERN SgChar   Sg_CharValue(SgObject c);
137 
138 /* '() */
139 /**
140    Returns '() nil object
141    @return '() scheme object
142  */
143 SG_EXTERN SgObject Sg_Nil();
144 /**
145    Check is the given object is '().
146    @param obj an object
147    @return 1 obj is '(), 0 obj is not '()
148  */
149 SG_EXTERN int      Sg_IsNull(SgObject obj);
150 /* EOF */
151 /**
152    Returns EOF object
153    @return EOF scheme object
154  */
155 SG_EXTERN SgObject Sg_Eof();
156 /**
157    Check is the given object is EOF object.
158    @param obj an object
159    @return 1 obj is EOF object, 0 obj is not EOF object
160  */
161 SG_EXTERN int      Sg_IsEof(SgObject obj);
162 /* Undef */
163 /**
164    Returns undefined object
165    @return scheme undefined object
166  */
167 SG_EXTERN SgObject Sg_Undefined();
168 /**
169    Check is the given object is undefined object.
170    @param obj an object
171    @return 1 obj is undefined object, 0 obj is not undefined object
172  */
173 SG_EXTERN int      Sg_IsUndefined(SgObject obj);
174 
175 SG_CDECL_END
176 
177 #endif	/* SAGITTARIUS_PLATFORM_H_ */
178