Elvelt

Standard Library

MPL Standard Library — module reference

MPL Standard Library — module reference

Every module, every function, with full signature, parameters, return type, behavior, and source-language mapping notes.

The C++ implementation reference is in MPL_Standard/CppImpl.h (335 lines). Each section below links the header source:line range for cross-reference.


Module 1: Console — standard input/output

Header: MPL_Standard/CppImpl.h:32-60

Namespace: mpl::System::Console

Function Signature Behavior Source mapping
WriteLine(text) void WriteLine(const std::string& text) Writes text followed by a newline (\n on Unix, \r\n on Windows via std::endl) to std::cout. JS console.log(text), Python print(text), Ruby puts text, C# Console.WriteLine(text), Java System.out.println(text)
WriteLine() void WriteLine() Writes just a newline (blank line). JS console.log(), Python print()
Write(text) void Write(const std::string& text) Writes text (no newline) to std::cout. JS process.stdout.write(text), Python print(text, end=""), Ruby print text, C# Console.Write(text)
ErrorWriteLine(text) void ErrorWriteLine(const std::string& text) Writes text + newline to std::cerr. JS console.error(text), Python print(text, file=sys.stderr), Ruby warn text, C# Console.Error.WriteLine(text)
ErrorWrite(text) void ErrorWrite(const std::string& text) Writes text (no newline) to std::cerr. JS process.stderr.write(text), C# Console.Error.Write(text)
ReadLine() std::string ReadLine() Reads one line from std::cin (blocking). Returns the line WITHOUT the trailing newline. Returns empty string on EOF. JS readline (Node), Python input(), Ruby gets, C# Console.ReadLine(), Java Scanner.nextLine()

JavaScript variadic behavior: console.log(a, b, c) outputs each argument stringified and space-separated. The IR's StandardLibraryCallNode carries multiple arguments; the C++ backend concatenates them via mpl::mpl_to_string(arg) + " " + mpl::mpl_to_string(arg2) + " " + mpl::mpl_to_string(arg3) and passes to WriteLine. See cpp-impl.md for the exact emission pattern.


Module 2: Environment — platform and environment info

Header: MPL_Standard/CppImpl.h:65-111

Namespace: mpl::System::Environment

Function Signature Behavior Source mapping
GetVariable(name) std::optional<std::string> GetVariable(const std::string& name) Reads an environment variable. Returns std::nullopt if not set. Wraps std::getenv. JS process.env[name], Python os.environ.get(name), Ruby ENV[name], C# Environment.GetEnvironmentVariable(name), Java System.getenv(name)
SetVariable(name, value) void SetVariable(const std::string& name, const std::string& value) Sets an environment variable. Windows uses _putenv_s; POSIX uses setenv(..., 1) (overwrite). JS process.env[name] = value, Python os.environ[name] = value, Ruby ENV[name] = value, C# Environment.SetEnvironmentVariable(name, value), Java — no direct equivalent; Java frontends emit UnsupportedNode
GetCurrentDirectory() std::string GetCurrentDirectory() Returns the absolute path of the current working directory. Wraps std::filesystem::current_path. JS process.cwd(), Python os.getcwd(), Ruby Dir.pwd, C# Environment.CurrentDirectory, Java System.getProperty("user.dir"), Go os.Getwd()
SetCurrentDirectory(path) void SetCurrentDirectory(const std::string& path) Changes the CWD. Wraps std::filesystem::current_path. JS process.chdir(path), Python os.chdir(path), Ruby Dir.chdir(path), C# Environment.CurrentDirectory = path, Java — no portable equivalent; Java frontends emit UnsupportedNode
GetPlatform() std::string GetPlatform() Returns one of "win32", "darwin", "linux", "unknown". JS process.platform, Python sys.platform, Ruby RUBY_PLATFORM, C# Environment.OSVersion.Platform.ToString(), Java — uses os.name; canonicalized to "win32"/"darwin"/"linux"
GetNewLine() std::string GetNewLine() Returns "\r\n" on Windows, "\n" elsewhere. JS os.EOL, Python os.linesep, Ruby $/, C# Environment.NewLine

