@theqrl/hypc 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +361 -0
  3. package/abi.js +80 -0
  4. package/bindings/compile.js +157 -0
  5. package/bindings/core.js +116 -0
  6. package/bindings/helpers.js +35 -0
  7. package/bindings/index.js +16 -0
  8. package/build/clean.js +6 -0
  9. package/build/pack-publish-block.js +10 -0
  10. package/build/postbuild.js +3 -0
  11. package/common/helpers.js +24 -0
  12. package/common/types.js +2 -0
  13. package/contractA_hyp_A.bin +1 -0
  14. package/contractB_hyp_B.bin +1 -0
  15. package/downloadCurrentVersion.js +93 -0
  16. package/formatters.js +17 -0
  17. package/hypc.js +259 -0
  18. package/hypjson.js +1733 -0
  19. package/importA_hyp_C.bin +1 -0
  20. package/importB_hyp_D.bin +1 -0
  21. package/index.js +7 -0
  22. package/libX_hyp_X.bin +1 -0
  23. package/libY_hyp_Y.bin +1 -0
  24. package/libZ_hyp_Z.bin +1 -0
  25. package/linker.js +156 -0
  26. package/package.json +74 -0
  27. package/smtchecker.js +39 -0
  28. package/smtsolver.js +89 -0
  29. package/test/abi.js +77 -0
  30. package/test/cli.js +245 -0
  31. package/test/compiler.js +791 -0
  32. package/test/index.js +36 -0
  33. package/test/linker.js +132 -0
  34. package/test/resources/fixtureAsmJson.hyp +8 -0
  35. package/test/resources/fixtureAsmJson.json +528 -0
  36. package/test/resources/fixtureAsmJson.output +101 -0
  37. package/test/resources/fixtureIncorrectSource.hyp +1 -0
  38. package/test/resources/fixtureSmoke.hyp +5 -0
  39. package/test/resources/importA.hyp +7 -0
  40. package/test/resources/importB.hyp +5 -0
  41. package/test/resources/importCallback/base/contractA.hyp +8 -0
  42. package/test/resources/importCallback/base/contractB.hyp +6 -0
  43. package/test/resources/importCallback/contractC.hyp +4 -0
  44. package/test/resources/importCallback/includeA/libX.hyp +4 -0
  45. package/test/resources/importCallback/includeA/libY.hyp +6 -0
  46. package/test/resources/importCallback/includeA/utils.hyp +4 -0
  47. package/test/resources/importCallback/includeB/libZ.hyp +4 -0
  48. package/test/resources/smtChecker/loop.hyp +8 -0
  49. package/test/resources/smtChecker/smoke.hyp +5 -0
  50. package/test/resources/smtChecker/smoke_with_engine.hyp +6 -0
  51. package/test/resources/smtChecker/smoke_with_multi_engine.hyp +8 -0
  52. package/test/smtcallback.js +221 -0
  53. package/test/smtchecker.js +83 -0
  54. package/test/translate.js +83 -0
  55. package/test_resources_fixtureSmoke_hyp_C.abi +1 -0
  56. package/test_resources_fixtureSmoke_hyp_C.bin +1 -0
  57. package/test_resources_importA_hyp_C.bin +1 -0
  58. package/test_resources_importB_hyp_D.bin +1 -0
  59. package/translate.js +186 -0
  60. package/tsconfig.json +25 -0
  61. package/utils_hyp_Utils.bin +1 -0
  62. package/verifyVersion.js +43 -0
  63. package/wrapper.js +143 -0
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ const semver = __importStar(require("semver"));
31
+ const _1 = __importDefault(require("./"));
32
+ const { version: packageVersion } = require('./package.json');
33
+ const hypcVersion = _1.default.version();
34
+ console.log('hypcVersion: ' + hypcVersion);
35
+ console.log('packageVersion: ' + packageVersion);
36
+ if (semver.eq(packageVersion, hypcVersion)) {
37
+ console.log('Version matching');
38
+ process.exit(0);
39
+ }
40
+ else {
41
+ console.log('Version mismatch');
42
+ process.exit(1);
43
+ }
package/wrapper.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const memorystream_1 = __importDefault(require("memorystream"));
6
+ const follow_redirects_1 = require("follow-redirects");
7
+ const formatters_1 = require("./formatters");
8
+ const helpers_1 = require("./common/helpers");
9
+ const bindings_1 = __importDefault(require("./bindings"));
10
+ const translate_1 = __importDefault(require("./translate"));
11
+ const Module = module.constructor;
12
+ function wrapper(hypjson) {
13
+ const { coreBindings, compileBindings, methodFlags } = (0, bindings_1.default)(hypjson);
14
+ return {
15
+ version: coreBindings.version,
16
+ semver: coreBindings.versionToSemver,
17
+ license: coreBindings.license,
18
+ lowlevel: {
19
+ compileSingle: compileBindings.compileJson,
20
+ compileMulti: compileBindings.compileJsonMulti,
21
+ compileCallback: compileBindings.compileJsonCallback,
22
+ compileStandard: compileBindings.compileStandard
23
+ },
24
+ features: {
25
+ legacySingleInput: methodFlags.compileJsonStandardSupported,
26
+ multipleInputs: methodFlags.compileJsonMultiSupported || methodFlags.compileJsonStandardSupported,
27
+ importCallback: methodFlags.compileJsonCallbackSuppported || methodFlags.compileJsonStandardSupported,
28
+ nativeStandardJSON: methodFlags.compileJsonStandardSupported
29
+ },
30
+ compile: compileStandardWrapper.bind(this, compileBindings),
31
+ // Loads the compiler of the given version from the github repository
32
+ // instead of from the local filesystem.
33
+ loadRemoteVersion,
34
+ // Use this if you want to add wrapper functions around the pure module.
35
+ setupMethods: wrapper
36
+ };
37
+ }
38
+ function loadRemoteVersion(versionString, callback) {
39
+ const memoryStream = new memorystream_1.default(null, { readable: false });
40
+ const url = `https://binaries.theqrl.org/bin/hypjson-${versionString}.js`;
41
+ follow_redirects_1.https.get(url, response => {
42
+ if (response.statusCode !== 200) {
43
+ callback(new Error(`Error retrieving binary: ${response.statusMessage}`));
44
+ }
45
+ else {
46
+ response.pipe(memoryStream);
47
+ response.on('end', () => {
48
+ // Based on the require-from-string package.
49
+ const hypjson = new Module();
50
+ hypjson._compile(memoryStream.toString(), `hypjson-${versionString}.js`);
51
+ if (module.parent && module.parent.children) {
52
+ // Make sure the module is plugged into the hierarchy correctly to have parent
53
+ // properly garbage collected.
54
+ module.parent.children.splice(module.parent.children.indexOf(hypjson), 1);
55
+ }
56
+ callback(null, wrapper(hypjson.exports));
57
+ });
58
+ }
59
+ }).on('error', function (error) {
60
+ callback(error);
61
+ });
62
+ }
63
+ // Expects a Standard JSON I/O but supports old compilers
64
+ function compileStandardWrapper(compile, inputRaw, readCallback) {
65
+ if (!(0, helpers_1.isNil)(compile.compileStandard)) {
66
+ return compile.compileStandard(inputRaw, readCallback);
67
+ }
68
+ let input;
69
+ try {
70
+ input = JSON.parse(inputRaw);
71
+ }
72
+ catch (e) {
73
+ return (0, formatters_1.formatFatalError)(`Invalid JSON supplied: ${e.message}`);
74
+ }
75
+ if (input.language !== 'Hyperion') {
76
+ return (0, formatters_1.formatFatalError)('Only "Hyperion" is supported as a language.');
77
+ }
78
+ // NOTE: this is deliberately `== null`
79
+ if ((0, helpers_1.isNil)(input.sources) || input.sources.length === 0) {
80
+ return (0, formatters_1.formatFatalError)('No input sources specified.');
81
+ }
82
+ const sources = translateSources(input);
83
+ const optimize = isOptimizerEnabled(input);
84
+ const libraries = librariesSupplied(input);
85
+ if ((0, helpers_1.isNil)(sources) || Object.keys(sources).length === 0) {
86
+ return (0, formatters_1.formatFatalError)('Failed to process sources.');
87
+ }
88
+ // Try to wrap around old versions
89
+ if (!(0, helpers_1.isNil)(compile.compileJsonCallback)) {
90
+ const inputJson = JSON.stringify({ sources: sources });
91
+ const output = compile.compileJsonCallback(inputJson, optimize, readCallback);
92
+ return translateOutput(output, libraries);
93
+ }
94
+ if (!(0, helpers_1.isNil)(compile.compileJsonMulti)) {
95
+ const output = compile.compileJsonMulti(JSON.stringify({ sources: sources }), optimize);
96
+ return translateOutput(output, libraries);
97
+ }
98
+ // Try our luck with an ancient compiler
99
+ if (!(0, helpers_1.isNil)(compile.compileJson)) {
100
+ if (Object.keys(sources).length > 1) {
101
+ return (0, formatters_1.formatFatalError)('Multiple sources provided, but compiler only supports single input.');
102
+ }
103
+ const input = sources[Object.keys(sources)[0]];
104
+ const output = compile.compileJson(input, optimize);
105
+ return translateOutput(output, libraries);
106
+ }
107
+ return (0, formatters_1.formatFatalError)('Compiler does not support any known interface.');
108
+ }
109
+ function isOptimizerEnabled(input) {
110
+ return input.settings && input.settings.optimizer && input.settings.optimizer.enabled;
111
+ }
112
+ function translateSources(input) {
113
+ const sources = {};
114
+ for (const source in input.sources) {
115
+ if (input.sources[source].content !== null) {
116
+ sources[source] = input.sources[source].content;
117
+ }
118
+ else {
119
+ // force failure
120
+ return null;
121
+ }
122
+ }
123
+ return sources;
124
+ }
125
+ function librariesSupplied(input) {
126
+ if (!(0, helpers_1.isNil)(input.settings))
127
+ return input.settings.libraries;
128
+ }
129
+ function translateOutput(outputRaw, libraries) {
130
+ let parsedOutput;
131
+ try {
132
+ parsedOutput = JSON.parse(outputRaw);
133
+ }
134
+ catch (e) {
135
+ return (0, formatters_1.formatFatalError)(`Compiler returned invalid JSON: ${e.message}`);
136
+ }
137
+ const output = translate_1.default.translateJsonCompilerOutput(parsedOutput, libraries);
138
+ if ((0, helpers_1.isNil)(output)) {
139
+ return (0, formatters_1.formatFatalError)('Failed to process output.');
140
+ }
141
+ return JSON.stringify(output);
142
+ }
143
+ module.exports = wrapper;