Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New MLscript frontend #187

Merged
merged 533 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
533 commits
Select commit Hold shift + click to select a range
ee1ab19
Merge branch 'new-definition-typing' into ucs-paper
chengluyu May 5, 2023
7a6d03c
add tests for inheritance
Meowcolm024 May 6, 2023
fabe0d3
Add abstract keyword
NeilKleistGao May 8, 2023
d335b3f
Add :e for the rejected test case
NeilKleistGao May 8, 2023
bad4013
WIP: Try to fix new keyword generation in backend
NeilKleistGao May 8, 2023
cd2a52d
WIP: Update test cases
NeilKleistGao May 10, 2023
9734d91
WIP: Undo changes for abstract
NeilKleistGao May 10, 2023
f4328ae
WIP: Try to add abstract and optional parameters(not ready)
NeilKleistGao May 10, 2023
eea3c1e
WIP: Freeze object before returning(not ready)
NeilKleistGao May 10, 2023
75d1470
Fix freshening of type definitions/methods and do not generalize meth…
LPTK May 10, 2023
9cda253
FIXED type members of parent trait
Meowcolm024 May 10, 2023
b2c5592
WIP: Support extend and pattern matching(not ready)
NeilKleistGao May 11, 2023
2d35696
WIP Add a test
LPTK May 11, 2023
e11001b
WIP: Refactor code
NeilKleistGao May 12, 2023
84a30f0
WIP: Force new in new NuTypeSym
NeilKleistGao May 12, 2023
176f7ce
WIP: Fix New generation
NeilKleistGao May 12, 2023
66d41f2
Fix comments
chengluyu May 12, 2023
8694f1c
WIP: Rename field and generate .class in new
NeilKleistGao May 16, 2023
f8c603a
WIP: Change NuTypeDef
NeilKleistGao May 16, 2023
37481e7
WIP: Add assignment for constructor and move constructor outside the …
NeilKleistGao May 17, 2023
34b1864
Update CI: run on all PRs
LPTK May 17, 2023
a098242
clean up
Meowcolm024 May 17, 2023
374f7c0
WIP: Generate overrided constructor
NeilKleistGao May 17, 2023
6531044
fix trait error msg
Meowcolm024 May 17, 2023
bd49339
small cleanup
Meowcolm024 May 17, 2023
002615d
Check constructor in mixin and module, fix spelling and improve code
NeilKleistGao May 18, 2023
0781e3e
Remove comment
NeilKleistGao May 18, 2023
70fd442
Fix minor problems mentioned in PR comments
chengluyu May 18, 2023
b89fa16
Fix the warning in UCS source files
chengluyu May 18, 2023
14a232a
Try to fix more warnings
chengluyu May 18, 2023
1fc7627
merge the class inheritance function
Meowcolm024 May 18, 2023
87f4fab
Update error message
NeilKleistGao May 18, 2023
c9edfca
Refactor
NeilKleistGao May 18, 2023
fec2eb8
fix some trait problems
Meowcolm024 May 18, 2023
2ea30ef
Use statement
NeilKleistGao May 19, 2023
771f60c
Add various tests
LPTK May 19, 2023
4848808
refactor
Meowcolm024 May 19, 2023
988f5fc
Merge branch 'trait-impl' of github.com:Meowcolm024/mlscript into tra…
Meowcolm024 May 19, 2023
ab848a1
WIP Refactor: move parent spec typing out of complete()
LPTK May 20, 2023
380209c
Change body's type
NeilKleistGao May 20, 2023
bf67ba8
WIP Add some tests
LPTK May 22, 2023
2cb36d4
WIP Use proper Dummy typed declarations
LPTK May 22, 2023
adf0a71
WIP Small improvements in error message
LPTK May 22, 2023
42ea186
Use Blk
NeilKleistGao May 22, 2023
4c8b5d5
WIP Improve memberUnion
Meowcolm024 May 22, 2023
7b06974
Changes from meeting
LPTK May 22, 2023
f45cfeb
WIP Add/update tests
LPTK May 22, 2023
7d68faf
refined frenshenAbove and refreshGen
Meowcolm024 May 22, 2023
5761dad
fix refresh for mixins
Meowcolm024 May 22, 2023
7da889c
Update shared/src/main/scala/mlscript/NewParser.scala
NeilKleistGao May 22, 2023
c71156a
WIP Add test related to polymorphism level mismatches in inheritance …
LPTK May 22, 2023
76c422f
WIP add test (ref to member in base class)
Meowcolm024 May 22, 2023
be8fe0c
WIP Rename test and add one case
LPTK May 22, 2023
7cc87c0
WIP add ty arg inference for class and traits
Meowcolm024 May 22, 2023
7405870
Make params optional
NeilKleistGao May 22, 2023
f2e0815
Merge branch 'abstract' of github.com:NeilKleistGao/mlscript into abs…
NeilKleistGao May 22, 2023
f5ff36c
Rerun test
NeilKleistGao May 22, 2023
17d05de
Describe `FIXME` without actual errors
chengluyu May 22, 2023
8ca4e93
Merge pull request #157 from chengluyu/ucs-paper
LPTK May 22, 2023
3e77b1c
WIP add type arg support for mixins
Meowcolm024 May 24, 2023
725e8db
WIP added tests
Meowcolm024 May 24, 2023
21d6dc5
small fix
Meowcolm024 May 25, 2023
c480f9a
Merge from new-definition-typing
NeilKleistGao May 25, 2023
856eff5
Refactor code
NeilKleistGao May 25, 2023
f8e792b
Don't print empty list for classes without parameters
NeilKleistGao May 26, 2023
ab12a0c
Ignore traits in inheritance clauses and improve translate parent err…
NeilKleistGao May 26, 2023
15209b6
Try to fix warnings
NeilKleistGao May 26, 2023
f4e0e69
Refactor
NeilKleistGao May 27, 2023
703200f
Fix errors in compiler
NeilKleistGao May 27, 2023
ca3e01d
Minor polish
LPTK May 31, 2023
73df7bd
Rename Ass to Eqn
LPTK May 31, 2023
b547a71
Update lifter pretty printer
NeilKleistGao May 31, 2023
a682450
Merge pull request #161 from NeilKleistGao/abstract
LPTK May 31, 2023
8e71947
WIP Fix general handling of signatures in classes and traits
LPTK May 31, 2023
d2d6451
Fix definition levels, freshening, and inferred pattern type arguments
LPTK May 31, 2023
4663ca6
Merge remote-tracking branch 'mlscript/new-definition-typing' into tr…
LPTK May 31, 2023
6bc021b
Minor changes
LPTK May 31, 2023
350f893
Do not make class pattern typing complete the class
LPTK May 31, 2023
49d452d
Try to avoid forcing completion upon field lookup
LPTK May 31, 2023
410300b
Fix trait parents handling
NeilKleistGao Jun 1, 2023
0feb065
Remove unnecessary TypedTypingUnit fields from typed type defs
LPTK Jun 1, 2023
2c6a16e
Make large refactoring, cleanup, and misc improvements pass
LPTK Jun 2, 2023
7ef1ded
Completely refactor inheritance checking code and fix many related is…
LPTK Jun 2, 2023
49d8ce7
Merge remote-tracking branch 'origin/new-definition-typing' into trai…
LPTK Jun 5, 2023
74d911b
Remove all the now useless `:NoJS` commands related to traits
LPTK Jun 5, 2023
03c1488
Merge pull request #163 from Meowcolm024/trait-impl
LPTK Jun 5, 2023
7e04047
Fix top-level mutually-recursive functions (#167)
NeilKleistGao Jun 5, 2023
8c4ce9d
New primitive types (#168)
LPTK Jun 6, 2023
4f373ec
Rename namespace/Nms -> module/Mod
LPTK Jun 6, 2023
3a521dc
Clean up constraint solver, removing unused def
LPTK Jun 6, 2023
0bdddde
Refactor abstract instantiation check
LPTK Jun 6, 2023
e2d140b
Improve type inference with variant type definitions
LPTK Jun 9, 2023
7c82d61
Don't type inherited mixin implementations polymorphically when tying…
LPTK Jun 9, 2023
b442056
Fix `this` capture for mixins in `globalThis` (#169)
NeilKleistGao Jun 9, 2023
7e4aca7
Update web demo examples and code
LPTK Jun 6, 2023
85fff5a
Do not refrain from expanding type aliases in constraint solver
LPTK Jun 10, 2023
367052d
Generalize methods more aggressively anywhere except mixins
LPTK Jun 12, 2023
acb6f6c
Add minor test file
LPTK Jun 19, 2023
8b14d68
Add tests showcasing we need to reject unapplied method accesses in t…
LPTK Jun 7, 2023
9f6e3eb
Add a couple of tests with functional trait signatures
LPTK Jun 26, 2023
2dd129e
Minor test update
LPTK Jun 28, 2023
e826d46
Minor test case addition
LPTK Jul 3, 2023
d121a31
Make various minor improvements
LPTK Jul 4, 2023
4f99999
Add UCS test showing current limitations
LPTK Jul 14, 2023
15c6ea1
Add interesting "array programming" test + fixes to make it work
LPTK Jul 17, 2023
687f39d
Add more interesting tests and some partial fixes
LPTK Jul 17, 2023
cf89a4d
Print AST on :p option + add small test
LPTK Jul 19, 2023
3a212cc
Add mixin test mirroring the TACO website post's example
LPTK Jul 20, 2023
d87c8ba
WIP: Cherry pick from val-let
NeilKleistGao Jun 9, 2023
f6acc41
WIP: Parse val in params
NeilKleistGao Jun 9, 2023
481ad44
WIP: Fix let-binding generation
NeilKleistGao Jun 10, 2023
9d8f897
WIP: Add unapply
NeilKleistGao Jun 10, 2023
2d6baec
WIP: Apply new pattern matching
NeilKleistGao Jun 12, 2023
ebc848a
WIP: Use array patterns and fix several problems
NeilKleistGao Jun 12, 2023
275e05b
WIP: Rerun test for cherry-pick
NeilKleistGao Jul 31, 2023
fe05a17
WIP: Implement val parameters(not ready)
NeilKleistGao Jul 31, 2023
50274e0
WIP: Fix captured variable access and ctor parameter overriding
NeilKleistGao Aug 4, 2023
e067ed7
WIP: Update test cases
NeilKleistGao Aug 4, 2023
1e6b659
WIP: Add virtual keyword
NeilKleistGao Aug 4, 2023
0daf10b
WIP: Add virtual check
NeilKleistGao Aug 8, 2023
38f420d
WIP: Add a primitive implementation to prevent this in ctors
NeilKleistGao Aug 13, 2023
258b722
WIP: Refactor code
NeilKleistGao Aug 14, 2023
b9f233f
WIP: Fix indirect `this` access in val rhs
NeilKleistGao Aug 14, 2023
59d2bb1
WIP: Add exception check and fix missing base class members
NeilKleistGao Aug 17, 2023
571ca82
WIP: Reject unqualified accesses to virtual members
NeilKleistGao Aug 21, 2023
c588f82
WIP: Fix signature symbol declarations and qualification check
NeilKleistGao Aug 21, 2023
5c193b8
WIP: Ignore signatures when checking this
NeilKleistGao Aug 21, 2023
3ff3238
WIP: Refactor code and improve test cases
NeilKleistGao Aug 21, 2023
f44a154
WIP: Fix Fld in ClassLifter
NeilKleistGao Aug 21, 2023
0a28326
WIP: Fix unapply with ucs
NeilKleistGao Aug 22, 2023
76ca37a
WIP: Refactor code
NeilKleistGao Aug 22, 2023
f4dca73
WIP: Fix missing case in class lifter
NeilKleistGao Aug 22, 2023
d7d0281
WIP: Refactor code
NeilKleistGao Aug 23, 2023
e5cfdeb
WIP: Remove Unapp and use normal App instead
NeilKleistGao Aug 25, 2023
03bf216
WIP: temp change
NeilKleistGao Aug 28, 2023
52ca8c8
WIP: Temp save
NeilKleistGao Aug 29, 2023
b38cd37
WIP: Temp save
NeilKleistGao Aug 29, 2023
d60314b
WIP: Remove CapturedSymbol
NeilKleistGao Aug 29, 2023
c5ea73d
WIP: Add forwarders for unapply methods
NeilKleistGao Aug 29, 2023
cdf4eac
Add test with TODOs for classes + minor fixes
LPTK Aug 29, 2023
bce198c
WIP: Refactor code
NeilKleistGao Aug 30, 2023
195be47
Merge branch 'new-definition-typing' into new-object-definition
NeilKleistGao Aug 30, 2023
edce33c
WIP: Rerun the test
NeilKleistGao Aug 30, 2023
80e1a05
WIP: Refactor code
NeilKleistGao Aug 30, 2023
ad44879
WIP: Fix unapply type
NeilKleistGao Aug 30, 2023
26b886c
Refactor code and add comments
NeilKleistGao Sep 7, 2023
9acf19d
Refactor AST with `FldFlags` (#176)
NeilKleistGao Sep 7, 2023
36245bd
Use is
NeilKleistGao Sep 7, 2023
8310bfa
Merge from new-definition-typing
NeilKleistGao Sep 7, 2023
9829e79
Merge remote-tracking branch 'origin/mlscript' into new-definition-ty…
LPTK Sep 8, 2023
90ac617
Clean up bizarre redundancies in ADT and UCS defs
LPTK Sep 8, 2023
a0084da
Merge remote-tracking branch 'origin/new-definition-typing' into new-…
LPTK Sep 8, 2023
cc872b4
Merge branch 'new-definition-typing' into new-object-definition
LPTK Sep 8, 2023
fcff7c4
Clean up unnecessarily messy logic
LPTK Sep 8, 2023
07a88c0
Minor changes and uncover bug
LPTK Sep 8, 2023
54999d8
WIP: Fix virtual check order
NeilKleistGao Sep 9, 2023
7d161e7
Remove linear searching
NeilKleistGao Sep 9, 2023
67ba7ed
Remove empty string check in checkThisInCtor
NeilKleistGao Sep 9, 2023
22a819f
Improve and disambiguate type pretty-printing
LPTK Sep 9, 2023
14dbd86
Add various tests, exposing some problems
LPTK Sep 9, 2023
732b598
Improve error messages and comments
NeilKleistGao Sep 9, 2023
1c529b4
Support "flat" lambdas, ie without an indented body
LPTK Sep 9, 2023
e9f8ca3
Add minor missing case (corner case; currently not covered)
LPTK Sep 9, 2023
adf0d0e
Remove outdated tests that were wrongly added back in a merge
LPTK Sep 9, 2023
97882d9
Refactor code
NeilKleistGao Sep 9, 2023
6a5f1ba
Fix match enumeration
NeilKleistGao Sep 9, 2023
ea95822
Merge from new-definition-typing
NeilKleistGao Sep 9, 2023
dfd9f9e
Improve error messages
NeilKleistGao Sep 9, 2023
9ef9820
Improve error messages
NeilKleistGao Sep 10, 2023
21700f6
Rename file that Windows doesn't like
LPTK Sep 11, 2023
aa9503b
Add test showing unintuitive operator precedence
LPTK Sep 11, 2023
34d976c
Add failing test exposing a code-gen bug + minor test
LPTK Sep 11, 2023
497da29
WIP: Minor changes
NeilKleistGao Sep 11, 2023
d6c2dc2
Merge branch 'new-definition-typing' into new-object-definition
NeilKleistGao Sep 11, 2023
f1a9d1b
WIP: Replace visitedSymbol with a mutable flag in RuntimeSymbol
NeilKleistGao Sep 11, 2023
c63a688
WIP: Refactor code
NeilKleistGao Sep 11, 2023
8018e47
WIP: Fix unexpected access to signatures
NeilKleistGao Sep 11, 2023
d408bad
WIP: Fix scopes in translateNewTypeDefinition
NeilKleistGao Sep 11, 2023
792b157
Implement user-defined symbolic operators & uncurry all operator appl…
LPTK Sep 12, 2023
cf6abb4
Fix parsing of symbolic names & improve error messages
LPTK Sep 12, 2023
157c3e7
Add a couple interesting tests
LPTK Sep 12, 2023
aea433d
Move test cases to correct file
LPTK Sep 12, 2023
fa2af75
Clean up some tests by using new operator support
LPTK Sep 13, 2023
781e90f
Adjust the precedence of => and uncover some unrelated type inference…
LPTK Sep 13, 2023
a86bc36
Fix omission and remove needless default argument value
LPTK Sep 13, 2023
0fde886
Merge pull request #177 from hkust-taco/symbolic-operators
LPTK Sep 13, 2023
1443e6c
Clean up inadvertently-polluted NuScratch.mls file
LPTK Sep 16, 2023
904988a
Update shared/src/main/scala/mlscript/NuTypeDefs.scala
NeilKleistGao Sep 16, 2023
2d5c659
Add test case
NeilKleistGao Sep 17, 2023
e82b124
Minor improvements
LPTK Sep 17, 2023
57b4221
Slightly improve the logic of the `unapply` hack
LPTK Sep 17, 2023
febbc0b
Merge from new-definition-typing
NeilKleistGao Sep 18, 2023
fd2215a
Merge pull request #175 from NeilKleistGao/new-object-definition
NeilKleistGao Sep 18, 2023
ebdf44c
Improve internal pretty-printing of tuples and type defs
LPTK Sep 19, 2023
639d202
Properly type check constructors, new expressions, val parameters & co
LPTK Sep 19, 2023
3f4fab3
Fix typing of non-val parameters and handling of abstract vals
LPTK Sep 19, 2023
a875109
Fix pretty-printing of `val` members
LPTK Sep 19, 2023
14829db
Type constructor and check this access
NeilKleistGao Sep 18, 2023
031ee4d
Minor improvements to ctor parsing and error reporting
LPTK Sep 20, 2023
86c7051
Address minor PR comments
LPTK Sep 20, 2023
5b21873
Merge pull request #179 from LPTK/aux-ctor-typing
LPTK Sep 20, 2023
bce48de
Fix #180
LPTK Sep 20, 2023
fa58624
Pretty-print long record types on several lines
LPTK Sep 20, 2023
354f0d6
Fix rigidity of explicit method parameters + add some tests
LPTK Sep 21, 2023
b428bfb
Add some minor tests
LPTK Sep 22, 2023
29762d0
Fix missing skolems in type of `this`, leading to unsound constraints
LPTK Sep 23, 2023
98282a9
Change usage of semicolons; support semicolon sequence expressions
LPTK Sep 23, 2023
4248d23
Forbid `val` and `fun` in declarations block scopes
LPTK Sep 23, 2023
f1bd93e
Improve parsing of type defs and ctors
LPTK Sep 23, 2023
941343c
Add test exposing a DiffTest bug
LPTK Sep 23, 2023
4d7b6e1
Add codebase doc (ECOOP23 artifact version) (#7)
andongfan Sep 28, 2023
08dee51
Named args (#174)
mbroughani81 Sep 29, 2023
b4d0551
Fix misuse of obsolete instanceType parameter
LPTK Sep 29, 2023
855945c
Implement right-associative ops & case expressions + add tests
LPTK Sep 29, 2023
b14bd8d
Fix that execution errors of a term are swallowed when there are func…
chengluyu Sep 30, 2023
8ddfd7b
Annotate RegionDSL to simplify types (#184)
andongfan Oct 1, 2023
2183bbc
Stop parsing round brackets as arrays
LPTK Oct 1, 2023
99bea65
Display `undefined` as `()` in pretty-printer
LPTK Oct 1, 2023
5a2fd3d
Fix small inconsistencies in parsing of tupled parameters
LPTK Oct 2, 2023
e7f6a14
Warn against statements with type different from unit
LPTK Oct 2, 2023
a00d04b
Add minor test case
LPTK Oct 2, 2023
3bb6e2b
Fix variance computation; remove redundant instanceType field
LPTK Oct 3, 2023
debf5c5
Adjust detection of non-unit statements + add some tests
LPTK Oct 4, 2023
2976832
Fix handling of polymorphic type aliases & add tests
LPTK Oct 4, 2023
4033135
Fix recursive type "unskidding"
LPTK Oct 6, 2023
ed08423
Fix unary minus behaviour (#188)
HarrisL2 Oct 11, 2023
f13624f
Approximate overloads less + add tests and notes
LPTK Oct 12, 2023
9d91cde
Add various tests
LPTK Oct 12, 2023
27752e9
Allow 'overriding' private members
LPTK Oct 12, 2023
38bf8fc
Update NodeTest
LPTK Oct 10, 2023
f5e9826
Add defunctionalizer prototype (#185)
HarrisL2 Oct 12, 2023
74d13f2
Fix parenthesization for binary operators (#189)
HarrisL2 Oct 23, 2023
1d3811c
Allow selecting tuple by integer indices (#192)
chengluyu Nov 22, 2023
8894b74
Update Scala and Wartremover versions
LPTK Nov 22, 2023
8ab9346
Fix corner case parsing bug
LPTK Nov 22, 2023
2a3a104
Overhaul support for `new` operator
LPTK Nov 28, 2023
b8db6a1
Clean up some tests + add some doc
LPTK Nov 28, 2023
4909975
Fix codegen error for global functions (#186)
NeilKleistGao Nov 30, 2023
b11b9cb
Add a potentially buggy test case
chengluyu Dec 2, 2023
231d9ec
Update SBT version
LPTK Dec 6, 2023
f121cd0
Support integer literals of different radices and decimal numeric lit…
chengluyu Jan 1, 2024
0049da9
Fix name duplication in code generation for new definition typing (#197)
chengluyu Jan 2, 2024
29e38d1
Remove inspection function for syntax tree nodes (#200)
chengluyu Jan 2, 2024
1a7463e
Fix code generation for local functions declared by `let rec` (#198)
chengluyu Jan 2, 2024
a36092e
Merge branch 'mlscript' into new-definition-typing
LPTK Jan 4, 2024
e362241
Update NodeTest
LPTK Jan 4, 2024
a68e1de
Introduce comma operator and use `,`/`;` instead of `;`/`;;` (#204)
LPTK Jan 11, 2024
cc2773d
Fix/virtual type arg params (#205)
LPTK Jan 11, 2024
0e5e01b
Allow somewhat flat if-then-else expressions
LPTK Jan 11, 2024
05752ff
Improve self-type handling (#206)
LPTK Jan 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ mlscript ]
pull_request:
branches: [ mlscript ]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ metals.sbt
project/Dependencies.scala
project/metals.sbt
**.worksheet.sc
.DS_Store
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"other": "off",
"strings": "off"
}
}
},
"files.autoSave": "off"
}
18 changes: 8 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import Wart._

enablePlugins(ScalaJSPlugin)

ThisBuild / scalaVersion := "2.13.9"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "io.lptk"
ThisBuild / organizationName := "LPTK"
ThisBuild / scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
)

lazy val root = project.in(file("."))
.aggregate(mlscriptJS, mlscriptJVM, ts2mlsTest, compilerJVM)
Expand All @@ -18,9 +23,6 @@ lazy val mlscript = crossProject(JSPlatform, JVMPlatform).in(file("."))
.settings(
name := "mlscript",
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
"-language:higherKinds",
"-Ywarn-value-discard",
"-Ypatmat-exhaust-depth:160",
Expand All @@ -36,7 +38,8 @@ lazy val mlscript = crossProject(JSPlatform, JVMPlatform).in(file("."))
StringPlusAny, Any, ToString,
JavaSerializable, Serializable, Product, ToString,
LeakingSealed, Overloading,
Option2Iterable, IterableOps, ListAppend
Option2Iterable, IterableOps, ListAppend, SeqApply,
TripleQuestionMark,
),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.12" % Test,
libraryDependencies += "com.lihaoyi" %%% "sourcecode" % "0.3.0",
Expand All @@ -60,10 +63,6 @@ lazy val mlscriptJS = mlscript.js
lazy val ts2mls = crossProject(JSPlatform, JVMPlatform).in(file("ts2mls"))
.settings(
name := "ts2mls",
scalaVersion := "2.13.8",
scalacOptions ++= Seq(
"-deprecation"
)
)
.jvmSettings()
.jsSettings(
Expand All @@ -76,7 +75,6 @@ lazy val ts2mlsJVM = ts2mls.jvm

lazy val ts2mlsTest = project.in(file("ts2mls"))
.settings(
scalaVersion := "2.13.8",
Test / test := ((ts2mlsJVM / Test / test) dependsOn (ts2mlsJS / Test / test)).value
)

Expand Down
341 changes: 221 additions & 120 deletions compiler/shared/main/scala/mlscript/compiler/ClassLifter.scala

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions compiler/shared/main/scala/mlscript/compiler/DataType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package mlscript.compiler

abstract class DataType

object DataType:
sealed class Singleton(value: Expr.Literal, dataType: DataType) extends DataType:
override def toString(): String = value.toString()

enum Primitive(name: String) extends DataType:
case Integer extends Primitive("int")
case Decimal extends Primitive("real")
case Boolean extends Primitive("bool")
case String extends Primitive("str")
override def toString(): String = this.name
end Primitive

sealed case class Tuple(elementTypes: List[DataType]) extends DataType:
override def toString(): String = elementTypes.mkString("(", ", ", ")")

sealed case class Class(declaration: Item.TypeDecl) extends DataType:
override def toString(): String = s"class ${declaration.name.name}"

sealed case class Function(parameterTypes: List[DataType], returnType: DataType) extends DataType:
def this(returnType: DataType, parameterTypes: DataType*) =
this(parameterTypes.toList, returnType)
override def toString(): String =
val parameterList = parameterTypes.mkString("(", ", ", ")")
s"$parameterList -> $returnType"

sealed case class Record(fields: Map[String, DataType]) extends DataType:
def this(fields: (String, DataType)*) = this(Map.from(fields))
override def toString(): String =
fields.iterator.map { (name, ty) => s"$name: $ty" }.mkString("{", ", ", "}")

case object Unknown extends DataType:
override def toString(): String = "unknown"
18 changes: 18 additions & 0 deletions compiler/shared/main/scala/mlscript/compiler/DataTypeInferer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mlscript.compiler
import mlscript.compiler.mono.MonomorphError

trait DataTypeInferer:
import DataType._

def findClassByName(name: String): Option[Item.TypeDecl]

def infer(expr: Expr, compatiableType: Option[DataType]): DataType =
expr match
case Expr.Tuple(elements) => DataType.Tuple(elements.map(infer(_, None)))
case lit @ Expr.Literal(value: BigInt) => Singleton(lit, Primitive.Integer)
case lit @ Expr.Literal(value: BigDecimal) => Singleton(lit, Primitive.Decimal)
case lit @ Expr.Literal(value: String) => Singleton(lit, Primitive.String)
case lit @ Expr.Literal(value: Boolean) => Singleton(lit, Primitive.Boolean)
case Expr.Apply(Expr.Ref(name), args) =>
findClassByName(name).fold(DataType.Unknown)(DataType.Class(_))
case _ => throw MonomorphError(s"I can't infer the type of $expr now")
177 changes: 177 additions & 0 deletions compiler/shared/main/scala/mlscript/compiler/Helpers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package mlscript
package compiler

import mlscript.compiler.mono.{Monomorph, MonomorphError}
import scala.collection.mutable.ArrayBuffer

object Helpers:
/**
* Extract parameters for monomorphization from a `Tup`.
*/
def toFuncParams(term: Term): Iterator[Parameter] = term match
case Tup(fields) => fields.iterator.flatMap {
// The new parser emits `Tup(_: UnitLit(true))` from `fun f() = x`.
case (_, Fld(FldFlags(_, _, _), UnitLit(true))) => None
case (None, Fld(FldFlags(_, spec, _), Var(name))) => Some((spec, Expr.Ref(name)))
case (Some(Var(name)), Fld(FldFlags(_, spec, _), _)) => Some((spec, Expr.Ref(name)))
case _ => throw new MonomorphError(
s"only `Var` can be parameters but we meet $term"
)
}
case _ => throw MonomorphError("expect the list of parameters to be a `Tup`")

def toFuncArgs(term: Term): IterableOnce[Term] = term match
// The new parser generates `(undefined, )` when no arguments.
// Let's do this temporary fix.
case Tup((_, Fld(FldFlags(_, _, _), UnitLit(true))) :: Nil) => Iterable.empty
case Tup(fields) => fields.iterator.map(_._2.value)
case _ => Some(term)

def term2Expr(term: Term): Expr = {
term match
case Var(name) => Expr.Ref(name)
case Lam(lhs, rhs) =>
val params = toFuncParams(lhs).toList
Expr.Lambda(params, term2Expr(rhs))
case App(App(Var("=>"), Bra(false, args: Tup)), body) =>
val params = toFuncParams(args).toList
Expr.Lambda(params, term2Expr(body))
case App(App(Var("."), self), App(Var(method), args: Tup)) =>
Expr.Apply(Expr.Select(term2Expr(self), Expr.Ref(method)), List.from(toFuncArgs(args).iterator.map(term2Expr)))
case App(lhs, rhs) =>
val callee = term2Expr(lhs)
val arguments = toFuncArgs(rhs).iterator.map(term2Expr).toList
Expr.Apply(callee, arguments)
case Tup(fields) =>
Expr.Tuple(fields.map {
case (_, Fld(FldFlags(mut, spec, genGetter), value)) => term2Expr(value)
})
case Rcd(fields) =>
Expr.Record(fields.map {
case (name, Fld(FldFlags(mut, spec, genGetter), value)) => (Expr.Ref(name.name), term2Expr(value))
})
case Sel(receiver, fieldName) =>
Expr.Select(term2Expr(receiver), Expr.Ref(fieldName.name))
case Let(rec, Var(name), rhs, body) =>
val exprRhs = term2Expr(rhs)
val exprBody = term2Expr(body)
Expr.LetIn(rec, Expr.Ref(name), exprRhs, exprBody)
case Blk(stmts) => Expr.Block(stmts.flatMap[Expr | Item.FuncDecl | Item.FuncDefn] {
case term: Term => Some(term2Expr(term))
case tyDef: NuTypeDef => throw MonomorphError(s"Unimplemented term2Expr ${term}")
case funDef: NuFunDef =>
val NuFunDef(_, nme, sn, targs, rhs) = funDef
val ret: Item.FuncDecl | Item.FuncDefn = rhs match
case Left(Lam(params, body)) =>
Item.FuncDecl(Expr.Ref(nme.name), toFuncParams(params).toList, term2Expr(body))
case Left(body: Term) => Item.FuncDecl(Expr.Ref(nme.name), Nil, term2Expr(body))
case Right(tp) => Item.FuncDefn(Expr.Ref(nme.name), targs, PolyType(Nil, tp)) //TODO: Check correctness in Type -> Polytype conversion
Some(ret)
case mlscript.DataDefn(_) => throw MonomorphError("unsupported DataDefn")
case mlscript.DatatypeDefn(_, _) => throw MonomorphError("unsupported DatatypeDefn")
case mlscript.TypeDef(_, _, _, _, _, _, _, _) => throw MonomorphError("unsupported TypeDef")
case mlscript.Def(_, _, _, _) => throw MonomorphError("unsupported Def")
case mlscript.LetS(_, _, _) => throw MonomorphError("unsupported LetS")
case mlscript.Constructor(_, _) => throw MonomorphError("unsupported Constructor")
})
case Bra(rcd, term) => term2Expr(term)
case Asc(term, ty) => Expr.As(term2Expr(term), ty)
case _: Bind => throw MonomorphError("cannot monomorphize `Bind`")
case _: Test => throw MonomorphError("cannot monomorphize `Test`")
case With(term, Rcd(fields)) =>
Expr.With(term2Expr(term), Expr.Record(fields.map {
case (name, Fld(FldFlags(mut, spec, getGetter), value)) => (Expr.Ref(name.name), term2Expr(term))
}))
case CaseOf(term, cases) =>
def rec(bra: CaseBranches)(using buffer: ArrayBuffer[CaseBranch]): Unit = bra match
case Case(pat, body, rest) =>
val newCase = pat match
case Var(name) => CaseBranch.Instance(Expr.Ref(name), Expr.Ref("_"), term2Expr(body))
case DecLit(value) => CaseBranch.Constant(Expr.Literal(value), term2Expr(body))
case IntLit(value) => CaseBranch.Constant(Expr.Literal(value), term2Expr(body))
case StrLit(value) => CaseBranch.Constant(Expr.Literal(value), term2Expr(body))
case UnitLit(undefinedOrNull) => CaseBranch.Constant(Expr.Literal(UnitValue.Undefined), term2Expr(body))
buffer.addOne(newCase)
rec(rest)
case NoCases => ()
case Wildcard(body) =>
buffer.addOne(CaseBranch.Wildcard(term2Expr(body)))
val branchBuffer = ArrayBuffer[CaseBranch]()
rec(cases)(using branchBuffer)
Expr.Match(term2Expr(term), branchBuffer)

case Subs(array, index) =>
Expr.Subscript(term2Expr(array), term2Expr(index))
case Assign(lhs, rhs) =>
Expr.Assign(term2Expr(lhs), term2Expr(rhs))
case New(None, body) =>
throw MonomorphError(s"Unimplemented term2Expr ${term}")
case New(Some((constructor, args)), body) =>
val typeName = constructor match
case AppliedType(TypeName(name), _) => name
case TypeName(name) => name
Expr.New(TypeName(typeName), toFuncArgs(args).iterator.map(term2Expr).toList)
// case Blk(unit) => Expr.Isolated(trans2Expr(TypingUnit(unit)))
case If(body, alternate) => body match
case IfThen(condition, consequent) =>
Expr.IfThenElse(
term2Expr(condition),
term2Expr(consequent),
alternate.map(term2Expr)
)
case term: IfElse => throw MonomorphError("unsupported IfElse")
case term: IfLet => throw MonomorphError("unsupported IfLet")
case term: IfOpApp => throw MonomorphError("unsupported IfOpApp")
case term: IfOpsApp => throw MonomorphError("unsupported IfOpsApp")
case term: IfBlock => throw MonomorphError("unsupported IfBlock")
case IntLit(value) => Expr.Literal(value)
case DecLit(value) => Expr.Literal(value)
case StrLit(value) => Expr.Literal(value)
case UnitLit(undefinedOrNull) =>
Expr.Literal(if undefinedOrNull
then UnitValue.Undefined
else UnitValue.Null)
case _ => throw MonomorphError("unsupported term"+ term.toString)
}

def func2Item(funDef: NuFunDef): Item.FuncDecl | Item.FuncDefn =
val NuFunDef(_, nme, sn, targs, rhs) = funDef
rhs match
case Left(Lam(params, body)) =>
Item.FuncDecl(Expr.Ref(nme.name), toFuncParams(params).toList, term2Expr(body))
case Left(body: Term) => Item.FuncDecl(Expr.Ref(nme.name), Nil, term2Expr(body))
case Right(tp) => Item.FuncDefn(Expr.Ref(nme.name), targs, PolyType(Nil, tp)) //TODO: Check correctness in Type -> Polytype conversion

def type2Item(tyDef: NuTypeDef): Item.TypeDecl =
val NuTypeDef(kind, className, tparams, params, _, _, parents, _, _, body) = tyDef
val isolation = Isolation(body.entities.flatMap {
// Question: Will there be pure terms in class body?
case term: Term =>
Some(term2Expr(term))
case subTypeDef: NuTypeDef => throw MonomorphError(s"Unimplemented func2Item ${tyDef}")
case subFunDef: NuFunDef =>
Some(func2Item(subFunDef))
case term => throw MonomorphError(term.toString)
})
val typeDecl: Item.TypeDecl = Item.TypeDecl(
Expr.Ref(className.name), // name
kind match // kind
case Als => TypeDeclKind.Alias
case Cls => TypeDeclKind.Class
case Trt => TypeDeclKind.Trait
case _ => throw MonomorphError(s"Unsupported TypeDefKind conversion ${kind}")
,
tparams.map(_._2), // typeParams
toFuncParams(params.getOrElse(Tup(Nil))).toList, // params
parents.map {
case Var(name) => (TypeName(name), Nil)
case App(Var(name), args) => (TypeName(name), term2Expr(args) match{
case Expr.Tuple(fields) => fields
case _ => Nil
})
case _ => throw MonomorphError("unsupported parent term")
}, // parents
isolation // body
)
typeDecl

20 changes: 10 additions & 10 deletions compiler/shared/main/scala/mlscript/compiler/PrettyPrinter.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package mlscript.compiler

import mlscript.{TypingUnit, NuFunDef, NuTypeDef, Term}
import mlscript.{TypingUnit, NuFunDef, NuTypeDef, Term, Tup}
import mlscript.compiler.debug.DebugOutput

// For pretty printing terms in debug output.
object PrettyPrinter:
def show(term: Term): DebugOutput = DebugOutput.Code(term.toString.linesIterator.toList)
def show(term: Term): DebugOutput = DebugOutput.Code(term.showDbg.linesIterator.toList)
def show(unit: TypingUnit): DebugOutput = DebugOutput.Code(showTypingUnit(unit, 0).linesIterator.toList)
def show(funDef: NuFunDef): DebugOutput = DebugOutput.Code(showFunDef(funDef).linesIterator.toList)
def show(tyDef: NuTypeDef): DebugOutput = DebugOutput.Code(showTypeDef(tyDef, 0).linesIterator.toList)
Expand All @@ -16,7 +16,7 @@ object PrettyPrinter:
case term: Term => show(term)
case tyDef: NuTypeDef => showTypeDef(tyDef)
case funDef: NuFunDef => showFunDef(funDef)
case others => others.toString()
case others => others.showDbg
}.mkString("{", "; ", "}")
if (singleLine.length < 60)
singleLine
Expand All @@ -26,7 +26,7 @@ object PrettyPrinter:
case term: Term => show(term)
case tyDef: NuTypeDef => showTypeDef(tyDef)
case funDef: NuFunDef => showFunDef(funDef)
case others => others.toString()
case others => others.showDbg
}.map(indentStr + " " + _).mkString("{\n", "\n", s"\n$indentStr}")

def showFunDef(funDef: NuFunDef): String =
Expand All @@ -36,19 +36,19 @@ object PrettyPrinter:
case Some(true) => "let'"
}
s"$st ${funDef.nme.name}"
+ (if funDef.targs.isEmpty
+ (if funDef.tparams.isEmpty
then ""
else funDef.targs.map(_.name).mkString("[", ", ", "]"))
else funDef.tparams.map(_.name).mkString("[", ", ", "]"))
+ " = "
+ funDef.rhs.fold(_.toString, _.body.show)
+ funDef.rhs.fold(_.showDbg, _.show(newDefs = true))

def showTypeDef(tyDef: NuTypeDef, indent: Int = 0): String =
s"${tyDef.kind.str} ${tyDef.nme.name}"
+ (if tyDef.tparams.isEmpty
then ""
else tyDef.tparams.map(_.name).mkString("[", ",", "]"))
+ "(" + tyDef.params + ")"
else tyDef.tparams.map(_._2.name).mkString("[", ",", "]"))
+ tyDef.params.fold("")(params => s"(${params.showDbg})")
+ (if tyDef.parents.isEmpty
then ""
else ": " + tyDef.parents.map(_.toString).mkString(", "))
else ": " + tyDef.parents.map(_.showDbg).mkString(", "))
+ showTypingUnit(tyDef.body, indent + 1)
Loading
Loading