Module 3: IO — file system operations

Header: MPL_Standard/CppImpl.h:116-187

Namespace: mpl::System::IO

Function Signature Behavior Source mapping
ReadFileText(path) std::string ReadFileText(const std::string& path) Reads the entire file at path as UTF-8 text. Throws std::runtime_error if the file cannot be opened. JS fs.readFileSync(path, 'utf8'), Python open(path).read(), Ruby File.read(path), C# File.ReadAllText(path), Java Files.readString(Path.of(path)), Go os.ReadFile(path)
WriteFileText(path, content) void WriteFileText(const std::string& path, const std::string& content) Writes content to path, overwriting if it exists. Throws on failure. JS fs.writeFileSync(path, content), Python open(path, 'w').write(content), Ruby File.write(path, content), C# File.WriteAllText(path, content), Java Files.writeString(Path.of(path), content)
FileExists(path) bool FileExists(const std::string& path) Returns true if path exists (file or directory). JS fs.existsSync(path), Python os.path.exists(path), Ruby File.exist?(path), C# File.Exists(path), Java Files.exists(Path.of(path))
DeleteFile(path) void DeleteFile(const std::string& path) Removes the file at path. No-op if it doesn't exist. JS fs.unlinkSync(path), Python os.remove(path), Ruby File.delete(path), C# File.Delete(path), Java Files.delete(Path.of(path))
CreateDirectory(path) void CreateDirectory(const std::string& path) Creates path and any necessary parents (like mkdir -p). No-op if it already exists. JS fs.mkdirSync(path, { recursive: true }), Python os.makedirs(path, exist_ok=True), Ruby FileUtils.mkdir_p(path), C# Directory.CreateDirectory(path), Java Files.createDirectories(Path.of(path))
DeleteDirectory(path) void DeleteDirectory(const std::string& path) Recursively removes path and all contents. JS fs.rmSync(path, { recursive: true }), Python shutil.rmtree(path), Ruby FileUtils.rm_rf(path), C# Directory.Delete(path, recursive: true), Java — needs recursive walk; may emit UnsupportedNode
GetDirectoryEntries(path) std::vector<std::string> GetDirectoryEntries(const std::string& path) Lists immediate entries of path (files + subdirectories). JS fs.readdirSync(path), Python os.listdir(path), Ruby Dir.entries(path), C# Directory.GetFiles(path) (and GetDirectories), Java Files.list(Path.of(path))

Module 4: Path — path manipulation (nested in IO)

Header: MPL_Standard/CppImpl.h:159-185

Namespace: mpl::System::IO::Path

Function Signature Behavior Source mapping
Join(parts) std::string Join(const std::vector<std::string>& parts) Joins path components using the platform separator. Wraps std::filesystem::path::operator/=. JS path.join(...), Python os.path.join(...), Ruby File.join(...), C# Path.Combine(...), Java Paths.get(a, b, c).toString()
GetDirectoryName(path) std::string GetDirectoryName(const std::string& path) Returns the parent directory portion of path. Returns empty string if path has no parent. JS path.dirname(path), Python os.path.dirname(path), Ruby File.dirname(path), C# Path.GetDirectoryName(path), Java path.getParent().toString()
GetFileName(path) std::string GetFileName(const std::string& path) Returns the filename portion of path (no directory). JS path.basename(path), Python os.path.basename(path), Ruby File.basename(path), C# Path.GetFileName(path), Java path.getFileName().toString()
GetExtension(path) std::string GetExtension(const std::string& path) Returns the extension including the leading . (e.g. ".txt"). Returns empty if no extension. JS path.extname(path), Python os.path.splitext(path)[1], Ruby File.extname(path), C# Path.GetExtension(path), Java — not directly available; may emit UnsupportedNode
GetFullPath(path) std::string GetFullPath(const std::string& path) Returns the absolute path. Wraps std::filesystem::absolute. JS path.resolve(path), Python os.path.abspath(path), Ruby File.expand_path(path), C# Path.GetFullPath(path), Java path.toAbsolutePath().toString()

