// Polyglot example: Java calling Rust native methods
//
// This example demonstrates how Java can call Rust functions via native methods.
//
// To compile and run:
// javac PolyglotExample.java
// jvmrs PolyglotExample

public class PolyglotExample {
    // Native methods implemented in Rust
    private native int add(int a, int b);
    private native String greet(String name);
    private native int[] generateFibonacci(int n);

    static {
        // Load JVMRS native library (this is automatically available in JVMRS)
        // System.loadLibrary("jvmrs");
    }

    public static void main(String[] args) {
        PolyglotExample example = new PolyglotExample();

        // Test 1: Simple arithmetic
        System.out.println("=== Test 1: Arithmetic ===");
        int sum = example.add(10, 20);
        System.out.println("10 + 20 = " + sum);

        // Test 2: String processing
        System.out.println("\n=== Test 2: String Processing ===");
        String greeting = example.greet("World");
        System.out.println(greeting);

        // Test 3: Array manipulation
        System.out.println("\n=== Test 3: Array Manipulation ===");
        int[] fib = example.generateFibonacci(10);
        System.out.print("Fibonacci sequence: ");
        for (int i = 0; i < fib.length; i++) {
            System.out.print(fib[i]);
            if (i < fib.length - 1) System.out.print(", ");
        }
        System.out.println();

        // Test 4: Java calling Java (standard)
        System.out.println("\n=== Test 4: Standard Java ===");
        int product = multiply(5, 6);
        System.out.println("5 * 6 = " + product);
    }

    // Pure Java method for comparison
    private static int multiply(int a, int b) {
        return a * b;
    }
}
