mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
101 lines
1.9 KiB
JavaScript
101 lines
1.9 KiB
JavaScript
// V_COMMIT_HASH 2943bdc
|
|
// V_CURRENT_COMMIT_HASH ad5deef
|
|
// Generated by the V compiler
|
|
|
|
"use strict";
|
|
|
|
/** @namespace builtin */
|
|
const builtin = (function () {
|
|
/**
|
|
* @function
|
|
* @param {any} s
|
|
* @returns {void}
|
|
*/
|
|
function println(s) {
|
|
console.log(s);
|
|
}
|
|
|
|
/**
|
|
* @function
|
|
* @param {any} s
|
|
* @returns {void}
|
|
*/
|
|
function print(s) {
|
|
process.stdout.write(s);
|
|
}
|
|
|
|
/* module exports */
|
|
return {
|
|
println,
|
|
print,
|
|
};
|
|
})();
|
|
|
|
/** @namespace main */
|
|
const main = (function () {
|
|
/**
|
|
* @function
|
|
* @param {...number} args
|
|
* @returns {void}
|
|
*/
|
|
function variadic(...args) {
|
|
builtin.println(args);
|
|
builtin.println(args[0]);
|
|
builtin.println(args[1]);
|
|
}
|
|
|
|
/**
|
|
* @function
|
|
* @returns {void}
|
|
*/
|
|
function vararg_test() {
|
|
variadic(1, 2, 3);
|
|
}
|
|
|
|
/* program entry point */
|
|
(function() {
|
|
vararg_test();
|
|
/** @type {string[]} */
|
|
const arr1 = ["Hello", "JS", "Backend"];
|
|
/** @type {number[]} */
|
|
let arr2 = [1, 2, 3, 4, 5];
|
|
/** @type {string[]} */
|
|
const slice1 = arr1.slice(1, 3);
|
|
/** @type {number[]} */
|
|
const slice2 = arr2.slice(0, 3);
|
|
/** @type {number[]} */
|
|
const slice3 = arr2.slice(3, arr2.length);
|
|
/** @type {string} */
|
|
const idx1 = slice1[1];
|
|
arr2[0] = 1;
|
|
arr2[0 + 1] = 2;
|
|
builtin.println(arr2);
|
|
arr2.push(6);
|
|
arr2.push(...[7, 8, 9]);
|
|
builtin.println(arr2);
|
|
/** @type {string} */
|
|
let slice4 = idx1.slice(0, 4);
|
|
builtin.println(slice4);
|
|
/** @type {number} */
|
|
const idx2 = slice4.charCodeAt(0);
|
|
builtin.println(idx2);
|
|
/** @type {Map<string, string>} */
|
|
let m = new Map();
|
|
/** @type {string} */
|
|
const key = "key";
|
|
m.set(key, "value");
|
|
/** @type {string} */
|
|
const val = m.get("key");
|
|
builtin.println(val);
|
|
builtin.println(arr1.includes("JS"));
|
|
builtin.println(!(arr2.includes(3)));
|
|
builtin.println(m.has("key"));
|
|
builtin.println(!(m.has("badkey")));
|
|
})();
|
|
|
|
/* module exports */
|
|
return {};
|
|
})();
|
|
|
|
|