30 typedef signed char s8
;
31 typedef signed short s16
;
32 typedef signed int s32
;
33 typedef signed long s64
;
34 typedef signed long long s128
;
36 typedef unsigned char u8
;
37 typedef unsigned short u16
;
38 typedef unsigned int u32
;
39 typedef unsigned long u64
;
40 typedef unsigned long long u128
;
46 typedef u32 FixnumType
;
47 typedef f32 FloatnumType
;
52 // smart pointer for pointing at lisp objects
53 template <typename T
> class ObjPtr
56 typedef T
* ActualPtrType
;
57 explicit ObjPtr( T
* o
) : p_(o
) {};
58 // ~ObjPtr( ) { delete p_; }
59 T
* operator->() { return get(); };
60 T
& operator*() { return *get(); };
69 explicit ObjPtr( void* o
) : p_(static_cast<T
*>(o
)) {};
76 void set(const void *p
)
78 p_
= reinterpret_cast<T
*>(p
);
83 template <typename ActualT
, typename CharT
, typename FixnumT
, typename FloatnumT
, typename PrimType
, typename PtrType
>
84 friend class TLispValue
;
87 // this is what we use to point at a lisp object
88 typedef ObjPtr
<LispObj
> PointerType
;
91 // straight primitive call with no environment / args
92 template <typename ArgPointer
, template <typename
> class ArgContainer
>
96 // err..what does a smart pointer to a pointer look like?
97 typedef PointerType (*PrimitivePtr
)(ArgContainer
<ArgPointer
>& args
);
99 explicit PrimitiveT(PrimitivePtr f
) : fn_(f
) {}
100 PointerType
operator()(ArgContainer
<ArgPointer
>& p
)
108 typedef PrimitiveT
< ObjPtr
<LispObj
>, std::vector
> PrimitiveType
;
112 // Primitive unboxed values (this must be POD)
113 template <typename ActualT
, typename CharT
, typename FixnumT
, typename FloatnumT
, typename PrimT
, typename PtrT
> class TLispValue
122 // need to be ablue to convert between ActualType and these types
123 operator PtrT() const
125 // convert it to a void * and construct a PtrT() around it
126 return PtrT(reinterpret_cast<void*>(value
));
130 // we can't overload by return type, so we use value conversion instead
131 operator FixnumT() const
136 operator FloatnumT() const
138 return *(static_cast<FloatnumT
*>(&value
));
141 operator CharT() const
143 return *(static_cast<CharT
*>(&value
));
146 operator PrimT() const
148 return *(static_cast<PrimT
*>(&value
));
151 TLispValue(const PtrT
& ptr
)
153 value
= reinterpret_cast<ActualT
>(reinterpret_cast<void*>(ptr
.get()));
156 TLispValue
& operator=(const PtrT
& ptr
)
158 value
= reinterpret_cast<ActualT
>(reinterpret_cast<void*>(ptr
.get()));
162 TLispValue(const FixnumT
& fn
)
167 TLispValue
& operator=(const FixnumT
& fn
)
173 TLispValue(const FloatnumT
& fn
)
175 (*static_cast<FloatnumT
*>(&value
)) = fn
;
178 TLispValue
& set(const FloatnumT
& fn
)
180 (*static_cast<FloatnumT
*>(&value
)) = fn
;
184 TLispValue(const CharT
& ch
)
186 (*static_cast<FloatnumT
*>(&value
)) = ch
;
189 TLispValue
& operator=(const CharT
& ch
)
191 (*static_cast<CharT
*>(&value
)) = ch
;
195 TLispValue(const PrimT
& prim
)
197 (*static_cast<FloatnumT
*>(&value
)) = prim
;
200 TLispValue
& operator=(const PrimT
& prim
)
202 (*static_cast<PrimT
*>(&value
)) = prim
;
209 // tag types (this doesn't have to be POD, but its advisable)
210 template <typename T
> class Tag
216 void setType(eObjectType tag
)
218 tagValue
= static_cast<eObjectType
>(tagValue
);
221 eObjectType
getType()
223 static_cast<eObjectType
>(tagValue
);
227 typedef Tag
<u8
> LispTag
;
228 typedef TLispValue
<u128
, CharType
, FixnumType
, FloatnumType
, PrimitiveType
, PointerType
> LispValue
;
231 // container of object data with a tag
232 template <typename T
, typename D
, template <typename
> class C
>
239 typedef C
<D
> ValueContainerType
;
242 ValueContainerType values
;
244 // T needs to implement sthing which will transform a tag to a
246 eObjectType
getType()
248 return tag
.getType(tag
);
251 void setType(eObjectType type
)
253 return tag
.setType(type
);
256 // container must have capacity
257 void resize(std::size_t s
)
263 // must be able to tell what that capacity is
264 std::size_t size() const
266 return values
.size();
271 // TO DO -- template template parameters?
274 TaggedObjData
<Tag
<unsigned char>, LispValue
, std::vector
> object
;
282 } // end namespace lisp