isac-java/src/java-tests/isac/bridge/TestTerm.scala
author Walther Neuper <walther.neuper@jku.at>
Fri, 26 Mar 2021 10:45:05 +0100
changeset 5239 b4e3883d7b66
permissions -rw-r--r--
reset mathematics-engine to Isabelle2015

note: for this version libisabelle was available,
which connects front-end (Java) and back-end (Isabelle/ML)
walther@5239
     1
package isac.bridge
walther@5239
     2
walther@5239
     3
import junit.framework.TestCase
walther@5239
     4
walther@5239
     5
import isac.util.BridgeMainPaths
walther@5239
     6
walther@5239
     7
import java.nio.file.Paths
walther@5239
     8
import java.io.InputStream
walther@5239
     9
import junit.framework.Assert._
walther@5239
    10
walther@5239
    11
import scala.concurrent._
walther@5239
    12
import scala.concurrent.ExecutionContext.Implicits.global
walther@5239
    13
import scala.concurrent.duration._
walther@5239
    14
//import org.scalatest.junit.JUnit3Suite
walther@5239
    15
//import org.scalatest.junit.AssertionsForJUnit
walther@5239
    16
walther@5239
    17
import edu.tum.cs.isabelle._
walther@5239
    18
import edu.tum.cs.isabelle.api._
walther@5239
    19
import edu.tum.cs.isabelle.japi._
walther@5239
    20
import edu.tum.cs.isabelle.pure._
walther@5239
    21
import edu.tum.cs.isabelle.hol._
walther@5239
    22
import edu.tum.cs.isabelle.setup.Setup
walther@5239
    23
walther@5239
    24
class TestTerm extends TestCase {
walther@5239
    25
walther@5239
    26
  val ReadTerm = Operation.implicitly[(String, Typ, String), Option[Term]]("read_term")
walther@5239
    27
  
walther@5239
    28
  val MakeInt = Operation.implicitly[Unit, Term]("make_int")
walther@5239
    29
  
walther@5239
    30
  var IsabelleHome: String = _
walther@5239
    31
  
walther@5239
    32
  // get ISABELLE_HOME from BridgeMain.properties, compare isac.bridge.TestPIDE in java
walther@5239
    33
//  override def setUp() {
walther@5239
    34
//    var inputStream: InputStream = null
walther@5239
    35
//    try {
walther@5239
    36
//      val prop = new Properties()
walther@5239
    37
//      GOON
walther@5239
    38
//    }
walther@5239
    39
//    catch { case e: Exception =>
walther@5239
    40
//      e.printStackTrace()
walther@5239
    41
//      sys.exit(1)
walther@5239
    42
//    }
walther@5239
    43
//    
walther@5239
    44
//    IsabelleHome = new StringBuilder("TODO")
walther@5239
    45
//  }
walther@5239
    46
walther@5239
    47
  // another temmplate: http://stackoverflow.com/questions/15658310/scala-load-java-properties
walther@5239
    48
//  override def setUp() {
walther@5239
    49
//    val IsabelleHome = 
walther@5239
    50
//      try {
walther@5239
    51
//        //val prop = new Properties(List[String])
walther@5239
    52
//        val prop = new Properties()
walther@5239
    53
//        prop.load(new FileInputStream("TODO"))
walther@5239
    54
//        (
walther@5239
    55
//          new String(prop.getProperty("ISABELLE_HOME"))
walther@5239
    56
//        ) 
walther@5239
    57
//        } catch { case e: Exception => 
walther@5239
    58
//          e.printStackTrace()
walther@5239
    59
//          sys.exit(1)
walther@5239
    60
//        }
walther@5239
    61
//    }
walther@5239
    62
 
walther@5239
    63
  
walther@5239
    64
  def testTerm() {
walther@5239
    65
    //val setup = Setup(Paths.get(IsabelleHome), JPlatform.guess(),
walther@5239
    66
//  val setup = Setup(Paths.get(BridgeMainPaths.ISABELLE_HOME), JPlatform.guess(),
walther@5239
    67
    val setup = Setup(Paths.get("/usr/local/isabisac/"), JPlatform.guess(),
walther@5239
    68
          new Version("2015"), Setup.defaultPackageName)
walther@5239
    69
    val env = JSetup.makeEnvironment(setup)
walther@5239
    70
    val config = Configuration.fromBuiltin("libisabelle_Isac")
walther@5239
    71
    val sys = Await.result(System.create(env, config), 10.seconds)
walther@5239
    72
    val thy = Theory(sys, "Main")
walther@5239
    73
    
walther@5239
    74
    val expr = Await.result(Expr.ofString[scala.math.BigInt](thy, "3"), 10.seconds)
walther@5239
    75
    println(expr)
walther@5239
    76
    
walther@5239
    77
    val expr2 = Await.result(sys.invoke(ReadTerm)(("3", Type("Int.int", Nil), "Main")), 10.seconds)
walther@5239
    78
    println(expr2)
walther@5239
    79
    
walther@5239
    80
    val expr3 = Await.result(sys.invoke(MakeInt)(()), 10.seconds)
walther@5239
    81
    println(expr3)
walther@5239
    82
    //----- in Protocol.thy#operation_setup make_int: HOLogic.mk_number @{typ int} 3
walther@5239
    83
    // HOLogic.mk_number @{typ int} 3
walther@5239
    84
    //--- ouput in SML:
walther@5239
    85
    //       Const ("Num.numeral_class.numeral", "num ⇒ int") $ (
walther@5239
    86
    //         Const ("Num.num.Bit1", "num ⇒ num") $ 
walther@5239
    87
    //         Const ("Num.num.One", "num"))
walther@5239
    88
    //----- from ../TestTerm.scala:
walther@5239
    89
    // result(sys.invoke(MakeInt)(())
walther@5239
    90
    //--- ouput in scala:
walther@5239
    91
    // Success(
walther@5239
    92
    //   App(Const(Num.numeral_class.numeral,Type(fun,List(Type(Num.num,List()), Type(Int.int,List())))),
walther@5239
    93
    //     App(Const(Num.num.Bit1,Type(fun,List(Type(Num.num,List()), Type(Num.num,List())))),
walther@5239
    94
    //         Const(Num.num.One,Type(Num.num,List())))))
walther@5239
    95
    
walther@5239
    96
    val t: Term = Const("HOL.True", Typ.dummyT)
walther@5239
    97
    
walther@5239
    98
    t match {
walther@5239
    99
      case Const(_, _) =>
walther@5239
   100
      case Free(_, _) =>
walther@5239
   101
      case Abs(_, _, _) =>
walther@5239
   102
      case App(_, _) =>
walther@5239
   103
      case Var(_, _) =>
walther@5239
   104
      case Bound(_) =>
walther@5239
   105
    }
walther@5239
   106
  }
walther@5239
   107
walther@5239
   108
}