Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 85 lines (68 sloc) 1.661 kb
7f48eb2b » Slava Pestov
2009-05-04 Use C++ namespaces
1 namespace factor
2 {
3
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
4 template<typename Type> cell tag(Type *value)
88c43ee0 » Slava Pestov
2009-05-02 Clean up VM's array code
5 {
d65296b3 » Slava Pestov
2009-11-02 vm: 4 bit tags, new representation of alien objects makes unbox-any-c…
6 return RETAG(value,Type::type_number);
1857f90e » Slava Pestov
2009-05-04 VM: use better abstractions for tagged pointers, eliminate get()/set(…
7 }
8
7c0a59f7 » Slava Pestov
2009-05-04 The great type renaming
9 inline static cell tag_dynamic(object *value)
1857f90e » Slava Pestov
2009-05-04 VM: use better abstractions for tagged pointers, eliminate get()/set(…
10 {
4168ffbc » Slava Pestov
2009-11-10 New identity-hashcode primitive
11 return RETAG(value,value->type());
88c43ee0 » Slava Pestov
2009-05-02 Clean up VM's array code
12 }
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
13
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
14 template<typename Type>
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
15 struct tagged
16 {
17 cell value_;
18
b3415274 » Slava Pestov
2009-11-02 vm: rename gc_root to data_root, add code_root to fix a problem where…
19 cell type() const
20 {
d65296b3 » Slava Pestov
2009-11-02 vm: 4 bit tags, new representation of alien objects makes unbox-any-c…
21 return TAG(value_);
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
22 }
23
f9fc3487 » Slava Pestov
2009-10-20 vm: change code heap layout somewhat, remove unused allocation bitmap…
24 bool type_p(cell type_) const
25 {
26 return type() == type_;
27 }
28
29 bool type_p() const
30 {
31 if(Type::type_number == TYPE_COUNT)
32 return true;
33 else
34 return type_p(Type::type_number);
35 }
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
36
b3415274 » Slava Pestov
2009-11-02 vm: rename gc_root to data_root, add code_root to fix a problem where…
37 cell value() const
38 {
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
39 #ifdef FACTOR_DEBUG
00f00663 » jckarter
2011-11-17 vm: replace assert with FACTOR_ASSERT
40 FACTOR_ASSERT(type_p());
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
41 #endif
9cfe50f3 » Slava Pestov
2009-10-25 vm: tagged typechecks work better with DEBUG=1
42 return value_;
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
43 }
b3415274 » Slava Pestov
2009-11-02 vm: rename gc_root to data_root, add code_root to fix a problem where…
44
45 Type *untagged() const
46 {
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
47 #ifdef FACTOR_DEBUG
00f00663 » jckarter
2011-11-17 vm: replace assert with FACTOR_ASSERT
48 FACTOR_ASSERT(type_p());
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
49 #endif
9cfe50f3 » Slava Pestov
2009-10-25 vm: tagged typechecks work better with DEBUG=1
50 return (Type *)(UNTAG(value_));
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
51 }
52
b3415274 » Slava Pestov
2009-11-02 vm: rename gc_root to data_root, add code_root to fix a problem where…
53 Type *untag_check(factor_vm *parent) const
54 {
9cfe50f3 » Slava Pestov
2009-10-25 vm: tagged typechecks work better with DEBUG=1
55 if(!type_p())
56 parent->type_error(Type::type_number,value_);
57 return untagged();
58 }
59
60 explicit tagged(cell tagged) : value_(tagged) {}
61 explicit tagged(Type *untagged) : value_(factor::tag(untagged)) {}
62
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
63 Type *operator->() const { return untagged(); }
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
64 cell *operator&() const { return &value_; }
65
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
66 const tagged<Type> &operator=(const Type *x) { value_ = tag(x); return *this; }
67 const tagged<Type> &operator=(const cell &x) { value_ = x; return *this; }
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
68
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
69 bool operator==(const tagged<Type> &x) { return value_ == x.value_; }
70 bool operator!=(const tagged<Type> &x) { return value_ != x.value_; }
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
71
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
72 template<typename NewType> tagged<NewType> as() { return tagged<NewType>(value_); }
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
73 };
74
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
75 template<typename Type> Type *factor_vm::untag_check(cell value)
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
76 {
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
77 return tagged<Type>(value).untag_check(this);
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
78 }
79
6ee56ca9 » Slava Pestov
2009-10-21 vm: use iostreams instead of printf for debug messages, clean up a fe…
80 template<typename Type> Type *untag(cell value)
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
81 {
38872925 » Slava Pestov
2009-10-03 Big VM cleanup
82 return tagged<Type>(value).untagged();
967bfa63 » Phil Dawes
2009-08-17 moved tagged template code back into tagged.hpp header
83 }
84
7f48eb2b » Slava Pestov
2009-05-04 Use C++ namespaces
85 }
Something went wrong with that request. Please try again.