Class RuntimeBuiltinFunctions

java.lang.Object
org.daiitech.naftah.builtin.functions.RuntimeBuiltinFunctions

public final class RuntimeBuiltinFunctions extends Object

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

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Returns the number of processor cores available to the JVM.
    static void
    exit(Number code)
    Terminates the currently running program with the specified exit code.
    static long
    Returns the amount of free (unused) memory currently available to the JVM.
    static long
    Returns the maximum amount of memory that the JVM will attempt to use.
    static void
    Requests that the Java Virtual Machine perform garbage collection.
    static long
    Returns the total amount of memory currently allocated by the JVM.
    static long
    Calculates the amount of memory currently in use by the JVM.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RuntimeBuiltinFunctions

      private RuntimeBuiltinFunctions()
      Private constructor to prevent instantiation. Throws NaftahBugError if called.
  • Method Details

    • exit

      public static void exit(Number code)
      Terminates the currently running program with the specified exit code.

      This method delegates directly to System.exit(int). A code of 0 usually 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.