Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
823 commits
Select commit Hold shift + click to select a range
6903027
Merge branch 'instrument-with-pretty-print' of https://github.com/Chi…
ChingLongTin Apr 6, 2026
350ea44
Merge branch 'hkmc2' into instrument-with-pretty-print
ChingLongTin Apr 6, 2026
f760046
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 6, 2026
b9f4b08
rerun tests
ChingLongTin Apr 6, 2026
c165abe
WIP: take into account printing parameters within a class
ChingLongTin Apr 6, 2026
5f63b5d
formatting
ChingLongTin Apr 6, 2026
48466fc
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 6, 2026
1b018cd
Merge branch 'instrument-with-pretty-print' into add-cache
ChingLongTin Apr 6, 2026
e94bdcb
Merge branch 'instrument-with-pretty-print' of https://github.com/Chi…
ChingLongTin Apr 6, 2026
521d20b
Revert "fix renaming for staging Select"
ChingLongTin Apr 6, 2026
c0bab5b
finish S-METHOD. remove some printing in reflectioninstrumeter.scala …
yeungsinchun Apr 6, 2026
6815418
Merge remote-tracking branch 'origin/add-cache' into shape
yeungsinchun Apr 6, 2026
3af6b41
Merge branch 'hkmc2' into instrument-with-pretty-print
ChingLongTin Apr 7, 2026
356a68f
fixup! Revert "fix renaming for staging Select"
ChingLongTin Apr 7, 2026
377957f
formatting
ChingLongTin Apr 7, 2026
3f8dc37
account for class and module both being staged
ChingLongTin Apr 7, 2026
1ac49a4
Revert "add shapeProp config"
ChingLongTin Apr 7, 2026
c741cf7
Fix S-METHOD
yeungsinchun Apr 7, 2026
27a41cd
clean up
ChingLongTin Apr 7, 2026
053a56b
formatting
ChingLongTin Apr 7, 2026
ccfd299
Merge branch 'instrument-with-pretty-print' of https://github.com/Chi…
ChingLongTin Apr 7, 2026
559cfc8
fixup! clean up
ChingLongTin Apr 7, 2026
8ced994
put the cache in the correct class companion
yeungsinchun Apr 7, 2026
b5e1511
wip: super()
yeungsinchun Apr 7, 2026
ac037e1
Merge remote-tracking branch 'origin/add-cache' into shape
yeungsinchun Apr 7, 2026
b256e81
add a fixme: select has a renaming problem
yeungsinchun Apr 7, 2026
c3943cb
fix a bug in shape selection
yeungsinchun Apr 7, 2026
dd6eb8b
refresh paramlist when copying functions
ChingLongTin Apr 7, 2026
5862484
remove printing for matching classes
ChingLongTin Apr 7, 2026
bc3850f
formatting
ChingLongTin Apr 7, 2026
7fe5fa6
replace ctor$ with ctor
yeungsinchun Apr 7, 2026
b8a9ae4
refresh paramlist when copying functions
ChingLongTin Apr 7, 2026
b73dd7c
WIP: Merge branch 'add-cache' into final🐤
ChingLongTin Apr 8, 2026
6c0660f
Merge branch 'add-cache' into shape
ChingLongTin Apr 8, 2026
3747be2
fixup! Merge branch 'add-cache' into shape
ChingLongTin Apr 8, 2026
842c067
Revert CachedHash import from commit 6c0660f9d5b6c31bcf845911456bc900…
ChingLongTin Apr 8, 2026
cca02ff
update api changes to tests
ChingLongTin Apr 8, 2026
5111b7e
rework rename logic
ChingLongTin Apr 8, 2026
c244a0e
Merge branch 'shape' into final🐤
ChingLongTin Apr 8, 2026
34a1cc6
clean up
ChingLongTin Apr 8, 2026
6669cba
Merge branch 'hkmc2' into instrument-with-pretty-print
ChingLongTin Apr 8, 2026
96b7472
Merge branch 'hkmc2' into add-cache
LPTK Apr 8, 2026
fdc34bd
add todo example
ChingLongTin Apr 8, 2026
ff44ea1
WIP: import
ChingLongTin Apr 9, 2026
7618b43
Merge branch 'print-patch' into final🐤
ChingLongTin Apr 9, 2026
e1e14cd
Merge branch 'hkmc2' into instrument-with-pretty-print
LPTK Apr 9, 2026
3317194
Merge branch 'hkmc2' into add-cache
LPTK Apr 9, 2026
8d4a243
apply suggestions
ChingLongTin Apr 9, 2026
8fa0bf7
Merge branch 'hkmc2' into instrument-with-pretty-print
ChingLongTin Apr 9, 2026
1ec85b4
udpate test
ChingLongTin Apr 9, 2026
fb117a7
wip
ChingLongTin Apr 9, 2026
334a53b
make note on test case
ChingLongTin Apr 9, 2026
b490c5d
Merge branch 'add-cache' of https://github.com/ChingLongTin/mlscript …
ChingLongTin Apr 9, 2026
aec8d57
Merge branch 'instrument-with-pretty-print' into add-cache
ChingLongTin Apr 9, 2026
cca2b0a
WIP
ChingLongTin Apr 9, 2026
2db59c2
Merge branch 'print-patch' into add-cache
ChingLongTin Apr 9, 2026
d394e3e
WIP: implement module/class printing
ChingLongTin Apr 9, 2026
ef1aa89
formatting
ChingLongTin Apr 9, 2026
4d2d118
Revert "WIP"
ChingLongTin Apr 9, 2026
131f335
bump successful tests
ChingLongTin Apr 9, 2026
03e7e87
Add label/break inlining
NeilKleistGao Apr 10, 2026
bfbf348
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 10, 2026
88dd8b4
fiddle with staging current module's symbol
ChingLongTin Apr 10, 2026
bf05e3c
allow instrumenting internal functions with multiple parameter lists
ChingLongTin Apr 10, 2026
65dee51
Merge branch 'hkmc2' into add-cache
ChingLongTin Apr 10, 2026
f1c58f6
Merge branch 'hkmc2' into add-cache
LPTK Apr 11, 2026
c47219a
Merge branch 'class-and-companion' into add-cache
ChingLongTin Apr 11, 2026
8ef0b53
Merge remote-tracking branch 'origin/add-cache' into add-cache
ChingLongTin Apr 11, 2026
fb1dcc8
fixup! Merge branch 'class-and-companion' into add-cache
ChingLongTin Apr 11, 2026
a9ef160
clean up
ChingLongTin Apr 11, 2026
8f58434
fix non-top-level staged classes' ClassSymbol
ChingLongTin Apr 11, 2026
42761b5
ctor fixes
ChingLongTin Apr 11, 2026
4121318
fix symbolMap to class and module maps
ChingLongTin Apr 11, 2026
89b4baf
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
ChingLongTin Apr 11, 2026
5554027
rerun tests
ChingLongTin Apr 11, 2026
706a9a1
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 11, 2026
c894f08
fix S-Method according to the new changes
yeungsinchun Apr 12, 2026
a0c0948
Merge remote-tracking branch 'origin/add-cache' into shape
yeungsinchun Apr 12, 2026
a3adcfa
fixing a compile test
yeungsinchun Apr 12, 2026
1750f08
Merge branch 'add-cache' into final🐤
ChingLongTin Apr 12, 2026
e57d0be
fixup merge
ChingLongTin Apr 12, 2026
318dd34
some fix to make tests work
yeungsinchun Apr 12, 2026
90f3fff
fix the cache name and genMap name for classes
yeungsinchun Apr 12, 2026
4be8dda
Merge remote-tracking branch 'mlscript/hkmc2' into final🐤
ChingLongTin Apr 13, 2026
b105d3f
update tests
ChingLongTin Apr 13, 2026
5634cf7
move ctor processing to instrumentation
ChingLongTin Apr 13, 2026
21ec5b1
combine entry functions for class + companion
ChingLongTin Apr 13, 2026
0852e19
move ctor processing to instrumentation
ChingLongTin Apr 13, 2026
f27bf56
bump test
ChingLongTin Apr 13, 2026
1d2d722
update api changes to tests
ChingLongTin Apr 8, 2026
2bf9571
Fix inconsistency in class val parameter selection symbol
LPTK Apr 13, 2026
d822a54
update tests
ChingLongTin Apr 13, 2026
ef374e4
Merge branch 'hkmc2' into add-cache
LPTK Apr 14, 2026
8bc8c86
wip: logic for constructor shape propagation
yeungsinchun Apr 14, 2026
d4525f3
Merge branch 'shape' of https://github.com/ChingLongTin/mlscript into…
yeungsinchun Apr 14, 2026
aa56c36
Merge branch 'shape' into final🐤
ChingLongTin Apr 14, 2026
7cca05c
clear the ctx during ctor specialize
yeungsinchun Apr 14, 2026
5681d59
use mutable ctx instead
yeungsinchun Apr 14, 2026
4acc055
add a ctx clone to avoid polluting the cache during constructor propa…
yeungsinchun Apr 14, 2026
91d3aea
add a fixme
yeungsinchun Apr 14, 2026
0ce2951
add a fixme of shadowing during inheritance
yeungsinchun Apr 14, 2026
2a7afab
add a fixme for change in S-METHOD
yeungsinchun Apr 14, 2026
dfd5e64
remove currentThis which
yeungsinchun Apr 14, 2026
b20813e
add constraint annotation for staging
ChingLongTin Apr 14, 2026
286f444
improve error message
ChingLongTin Apr 14, 2026
ebaf4f3
lift codegen function
ChingLongTin Apr 14, 2026
5335489
update test output
ChingLongTin Apr 14, 2026
8d1f6de
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 14, 2026
009248c
update tests
ChingLongTin Apr 14, 2026
303e362
Minor fix
NeilKleistGao Apr 15, 2026
a7207ce
WIP: Add linear algebra benchmark
NeilKleistGao Apr 15, 2026
6fa973a
Staged
NeilKleistGao Apr 15, 2026
ba8d96e
Add simple benchmarking
NeilKleistGao Apr 15, 2026
7a1d53f
Merge remote-tracking branch 'origin/final🐤' into final🐤
ChingLongTin Apr 15, 2026
51b1fa5
add constraint annotation for staging
ChingLongTin Apr 14, 2026
47fd77b
Merge branch 'shape' of https://github.com/ChingLongTin/mlscript into…
ChingLongTin Apr 15, 2026
580e86d
add check to reflection constraint
ChingLongTin Apr 15, 2026
5168b92
fix abug with ctor propagation
yeungsinchun Apr 15, 2026
6f07ead
Merge branch 'shape' of https://github.com/ChingLongTin/mlscript into…
yeungsinchun Apr 15, 2026
d0d6591
fix removal of valdefn
yeungsinchun Apr 15, 2026
3e877f2
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 16, 2026
d4c207c
fixup! Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 16, 2026
de8ab53
Merge branch 'add-cache' into final🐤
ChingLongTin Apr 16, 2026
0f8b2a7
wip: allow shape inference of variables in valDefnCtx
yeungsinchun Apr 16, 2026
36802df
fix the this shape inference
yeungsinchun Apr 16, 2026
4876527
UCS
yeungsinchun Apr 16, 2026
dae3a7a
Merge branch 'shape' into final🐤
ChingLongTin Apr 16, 2026
c3b2d54
Revert "move ctor processing to instrumentation"
ChingLongTin Apr 16, 2026
7a5e20f
make the naming correct
yeungsinchun Apr 16, 2026
c0020cb
.
yeungsinchun Apr 16, 2026
39545a4
remove obsolete file
yeungsinchun Apr 16, 2026
081a812
Merge branch 'shape' into final🐤 and some fix
yeungsinchun Apr 16, 2026
4b0c647
fix subclass pattern matching
yeungsinchun Apr 17, 2026
ab3b9ce
Support multiple generation
NeilKleistGao Apr 18, 2026
e6eb83e
fix makeClassFromMap and some cleanup
yeungsinchun Apr 20, 2026
4462a46
Merge remote-tracking branch 'upstream/hkmc2' into final🐤
yeungsinchun Apr 20, 2026
e9e3d3e
update diff test
yeungsinchun Apr 20, 2026
a083a30
sop on one static operand of builtin
yeungsinchun Apr 21, 2026
20ea9aa
refactoring of sor
yeungsinchun Apr 21, 2026
8f952e6
Fix escaping characters
NeilKleistGao Apr 21, 2026
c100404
Merge from hkmc2
NeilKleistGao Apr 22, 2026
e50996b
WIP: Improve benchmarking
NeilKleistGao Apr 22, 2026
2610c0e
adjust symbol and codegen
ChingLongTin Apr 23, 2026
8f9cef3
Fix class generation
NeilKleistGao Apr 23, 2026
a33a705
WIP: collect assigned names for symbols
ChingLongTin Apr 23, 2026
dbb52f3
adjust symbol renaming/scope allocation again
ChingLongTin Apr 23, 2026
6f64e05
Improve pattern match codegen
NeilKleistGao Apr 24, 2026
104de9e
Merge remote-tracking branch 'origin/final🐤' into final🐤
ChingLongTin Apr 24, 2026
be42894
add redirect field to staged class/module symbol
ChingLongTin Apr 24, 2026
69f8387
get class symbol from valueNameCtx
ChingLongTin Apr 24, 2026
43bea8c
rerun tests
ChingLongTin Apr 24, 2026
0421e3b
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
ChingLongTin Apr 24, 2026
91500b6
Merge remote-tracking branch 'mlscript/hkmc2' into final🐤
ChingLongTin Apr 24, 2026
8493611
update test
ChingLongTin Apr 24, 2026
10a6e09
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin Apr 24, 2026
3943f6e
make symbol map global
ChingLongTin Apr 26, 2026
cfa50a2
fix this.x.f()
yeungsinchun Apr 26, 2026
6b29b81
remove an unused test
yeungsinchun Apr 26, 2026
ab5f94f
add a union(...s) for better readability and renamed binary union to …
yeungsinchun Apr 26, 2026
f79dfd4
add a test to union
yeungsinchun Apr 26, 2026
ba40d2e
fix pattern matching
yeungsinchun Apr 26, 2026
f46b247
update staged block printing
ChingLongTin Apr 26, 2026
d9824f5
make staged classes in staged moduels work
ChingLongTin Apr 26, 2026
bd4f87b
Merge remote-tracking branch 'origin/final🐤' into final🐤
ChingLongTin Apr 26, 2026
9ef8876
add a test
yeungsinchun Apr 26, 2026
4a54104
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
yeungsinchun Apr 26, 2026
0bc7da7
Merge branch 'hkmc2' into final🐤
LPTK Apr 27, 2026
7a69235
WIP: Continue to improve benchmarking and fix some minor problems
NeilKleistGao Apr 27, 2026
191ca1b
Merge branch 'final🐤' of github.com:ChingLongTin/mlscript into final🐤
NeilKleistGao Apr 27, 2026
f18ae88
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
yeungsinchun Apr 27, 2026
01f21fc
make naming consistent
yeungsinchun Apr 27, 2026
ee07223
fix the map from runtime value to symbol
yeungsinchun Apr 27, 2026
e1b8e09
Update Syntax.mls
ChingLongTin Apr 28, 2026
60c42d1
add some opt
yeungsinchun Apr 28, 2026
b28b2c4
.
yeungsinchun Apr 28, 2026
7116803
wip: print staged class cache
yeungsinchun Apr 28, 2026
c522c3f
add propagate
yeungsinchun Apr 29, 2026
0d6bbc0
optimization: remove parameters with Lit shape
yeungsinchun Apr 30, 2026
b963ddf
wip: fix val2path
yeungsinchun May 1, 2026
2f5f413
skip redirection in classes
ChingLongTin May 3, 2026
c3c6012
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
ChingLongTin May 3, 2026
ef2e6b0
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
yeungsinchun May 3, 2026
ae7a4cf
Merge from hkmc2 and fix some problems
NeilKleistGao May 4, 2026
0b57882
Add dpe
NeilKleistGao May 4, 2026
061f974
Fix class inst
NeilKleistGao May 5, 2026
9362b00
Fix class inst and missing `val`
NeilKleistGao May 5, 2026
a12222b
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
yeungsinchun May 5, 2026
1f0319c
Remove wrong forwarding
NeilKleistGao May 5, 2026
65c66dc
Fix parent class path
NeilKleistGao May 5, 2026
1eba348
Add fresh name for specialization
NeilKleistGao May 7, 2026
0937d5f
Fix ctor parameter inlining
NeilKleistGao May 7, 2026
8ab6a32
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
yeungsinchun May 7, 2026
d3a6b18
replace val2path
ChingLongTin May 8, 2026
c97249d
Merge branch 'final🐤' of https://github.com/ChingLongTin/mlscript int…
yeungsinchun May 10, 2026
819ba3c
remove DPE from specializer
yeungsinchun May 10, 2026
a708914
Rerun test
NeilKleistGao May 11, 2026
9f875b1
Merge from hkmc2
NeilKleistGao May 11, 2026
ecea593
Update hkmc2/shared/src/test/mlscript-compile/Block.mls
ChingLongTin May 11, 2026
9923004
Fix name conflicts with previous stage module and missing redirection
NeilKleistGao May 12, 2026
7284a67
limit class redirection to top-level classes
ChingLongTin May 12, 2026
751e92d
clean up codegen
ChingLongTin May 12, 2026
4556580
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 12, 2026
01a3bc9
WIP: fix tests
ChingLongTin May 12, 2026
2471e00
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 12, 2026
6447f20
Merge remote-tracking branch 'mlscript/hkmc2' into final🐤
ChingLongTin May 12, 2026
03f9b42
Rerun test
NeilKleistGao May 15, 2026
9bc976b
Fix code printing
NeilKleistGao May 15, 2026
19c6e60
cleanup
ChingLongTin May 16, 2026
1e9f182
group config into a class
ChingLongTin May 16, 2026
a960362
nit
ChingLongTin May 16, 2026
5379002
adjust printing to print referenced top-level staged classes
ChingLongTin May 16, 2026
1ea501d
rerun tests
ChingLongTin May 16, 2026
1d4aa1d
remove debug printing
ChingLongTin May 16, 2026
d6697c4
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 20, 2026
36f1a0b
rerun tests
ChingLongTin May 20, 2026
9ce7ef7
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 22, 2026
0f2f7b0
rerun test
ChingLongTin May 25, 2026
9000bb8
remove redundant assignment
ChingLongTin May 25, 2026
693b098
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 25, 2026
8319b06
update test
ChingLongTin May 25, 2026
0d13f11
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 26, 2026
568ff22
update prector printing
ChingLongTin May 26, 2026
ea358f2
Remove implicit Return flag
LPTK May 25, 2026
f1935ae
update prector printing
ChingLongTin May 26, 2026
ed226c6
Turn private fields of staged compiler-generated classes public
ChingLongTin May 25, 2026
e78d3b0
rerun tests
ChingLongTin May 26, 2026
8297813
refactor
ChingLongTin May 26, 2026
d50c7a1
fixup! refactor
ChingLongTin May 26, 2026
4fbf102
Merge branch 'add-cache' into final🐤
ChingLongTin May 27, 2026
558065d
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 27, 2026
f3b5ffc
update Value.Ref
ChingLongTin May 27, 2026
04aa916
add Value.This to Block.mls
ChingLongTin May 28, 2026
dcc22f7
formatting
ChingLongTin May 28, 2026
6ad8790
remove valueNameCtx
ChingLongTin May 28, 2026
9c68e37
Revert "formatting"
ChingLongTin May 28, 2026
bc9758d
formatting
ChingLongTin May 28, 2026
de6dc1f
Merge remote-tracking branch 'mlscript/hkmc2' into add-cache
ChingLongTin May 28, 2026
3fbb1f0
rerun test
ChingLongTin May 28, 2026
8e8a52d
remove implicit parameter from Return
ChingLongTin May 29, 2026
77945d2
simplify printing with noModuleCheck
ChingLongTin May 29, 2026
744dd38
copyediting
ChingLongTin May 29, 2026
d843eb5
remove unused variables defined when staging
ChingLongTin May 29, 2026
ed2fef8
add carveout for top-level user-definde staged classes
ChingLongTin May 29, 2026
af3bf82
rerun tests
ChingLongTin May 29, 2026
0844797
Merge branch 'fix-private-fields' into final🐤
ChingLongTin May 29, 2026
c047f69
Merge remote-tracking branch 'mlscript/hkmc2' into final🐤
ChingLongTin May 29, 2026
86cf7e6
Merge branch 'add-cache' into final🐤
ChingLongTin May 30, 2026
feab33d
fix Value.Ref
ChingLongTin May 30, 2026
80bfd72
WIP: fix tests
ChingLongTin May 30, 2026
10bbc0e
Fix missing cases and wrong rewrite
NeilKleistGao Jun 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion hkmc2/js/src/main/scala/hkmc2/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ class Compiler(paths: MLsCompiler.Paths)(using cctx: CompilerCtx):
perFileDiagnostics

