Skip to content

Commit

Permalink
Add sync compile function
Browse files Browse the repository at this point in the history
  • Loading branch information
Karang committed May 15, 2020
1 parent 729189d commit d8214b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions doc/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit d8214b5

Please sign in to comment.