aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/pickling/TastyPickler.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-02-08 10:06:43 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:09:43 +0100
commit340dc52a567de022c56acb1533c5772d21405f2a (patch)
treeae5dc41d2de3879d27abffc6413c18b25019e61b /src/dotty/tools/dotc/core/pickling/TastyPickler.scala
parent61cb51acaedbe603add8c4af9e390a27f8b33f09 (diff)
downloaddotty-340dc52a567de022c56acb1533c5772d21405f2a.tar.gz
dotty-340dc52a567de022c56acb1533c5772d21405f2a.tar.bz2
dotty-340dc52a567de022c56acb1533c5772d21405f2a.zip
First prototype of pickler.
Diffstat (limited to 'src/dotty/tools/dotc/core/pickling/TastyPickler.scala')
-rw-r--r--src/dotty/tools/dotc/core/pickling/TastyPickler.scala50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/pickling/TastyPickler.scala b/src/dotty/tools/dotc/core/pickling/TastyPickler.scala
new file mode 100644
index 000000000..2ae6848e0
--- /dev/null
+++ b/src/dotty/tools/dotc/core/pickling/TastyPickler.scala
@@ -0,0 +1,50 @@
+package dotty.tools
+package dotc
+package core
+package pickling
+
+import PickleFormat._
+import collection.mutable
+import TastyBuffer._
+
+class TastyPickler {
+
+ private val sections = new mutable.ArrayBuffer[(TastyName.Ref, TastyBuffer)]
+
+ private val headerBuffer = {
+ val buf = new TastyBuffer(16)
+ for (ch <- header) buf.writeByte(ch.toByte)
+ buf.writeNat(MajorVersion)
+ buf.writeNat(MinorVersion)
+ buf
+ }
+
+ val nameBuffer = new NameBuffer
+
+ def newSection(name: String, buf: TastyBuffer) =
+ sections += ((nameBuffer.nameIndex(name), buf))
+
+ def assembleParts: Array[Byte] = {
+ def lengthWithLength(buf: TastyBuffer) = {
+ buf.assemble()
+ buf.length + natSize(buf.length)
+ }
+ val totalSize =
+ headerBuffer.length +
+ lengthWithLength(nameBuffer) + {
+ for ((nameRef, buf) <- sections) yield
+ natSize(nameRef.index) + lengthWithLength(buf)
+ }.sum
+ val all = new TastyBuffer(totalSize)
+ all.writeBytes(headerBuffer.bytes, headerBuffer.length)
+ all.writeNat(nameBuffer.length)
+ all.writeBytes(nameBuffer.bytes, nameBuffer.length)
+ for ((nameRef, buf) <- sections) {
+ all.writeNat(nameRef.index)
+ all.writeNat(buf.length)
+ all.writeBytes(buf.bytes, buf.length)
+ }
+ assert(all.length == totalSize && all.bytes.length == totalSize)
+ all.bytes
+ }
+}