Saltar al contenido

Lenguajes e interoperabilidad

Qué lenguajes ejecuta Elide, cómo iniciar cada uno y cómo Python, JavaScript y WebAssembly se llaman entre sí con --interop y en el REPL.

Leer sin conexiónelide help --lang es languages

En esta página

Elide ejecuta estos lenguajes desde un único binario:

Lenguaje Estado Se ejecuta como Iniciar con Interoperabilidad
JavaScript Compatible Script elide app.js, elide -s CODE Python: --interop; WASM: sin opción
TypeScript Compatible Script, sin tipos elide app.ts, elide -l ts -s CODE Como JavaScript
Python Experimental Python 3.13 elide app.py, elide python -m MOD JavaScript: --interop
WebAssembly Experimental Comando WASI Preview 1 elide app.wasm (_start o _main) Desde JS/TS, sin opción
Java, Kotlin Compatible Compilado, se ejecuta en el JDK incluido elide run Main.kt, proyectos elide.pkl Ninguna
Pkl Compatible Configuración Manifiestos elide.pkl Ninguna

elide info lista los lenguajes de su binario; elide setup python añade Python. Páginas por lenguaje: JavaScript y TypeScript, Python, Java y Kotlin, WebAssembly.

elide --interop: Python llama a JavaScript y JavaScript importa Python
 ~/demo  bat mod.py main.mjs
───────┬────────────────────────────────────────────────────────────────────────────────────────────
       │ File: mod.py
       │ Size: 58 B
───────┼────────────────────────────────────────────────────────────────────────────────────────────
   1   │ def greet(name):
   2   │     return f"Hello from Python, {name}!"
───────┴────────────────────────────────────────────────────────────────────────────────────────────
───────┬────────────────────────────────────────────────────────────────────────────────────────────
       │ File: main.mjs
       │ Size: 58 B
───────┼────────────────────────────────────────────────────────────────────────────────────────────
   1   │ import py from "./mod.py";
   2   │ 
   3   │ console.log(py.greet("Ada"));
───────┴────────────────────────────────────────────────────────────────────────────────────────────
 ~/demo  elide --interop main.mjs
Hello from Python, Ada!
 

Python llama a JavaScript

python
# sum.py
from elide import js

print(js("[1,2,3].reduce((a,b)=>a+b,0)"))
utf-8 · python · Líneas: 4
Terminal
bash
elide --interop python sum.py
text
6
utf-8 · text · Líneas: 1

JavaScript importa Python

python
# mod.py
def greet(name):
    return f"hello {name}"
utf-8 · python · Líneas: 3
javascript
// main.mjs
import mod from "./mod.py";
console.log(mod.greet("elide"));
utf-8 · javascript · Líneas: 3
Terminal
bash
elide --interop main.mjs
text
hello elide
utf-8 · text · Líneas: 1

La exportación default es el módulo de Python. Use una entrada .mjs.

Sin --interop

Cada programa ejecuta solo su lenguaje de entrada, más WebAssembly en JS/TS. Las llamadas entre lenguajes fallan:

Programa Error
sum.py ValueError: polyglot language 'js' not found
main.mjs Cannot import 'mod.py': JavaScript entries run without Python. Re-run with --interop to use it.

Pase --interop solo a los programas que hacen llamadas entre lenguajes. Con --interop, los hilos de Python fallan con Creating threads is not allowed.

JavaScript y WebAssembly

javascript
import { add } from "./math.wasm";
console.log(add(1, 2));
utf-8 · javascript · Líneas: 2

Las importaciones de .wasm y la API WebAssembly funcionan en todos los programas de JavaScript y TypeScript. Cuando Python está instalado, los módulos que usan instrucciones SIMD fallan con Vector instructions are not enabled.

En el REPL

El REPL comparte valores entre lenguajes sin --interop; consulte REPL interactivo.

Ejemplos

¿Te resultó útil esta página?