88 inline Atom Atom::Float(float32 f) {
91 uint32 a = *
reinterpret_cast<uint32 *
>(&_f);
95 inline Atom Atom::PlusInfinity() {
97 return Atom(0x3FC00000);
100 inline Atom Atom::MinusInfinity() {
102 return Atom(0x7FC00000);
105 inline Atom Atom::UndefinedFloat() {
107 return Atom(0xFFFFFFF);
110 inline Atom Atom::Nil() {
112 return Atom((uint32)(NIL << 24));
115 inline Atom Atom::Boolean(
bool value) {
117 return Atom((BOOLEAN_ << 24) + value);
120 inline Atom Atom::UndefinedBoolean() {
122 return Atom(0x81FFFFFF);
125 inline Atom Atom::Wildcard(uint16 opcode) {
127 return Atom((WILDCARD << 24) + ((opcode & 0x0FFF) << 8));
130 inline Atom Atom::TailWildcard() {
132 return Atom((uint32)(T_WILDCARD << 24));
135 inline Atom Atom::IPointer(uint16 index) {
137 return Atom((I_PTR << 24) + (index & 0x0FFF));
140 inline Atom Atom::VLPointer(uint16 index) {
142 return Atom((VL_PTR << 24) + (index & 0x0FFF));
145 inline Atom Atom::RPointer(uint16 index) {
147 return Atom((R_PTR << 24) + (index & 0x0FFF));
150 inline Atom Atom::IPGMPointer(uint16 index) {
152 return Atom((IPGM_PTR << 24) + (index & 0x0FFF));
155 inline Atom Atom::InObjPointer(uint8 input_index, uint16 index) {
157 return Atom((IN_OBJ_PTR << 24) + (input_index << 12) + (index & 0x0FFF));
160 inline Atom Atom::DInObjPointer(uint8 relative_index, uint16 index) {
162 return Atom((D_IN_OBJ_PTR << 24) + (relative_index << 12) + (index & 0x0FFF));
165 inline Atom Atom::OutObjPointer(uint16 index) {
167 return Atom((OUT_OBJ_PTR << 24) + (index & 0x0FFF));
170 inline Atom Atom::ValuePointer(uint16 index) {
172 return Atom((VALUE_PTR << 24) + (index & 0x0FFF));
175 inline Atom Atom::ProductionPointer(uint16 index) {
177 return Atom((PROD_PTR << 24) + (index & 0x0FFF));
180 inline Atom Atom::AssignmentPointer(uint8 variable_index, uint16 index) {
182 return Atom((ASSIGN_PTR << 24) + (variable_index << 16) + (index & 0x0FFF));
185 inline Atom Atom::CodeVLPointer(uint16 index, uint16 cast_opcode) {
187 return Atom((CODE_VL_PTR << 24) + ((cast_opcode & 0x0FFF) << 12) + (index & 0x0FFF));
190 inline Atom Atom::This() {
192 return Atom((uint32)(THIS << 24));
195 inline Atom Atom::View() {
197 return Atom((uint32)(VIEW << 24));
200 inline Atom Atom::Mks() {
202 return Atom((uint32)(MKS << 24));
205 inline Atom Atom::Vws() {
207 return Atom((uint32)(VWS << 24));
210 inline Atom Atom::SSet(uint16 opcode, uint8 element_count) {
212 return Atom((S_SET << 24) + ((opcode & 0x0FFF) << 8) + element_count);
215 inline Atom Atom::Set(uint8 element_count) {
217 return Atom((SET << 24) + element_count);
220 inline Atom Atom::CPointer(uint8 element_count) {
222 return Atom((C_PTR << 24) + element_count);
225 inline Atom Atom::Object(uint16 opcode, uint8 arity) {
227 return Atom((OBJECT << 24) + ((opcode & 0x0FFF) << 8) + arity);
230 inline Atom Atom::Marker(uint16 opcode, uint8 arity) {
232 return Atom((MARKER << 24) + ((opcode & 0x0FFF) << 8) + arity);
235 inline Atom Atom::Operator(uint16 opcode, uint8 arity) {
237 return Atom((OPERATOR << 24) + ((opcode & 0x0FFF) << 8) + arity);
240 inline Atom Atom::Node(uint8 node_id) {
242 return Atom((NODE << 24) + (node_id << 8));
245 inline Atom Atom::UndefinedNode() {
247 return Atom(0xA0FFFFFF);
250 inline Atom Atom::Device(uint8 node_id, uint8 class_id, uint8 dev_id) {
252 return Atom((DEVICE << 24) + (node_id << 16) + (class_id << 8) + dev_id);
255 inline Atom Atom::UndefinedDevice() {
257 return Atom(0xA1FFFFFF);
260 inline Atom Atom::DeviceFunction(uint16 opcode) {
262 return Atom((DEVICE_FUNCTION << 24) + (opcode << 8));
265 inline Atom Atom::UndefinedDeviceFunction() {
267 return Atom(0xA2FFFFFF);
270 inline Atom Atom::String(uint8 character_count) {
272 uint8 blocks = character_count / 4;
273 if (character_count % 4)
275 return Atom((STRING << 24) + (blocks << 8) + character_count);
278 inline Atom Atom::UndefinedString() {
280 return Atom(0xC6FFFFFF);
283 inline Atom Atom::Timestamp() {
285 return Atom((uint32)(TIMESTAMP << 24));
288 inline Atom Atom::UndefinedTimestamp() {
290 return Atom(0xC7FFFFFF);
293 inline Atom Atom::Duration() {
294 return Atom((uint32)(DURATION << 24));
297 inline Atom Atom::InstantiatedProgram(uint16 opcode, uint8 arity) {
299 return Atom((INSTANTIATED_PROGRAM << 24) + ((opcode & 0x0FFF) << 8) + arity);
302 inline Atom Atom::Group(uint16 opcode, uint8 arity) {
304 return Atom((GROUP << 24) + ((opcode & 0x0FFF) << 8) + arity);
307 inline Atom Atom::InstantiatedCPPProgram(uint16 opcode, uint8 arity) {
309 return Atom((INSTANTIATED_CPP_PROGRAM << 24) + ((opcode & 0x0FFF) << 8) + arity);
312 inline Atom Atom::InstantiatedAntiProgram(uint16 opcode, uint8 arity) {
314 return Atom((INSTANTIATED_ANTI_PROGRAM << 24) + ((opcode & 0x0FFF) << 8) + arity);
317 inline Atom Atom::InstantiatedInputLessProgram(uint16 opcode, uint8 arity) {
319 return Atom((INSTANTIATED_INPUT_LESS_PROGRAM << 24) + ((opcode & 0x0FFF) << 8) + arity);
322 inline Atom Atom::CompositeState(uint16 opcode, uint8 arity) {
324 return Atom((COMPOSITE_STATE << 24) + ((opcode & 0x0FFF) << 8) + arity);
327 inline Atom Atom::Model(uint16 opcode, uint8 arity) {
329 return Atom((MODEL << 24) + ((opcode & 0x0FFF) << 8) + arity);
332 inline Atom Atom::NullProgram(
bool take_past_inputs) {
334 return Atom((NULL_PROGRAM << 24) + (take_past_inputs ? 1 : 0));
340 inline Atom Atom::RawPointer(
void *pointer) {
342 return Atom((uint32)pointer);
346 inline Atom::Atom(uint32 a) : atom_(a) {
349 inline Atom::~Atom() {
352 inline Atom &Atom::operator =(
const Atom& a) {
358 inline bool Atom::operator ==(
const Atom& a)
const {
360 return atom_ == a.atom_;
363 inline bool Atom::operator !=(
const Atom& a)
const {
365 return atom_ != a.atom_;
368 inline bool Atom::operator !()
const {
370 return isUndefined();
373 inline Atom::operator size_t ()
const {
375 return (
size_t)atom_;
378 inline bool Atom::isUndefined()
const {
380 return atom_ == 0xFFFFFFFF;
383 inline uint8 Atom::getDescriptor()
const {
388 inline bool Atom::isStructural()
const {
390 return ((atom_ & 0xC0000000) == 0xC0000000 || (atom_ & 0xD0000000) == 0xD0000000);
393 inline bool Atom::isFloat()
const {
395 return atom_ >> 31 == 0;
398 inline bool Atom::readsAsNil()
const {
400 return atom_ == 0x80000000 ||
401 atom_ == 0x3FFFFFFF ||
402 atom_ == 0x81FFFFFF ||
403 atom_ == 0xC1000000 ||
404 atom_ == 0xA0FFFFFF ||
405 atom_ == 0xA1FFFFFF ||
406 atom_ == 0xA2FFFFFF ||
410 inline float32 Atom::asFloat()
const {
412 uint32 _f = atom_ << 1;
413 return *
reinterpret_cast<const float32 *
>(&_f);
416 inline bool Atom::asBoolean()
const {
418 return atom_ & 0x000000FF;
421 inline bool Atom::isBooleanTrue()
const {
return getDescriptor() == BOOLEAN_ && asBoolean(); }
423 inline bool Atom::isBooleanFalse()
const {
return getDescriptor() == BOOLEAN_ && !asBoolean(); }
425 inline uint16 Atom::asIndex()
const {
427 return atom_ & 0x00000FFF;
430 inline uint8 Atom::asInputIndex()
const {
432 return (uint8)((atom_ & 0x000FF000) >> 12);
435 inline uint8 Atom::asRelativeIndex()
const {
437 return (uint8)((atom_ & 0x000FF000) >> 12);
440 inline uint16 Atom::asOpcode()
const {
442 return (atom_ >> 8) & 0x00000FFF;
445 inline uint16 Atom::asCastOpcode()
const {
447 return (uint16)((atom_ & 0x00FFF000) >> 12);
450 inline uint8 Atom::getNodeID()
const {
452 return (uint8)((atom_ & 0x00FF0000) >> 16);
455 inline uint8 Atom::getClassID()
const {
457 return (uint8)((atom_ & 0x0000FF00) >> 8);
460 inline uint8 Atom::getDeviceID()
const {
462 return (uint8)(atom_ & 0x000000FF);
465 inline uint8 Atom::asAssignmentIndex()
const {
467 return (uint8)((atom_ & 0x00FF0000) >> 16);
470 inline uint8 Atom::getAtomCount()
const {
472 switch (getDescriptor()) {
478 case INSTANTIATED_PROGRAM:
479 case INSTANTIATED_CPP_PROGRAM:
480 case INSTANTIATED_INPUT_LESS_PROGRAM:
481 case INSTANTIATED_ANTI_PROGRAM:
482 case COMPOSITE_STATE:
485 case S_SET:
return atom_ & 0x000000FF;
486 case STRING:
return (atom_ & 0x0000FF00) >> 8;
487 case TIMESTAMP:
return 2;
488 case DURATION:
return 2;
494 inline bool Atom::takesPastInputs()
const {
496 return atom_ & 0x00000001;