tolk-codegen
Version:
## Example generator ### Create builder file in root folder ``builder.ts``
48 lines (47 loc) • 2.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.storeMayBeIsDeclaration = exports.loadMayBeIsDeclaration = exports.loadMayBeRef = exports.storeMayBe = exports.storeMayBeRef = exports.mapBuildTypeToTolkSliceFunction = exports.mapBuildTypeToTolkBuilderFunction = exports.mapBuildTypeToTolkType = void 0;
const decorators_1 = require("../decorators");
function argsJoin(args) {
return args.filter(value => value).join(', ');
}
exports.mapBuildTypeToTolkType = {
[decorators_1.DataType.REF]: 'cell',
[decorators_1.DataType.DICT]: 'cell',
[decorators_1.DataType.ADDRESS]: 'slice',
[decorators_1.DataType.SLICE]: 'slice',
[decorators_1.DataType.BIT]: 'int',
[decorators_1.DataType.UINT]: 'int',
[decorators_1.DataType.INT]: 'int',
[decorators_1.DataType.COINS]: 'int',
};
exports.mapBuildTypeToTolkBuilderFunction = {
[decorators_1.DataType.REF]: (field) => `storeRef(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.ADDRESS]: (field) => `storeSlice(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.BIT]: (field) => `storeBool(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.INT]: (field) => `storeInt(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.UINT]: (field) => `storeUint(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.COINS]: (field) => `storeCoins(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.DICT]: (field) => `storeDict(${argsJoin([field.name, field.size])})`,
[decorators_1.DataType.SLICE]: (field) => `storeSlice(${argsJoin([field.name])})`,
};
exports.mapBuildTypeToTolkSliceFunction = {
[decorators_1.DataType.REF]: (field) => `loadRef()`,
[decorators_1.DataType.ADDRESS]: (field) => `loadAddress(${argsJoin([field.size])})`,
[decorators_1.DataType.BIT]: (field) => `loadBool()`,
[decorators_1.DataType.INT]: (field) => `loadInt(${argsJoin([field.size])})`,
[decorators_1.DataType.UINT]: (field) => `loadUint(${argsJoin([field.size])})`,
[decorators_1.DataType.COINS]: (field) => `loadCoins()`,
[decorators_1.DataType.DICT]: (field) => `loadDict()`,
[decorators_1.DataType.SLICE]: (field, args) => `loadBits(${argsJoin([field.size, ...args || []])})`,
};
const storeMayBeRef = (field) => `storeMaybeRef(${field.name})`;
exports.storeMayBeRef = storeMayBeRef;
const storeMayBe = (field) => `storeBool(${field.name} != null)`;
exports.storeMayBe = storeMayBe;
const loadMayBeRef = (field) => `loadMaybeRef()`;
exports.loadMayBeRef = loadMayBeRef;
const loadMayBeIsDeclaration = (field, fiendName, loadDeclaration) => `${fiendName}.loadBool() ? ${loadDeclaration} : null`;
exports.loadMayBeIsDeclaration = loadMayBeIsDeclaration;
const storeMayBeIsDeclaration = (field, storeDeclaration) => `if(${field.name} != null) {\n\t\t${storeDeclaration}}\n\t`;
exports.storeMayBeIsDeclaration = storeMayBeIsDeclaration;