From 22f4766ea65b7eca31b7a9150210124135e68fc9 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Mon, 12 Feb 2024 12:15:12 +0400 Subject: [PATCH] github pages --- index.html | 5 ++- js/kotlin-kotlin-stdlib.js | 76 ++++++++------------------------ js/tlb.d.ts | 4 +- js/tlb.js | 64 ++++++++++++++++----------- src/jsMain/kotlin/FuncCodeGen.kt | 15 ++++--- 5 files changed, 72 insertions(+), 92 deletions(-) diff --git a/index.html b/index.html index c48d638..84cb976 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,10 @@

TL-B -> FunC Generator (DEVELOPER PREVIEW)

- +
+ TL-B Types Debug + +
diff --git a/js/kotlin-kotlin-stdlib.js b/js/kotlin-kotlin-stdlib.js index 9342640..4a2d36d 100644 --- a/js/kotlin-kotlin-stdlib.js +++ b/js/kotlin-kotlin-stdlib.js @@ -94,7 +94,6 @@ if (typeof String.prototype.startsWith === 'undefined') { setMetadataFor(KotlinNothingValueException, 'KotlinNothingValueException', classMeta, RuntimeException, VOID, KotlinNothingValueException_init_$Create$); setMetadataFor(Annotation, 'Annotation', interfaceMeta); setMetadataFor(ExperimentalJsFileName, 'ExperimentalJsFileName', classMeta, VOID, [Annotation]); - setMetadataFor(ExperimentalJsExport, 'ExperimentalJsExport', classMeta, VOID, [Annotation]); setMetadataFor(IntrinsicConstEvaluation, 'IntrinsicConstEvaluation', classMeta, VOID, [Annotation]); setMetadataFor(Companion, 'Companion', objectMeta); setMetadataFor(Comparable, 'Comparable', interfaceMeta); @@ -202,8 +201,6 @@ if (typeof String.prototype.startsWith === 'undefined') { setMetadataFor(StringCompanionObject, 'StringCompanionObject', objectMeta); setMetadataFor(BooleanCompanionObject, 'BooleanCompanionObject', objectMeta); setMetadataFor(AutoCloseable, 'AutoCloseable', interfaceMeta); - setMetadataFor(Ignore, 'Ignore', classMeta, VOID, [Annotation]); - setMetadataFor(JsExport, 'JsExport', classMeta, VOID, [Annotation]); setMetadataFor(JsName, 'JsName', classMeta, VOID, [Annotation]); setMetadataFor(JsQualifier, 'JsQualifier', classMeta, VOID, [Annotation]); setMetadataFor(JsFileName, 'JsFileName', classMeta, VOID, [Annotation]); @@ -968,6 +965,10 @@ if (typeof String.prototype.startsWith === 'undefined') { return new _no_name_provided__qut3iv(_this__u8e3s4); } + function component2(_this__u8e3s4) { + return _this__u8e3s4.get_c1px32_k$(1); + } + function indexOfLast(_this__u8e3s4, predicate) { var iterator = _this__u8e3s4.listIterator_70e65o_k$(_this__u8e3s4.get_size_woubt6_k$()); while (iterator.hasPrevious_qh0629_k$()) { @@ -1031,6 +1032,10 @@ if (typeof String.prototype.startsWith === 'undefined') { return false; } + function component1(_this__u8e3s4) { + return _this__u8e3s4.get_c1px32_k$(0); + } + function mapIndexedNotNull(_this__u8e3s4, transform) { // Inline function 'kotlin.collections.mapIndexedNotNullTo' call var destination = ArrayList_init_$Create$(); @@ -2062,22 +2067,6 @@ if (typeof String.prototype.startsWith === 'undefined') { return '@kotlin.js.ExperimentalJsFileName()'; }; - function ExperimentalJsExport() { - } - - protoOf(ExperimentalJsExport).equals = function (other) { - if (!(other instanceof ExperimentalJsExport)) - return false; - other instanceof ExperimentalJsExport || THROW_CCE(); - return true; - }; - protoOf(ExperimentalJsExport).hashCode = function () { - return 0; - }; - protoOf(ExperimentalJsExport).toString = function () { - return '@kotlin.js.ExperimentalJsExport()'; - }; - function IntrinsicConstEvaluation() { } @@ -6907,38 +6896,6 @@ if (typeof String.prototype.startsWith === 'undefined') { return tmp; } - function Ignore() { - } - - protoOf(Ignore).equals = function (other) { - if (!(other instanceof Ignore)) - return false; - other instanceof Ignore || THROW_CCE(); - return true; - }; - protoOf(Ignore).hashCode = function () { - return 0; - }; - protoOf(Ignore).toString = function () { - return '@kotlin.js.JsExport.Ignore()'; - }; - - function JsExport() { - } - - protoOf(JsExport).equals = function (other) { - if (!(other instanceof JsExport)) - return false; - other instanceof JsExport || THROW_CCE(); - return true; - }; - protoOf(JsExport).hashCode = function () { - return 0; - }; - protoOf(JsExport).toString = function () { - return '@kotlin.js.JsExport()'; - }; - function JsName(name) { this.name_1 = name; } @@ -13526,7 +13483,7 @@ if (typeof String.prototype.startsWith === 'undefined') { return tmp; } - function component1(_this__u8e3s4) { + function component1_0(_this__u8e3s4) { return _this__u8e3s4.get_key_18j28a_k$(); } @@ -13538,7 +13495,7 @@ if (typeof String.prototype.startsWith === 'undefined') { return pairs.length > 0 ? toMap_0(pairs, LinkedHashMap_init_$Create$_0(mapCapacity(pairs.length))) : emptyMap(); } - function component2(_this__u8e3s4) { + function component2_0(_this__u8e3s4) { return _this__u8e3s4.get_value_j01efc_k$(); } @@ -17153,13 +17110,18 @@ if (typeof String.prototype.startsWith === 'undefined') { return this_0.toString(); } - function appendLine_0(_this__u8e3s4, value) { + function appendLine_0(_this__u8e3s4) { + return _this__u8e3s4.append_am5a4z_k$(_Char___init__impl__6a9atx(10)); + } + + function appendLine_1(_this__u8e3s4, value) { // Inline function 'kotlin.text.appendLine' call - return _this__u8e3s4.append_22ad7x_k$(value).append_am5a4z_k$(_Char___init__impl__6a9atx(10)); + return _this__u8e3s4.append_t8pm91_k$(value).append_am5a4z_k$(_Char___init__impl__6a9atx(10)); } - function appendLine_1(_this__u8e3s4) { - return _this__u8e3s4.append_am5a4z_k$(_Char___init__impl__6a9atx(10)); + function appendLine_2(_this__u8e3s4, value) { + // Inline function 'kotlin.text.appendLine' call + return _this__u8e3s4.append_22ad7x_k$(value).append_am5a4z_k$(_Char___init__impl__6a9atx(10)); } function toIntOrNull(_this__u8e3s4) { diff --git a/js/tlb.d.ts b/js/tlb.d.ts index f792590..3d0d1fd 100644 --- a/js/tlb.d.ts +++ b/js/tlb.d.ts @@ -1,5 +1,3 @@ type Nullable = T | null | undefined -export declare namespace org.ton.tlb { - function funcCodeGen(src: string): string; -} + export as namespace tlb; \ No newline at end of file diff --git a/js/tlb.js b/js/tlb.js index 99dca1d..83648b6 100644 --- a/js/tlb.js +++ b/js/tlb.js @@ -8545,6 +8545,15 @@ return true; }; + function main() { + var tmp0_safe_receiver = document.getElementById('compile'); + if (tmp0_safe_receiver == null) + null; + else { + tmp0_safe_receiver.addEventListener('click', main$lambda); + } + } + function funcCodeGen(src) { try { var ast = (new TlbGrammar()).parseOrThrow_n30fme_k$(src); @@ -8575,26 +8584,33 @@ funcCodeGen.generate_arbnv5_k$(this_0); } var output = this_0.toString(); - return output; + // Inline function 'kotlin.text.buildString' call + // Inline function 'kotlin.contracts.contract' call + // Inline function 'kotlin.apply' call + var this_1 = StringBuilder_init_$Create$(); + // Inline function 'kotlin.contracts.contract' call + // Inline function 'org.ton.tlb.funcCodeGen.' call + // Inline function 'kotlin.collections.forEach' call + var tmp0_iterator_1 = compiler.get_types_izd7io_k$().get_values_ksazhn_k$().iterator_jk1svi_k$(); + while (tmp0_iterator_1.hasNext_bitz1p_k$()) { + var element_1 = tmp0_iterator_1.next_20eer_k$(); + // Inline function 'org.ton.tlb.funcCodeGen..' call + // Inline function 'kotlin.text.appendLine' call + // Inline function 'kotlin.text.appendLine' call + this_1.append_t8pm91_k$(element_1).append_am5a4z_k$(_Char___init__impl__6a9atx(10)); + } + var tmp$ret$7 = this_1.toString(); + return listOf_0([output, tmp$ret$7]); } catch ($p) { if ($p instanceof Exception) { var e = $p; - return stackTraceToString(e); + return listOf_0([stackTraceToString(e), '']); } else { throw $p; } } } - function main() { - var tmp0_safe_receiver = document.getElementById('compile'); - if (tmp0_safe_receiver == null) - null; - else { - tmp0_safe_receiver.addEventListener('click', main$lambda); - } - } - function main$lambda(it) { var tmp0_safe_receiver = document.getElementById('src'); var tmp; @@ -8606,10 +8622,18 @@ } var tmp_0 = tmp.value; var src = (!(tmp_0 == null) ? typeof tmp_0 === 'string' : false) ? tmp_0 : THROW_CCE(); - var output = funcCodeGen(src); - var tmp1_safe_receiver = document.getElementById('output'); - if (tmp1_safe_receiver != null) { - tmp1_safe_receiver.textContent = output; + var tmp1_container = funcCodeGen(src); + // Inline function 'kotlin.collections.component1' call + var output = tmp1_container.get_c1px32_k$(0); + // Inline function 'kotlin.collections.component2' call + var debug = tmp1_container.get_c1px32_k$(1); + var tmp2_safe_receiver = document.getElementById('output'); + if (tmp2_safe_receiver != null) { + tmp2_safe_receiver.textContent = output; + } + var tmp3_safe_receiver = document.getElementById('debug'); + if (tmp3_safe_receiver != null) { + tmp3_safe_receiver.textContent = debug; } return Unit_getInstance(); } @@ -8671,16 +8695,6 @@ ALL = new Long(0, -2147483648); HEX_DIGITS = '0123456789abcdef'; //endregion - //region block: exports - function $jsExportAll$(_) { - var $org = _.org || (_.org = {}); - var $org$ton = $org.ton || ($org.ton = {}); - var $org$ton$tlb = $org$ton.tlb || ($org$ton.tlb = {}); - $org$ton$tlb.funcCodeGen = funcCodeGen; - } - - $jsExportAll$(_); - //endregion main(); return _; })); diff --git a/src/jsMain/kotlin/FuncCodeGen.kt b/src/jsMain/kotlin/FuncCodeGen.kt index 325a85d..15ee1ac 100644 --- a/src/jsMain/kotlin/FuncCodeGen.kt +++ b/src/jsMain/kotlin/FuncCodeGen.kt @@ -8,14 +8,13 @@ import org.ton.tlb.parser.TlbGrammar fun main() { document.getElementById("compile")?.addEventListener("click", { val src = document.getElementById("src")?.asDynamic().value as String - val output = funcCodeGen(src) + val (output, debug) = funcCodeGen(src) document.getElementById("output")?.textContent = output + document.getElementById("debug")?.textContent = debug }) } -@OptIn(ExperimentalJsExport::class) -@JsExport -fun funcCodeGen(src: String): String { +fun funcCodeGen(src: String): List { try { val ast = TlbGrammar().parseOrThrow(src) val compiler = TlbCompiler() @@ -31,8 +30,12 @@ fun funcCodeGen(src: String): String { funcCodeGen.generate(this) } } - return output + return listOf(output, buildString { + compiler.types.values.forEach { type -> + appendLine(type) + } + }) } catch (e: Exception) { - return e.stackTraceToString() + return listOf(e.stackTraceToString(), "") } }