Module 5: Process — process control and information

Header: MPL_Standard/CppImpl.h:192-207

Namespace: mpl::System::Process

Function Signature Behavior Source mapping
Exit(code) void Exit(int code) Terminates the process with the given exit code. Wraps std::exit. JS process.exit(code), Python sys.exit(code), Ruby exit(code), C# Environment.Exit(code), Java System.exit(code), Go os.Exit(code)
GetCommandLineArgs() std::vector<std::string> GetCommandLineArgs() Returns the command-line arguments. The C++ placeholder returns {}; real implementation requires integration with main(int argc, char** argv). JS process.argv, Python sys.argv, Ruby ARGV, C# Environment.GetCommandLineArgs(), Java args parameter of main, Go os.Args
GetRuntimeVersion() std::string GetRuntimeVersion() Returns "MPL_Runtime_1.0". JS process.version, Python sys.version, Ruby RUBY_VERSION, C# Environment.Version, Java System.getProperty("java.version"), Go runtime.Version()

Module 6: Math — mathematical operations

Header: MPL_Standard/CppImpl.h:212-254

Namespace: mpl::System::Math

All functions take and return double unless otherwise noted. All wrap the corresponding <cmath> function.

Function Signature Behavior Source mapping
Abs(value) double Abs(double value) Absolute value. JS Math.abs(x), Python abs(x), Ruby x.abs, C# Math.Abs(x), Java Math.abs(x), Go math.Abs(x)
Floor(value) double Floor(double value) Round toward -∞. JS Math.floor(x), Python math.floor(x), Ruby x.floor, C# Math.Floor(x), Java Math.floor(x), Go math.Floor(x)
Ceil(value) double Ceil(double value) Round toward +∞. JS Math.ceil(x), Python math.ceil(x), Ruby x.ceil, C# Math.Ceiling(x), Java Math.ceil(x), Go math.Ceil(x)
Round(value) double Round(double value) Round half-away-from-zero. JS Math.round(x), Python round(x), Ruby x.round, C# Math.Round(x), Java Math.round(x), Go math.Round(x)
Sqrt(value) double Sqrt(double value) Square root. Returns NaN for negative input. JS Math.sqrt(x), Python math.sqrt(x), Ruby Math.sqrt(x), C# Math.Sqrt(x), Java Math.sqrt(x), Go math.Sqrt(x)
Pow(base, exponent) double Pow(double base, double exponent) base ** exponent. JS Math.pow(x, y), Python x ** y or math.pow(x, y), Ruby x ** y, C# Math.Pow(x, y), Java Math.pow(x, y), Go math.Pow(x, y)
Max(a, b) double Max(double a, double b) Maximum of two values. JS Math.max(a, b), Python max(a, b), Ruby [a, b].max, C# Math.Max(a, b), Java Math.max(a, b), Go math.Max(a, b)
Min(a, b) double Min(double a, double b) Minimum of two values. JS Math.min(a, b), Python min(a, b), Ruby [a, b].min, C# Math.Min(a, b), Java Math.min(a, b), Go math.Min(a, b)
Pi() double Pi() Returns 3.14159265358979323846. JS Math.PI, Python math.pi, Ruby Math::PI, C# Math.PI, Java Math.PI, Go math.Pi
E() double E() Returns 2.71828182845904523536. JS Math.E, Python math.e, Ruby Math::E, C# Math.E, Java Math.E, Go math.E

Module 7: String — string manipulation utilities

Header: MPL_Standard/CppImpl.h:259-315

Namespace: mpl::System::String

