diff --git a/core/src/main/scala/org/bykn/bosatsu/codegen/clang/ClangGen.scala b/core/src/main/scala/org/bykn/bosatsu/codegen/clang/ClangGen.scala index 04a32b05a..51d2a794b 100644 --- a/core/src/main/scala/org/bykn/bosatsu/codegen/clang/ClangGen.scala +++ b/core/src/main/scala/org/bykn/bosatsu/codegen/clang/ClangGen.scala @@ -715,100 +715,6 @@ object ClangGen { } yield Code.declareInt(offsetIdent, Some(0)) +: res } - def searchList( - locMut: LocalAnonMut, - initVL: Code.ValueLike, - checkVL: Code.ValueLike, - optLeft: Option[LocalAnonMut] - ): T[Code.ValueLike] = { - import Code.Expression - - val emptyList: Expression = - Code.Ident("alloc_enum0")(Code.IntLiteral(0)) - - def isNonEmptyList(expr: Expression): Expression = - Code.Ident("get_variant")(expr) =:= Code.IntLiteral(1) - - def headList(expr: Expression): Expression = - Code.Ident("get_enum_index")(expr, Code.IntLiteral(0)) - - def tailList(expr: Expression): Expression = - Code.Ident("get_enum_index")(expr, Code.IntLiteral(1)) - - def consList(head: Expression, tail: Expression): Expression = - Code.Ident("alloc_enum2")(Code.IntLiteral(1), head, tail) - /* - * here is the implementation from MatchlessToValue - * - Dynamic { (scope: Scope) => - var res = false - var currentList = initF(scope) - var leftList = VList.VNil - while (currentList ne null) { - currentList match { - case nonempty@VList.Cons(head, tail) => - scope.updateMut(mutV, nonempty) - scope.updateMut(left, leftList) - res = checkF(scope) - if (res) { currentList = null } - else { - currentList = tail - leftList = VList.Cons(head, leftList) - } - case _ => - currentList = null - // we don't match empty lists - } - } - res - } - */ - for { - currentList <- getAnon(locMut.ident) - optLeft <- optLeft.traverse(lm => getAnon(lm.ident)) - res <- newLocalName("result") - tmpList <- newLocalName("tmp_list") - declTmpList <- Code.ValueLike.declareVar(Code.TypeIdent.BValue, tmpList, initVL)(newLocalName) - /* - top <- currentTop - _ = println(s"""in $top: searchList( - $locMut: LocalAnonMut, - $initVL: Code.ValueLike, - $checkVL: Code.ValueLike, - $optLeft: Option[LocalAnonMut] - )""") - */ - } yield - (Code - .Statements( - Code.DeclareVar(Nil, Code.TypeIdent.Bool, res, Some(Code.FalseLit)), - declTmpList - ) - .maybeCombine( - optLeft.map(_ := emptyList), - ) + - // we don't match empty lists, so if currentList reaches Empty we are done - Code.While( - isNonEmptyList(tmpList), - Code.block( - currentList := tmpList, - res := checkVL, - Code.ifThenElse(res, - { tmpList := emptyList }, - { - (tmpList := tailList(tmpList)) - .maybeCombine( - optLeft.map { left => - left := consList(headList(currentList), left) - } - ) - } - ) - ) - ) - ) :+ res - } - def boxFn(ident: Code.Ident, arity: Int): Code.Expression = Code.Ident(s"alloc_boxed_pure_fn$arity")(ident) diff --git a/core/src/main/scala/org/bykn/bosatsu/codegen/python/PythonGen.scala b/core/src/main/scala/org/bykn/bosatsu/codegen/python/PythonGen.scala index 1d0e2999d..f76a56e30 100644 --- a/core/src/main/scala/org/bykn/bosatsu/codegen/python/PythonGen.scala +++ b/core/src/main/scala/org/bykn/bosatsu/codegen/python/PythonGen.scala @@ -1585,72 +1585,6 @@ object PythonGen { } yield (offsetIdent := 0).withValue(res) } - def searchList( - locMut: LocalAnonMut, - initVL: ValueLike, - checkVL: ValueLike, - optLeft: Option[LocalAnonMut] - ): Env[ValueLike] = - /* - * here is the implementation from MatchlessToValue - * - Dynamic { (scope: Scope) => - var res = false - var currentList = initF(scope) - var leftList = VList.VNil - while (currentList ne null) { - currentList match { - case nonempty@VList.Cons(head, tail) => - scope.updateMut(mutV, nonempty) - scope.updateMut(left, leftList) - res = checkF(scope) - if (res) { currentList = null } - else { - currentList = tail - leftList = VList.Cons(head, leftList) - } - case _ => - currentList = null - // we don't match empty lists - } - } - res - } - */ - ( - Env.nameForAnon(locMut.ident), - optLeft.traverse(lm => Env.nameForAnon(lm.ident)), - Env.newAssignableVar, - Env.newAssignableVar - ) - .mapN { (currentList, optLeft, res, tmpList) => - Code - .block( - res := Code.Const.False, - tmpList := initVL, - optLeft.fold(Code.pass)(_ := emptyList), - // we don't match empty lists, so if currentList reaches Empty we are done - Code.While( - isNonEmpty(tmpList), - Code.block( - currentList := tmpList, - res := checkVL, - Code.ifElseS( - res, - tmpList := emptyList, - Code.block( - tmpList := tailList(tmpList), - optLeft.fold(Code.pass) { left => - left := consList(headList(currentList), left) - } - ) - ) - ) - ) - ) - .withValue(res) - } - // if expr is a Lambda handle it def topFn( name: Code.Ident,