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:

LenguajeEstadoSe ejecuta comoIniciar conInteroperabilidad
JavaScriptCompatibleScriptelide app.js, elide -s CODEPython: --interop; WASM: sin opción
TypeScriptCompatibleScript, sin tiposelide app.ts, elide -l ts -s CODEComo JavaScript
PythonExperimentalPython 3.13elide app.py, elide python -m MODJavaScript: --interop
WebAssemblyExperimentalComando WASI Preview 1elide app.wasm (_start o _main)Desde JS/TS, sin opción
Java, KotlinCompatibleCompilado, se ejecuta en el JDK incluidoelide run Main.kt, proyectos elide.pklNinguna
PklCompatibleConfiguraciónManifiestos elide.pklNinguna

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:

ProgramaError
sum.pyValueError: polyglot language 'js' not found
main.mjsCannot 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?