1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef _MDB_
7 # include "mdb.h"
8 #endif
9
10 #ifndef _MORK_
11 # include "mork.h"
12 #endif
13
14 #ifndef _MORKNODE_
15 # include "morkNode.h"
16 #endif
17
18 #ifndef _MORKSTORE_
19 # include "morkStore.h"
20 #endif
21
22 #ifndef _MORKPOOL_
23 # include "morkPool.h"
24 #endif
25
26 #ifndef _MORKENV_
27 # include "morkEnv.h"
28 #endif
29
30 #ifndef _MORKCELL_
31 # include "morkCell.h"
32 #endif
33
34 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
35
SetYarn(morkEnv * ev,const mdbYarn * inYarn,morkStore * ioStore)36 void morkCell::SetYarn(morkEnv* ev, const mdbYarn* inYarn, morkStore* ioStore) {
37 morkAtom* atom = ioStore->YarnToAtom(ev, inYarn, true /* create */);
38 if (atom) this->SetAtom(ev, atom, ioStore->StorePool()); // refcounts atom
39 }
40
GetYarn(morkEnv * ev,mdbYarn * outYarn) const41 void morkCell::GetYarn(morkEnv* ev, mdbYarn* outYarn) const {
42 MORK_USED_1(ev);
43 morkAtom::GetYarn(mCell_Atom, outYarn);
44 }
45
AliasYarn(morkEnv * ev,mdbYarn * outYarn) const46 void morkCell::AliasYarn(morkEnv* ev, mdbYarn* outYarn) const {
47 MORK_USED_1(ev);
48 morkAtom::AliasYarn(mCell_Atom, outYarn);
49 }
50
SetCellClean()51 void morkCell::SetCellClean() {
52 mork_column col = this->GetColumn();
53 this->SetColumnAndChange(col, morkChange_kNil);
54 }
55
SetCellDirty()56 void morkCell::SetCellDirty() {
57 mork_column col = this->GetColumn();
58 this->SetColumnAndChange(col, morkChange_kAdd);
59 }
60
SetAtom(morkEnv * ev,morkAtom * ioAtom,morkPool * ioPool)61 void morkCell::SetAtom(morkEnv* ev, morkAtom* ioAtom, morkPool* ioPool)
62 // SetAtom() "acquires" the new ioAtom if non-nil, by calling AddCellUse()
63 // to increase the refcount, and puts ioAtom into mCell_Atom. If the old
64 // atom in mCell_Atom is non-nil, then it is "released" first by a call to
65 // CutCellUse(), and if the use count then becomes zero, then the old atom
66 // is deallocated by returning it to the pool ioPool. (And this is
67 // why ioPool is a parameter to this method.) Note that ioAtom can be nil
68 // to cause the cell to refer to nothing, and the old atom in mCell_Atom
69 // can also be nil, and all the atom refcounting is handled correctly.
70 //
71 // Note that if ioAtom was just created, it typically has a zero use count
72 // before calling SetAtom(). But use count is one higher after SetAtom().
73 {
74 morkAtom* oldAtom = mCell_Atom;
75 if (oldAtom != ioAtom) // ioAtom is not already installed in this cell?
76 {
77 if (oldAtom) {
78 mCell_Atom = 0;
79 if (oldAtom->CutCellUse(ev) == 0) {
80 // this was zapping atoms still in use - comment out until davidmc
81 // can figure out a better fix.
82 // if ( ioPool )
83 // {
84 // if ( oldAtom->IsBook() )
85 // ((morkBookAtom*) oldAtom)->CutBookAtomFromSpace(ev);
86
87 // ioPool->ZapAtom(ev, oldAtom);
88 // }
89 // else
90 // ev->NilPointerError();
91 }
92 }
93 if (ioAtom) ioAtom->AddCellUse(ev);
94
95 mCell_Atom = ioAtom;
96 }
97 }
98
99 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
100