@JSExportTopLevel("Paths")
final class Paths(prelude: Str, runtime: Str, term: Str) extends MLsCompiler.Paths:
final class Paths(prelude: Str, runtime: Str, term: Str, block: Str, spHelper: Str, option: Str, ss: Str) extends MLsCompiler.Paths:
val preludeFile = Path(prelude)
val runtimeFile = Path(runtime)
val termFile = Path(term)
val blockFile = Path(block)
val specializeHelpersFile = Path(spHelper)
val optionFile = Path(option)
val shapeSetFile = Path(ss)
2 changes: 1 addition & 1 deletion hkmc2/js/src/test/scala/hkmc2/CompilerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CompilerTest extends AnyFunSuite:
None
.toMap + ("/std/Prelude.mls" -> node.fs.readFileSync(preludePath, "utf-8"))

private val paths = new Paths("/std/Prelude.mls", "/std/Runtime.mjs", "/std/Term.mjs")
private val paths = new Paths("/std/Prelude.mls", "/std/Runtime.mjs", "/std/Term.mjs", "/std/Block.mls", "/std/SpecializeHelpers.mls", "/std/Option.mls", "/std/ShapeSet.mls")

private def createCompiler(): (InMemoryFileSystem, Compiler) =
val stdLib = loadStandardLibrary()
Expand Down
6 changes: 5 additions & 1 deletion hkmc2/jvm/src/test/scala/hkmc2/CompileTestRunnerBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ abstract class CompileTestRunnerBase(
paths = new MLsCompiler.Paths:
val preludeFile = mainTestDir / "mlscript" / "decls" / "Prelude.mls"
val runtimeFile = mainTestDir / "mlscript-compile" / "Runtime.mjs"
val termFile = mainTestDir / "mlscript-compile" / "Term.mjs",
val termFile = mainTestDir / "mlscript-compile" / "Term.mjs"
val blockFile = mainTestDir / "mlscript-compile" / "Block.mjs"
val optionFile = mainTestDir / "mlscript-compile" / "Option.mjs"
val shapeSetFile = mainTestDir / "mlscript-compile" / "ShapeSet.mjs"
val specializeHelpersFile = mainTestDir / "mlscript-compile" / "SpecializeHelpers.mjs",
mkRaise = report.mkRaise
)
compiler.compileModule(file)
Expand Down
23 changes: 20 additions & 3 deletions hkmc2/shared/src/main/scala/hkmc2/MLsCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ object MLsCompiler:
def preludeFile: io.Path
def runtimeFile: io.Path
def termFile: io.Path
def blockFile: io.Path
def specializeHelpersFile: io.Path
def optionFile: io.Path
def shapeSetFile: io.Path

