Skip to content

Commit

Permalink
fix warning in source
Browse files Browse the repository at this point in the history
  • Loading branch information
Guest0x0 committed Jan 17, 2025
1 parent 41b31dc commit 77b6447
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 94 deletions.
4 changes: 2 additions & 2 deletions next/sources/gmachine/src/part1/ast.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn ScDef::new[T](

// start prelude_defs definition
let prelude_defs : List[ScDef[String]] = {
let args : (FixedArray[String]) -> List[String] = List::of
let args : (FixedArray[String]) -> List[String] = @immut/list.of
let id = ScDef::new("I", args(["x"]), Var("x")) // id x = x
let k =
ScDef::new(
Expand Down Expand Up @@ -67,6 +67,6 @@ let prelude_defs : List[ScDef[String]] = {
args(["f"]),
App(App(Var("compose"), Var("f")), Var("f"))
) // twice f = compose f f
List::of([id, k, k1, s, compose, twice])
@immut/list.of([id, k, k1, s, compose, twice])
}
// end prelude_defs definition
12 changes: 6 additions & 6 deletions next/sources/gmachine/src/part1/compile.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ fn compileR(
arity : Int
) -> List[Instruction] {
if arity == 0 {
compileC(self, env) + List::of([Update(arity), Unwind])
compileC(self, env) + @immut/list.of([Update(arity), Unwind])
} else {
compileC(self, env) + List::of([Update(arity), Pop(arity), Unwind])
compileC(self, env) + @immut/list.of([Update(arity), Pop(arity), Unwind])
}
}
// end compile_r definition
Expand All @@ -40,12 +40,12 @@ fn compileC(
match self {
Var(s) =>
match env.lookup(s) {
None => List::of([PushGlobal(s)])
Some(n) => List::of([PushArg(n)])
None => @immut/list.of([PushGlobal(s)])
Some(n) => @immut/list.of([PushArg(n)])
}
Num(n) => List::of([PushInt(n)])
Num(n) => @immut/list.of([PushInt(n)])
App(e1, e2) =>
compileC(e2, env) + compileC(e1, argOffset(1, env)) + List::of([MkApp])
compileC(e2, env) + compileC(e1, argOffset(1, env)) + @immut/list.of([MkApp])
_ => abort("not support yet")
}
}
Expand Down
2 changes: 1 addition & 1 deletion next/sources/gmachine/src/part1/syntax.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn parse_alts(
self.next()
let x = self.parse_var!()
let xs = self.parse_var!()
(1, List::of([x, xs]))
(1, @immut/list.of([x, xs]))
}
other =>
raise ParseError("parse_alts(): expect NIL or CONS but got \{other}")
Expand Down
8 changes: 4 additions & 4 deletions next/sources/gmachine/src/part1/top.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn run(codes : List[String]) -> Node {
let initialState : GState = {
heap : heap,
stack : Nil,
code : List::of([PushGlobal("main"), Unwind]),
code : @immut/list.of([PushGlobal("main"), Unwind]),
globals : globals,
stats : 0
}
Expand All @@ -29,11 +29,11 @@ fn run(codes : List[String]) -> Node {
test "basic eval" {
// S K K x => ((K x (K x)) => x
let main = "(defn main[] (S K K 3))"
inspect!(run(List::of([main])), content = "NNum(3)")
inspect!(run(@immut/list.of([main])), content = "NNum(3)")
let main = "(defn main[] (K 0 1))"
inspect!(run(List::of([main])), content = "NNum(0)")
inspect!(run(@immut/list.of([main])), content = "NNum(0)")
let main = "(defn main[] (K1 0 1))"
inspect!(run(List::of([main])), content = "NNum(1)")
inspect!(run(@immut/list.of([main])), content = "NNum(1)")
let r = LazyRef::{ data : Waiting(fn (){ 3 + 4 })}
inspect!(square(r), content = "49")
}
4 changes: 2 additions & 2 deletions next/sources/gmachine/src/part2/ast.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn ScDef::new[T](
}

let prelude_defs : List[ScDef[String]] = {
let args : (FixedArray[String]) -> List[String] = List::of
let args : (FixedArray[String]) -> List[String] = @immut/list.of
let id = ScDef::new("I", args(["x"]), Var("x")) // id x = x
let k =
ScDef::new(
Expand Down Expand Up @@ -65,5 +65,5 @@ let prelude_defs : List[ScDef[String]] = {
args(["f"]),
App(App(Var("compose"), Var("f")), Var("f"))
) // twice f = compose f f
List::of([id, k, k1, s, compose, twice])
@immut/list.of([id, k, k1, s, compose, twice])
}
44 changes: 22 additions & 22 deletions next/sources/gmachine/src/part2/compile.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fn compileR(
arity : Int
) -> List[Instruction] {
if arity == 0 {
compileC(self, env) + List::of([Update(arity), Unwind])
compileC(self, env) + @immut/list.of([Update(arity), Unwind])
} else {
compileC(self, env) + List::of([Update(arity), Pop(arity), Unwind])
compileC(self, env) + @immut/list.of([Update(arity), Pop(arity), Unwind])
}
}

Expand All @@ -36,12 +36,12 @@ fn compileC(
match self {
Var(s) =>
match env.lookup(s) {
None => List::of([PushGlobal(s)])
Some(n) => List::of([Push(n)])
None => @immut/list.of([PushGlobal(s)])
Some(n) => @immut/list.of([Push(n)])
}
Num(n) => List::of([PushInt(n)])
Num(n) => @immut/list.of([PushInt(n)])
App(e1, e2) =>
compileC(e2, env) + compileC(e1, argOffset(1, env)) + List::of([MkApp])
compileC(e2, env) + compileC(e1, argOffset(1, env)) + @immut/list.of([MkApp])
Let(rec, defs, e) =>
if rec {
compileLetrec(compileC, defs, e, env)
Expand Down Expand Up @@ -71,7 +71,7 @@ fn compileLet(
continue env, acc + code, rest
}
}
codes + comp(expr, env) + List::of([Slide(defs.length())])
codes + comp(expr, env) + @immut/list.of([Slide(defs.length())])
}
// end compile_let definition

Expand All @@ -96,7 +96,7 @@ fn compileLetrec(
offset : Int
) -> List[Instruction] {
match defs {
Nil => comp(expr, env) + List::of([Slide(n)])
Nil => comp(expr, env) + @immut/list.of([Slide(n)])
Cons((_, expr), rest) =>
compileC(expr, env) +
Cons(Update(offset), compileDefs(rest, offset - 1))
Expand All @@ -108,70 +108,70 @@ fn compileLetrec(
// end compile_letrec definition

// start prim definition
let compiled_primitives : List[(String, Int, List[Instruction])] = List::of(
let compiled_primitives : List[(String, Int, List[Instruction])] = @immut/list.of(
[
// Arith
(
"add",
2,
List::of([Push(1), Eval, Push(1), Eval, Add, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Add, Update(2), Pop(2), Unwind]),
),
(
"sub",
2,
List::of([Push(1), Eval, Push(1), Eval, Sub, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Sub, Update(2), Pop(2), Unwind]),
),
(
"mul",
2,
List::of([Push(1), Eval, Push(1), Eval, Mul, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Mul, Update(2), Pop(2), Unwind]),
),
(
"div",
2,
List::of([Push(1), Eval, Push(1), Eval, Div, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Div, Update(2), Pop(2), Unwind]),
),
// Compare
(
"eq",
2,
List::of([Push(1), Eval, Push(1), Eval, Eq, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Eq, Update(2), Pop(2), Unwind]),
),
(
"neq",
2,
List::of([Push(1), Eval, Push(1), Eval, Ne, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Ne, Update(2), Pop(2), Unwind]),
),
(
"ge",
2,
List::of([Push(1), Eval, Push(1), Eval, Ge, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Ge, Update(2), Pop(2), Unwind]),
),
(
"gt",
2,
List::of([Push(1), Eval, Push(1), Eval, Gt, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Gt, Update(2), Pop(2), Unwind]),
),
(
"le",
2,
List::of([Push(1), Eval, Push(1), Eval, Le, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Le, Update(2), Pop(2), Unwind]),
),
(
"lt",
2,
List::of([Push(1), Eval, Push(1), Eval, Lt, Update(2), Pop(2), Unwind]),
@immut/list.of([Push(1), Eval, Push(1), Eval, Lt, Update(2), Pop(2), Unwind]),
),
// MISC
("negate", 1, List::of([Push(0), Eval, Neg, Update(1), Pop(1), Unwind])),
("negate", 1, @immut/list.of([Push(0), Eval, Neg, Update(1), Pop(1), Unwind])),
(
"if",
3,
List::of(
@immut/list.of(
[
Push(0),
Eval,
Cond(List::of([Push(1)]), List::of([Push(2)])),
Cond(@immut/list.of([Push(1)]), @immut/list.of([Push(2)])),
Update(3),
Pop(3),
Unwind,
Expand Down
2 changes: 1 addition & 1 deletion next/sources/gmachine/src/part2/syntax.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn parse_alts(
self.next()
let x = self.parse_var!()
let xs = self.parse_var!()
(1, List::of([x, xs]))
(1, @immut/list.of([x, xs]))
}
other =>
raise ParseError("parse_alts(): expect NIL or CONS but got \{other}")
Expand Down
6 changes: 3 additions & 3 deletions next/sources/gmachine/src/part2/top.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn run(codes : List[String]) -> Node {
heap : heap,
stack : Nil,
// start init definition
code : List::of([PushGlobal("main"), Eval]),
code : @immut/list.of([PushGlobal("main"), Eval]),
// end init definition
globals : globals,
stats : 0,
Expand All @@ -31,7 +31,7 @@ fn run(codes : List[String]) -> Node {

test "basic eval" {
let main = "(defn main[] (let ([add1 (add 1)]) (add1 1)))"
inspect!(run(List::of([main])), content = "NNum(2)")
inspect!(run(@immut/list.of([main])), content = "NNum(2)")
let main = "(defn main[] (let ([x 4] [y 5]) (sub x y)))"
inspect!(run(List::of([main])), content = "NNum(-1)")
inspect!(run(@immut/list.of([main])), content = "NNum(-1)")
}
8 changes: 4 additions & 4 deletions next/sources/gmachine/src/part2/vm.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn unwind(self : GState) -> Unit {
NApp(a1, _) => {
self.put_stack(addr)
self.put_stack(a1)
self.put_code(List::of([Unwind]))
self.put_code(@immut/list.of([Unwind]))
}
NGlobal(_, n, c) => {
if self.stack.length() < n {
Expand All @@ -193,7 +193,7 @@ fn unwind(self : GState) -> Unit {
}
NInd(a) => {
self.put_stack(a)
self.put_code(List::of([Unwind]))
self.put_code(@immut/list.of([Unwind]))
}
}
}
Expand All @@ -213,8 +213,8 @@ fn alloc_nodes(self : GState, n : Int) -> Unit {
fn eval(self : GState) -> Unit {
let addr = self.pop1()
self.put_dump(self.code, self.stack)
self.stack = List::of([addr])
self.code = List::of([Unwind])
self.stack = @immut/list.of([addr])
self.code = @immut/list.of([Unwind])
}
// end eval definition

Expand Down
4 changes: 2 additions & 2 deletions next/sources/gmachine/src/part3/ast.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn ScDef::new[T](
}

let prelude_defs : List[ScDef[String]] = {
let args : (FixedArray[String]) -> List[String] = List::of
let args : (FixedArray[String]) -> List[String] = @immut/list.of
let id = ScDef::new("I", args(["x"]), Var("x")) // id x = x
let k =
ScDef::new(
Expand Down Expand Up @@ -65,5 +65,5 @@ let prelude_defs : List[ScDef[String]] = {
args(["f"]),
App(App(Var("compose"), Var("f")), Var("f"))
) // twice f = compose f f
List::of([id, k, k1, s, compose, twice])
@immut/list.of([id, k, k1, s, compose, twice])
}
Loading

0 comments on commit 77b6447

Please sign in to comment.