Skip to content

Commit 322eb0f

Browse files
committed
Tolk v1.0: handle import without ".tolk", release wasm and stdlib
1 parent 94017c4 commit 322eb0f

16 files changed

+461
-375
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# WASM wrapper for TON Tolk Language
22

3-
**Tolk** is a new language for writing smart contracts in TON. Think of Tolk as the "next‑generation FunC".
4-
Tolk compiler is literally a fork of FunC compiler, introducing familiar syntax similar to TypeScript,
5-
but leaving all low-level optimizations untouched.
3+
**Tolk** is a next-generation language for smart contracts in TON.
4+
It replaces FunC with modern syntax, strong types, and built-in serialization — while generating even more efficient assembler code.
65

76
**tolk-js** is a WASM wrapper for Tolk compiler.
87
[Blueprint](https://github.com/ton-org/blueprint) uses tolk-js to compile `.tolk` files,
@@ -81,13 +80,14 @@ The function `runTolkCompiler()` accepts the following properties (look up `Tolk
8180
* `entrypointFileName` — obvious
8281
* `fsReadCallback` — explained above
8382
* `optimizationLevel` (default 2) — controls Tolk compiler stack optimizer
84-
* `withStackComments` (default false) — Fift output will contain comments, if you wish to debug its output
83+
* `withStackComments` (default false) — Fift output will contain stack comments, if you wish to debug its output
84+
* `withSrcLineComments` (default false) — Fift output will contain line comments from original .tolk files
8585
* `experimentalOptions` (default '') — you can pass experimental compiler options here
8686

8787

8888
## Embedded stdlib functions
8989

90-
Tolk standard functions (`beginCell`, `assertEndOfSlice`, and lots of others) are available out of the box *(if you worked with FunC earlier, you had to download stdlib.fc and store in your project; in Tolk, you don't need any additional files)*.
90+
Tolk standard functions (`beginCell`, `assertEnd`, and lots of others) are available out of the box *(if you worked with FunC earlier, you had to download stdlib.fc and store in your project; in Tolk, you don't need any additional files)*.
9191

9292
It works, because all stdlib files are embedded into JS, placed near wasm. If you `import "@stdlib/tvm-dicts"` for example, tolk-js will handle it, `fsReadCallback` won't be called.
9393

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ton/tolk-js",
3-
"version": "0.99.0",
3+
"version": "1.0.0",
44
"description": "Tolk Language compiler (next-generation FunC)",
55
"main": "dist/index.js",
66
"bin": "./dist/cli.js",

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export async function runTolkCompiler(compilerConfig: TolkCompilerConfig): Promi
8686
const callbackPtr = mod.addFunction(function (kind: number, dataPtr: any, destContents: any, destError: any) {
8787
switch (kind) { // enum ReadCallback::Kind in C++
8888
case 0: // realpath
89-
let relativeFilename = copyFromCString(mod, dataPtr)
90-
if (relativeFilename.startsWith('@stdlib/') && !relativeFilename.endsWith('.tolk')) {
91-
relativeFilename += '.tolk' // import "@stdlib/gas-payments"
89+
let relativeFilename = copyFromCString(mod, dataPtr) // from `import` statement, relative to cur file
90+
if (!relativeFilename.endsWith('.tolk')) {
91+
relativeFilename += '.tolk'
9292
}
9393
allocatedPointers.push(copyToCStringPtr(mod, realpath(relativeFilename), destContents))
9494
break

src/path-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ function posixNormalize(path: string, allowAboveRoot: boolean): string {
7777
return res
7878
}
7979

80-
// 'realpath' in Tolk internals is used to resolve #include
81-
// (e.g., to detect that #include "a.tolk" and #include "dir/../a.tolk" reference the same file)
80+
// 'realpath' in Tolk internals is used to resolve imports
81+
// (e.g., to detect that `import "a.tolk"` and `import "dir/../a"` reference the same file)
8282
// here we do the same using manual normalization, taken from Node internals (to work in web)
8383
//
8484
// also, 'realpath' in C++ resolves symlinks

0 commit comments

Comments
 (0)