Skip to content

Commit 227a08a

Browse files
committed
Tolk v0.11 wasm and stdlib
1 parent 1f83b2c commit 227a08a

File tree

12 files changed

+103
-89
lines changed

12 files changed

+103
-89
lines changed

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.10.0",
3+
"version": "0.11.0",
44
"description": "Tolk Language compiler (next-generation FunC)",
55
"main": "dist/index.js",
66
"bin": "./dist/cli.js",

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,20 @@ export async function runTolkCompiler(compilerConfig: TolkCompilerConfig): Promi
8585
const callbackPtr = mod.addFunction(function (kind: number, dataPtr: any, destContents: any, destError: any) {
8686
switch (kind) { // enum ReadCallback::Kind in C++
8787
case 0: // realpath
88-
const relativeFilename = copyFromCString(mod, dataPtr)
88+
let relativeFilename = copyFromCString(mod, dataPtr)
89+
if (relativeFilename.startsWith('@stdlib/') && !relativeFilename.endsWith('.tolk')) {
90+
relativeFilename += '.tolk' // import "@stdlib/gas-payments"
91+
}
8992
allocatedPointers.push(copyToCStringPtr(mod, realpath(relativeFilename), destContents))
9093
break
9194
case 1: // read file
9295
try {
9396
const filename = copyFromCString(mod, dataPtr) // already normalized (as returned above)
9497
if (filename.startsWith('@stdlib/')) {
95-
const stdlibKey = filename.endsWith('.tolk') ? filename : filename + '.tolk'
96-
if (!(stdlibKey in stdlibContents)) {
97-
allocatedPointers.push(copyToCStringPtr(mod, stdlibKey + " not found", destError))
98+
if (filename in stdlibContents) {
99+
allocatedPointers.push(copyToCStringPtr(mod, stdlibContents[filename], destContents))
98100
} else {
99-
allocatedPointers.push(copyToCStringPtr(mod, stdlibContents[stdlibKey], destContents))
101+
allocatedPointers.push(copyToCStringPtr(mod, filename + " not found", destError))
100102
}
101103
} else {
102104
const contents = compilerConfig.fsReadCallback(filename)

src/tolk-stdlib/common.tolk

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// Standard library for Tolk (LGPL licence).
22
// It contains common functions that are available out of the box, the user doesn't have to import anything.
33
// More specific functions are required to be imported explicitly, like "@stdlib/tvm-dicts".
4-
tolk 0.10
4+
tolk 0.11
5+
6+
/// In Tolk v1.x there would be a type `map<K,V>`.
7+
/// Currently, working with dictionaries is still low-level, with raw cells.
8+
/// But just for clarity, we use "dict" instead of a "cell?" where a cell-dictionary is assumed.
9+
/// Every dictionary object can be null. TVM NULL is essentially "empty dictionary".
10+
type dict = cell?;
511

612
/**
713
Tuple manipulation primitives.
@@ -144,9 +150,9 @@ fun getMyOriginalBalance(): int
144150

145151
/// Same as [getMyOriginalBalance], but returns a tuple:
146152
/// `int` — balance in nanotoncoins;
147-
/// `cell` — a dictionary with 32-bit keys representing the balance of "extra currencies".
153+
/// `dict` — a dictionary with 32-bit keys representing the balance of "extra currencies".
148154
@pure
149-
fun getMyOriginalBalanceWithExtraCurrencies(): [int, cell?]
155+
fun getMyOriginalBalanceWithExtraCurrencies(): [int, dict]
150156
asm "BALANCE";
151157

152158
/// Returns the logical time of the current transaction.
@@ -476,12 +482,12 @@ fun getLastBits(self: slice, len: int): slice
476482
/// Loads a dictionary (TL HashMapE structure, represented as TVM cell) from a slice.
477483
/// Returns `null` if `nothing` constructor is used.
478484
@pure
479-
fun loadDict(mutate self: slice): cell?
485+
fun loadDict(mutate self: slice): dict
480486
asm( -> 1 0) "LDDICT";
481487

482488
/// Preloads a dictionary (cell) from a slice.
483489
@pure
484-
fun preloadDict(self: slice): cell?
490+
fun preloadDict(self: slice): dict
485491
asm "PLDDICT";
486492

487493
/// Loads a dictionary as [loadDict], but returns only the remainder of the slice.
@@ -556,7 +562,7 @@ fun storeBool(mutate self: builder, x: bool): self
556562
/// Stores dictionary (represented by TVM `cell` or `null`) into a builder.
557563
/// In other words, stores a `1`-bit and a reference to [c] if [c] is not `null` and `0`-bit otherwise.
558564
@pure
559-
fun storeDict(mutate self: builder, c: cell?): self
565+
fun storeDict(mutate self: builder, c: dict): self
560566
asm(c self) "STDICT";
561567

562568
/// Stores (Maybe ^Cell) into a builder.
@@ -720,7 +726,7 @@ fun reserveToncoinsOnBalance(nanoTonCoins: int, reserveMode: int): void
720726

721727
/// Similar to [reserveToncoinsOnBalance], but also accepts a dictionary extraAmount (represented by a cell or null)
722728
/// with extra currencies. In this way currencies other than Toncoin can be reserved.
723-
fun reserveExtraCurrenciesOnBalance(nanoTonCoins: int, extraAmount: cell?, reserveMode: int): void
729+
fun reserveExtraCurrenciesOnBalance(nanoTonCoins: int, extraAmount: dict, reserveMode: int): void
724730
asm "RAWRESERVEX";
725731

726732

src/tolk-stdlib/gas-payments.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.10
2+
tolk 0.11
33

44
/**
55
Gas and payment related primitives.

src/tolk-stdlib/lisp-lists.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A part of standard library for Tolk
2-
tolk 0.10
2+
tolk 0.11
33

44
/**
55
Lisp-style lists are nested 2-elements tuples: `(1, (2, (3, null)))` represents list `[1, 2, 3]`.

0 commit comments

Comments
 (0)