Function Signature Behavior Source mapping
Trim(s) std::string Trim(const std::string& s) Strips leading and trailing whitespace (spaces, tabs, \r, \n). Returns empty string if all-whitespace. JS s.trim(), Python s.strip(), Ruby s.strip, C# s.Trim(), Java s.trim(), Go strings.TrimSpace(s)
ToLower(s) std::string ToLower(const std::string& s) Lowercases ASCII characters. Locale-independent. JS s.toLowerCase(), Python s.lower(), Ruby s.downcase, C# s.ToLower(), Java s.toLowerCase(), Go strings.ToLower(s)
ToUpper(s) std::string ToUpper(const std::string& s) Uppercases ASCII characters. Locale-independent. JS s.toUpperCase(), Python s.upper(), Ruby s.upcase, C# s.ToUpper(), Java s.toUpperCase(), Go strings.ToUpper(s)
StartsWith(s, prefix) bool StartsWith(const std::string& s, const std::string& prefix) true if s begins with prefix. JS s.startsWith(prefix), Python s.startswith(prefix), Ruby s.start_with?(prefix), C# s.StartsWith(prefix), Java s.startsWith(prefix), Go strings.HasPrefix(s, prefix)
EndsWith(s, suffix) bool EndsWith(const std::string& s, const std::string& suffix) true if s ends with suffix. JS s.endsWith(suffix), Python s.endswith(suffix), Ruby s.end_with?(suffix), C# s.EndsWith(suffix), Java s.endsWith(suffix), Go strings.HasSuffix(s, suffix)
Split(s, delimiter) std::vector<std::string> Split(const std::string& s, const std::string& delimiter) Splits s on each occurrence of delimiter. Empty entries preserved if consecutive delimiters. JS s.split(delim), Python s.split(delim), Ruby s.split(delim), C# s.Split(delim), Java s.split(Pattern.quote(delim)), Go — Go lacks strings.Split with arbitrary string; uses strings.SplitAfter after wrapping
Join(parts, delimiter) std::string Join(const std::vector<std::string>& parts, const std::string& delimiter) Concatenates parts with delimiter between each. Returns empty string for empty list. JS parts.join(delim), Python delim.join(parts), Ruby parts.join(delim), C# string.Join(delim, parts), Java String.join(delim, parts), Go strings.Join(parts, delim)

Module 8: DateTime — date and time operations

Header: MPL_Standard/CppImpl.h:320-332

Namespace: mpl::System::DateTime

Function Signature Behavior Source mapping
NowUnixMs() int64_t NowUnixMs() Milliseconds since Unix epoch (1970-01-01 00:00:00 UTC). JS Date.now(), Python int(time.time() * 1000), Ruby (Time.now.to_f * 1000).to_i, C# DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), Java Instant.now().toEpochMilli(), Go time.Now().UnixMilli()
NowUnixSeconds() int64_t NowUnixSeconds() Seconds since Unix epoch. JS Math.floor(Date.now() / 1000), Python int(time.time()), Ruby Time.now.to_i, C# DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Java Instant.now().getEpochSecond(), Go time.Now().Unix()

Source-mapping notes

JavaScript

JS frontend maps language built-ins to stdlib as follows:

JS Stdlib IR
console.log(...) Console.WriteLine (variadic)
console.warn(...) / console.error(...) Console.ErrorWriteLine
process.stdout.write(...) Console.Write
process.stderr.write(...) Console.ErrorWrite
readline(...) (Node readline interface) Console.ReadLine
process.env[name] Environment.GetVariable(name)
process.env[name] = value Environment.SetVariable(name, value)
process.cwd() Environment.GetCurrentDirectory()
process.chdir(p) Environment.SetCurrentDirectory(p)
process.platform Environment.GetPlatform()
os.EOL Environment.GetNewLine()
fs.readFileSync(p, "utf8") IO.ReadFileText(p)
fs.writeFileSync(p, c) IO.WriteFileText(p, c)
fs.existsSync(p) IO.FileExists(p)
fs.unlinkSync(p) IO.DeleteFile(p)
fs.mkdirSync(p, { recursive: true }) IO.CreateDirectory(p)
fs.rmSync(p, { recursive: true }) IO.DeleteDirectory(p)
fs.readdirSync(p) IO.GetDirectoryEntries(p)
path.join(...) IO.Path.Join(...)
path.dirname(p) IO.Path.GetDirectoryName(p)
path.basename(p) IO.Path.GetFileName(p)
path.extname(p) IO.Path.GetExtension(p)
path.resolve(p) IO.Path.GetFullPath(p)
process.exit(c) Process.Exit(c)
process.argv Process.GetCommandLineArgs()
process.version Process.GetRuntimeVersion()
Math.abs/floor/ceil/round/sqrt/pow/max/min/PI/E Math.*
s.trim/toLowerCase/toUpperCase/startsWith/endsWith/split String.*
Date.now() DateTime.NowUnixMs()
Math.floor(Date.now() / 1000) DateTime.NowUnixSeconds()

