Skip to content

Conversation

@chengluyu
Copy link
Member

@chengluyu chengluyu commented Dec 1, 2025

When I make web demos, one of the headaches is that os.Path doesn’t compile when the target is JavaScript. I made a hack on my web demo branch. But the implementation is a bit crappy, especially after merging the latest changes for a few times. Therefore, I want to introduce a path representation and abstract read operations that both supports a real file system or a virtual one (e.g., when the compiler is running on the web).

This PR intends to do the following things.

  • Provide an abstraction layer of path and file system operations.
  • Call the MLscript compiler from JavaScript.
    • Compile single MLscript source file.
    • Compile multiple MLscript source files.
  • Provide a minimal web demo to showcase the ability to compile multiple files. This will be done in a separate PR.

@chengluyu chengluyu marked this pull request as ready for review December 11, 2025 10:46
@LPTK
Copy link
Contributor

LPTK commented Dec 11, 2025

Nice! But please remove all useless whitespace changes from the diff.

@chengluyu chengluyu requested a review from LPTK December 11, 2025 18:32
Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

However, your changes broke diagnostic reporting.

First, the diagnostics are no longer colored in the console.

Second, they are no longer synchronized. For instance, add a bunch of errors in compilation-test files and watch the output get mangled.

Screenshot 2025-12-12 at 15 00 48

Compare with the previous output:

Screenshot 2025-12-12 at 15 02 47

While the Compiling: and /!!!\ Error messages are not synchronized (would be easy to fix), each error is properly reported separately and not interleaved.

Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it mostly LGTM, but please address these extra commnets and what we discussed by messages.

val preludeFile = preludePath
val runtimeFile = rootPath/"hkmc2"/"shared"/"src"/"test"/"mlscript-compile"/"Runtime.mjs"
val termFile = rootPath/"hkmc2"/"shared"/"src"/"test"/"mlscript-compile"/"Term.mjs",
mkRaise = ReportFormatter(System.out.println, colorize = false).mkRaise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no color there?

Suggested change
mkRaise = ReportFormatter(System.out.println, colorize = false).mkRaise
mkRaise = ReportFormatter(System.out.println, colorize = true).mkRaise

Comment on lines +9 to +12
import _root_.io.methvin.better.files.*
import _root_.io.methvin.watcher.{DirectoryWatcher, PathUtils}
import _root_.io.methvin.watcher.{DirectoryChangeEvent, DirectoryChangeListener}
import _root_.io.methvin.watcher.hashing.{FileHash, FileHasher}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import _root_.io.methvin.better.files.*
import _root_.io.methvin.watcher.{DirectoryWatcher, PathUtils}
import _root_.io.methvin.watcher.{DirectoryChangeEvent, DirectoryChangeListener}
import _root_.io.methvin.watcher.hashing.{FileHash, FileHasher}
import _root_.io.methvin
import methvin.better.files.*
import methvin.watcher.{DirectoryWatcher, PathUtils, DirectoryChangeEvent, DirectoryChangeListener}
import methvin.watcher.hashing.{FileHash, FileHasher}

Comment on lines +514 to +517
/** Check if the term satisfies the predicate. The reason I did not use
* `subTerms` and `subStatements` for traversal is that they consume a
* considerable amount of time and memory, and they fail to terminate on
* `Rule.mls`. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description sounds like the problem isn't purely time and memory, but more problematically these things having the wrong complexity. It's easy to imagine, given that they use list concatenation. Could you try making them return Vectors instead?

Copy link
Contributor

@LPTK LPTK Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if that still doesn't work well enough, it'll be better to have aforeach method that doesn't recurse deeply into the term (recursion should be done by the caller, for finer control).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants