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

Add code generation for bbml #245

Merged
merged 36 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f654551
Map builtin operators
NeilKleistGao Nov 26, 2024
270ff3e
WIP: Fix num and sel code gen & add predef
NeilKleistGao Nov 26, 2024
6896564
WIP: Add throw
NeilKleistGao Nov 26, 2024
c25ebd5
WIP: Fix predef
NeilKleistGao Nov 26, 2024
b9e3782
Fix getter generation & split.end typing
NeilKleistGao Nov 27, 2024
dc58521
Generate code for region & ref
NeilKleistGao Nov 27, 2024
7c56b26
WIP: Add tests
NeilKleistGao Nov 29, 2024
a40e1cc
Merge from main branch
NeilKleistGao Nov 29, 2024
c2deec1
Fix class matching typing
NeilKleistGao Nov 30, 2024
ddeb04a
Merge from main branch
NeilKleistGao Nov 30, 2024
a81aae2
Fix num ops code gen
NeilKleistGao Nov 30, 2024
dae1d36
Fix getter generation
NeilKleistGao Dec 1, 2024
4afe46f
Clean
NeilKleistGao Dec 1, 2024
b0c3f38
Merge from mlscript
NeilKleistGao Dec 1, 2024
a683de6
Update bbml predef
NeilKleistGao Dec 1, 2024
af42e40
Minor
NeilKleistGao Dec 1, 2024
182237f
Reuse getBuiltin
NeilKleistGao Dec 4, 2024
5443f1f
Fix GetElem implementation
NeilKleistGao Dec 4, 2024
89f5c6c
Merge branch 'hkmc2' of https://github.com/hkust-taco/mlscript into b…
NeilKleistGao Dec 5, 2024
ebe9103
Rerun tests
NeilKleistGao Dec 5, 2024
8e63fae
Move defn check to symbol
NeilKleistGao Dec 6, 2024
0ff406f
Fix module getter generation and ctx.get use
NeilKleistGao Dec 6, 2024
ce6f2cf
Refactor getter typing
NeilKleistGao Dec 6, 2024
e0a22ad
Update hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala
NeilKleistGao Dec 8, 2024
313d680
Merge from main branch
NeilKleistGao Dec 8, 2024
0bb46f1
WIP: Fix shadowing
NeilKleistGao Dec 8, 2024
5557984
Forbid getters from being defined in non-module and non-function scopes
NeilKleistGao Dec 8, 2024
52e2bd2
Update hkmc2/shared/src/main/scala/hkmc2/semantics/Term.scala
NeilKleistGao Dec 12, 2024
ae7bfd5
Remove top-level getter selection check
NeilKleistGao Dec 12, 2024
bbc8f9f
Add empty lines
NeilKleistGao Dec 12, 2024
710831f
Fix diff
NeilKleistGao Dec 12, 2024
6e7a96a
Fix diff
NeilKleistGao Dec 12, 2024
7ca79b9
Fix getter logic
NeilKleistGao Dec 12, 2024
634748d
Merge from main branch
NeilKleistGao Dec 12, 2024
e0c2e5e
Minor changes
NeilKleistGao Dec 12, 2024
ea0c9c8
Remove the unused import and update the comment
NeilKleistGao Dec 12, 2024
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
12 changes: 9 additions & 3 deletions hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,15 @@ extends Importer:
N
case N =>
N
case S(_: TopLevelSymbol) => ctx.get(nme.name).flatMap(_.symbol) match
case S(sym: FieldSymbol) => S(sym)
case _ => N
case S(_: TopLevelSymbol) =>
def rec(ctx: Ctx): Opt[Ctx] = // * To avoid shadowing if users write `globalThis.somefield`
NeilKleistGao marked this conversation as resolved.
Show resolved Hide resolved
if ctx.getOuter.filter(_.isInstanceOf[TopLevelSymbol]).nonEmpty then S(ctx)
else ctx.parent match
case S(p) => rec(p)
case N => N
rec(ctx).flatMap(_.get(nme.name)).flatMap(_.symbol) match
case S(sym: FieldSymbol) => S(sym)
case _ => N
case _ => N

def cls(tree: Tree, inAppPrefix: Bool): Ctxl[Term] = trace[Term](s"Elab class ${tree.showDbg}", r => s"~> $r"):
Expand Down
2 changes: 1 addition & 1 deletion hkmc2/shared/src/test/mlscript-compile/Predef.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const Predef$class = class Predef {
tmp7 = tmp6 + expected;
tmp8 = tmp7 + " arguments but got ";
tmp9 = tmp8 + got;
throw globalThis.Error(tmp9);
throw globalThis.Error(tmp9) ?? null;
} else {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion hkmc2/shared/src/test/mlscript-compile/Str.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Str$class = class Str {
return a + b;
}
string(value) {
return globalThis.String(value);
return globalThis.String(value) ?? null;
}
toString() { return "Str"; }
}; const Str = new Str$class;
Expand Down
43 changes: 43 additions & 0 deletions hkmc2/shared/src/test/mlscript/codegen/Getters.mls
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,49 @@ this.t
//│ = 42


:sjs
module T with
fun t() = 1
val a = globalThis.t
val b = this.t
//│ JS:
//│ const T$class = class T {
//│ constructor() {
//│ let selRes, tmp, tmp1, selRes1, tmp2;
//│ selRes = globalThis.t;
//│ if (selRes === undefined) {
//│ throw new globalThis.Error("Access to required field 't' yielded 'undefined'");
//│ } else {
//│ tmp = selRes;
//│ }
//│ tmp1 = tmp();
//│ this.a = tmp1;
//│ selRes1 = this.t;
//│ if (selRes1 === undefined) {
//│ throw new globalThis.Error("Access to required field 't' yielded 'undefined'");
//│ } else {
//│ tmp2 = selRes1;
//│ }
//│ this.b = tmp2;
//│ }
//│ t(...args) {
//│ globalThis.Predef.checkArgs("t", 0, true, args.length);
//│ return 1;
//│ }
//│ toString() { return "T"; }
//│ };
//│ this.T = new T$class;
//│ this.T.class = T$class;
//│ null


T.a
//│ = 42

T.b
//│ = [Function: t]


:sjs
module M with
fun t = 0
Expand Down