Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Running Phel in browser via PHP-WASM#816

jasalt started this conversation inIdeas
Discussion options

jasalt
May 30, 2025
Collaborator

I did some exploration to get the Phel classes loading from Composer installation and Phel evaluation of working from JavaScript withhttps://github.com/seanmorris/php-wasm. Copying Composer files to Emscripten filesystem is bit of a hurdle but afterwards I figured out following custom Phel initialization in PHP script that publishesphelEval function to JS.

# This is the WASM PHP entrypointrequire_once'/vendor/autoload.php';try {Gacela\Framework\Gacela::bootstrap("/", \Phel\Phel::configFn());$runFacade =newPhel\Run\RunFacade();$srcDirectories =$runFacade->getAllPhelDirectories();$namespaceInformation =$runFacade->getDependenciesForNamespace($srcDirectories, ['phel\\core']);// Suppress deprecation warnings from evalFileerror_reporting(E_ALL ^E_DEPRECATED);//  ^ E_NOTICE// Deprecated: Implicit conversion from float 4294967295 to int loses precision in /vendor/phel-lang/phel-lang/src/php/Compiler/Domain/Emitter/OutputEmitter/SourceMap/VLQ.php on line 158foreach ($namespaceInformationas$info) {$runFacade->evalFile($info);        }$compilerOpts =newPhel\Compiler\Infrastructure\CompileOptions();functionphelEval($phelCode){global$runFacade,$compilerOpts;$runFacade->eval($phelCode,$compilerOpts);}phelEval('(let [a 4] (println "Phel calculation is " (+ 96 a)))');phelEval('(println "YAY")');}catch (\Exception$e) {echo"Error using Phel:" .$e->getMessage() ."\n";}

Example code with some more contexthttps://git.sr.ht/~jasalt/php-wasm-testing/tree/master/item/composer-autoload-phel.

Looking possibly to make something useful with this like a REPL for Phel docs when I have time but thought to share this snippet here for now if somebody finds use for it.

linux_desktop_recording-2025-05-30_14.40.25.mp4
You must be logged in to vote

Replies: 1 comment

Comment options

@jasalt after 0.17, Gacela will be totally hidden from Phel (code)

- Gacela\Framework\Gacela::bootstrap("/", \Phel\Phel::configFn());+ \Phel\Phel::bootstrap("/");

https://github.com/phel-lang/phel-lang/releases/tag/v0.17.0

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
2 participants
@jasalt@Chemaclass

[8]ページ先頭

©2009-2025 Movatter.jp