Python

Python Stdlib IR
print(...) Console.WriteLine (variadic)
print(..., file=sys.stderr) Console.ErrorWriteLine
input() Console.ReadLine
os.environ.get(name) Environment.GetVariable(name)
os.environ[name] = value Environment.SetVariable(name, value)
os.getcwd() Environment.GetCurrentDirectory()
os.chdir(p) Environment.SetCurrentDirectory(p)
sys.platform Environment.GetPlatform()
os.linesep Environment.GetNewLine()
open(p).read() IO.ReadFileText(p)
open(p, 'w').write(c) IO.WriteFileText(p, c)
os.path.exists(p) IO.FileExists(p)
os.remove(p) IO.DeleteFile(p)
os.makedirs(p, exist_ok=True) IO.CreateDirectory(p)
shutil.rmtree(p) IO.DeleteDirectory(p)
os.listdir(p) IO.GetDirectoryEntries(p)
os.path.join(...) IO.Path.Join(...)
os.path.dirname(p) IO.Path.GetDirectoryName(p)
os.path.basename(p) IO.Path.GetFileName(p)
os.path.splitext(p)[1] IO.Path.GetExtension(p)
os.path.abspath(p) IO.Path.GetFullPath(p)
sys.exit(c) Process.Exit(c)
sys.argv Process.GetCommandLineArgs()
sys.version Process.GetRuntimeVersion()
math.floor/ceil/... Math.*
s.strip/lower/upper/startswith/endswith/split String.*
time.time() DateTime.NowUnixSeconds()
int(time.time() * 1000) DateTime.NowUnixMs()

Ruby

Ruby Stdlib IR
puts ... Console.WriteLine (variadic)
print ... Console.Write (variadic, no newline)
warn ... Console.ErrorWriteLine
STDIN.gets / gets Console.ReadLine
ENV[name] Environment.GetVariable(name)
ENV[name] = value Environment.SetVariable(name, value)
Dir.pwd Environment.GetCurrentDirectory()
Dir.chdir(p) Environment.SetCurrentDirectory(p)
RUBY_PLATFORM Environment.GetPlatform()
$/ Environment.GetNewLine()
File.read(p) IO.ReadFileText(p)
File.write(p, c) IO.WriteFileText(p, c)
File.exist?(p) IO.FileExists(p)
File.delete(p) IO.DeleteFile(p)
FileUtils.mkdir_p(p) IO.CreateDirectory(p)
FileUtils.rm_rf(p) IO.DeleteDirectory(p)
Dir.entries(p) IO.GetDirectoryEntries(p)
File.join(...) IO.Path.Join(...)
File.dirname(p) IO.Path.GetDirectoryName(p)
File.basename(p) IO.Path.GetFileName(p)
File.extname(p) IO.Path.GetExtension(p)
File.expand_path(p) IO.Path.GetFullPath(p)
exit(c) Process.Exit(c)
ARGV Process.GetCommandLineArgs()
RUBY_VERSION Process.GetRuntimeVersion()
Math.sqrt(x), x.floor, etc. Math.*
s.strip/downcase/upcase/start_with?/end_with?/split String.*
Time.now.to_i DateTime.NowUnixSeconds()
(Time.now.to_f * 1000).to_i DateTime.NowUnixMs()

See also

  • cpp-impl.md — C++ implementation reference (header source:line for each function)
  • runtime.md — runtime utilities (process helpers, OS info, crypto UUID, ISO 8601)
  • pqc.md — post-quantum crypto (separate module for advanced use)
  • headers.md — header hierarchy and when to include each
  • ../empl/nodes/calls.mdStandardLibraryCallNode reference