1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[Tolk] Completely rework stdlib: multiple files and renaming

- split stdlib.tolk into multiple files (tolk-stdlib/ folder)
  (the "core" common.tolk is auto-imported, the rest are
  needed to be explicitly imported like "@stdlib/tvm-dicts.tolk")
- all functions were renamed to long and clear names
- new naming is camelCase
This commit is contained in:
tolk-vm 2024-10-31 11:16:19 +04:00
parent e2edadba92
commit 12ff28ac94
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
48 changed files with 2966 additions and 2458 deletions

View file

@ -27,6 +27,7 @@ const TOLKFIFTLIB_MODULE = getenv('TOLKFIFTLIB_MODULE')
const TOLKFIFTLIB_WASM = getenv('TOLKFIFTLIB_WASM')
const FIFT_EXECUTABLE = getenv('FIFT_EXECUTABLE')
const FIFT_LIBS_FOLDER = getenv('FIFTPATH') // this env is needed for fift to work properly
const STDLIB_FOLDER = __dirname + '/../crypto/smartcont/tolk-stdlib'
const TMP_DIR = os.tmpdir()
class CmdLineOptions {
@ -475,25 +476,33 @@ function copyToCStringPtr(mod, str, ptr) {
return allocated;
}
/** @return {string} */
function copyFromCString(mod, ptr) {
return mod.UTF8ToString(ptr);
}
/** @return {{status: string, message: string, fiftCode: string, codeBoc: string, codeHashHex: string}} */
function compileFile(mod, filename, experimentalOptions) {
// see tolk-wasm.cpp: typedef void (*CStyleReadFileCallback)(int, char const*, char**, char**)
// see tolk-wasm.cpp: typedef void (*WasmFsReadCallback)(int, char const*, char**, char**)
const callbackPtr = mod.addFunction((kind, dataPtr, destContents, destError) => {
if (kind === 0) { // realpath
try {
const relativeFilename = copyFromCString(mod, dataPtr)
copyToCStringPtr(mod, fs.realpathSync(relativeFilename), destContents);
let relative = copyFromCString(mod, dataPtr)
if (relative.startsWith('@stdlib/')) {
// import "@stdlib/filename" or import "@stdlib/filename.tolk"
relative = STDLIB_FOLDER + '/' + relative.substring(7)
if (!relative.endsWith('.tolk')) {
relative += '.tolk'
}
}
copyToCStringPtr(mod, fs.realpathSync(relative), destContents);
} catch (err) {
copyToCStringPtr(mod, 'cannot find file', destError);
}
} else if (kind === 1) { // read file
try {
const filename = copyFromCString(mod, dataPtr) // already normalized (as returned above)
copyToCStringPtr(mod, fs.readFileSync(filename).toString('utf-8'), destContents);
const absolute = copyFromCString(mod, dataPtr) // already normalized (as returned above)
copyToCStringPtr(mod, fs.readFileSync(absolute).toString('utf-8'), destContents);
} catch (err) {
copyToCStringPtr(mod, err.message || err.toString(), destError);
}
@ -506,7 +515,6 @@ function compileFile(mod, filename, experimentalOptions) {
optimizationLevel: 2,
withStackComments: true,
experimentalOptions: experimentalOptions || undefined,
stdlibLocation: __dirname + '/../crypto/smartcont/stdlib.tolk',
entrypointFileName: filename
};