diff --git a/README.md b/README.md index 9abb658..234e991 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ See [example](example.js) See the language independent [ProtoDef](https://github.com/ProtoDef-io/ProtoDef) specification. * [api.md](doc/api.md) documents the exposed functions and classes +* [compiler.md](doc/compiler.md) documents the ProtoDef Compiler * [datatypes.md](https://github.com/ProtoDef-io/ProtoDef/blob/master/doc/datatypes.md) documents the default datatypes provided by Protodef. * [newDatatypes.md](doc/newDatatypes.md) explains how to create new datatypes for protodef * [history.md](doc/history.md) is the releases history diff --git a/doc/compiler.md b/doc/compiler.md index 3ad6458..bb1af16 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -96,6 +96,8 @@ const UUID = require('uuid-1345') } ``` +The native types implementations are compatible with the native functions of the ProtoDef interpreter, and can reuse them. + ### Context Type A context type is a type that will be called in the protocol's context. It can refer to registred native types using `native.{type}()` or context types (provided and generated) using `ctx.{type}()`, but cannot access its original context. diff --git a/src/compiler.js b/src/compiler.js index b7d052e..395686c 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -34,6 +34,24 @@ class ProtoDefCompiler { this.sizeOfCompiler.addProtocol(protocolData, path) } + compileProtoDefSync (options = { printCode: false }) { + const sizeOfCode = this.sizeOfCompiler.generate() + const writeCode = this.writeCompiler.generate() + const readCode = this.readCompiler.generate() + if (options.printCode) { + console.log('// SizeOf:') + console.log(sizeOfCode) + console.log('// Write:') + console.log(writeCode) + console.log('// Read:') + console.log(readCode) + } + const sizeOfCtx = this.sizeOfCompiler.compile(sizeOfCode) + const writeCtx = this.writeCompiler.compile(writeCode) + const readCtx = this.readCompiler.compile(readCode) + return new CompiledProtodef(sizeOfCtx, writeCtx, readCtx) + } + compileProtoDef (options = { optimize: false, printCode: false, printOptimizedCode: false }) { let c = this return new Promise(resolve => {