Class RuntimeBuiltinFunctions
Runtime Built-in Functions
This class provides a collection of built-in functions derived from the
Runtime API. These functions expose system-level capabilities such as
memory management, garbage collection, and process control to the Naftah scripting environment.
Each function can be invoked using its Arabic name as defined in the NaftahFn annotations.
Example usage:
اخرج(0)
ذاكرة_إجمالية()
عدد_المعالجات()
جمع_القمامة()
- Author:
- Chakib Daii
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic intReturns the number of processor cores available to the JVM.static voidTerminates the currently running program with the specified exit code.static longReturns the amount of free (unused) memory currently available to the JVM.static longReturns the maximum amount of memory that the JVM will attempt to use.static voidRequests that the Java Virtual Machine perform garbage collection.static longReturns the total amount of memory currently allocated by the JVM.static longCalculates the amount of memory currently in use by the JVM.
-
Constructor Details
-
RuntimeBuiltinFunctions
private RuntimeBuiltinFunctions()Private constructor to prevent instantiation. ThrowsNaftahBugErrorif called.
-
-
Method Details
-
exit
Terminates the currently running program with the specified exit code.This method delegates directly to
System.exit(int). A code of0usually indicates normal termination.Example:
اخرج(0)- Parameters:
code- the exit code (usually 0 or a positive number to indicate an error type)
-
totalMemory
public static long totalMemory()Returns the total amount of memory currently allocated by the JVM.- Returns:
- the total memory (in bytes) currently allocated.
-
maxMemory
public static long maxMemory()Returns the maximum amount of memory that the JVM will attempt to use.- Returns:
- the maximum memory (in bytes) available to the JVM.
-
freeMemory
public static long freeMemory()Returns the amount of free (unused) memory currently available to the JVM.- Returns:
- the amount of free memory (in bytes).
-
usedMemory
public static long usedMemory()Calculates the amount of memory currently in use by the JVM.Computed as:
totalMemory() - freeMemory().- Returns:
- the amount of used memory (in bytes).
-
runGarbageCollector
public static void runGarbageCollector()Requests that the Java Virtual Machine perform garbage collection.This method only suggests that the JVM initiate garbage collection and does not guarantee that it will happen immediately or at all.
-
availableProcessors
public static int availableProcessors()Returns the number of processor cores available to the JVM.This typically reflects the number of logical processors available on the host machine.
- Returns:
- the number of available processors.
-