/**
* The compiler that compiles MLscript code into JavaScript modules.
Expand Down Expand Up @@ -103,14 +107,27 @@ class MLsCompiler
case Term.Quoted(_) | Term.Unquoted(_) => true
case Term.Ref(sym) => sym === State.termSymbol
case _ => t.subTerms.exists(findQuote)
def findStage(t: semantics.Statement): Bool = t match
case d: semantics.Definition => d.hasStagedModifier.isDefined
case _ => t.subStatements.exists(findStage)

val hasQuote = findQuote(blk0)
val isStaged = findStage(blk0)
// println(s"yydz: ${blk0.subTerms}")
val blk = new Term.Blk(
Import(State.runtimeSymbol, runtimeFile.toString, runtimeFile) ::
// Only import `Term.mls` when necessary.
// Only import files when necessary.
(if hasQuote then
Import(State.termSymbol, termFile.toString, termFile) :: blk0.stats
Import(State.termSymbol, termFile.toString, termFile) :: Nil
else
blk0.stats),
Nil) :::
(if isStaged then
Import(State.optionSymbol, optionFile.toString, optionFile) ::
Import(State.shapeSetSymbol, shapeSetFile.toString, shapeSetFile) ::
Import(State.blockSymbol, blockFile.toString, blockFile) ::
Import(State.specializeHelpersSymbol, specializeHelpersFile.toString, specializeHelpersFile) :: Nil
else
Nil) ::: blk0.stats,
blk0.res
)
val low = ltl.givenIn:
Expand Down
4 changes: 1 addition & 3 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -761,17 +761,15 @@ final case class ClsLikeBody(
ctor.freeVars ++ methods.flatMap(_.freeVars)
lazy val size = 1 + methods.map(_.size).sum + ctor.size

/*
object ClsLikeBody:
// TODO rm `empty`? it's currently unused
def empty(id: Tree.Ident)(using State) = ClsLikeBody(
isym = ModuleOrObjectSymbol(Tree.DummyTypeDef(syntax.Mod), id),
methods = Nil,
privateFields = Nil,
publicFields = Nil,
ctor = End(),
annotations = Nil,
)
*/

