MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxUseSnapshot

Function fxUseSnapshot

xs/sources/xsSnapshot.c:1830–1944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1828}
1829
1830int fxUseSnapshot(txMachine* the, txSnapshot* snapshot)
1831{
1832 Atom atom;
1833 txByte byte;
1834 txCreation creation;
1835 txID profileID;
1836 txInteger tag;
1837 txByte* buffer;
1838 txSize size;
1839 txSlot* slot;
1840 mxTry(the) {
1841 snapshot->error = 0;
1842
1843 fxReadAtom(the, snapshot, &atom, "XS_M");
1844 fxReadAtom(the, snapshot, &atom, "VERS");
1845 mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1846 mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1847 mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1848 mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1849 fxReadAtom(the, snapshot, &atom, "SIGN");
1850 while (atom.atomSize) {
1851 mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1852 atom.atomSize--;
1853 }
1854 fxReadAtom(the, snapshot, &atom, "CREA");
1855 mxThrowIf((*snapshot->read)(snapshot->stream, &creation, sizeof(txCreation)));
1856 mxThrowIf((*snapshot->read)(snapshot->stream, &profileID, sizeof(txID)));
1857 mxThrowIf((*snapshot->read)(snapshot->stream, &tag, sizeof(txInteger)));
1858
1859 buffer = (txByte*)the->firstBlock;
1860 size = the->firstBlock->limit - buffer;
1861 c_memset(buffer, 0, size);
1862 the->firstBlock->current = buffer + sizeof(txBlock);
1863 the->firstBlock->limit = buffer + size;
1864
1865 the->freeHeap = slot = the->firstHeap + 1;
1866 size = the->maximumHeapCount - 1;
1867 while (size--) {
1868 txSlot* next = slot + 1;
1869 slot->next = next;
1870 slot->flag = XS_NO_FLAG;
1871 slot->kind = XS_UNDEFINED_KIND;
1872 slot = next;
1873 }
1874 slot->next = C_NULL;
1875 slot->flag = XS_NO_FLAG;
1876 slot->kind = XS_UNDEFINED_KIND;
1877 the->firstWeakListLink = C_NULL;
1878
1879 snapshot->firstChunk = the->firstBlock->current;
1880 snapshot->firstSlot = the->firstHeap;
1881
1882 fxReadAtom(the, snapshot, &atom, "BLOC");
1883 mxThrowIf((*snapshot->read)(snapshot->stream, the->firstBlock->current, atom.atomSize));
1884 the->currentChunksSize = atom.atomSize;
1885 the->firstBlock->current += atom.atomSize;
1886
1887 fxReadAtom(the, snapshot, &atom, "HEAP");

Callers

nothing calls this directly

Calls 6

fxReadAtomFunction · 0.85
fxReadSlotFunction · 0.85
fxReadMapSetFunction · 0.85
fxReadSlotTableFunction · 0.85
fxLinkChunksFunction · 0.85
fxReadKeyholeFunction · 0.85

Tested by

no test coverage detected