From 9d2d6f84cd2d13f55d565470a63274bfc449159c Mon Sep 17 00:00:00 2001 From: Guset0x0 Date: Fri, 17 Jan 2025 07:27:34 +0000 Subject: [PATCH] fix warning in source --- next/sources/gmachine/src/part1/ast.mbt | 4 +- next/sources/gmachine/src/part1/compile.mbt | 12 ++-- next/sources/gmachine/src/part1/syntax.mbt | 2 +- next/sources/gmachine/src/part1/top.mbt | 8 +-- next/sources/gmachine/src/part2/ast.mbt | 4 +- next/sources/gmachine/src/part2/compile.mbt | 44 ++++++------- next/sources/gmachine/src/part2/syntax.mbt | 2 +- next/sources/gmachine/src/part2/top.mbt | 6 +- next/sources/gmachine/src/part2/vm.mbt | 8 +-- next/sources/gmachine/src/part3/ast.mbt | 4 +- next/sources/gmachine/src/part3/compile.mbt | 68 ++++++++++----------- next/sources/gmachine/src/part3/syntax.mbt | 2 +- next/sources/gmachine/src/part3/top.mbt | 6 +- next/sources/gmachine/src/part3/vm.mbt | 10 +-- next/sources/language/src/operator/top.mbt | 2 +- next/sources/segment-tree/src/part2/top.mbt | 6 +- 16 files changed, 94 insertions(+), 94 deletions(-) diff --git a/next/sources/gmachine/src/part1/ast.mbt b/next/sources/gmachine/src/part1/ast.mbt index 0b62d79c..781edb64 100644 --- a/next/sources/gmachine/src/part1/ast.mbt +++ b/next/sources/gmachine/src/part1/ast.mbt @@ -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( @@ -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 \ No newline at end of file diff --git a/next/sources/gmachine/src/part1/compile.mbt b/next/sources/gmachine/src/part1/compile.mbt index b00ab4f6..90a30693 100644 --- a/next/sources/gmachine/src/part1/compile.mbt +++ b/next/sources/gmachine/src/part1/compile.mbt @@ -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 @@ -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") } } diff --git a/next/sources/gmachine/src/part1/syntax.mbt b/next/sources/gmachine/src/part1/syntax.mbt index e4e6717f..21f54acc 100644 --- a/next/sources/gmachine/src/part1/syntax.mbt +++ b/next/sources/gmachine/src/part1/syntax.mbt @@ -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}") diff --git a/next/sources/gmachine/src/part1/top.mbt b/next/sources/gmachine/src/part1/top.mbt index 5dab3340..272b7f8f 100644 --- a/next/sources/gmachine/src/part1/top.mbt +++ b/next/sources/gmachine/src/part1/top.mbt @@ -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 } @@ -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") } \ No newline at end of file diff --git a/next/sources/gmachine/src/part2/ast.mbt b/next/sources/gmachine/src/part2/ast.mbt index 617a7aa2..b257ab4a 100644 --- a/next/sources/gmachine/src/part2/ast.mbt +++ b/next/sources/gmachine/src/part2/ast.mbt @@ -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( @@ -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]) } \ No newline at end of file diff --git a/next/sources/gmachine/src/part2/compile.mbt b/next/sources/gmachine/src/part2/compile.mbt index 307b11b8..46efe802 100644 --- a/next/sources/gmachine/src/part2/compile.mbt +++ b/next/sources/gmachine/src/part2/compile.mbt @@ -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]) } } @@ -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) @@ -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 @@ -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)) @@ -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, diff --git a/next/sources/gmachine/src/part2/syntax.mbt b/next/sources/gmachine/src/part2/syntax.mbt index e4e6717f..21f54acc 100644 --- a/next/sources/gmachine/src/part2/syntax.mbt +++ b/next/sources/gmachine/src/part2/syntax.mbt @@ -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}") diff --git a/next/sources/gmachine/src/part2/top.mbt b/next/sources/gmachine/src/part2/top.mbt index 7eef55e9..03d83d88 100644 --- a/next/sources/gmachine/src/part2/top.mbt +++ b/next/sources/gmachine/src/part2/top.mbt @@ -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, @@ -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)") } \ No newline at end of file diff --git a/next/sources/gmachine/src/part2/vm.mbt b/next/sources/gmachine/src/part2/vm.mbt index f0e04dec..f4b457c0 100644 --- a/next/sources/gmachine/src/part2/vm.mbt +++ b/next/sources/gmachine/src/part2/vm.mbt @@ -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 { @@ -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])) } } } @@ -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 diff --git a/next/sources/gmachine/src/part3/ast.mbt b/next/sources/gmachine/src/part3/ast.mbt index 617a7aa2..b257ab4a 100644 --- a/next/sources/gmachine/src/part3/ast.mbt +++ b/next/sources/gmachine/src/part3/ast.mbt @@ -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( @@ -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]) } \ No newline at end of file diff --git a/next/sources/gmachine/src/part3/compile.mbt b/next/sources/gmachine/src/part3/compile.mbt index f84a8074..1be0935a 100644 --- a/next/sources/gmachine/src/part3/compile.mbt +++ b/next/sources/gmachine/src/part3/compile.mbt @@ -23,9 +23,9 @@ fn compileR( arity : Int ) -> List[Instruction] { if arity == 0 { - compileE(self, env) + List::of([Update(arity), Unwind]) + compileE(self, env) + @immut/list.of([Update(arity), Unwind]) } else { - compileE(self, env) + List::of([Update(arity), Pop(arity), Unwind]) + compileE(self, env) + @immut/list.of([Update(arity), Pop(arity), Unwind]) } } @@ -36,20 +36,20 @@ 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)]) // start c_constr definition App(App(Constructor(tag = 1, arity = 2), x), xs) => { // Cons(x, xs) - compileC(xs, env) + compileC(x, argOffset(1, env)) + List::of([Pack(1, 2)]) + compileC(xs, env) + compileC(x, argOffset(1, env)) + @immut/list.of([Pack(1, 2)]) } // Nil - Constructor(tag = 0, arity = 0) => List::of([Pack(0, 0)]) + Constructor(tag = 0, arity = 0) => @immut/list.of([Pack(0, 0)]) // end c_constr definition 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) @@ -63,7 +63,7 @@ fn compileC( fn compileE(self : RawExpr[String], env : List[(String, Int)]) -> List[Instruction] { match self { // start num definition - Num(n) => List::of([PushInt(n)]) + Num(n) => @immut/list.of([PushInt(n)]) // end num definition // start let definition Let(rec, defs, e) => { @@ -79,39 +79,39 @@ fn compileE(self : RawExpr[String], env : List[(String, Int)]) -> List[Instructi let condition = compileE(b, env) let branch1 = compileE(e1, env) let branch2 = compileE(e2, env) - condition + List::of([Cond(branch1, branch2)]) + condition + @immut/list.of([Cond(branch1, branch2)]) } App(Var("negate"), e) => { - compileE(e, env) + List::of([Neg]) + compileE(e, env) + @immut/list.of([Neg]) } // end if_and_neg definition // start binop definition App(App(Var(op), e0), e1) => { match builtinOpS[op] { - None => compileC(self, env) + List::of([Eval]) + None => compileC(self, env) + @immut/list.of([Eval]) Some(instr) => { let code1 = compileE(e1, env) let code0 = compileE(e0, argOffset(1, env)) - code1 + code0 + List::of([instr]) + code1 + code0 + @immut/list.of([instr]) } } } // end binop definition // start e_constr_case definition Case(e, alts) => { - compileE(e, env) + List::of([CaseJump(compileAlts(alts, env))]) + compileE(e, env) + @immut/list.of([CaseJump(compileAlts(alts, env))]) } Constructor(tag = 0, arity = 0) => { // Nil - List::of([Pack(0, 0)]) + @immut/list.of([Pack(0, 0)]) } App(App(Constructor(tag = 1, arity = 2), x), xs) => { // Cons(x, xs) - compileC(xs, env) + compileC(x, argOffset(1, env)) + List::of([Pack(1, 2)]) + compileC(xs, env) + compileC(x, argOffset(1, env)) + @immut/list.of([Pack(1, 2)]) } // end e_constr_case definition // start default definition - _ => compileC(self, env) + List::of([Eval]) + _ => compileC(self, env) + @immut/list.of([Eval]) // end default definition } } @@ -133,7 +133,7 @@ fn compileAlts(alts : List[(Int, List[String], RawExpr[String])], env : List[(St let offset = variables.length() let env = buildenv(variables, 0) + argOffset(offset, env) let code = - List::of([Split]) + compileE(body, env) + List::of([Slide(offset)]) + @immut/list.of([Split]) + compileE(body, env) + @immut/list.of([Slide(offset)]) Cons((tag, code), go(rest)) } } @@ -161,7 +161,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())]) } fn compileLetrec( @@ -184,7 +184,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)) @@ -196,70 +196,70 @@ fn compileLetrec( -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, diff --git a/next/sources/gmachine/src/part3/syntax.mbt b/next/sources/gmachine/src/part3/syntax.mbt index e4e6717f..21f54acc 100644 --- a/next/sources/gmachine/src/part3/syntax.mbt +++ b/next/sources/gmachine/src/part3/syntax.mbt @@ -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}") diff --git a/next/sources/gmachine/src/part3/top.mbt b/next/sources/gmachine/src/part3/top.mbt index bb71c2ab..266f5a4d 100644 --- a/next/sources/gmachine/src/part3/top.mbt +++ b/next/sources/gmachine/src/part3/top.mbt @@ -20,7 +20,7 @@ fn run(codes : List[String]) -> String { heap : heap, stack : Nil, // start init definition - code : List::of([PushGlobal("main"), Eval, Print]), + code : @immut/list.of([PushGlobal("main"), Eval, Print]), // end init definition globals : globals, stats : 0, @@ -36,8 +36,8 @@ test "basic eval" { let (_, v) = kv basic.push(v) } - let basic = List::from_array(basic) + let basic = @immut/list.from_array(basic) let main = "(defn main[] (take 20 fibs))" inspect!(run(Cons(main, basic)), content = "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 Nil") -} \ No newline at end of file +} diff --git a/next/sources/gmachine/src/part3/vm.mbt b/next/sources/gmachine/src/part3/vm.mbt index b83ed44d..6650cce4 100644 --- a/next/sources/gmachine/src/part3/vm.mbt +++ b/next/sources/gmachine/src/part3/vm.mbt @@ -175,7 +175,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])) } // start unwind_g definition NGlobal(_, n, c) => { @@ -204,7 +204,7 @@ fn unwind(self : GState) -> Unit { // end unwind_g definition NInd(a) => { self.put_stack(a) - self.put_code(List::of([Unwind])) + self.put_code(@immut/list.of([Unwind])) } NConstr(_, _) => { match self.dump { @@ -231,8 +231,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]) } fn condition(self : GState, i1 : List[Instruction], i2 : List[Instruction]) -> Unit { @@ -336,7 +336,7 @@ fn gprint(self : GState) -> Unit { } NConstr(0, Nil) => self.output.write_string("Nil") NConstr(1, Cons(addr1, Cons(addr2, Nil))) => { - self.code = List::of([Instruction::Eval, Print, Eval, Print]) + self.code + self.code = @immut/list.of([Instruction::Eval, Print, Eval, Print]) + self.code self.put_stack(addr2) self.put_stack(addr1) } diff --git a/next/sources/language/src/operator/top.mbt b/next/sources/language/src/operator/top.mbt index 552aa009..913e7860 100644 --- a/next/sources/language/src/operator/top.mbt +++ b/next/sources/language/src/operator/top.mbt @@ -55,7 +55,7 @@ fn add(i : Int, j : Int) -> Int { fn pipe() -> Unit { // start operator 4 5 |> ignore // <=> ignore(5) - [] |> push(5) // <=> push([], 5) + [] |> Array::push(5) // <=> Array::push([], 5) 1 |> add(5) // <=> add(1, 5) |> ignore // <=> ignore(add(1, 5)) diff --git a/next/sources/segment-tree/src/part2/top.mbt b/next/sources/segment-tree/src/part2/top.mbt index cceeea2a..8ab2a85b 100644 --- a/next/sources/segment-tree/src/part2/top.mbt +++ b/next/sources/segment-tree/src/part2/top.mbt @@ -45,14 +45,14 @@ impl ToJson for Node with to_json(node) { } // start op_add definition -fn op_add(self : Data, v : Data) -> Data { +fn Data::op_add(self : Data, v : Data) -> Data { match (self, v) { (Data(sum=a, len=len_a), Data(sum=b, len=len_b)) => Data(sum=a + b, len=len_a + len_b) } } -fn op_add(self : Node, v : Node) -> Node { +fn Node::op_add(self : Node, v : Node) -> Node { match (self, v) { (Node(data=l, ..), Node(data=r, ..)) => Node(data=l + r, tag=Nil, left=self, right=v) @@ -64,7 +64,7 @@ fn op_add(self : Node, v : Node) -> Node { // end op_add definition // start lazytag definition -fn op_add(self : LazyTag, v : LazyTag) -> LazyTag { +fn LazyTag::op_add(self : LazyTag, v : LazyTag) -> LazyTag { match (self, v) { (Tag(a), Tag(b)) => Tag(a + b) (Nil, t) | (t, Nil) => t