final case class Handler(
sym: BlockMemberSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class FirstClassFunctionTransformer
End()), End(), None, None)(N, annotations = Nil)

private def getParamList(l: BlockMemberSymbol): Option[ParamList] = funDefns.get(l) match
case Some(fd) => fd.params.headOption
case Some(fd) => fd.params.headOption.map(pl =>
ParamList(pl.flags, pl.params.map(p => Param(p.flags, VarSymbol(p.sym.id), p.sign, p.modulefulness)), pl.restParam))
case _ => l.tsym.flatMap(getParamList)

private def getParamList(ts: TermSymbol): Option[ParamList] =
Expand Down Expand Up @@ -117,4 +118,19 @@ class FirstClassFunctionTransformer
def transform(b: Block): Block =
val desugared = new DesugarMultipleParamList().applyBlock(b)
new CollectFunDefns().applyBlock(desugared)
applyBlock(desugared)
new LabelTransformer().applyBlock(applyBlock(desugared))


class LabelTransformer(using State, Raise) extends BlockTransformer(new SymbolSubst()):
private val contMap = HashMap.empty[Symbol, Symbol]

override def applyBlock(b: Block): Block = b match
case Label(label, false, body, rest) =>
val contSym = BlockMemberSymbol("cont$", Nil, false)
val contFun = FunDefn.withFreshSymbol(N, contSym, PlainParamList(Nil) :: Nil, rest)(N, Nil)
contMap.addOne(label -> contSym)
super.applyBlock(Scoped(Set(contSym), Define(contFun, body)))
case Break(label) => contMap.get(label) match
case Some(sym: Symbol) => Return(Call(Value.Ref(sym, N), Nil ne_:: Nil)(true, false, false))
case _ => super.applyBlock(b)
case _ => super.applyBlock(b)
5 changes: 1 addition & 4 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/Lowering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,13 @@ class Lowering()(using Config, TL, Raise, State, Ctx, SymbolPrinter):
mod.classCompanion match
case S(comp) => comp.defn.getOrElse(wat("Module companion without definition", mod.companion))
case N =>
val stagedAnnots = mod.annotations.collect {
case Annot.Modifier(Keyword.`staged`) => Annot.Modifier(Keyword.`staged`)
}
ClassDef.Plain(mod.owner, syntax.Cls, new ClassSymbol(Tree.DummyTypeDef(syntax.Cls), mod.sym.id),
mod.bsym,
Nil,
N,
ObjBody(Blk(Nil, UnitVal())),
S(mod.sym),
stagedAnnots,
Nil,
Nil,
N,
)
Expand Down
Loading