Skip to content

Commit

Permalink
move support wrappers classes for primitives in it.unibo.tuprolog.sol…
Browse files Browse the repository at this point in the history
…ve.primitive
  • Loading branch information
gciatto committed Jun 11, 2020
1 parent 8a9e10c commit b8b1f42
Show file tree
Hide file tree
Showing 46 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.exception.PrologError
import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException
import it.unibo.tuprolog.solve.exception.error.MessageError
import it.unibo.tuprolog.solve.primitive.UnaryPredicate

object Throw : UnaryPredicate<ExecutionContext>("throw") {
override fun uncheckedImplementation(request: Solve.Request<ExecutionContext>): Sequence<Solve.Response> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.core.Term
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper

/** Base class to implement primitives that relate two [Term]s and provide a single response */
abstract class BinaryRelation<E : ExecutionContext>(operator: String) : PrimitiveWrapper<E>(operator, 2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper

/** Base class to implement primitives that relate tree [Term]s and are not back-trackable */
abstract class NonBacktrackableTernaryRelation<E : ExecutionContext>(operator: String) : TernaryRelation<E>(operator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper

/** A base class to implement predicates with zero argument */
abstract class PredicateWithoutArguments<E : ExecutionContext>(operator: String) : PrimitiveWrapper<E>(operator, 0)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.core.Term
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper

/** Base class to implement primitives that relate tree [Term]s */
abstract class TernaryRelation<E : ExecutionContext>(operator: String) : PrimitiveWrapper<E>(operator, 3) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException

abstract class TypeEnsurer<E : ExecutionContext>(typeName: String) : UnaryPredicate<E>(typeName) {
override fun uncheckedImplementation(request: Solve.Request<E>): Sequence<Solve.Response> = sequence {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.unibo.tuprolog.solve.stdlib.primitive
package it.unibo.tuprolog.solve.primitive

import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper

/** A base class to implement predicates with one argument */
abstract class UnaryPredicate<E : ExecutionContext>(operator: String) : PrimitiveWrapper<E>(operator, 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package it.unibo.tuprolog.solve.primitive

typealias ZeroaryPredicate<E> = PredicateWithoutArguments<E>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.SideEffect1

abstract class AbstractAssert(suffix: String, private val before: Boolean) : SideEffect1<ExecutionContext>("assert$suffix") {
override fun accept(request: Solve.Request<ExecutionContext>, term: Term): Solve.Response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation

/** Implementation of '=:='/2 predicate */
object ArithmeticEqual : ArithmeticRelation<ExecutionContext>("=:=") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation

/** Implementation of '>'/2 predicate */
object ArithmeticGreaterThan : ArithmeticRelation<ExecutionContext>(">") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation

/** Implementation of '>='/2 predicate */
object ArithmeticGreaterThanOrEqualTo : ArithmeticRelation<ExecutionContext>(">=") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation

/** Implementation of '<'/2 predicate */
object ArithmeticLowerThan : ArithmeticRelation<ExecutionContext>("<") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation

/** Implementation of '=<'/2 predicate */
object ArithmeticLowerThanOrEqualTo : ArithmeticRelation<ExecutionContext>("=<") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation

/** Implementation of '=\='/2 predicate */
object ArithmeticNotEqual : ArithmeticRelation<ExecutionContext>("=\\=") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Atom : TypeTester<ExecutionContext>("atom") {
override fun testType(term: Term): Boolean = term is it.unibo.tuprolog.core.Atom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Constant
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Atomic : TypeTester<ExecutionContext>("atomic") {
override fun testType(term: Term): Boolean = term is Constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Callable : TypeTester<ExecutionContext>("callable") {
override fun testType(term: Term): Boolean = term is Struct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Compound : TypeTester<ExecutionContext>("compound") {
override fun testType(term: Term): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import it.unibo.tuprolog.solve.Signature
import it.unibo.tuprolog.solve.exception.error.InstantiationError
import it.unibo.tuprolog.solve.exception.error.TypeError
import it.unibo.tuprolog.solve.extractSignature
import it.unibo.tuprolog.solve.primitive.TypeEnsurer

object EnsureExecutable : TypeEnsurer<ExecutionContext>("ensure_executable") {
private fun ensurerVisitor(context: ExecutionContext, procedure: Signature): TermVisitor<Unit> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.exception.error.MetaError
import it.unibo.tuprolog.solve.primitive.NonBacktrackableTernaryRelation
import it.unibo.tuprolog.unify.Unificator.Companion.mguWith

object FindAll : NonBacktrackableTernaryRelation<ExecutionContext>("findall") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Real
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Float : TypeTester<ExecutionContext>("float") {
override fun testType(term: Term): Boolean = term is Real
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Ground : TypeTester<ExecutionContext>("ground") {
override fun testType(term: Term): Boolean = term.isGround
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Integer : TypeTester<ExecutionContext>("integer") {
override fun testType(term: Term): Boolean = term is it.unibo.tuprolog.core.Integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.function.ArithmeticEvaluator
import it.unibo.tuprolog.solve.primitive.TermRelation
import it.unibo.tuprolog.unify.Unificator.Companion.mguWith

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.UnaryPredicate
import org.gciatto.kt.math.BigInteger

// TODO doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.SideEffect0

object NewLine : SideEffect0<ExecutionContext>("nl") {
override fun accept(request: Solve.Request<ExecutionContext>): Solve.Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object NonVar : TypeTester<ExecutionContext>("nonvar") {
override fun testType(term: Term): Boolean = term !is it.unibo.tuprolog.core.Var
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TermRelation
import it.unibo.tuprolog.unify.Unificator.Companion.matches

/** Implementation of '\='/2 predicate */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Number : TypeTester<ExecutionContext>("number") {
override fun testType(term: Term): Boolean = term is Numeric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.*
import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.BacktrackableSideEffect1
import it.unibo.tuprolog.theory.RetractResult
import it.unibo.tuprolog.unify.Unificator.Companion.mguWith

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TermRelation

/** Implementation of '=='/2 predicate */
object TermIdentical : TermRelation.WithoutSideEffects<ExecutionContext>("==") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TermRelation

/** Implementation of `'\=='/2` predicate */
object TermNotIdentical : TermRelation.WithoutSideEffects<ExecutionContext>("\\==") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TermRelation
import it.unibo.tuprolog.unify.Unificator.Companion.mguWith

/** Implementation of '='/2 predicate */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.primitive.TypeTester

object Var : TypeTester<ExecutionContext>("var") {
override fun testType(term: Term): Boolean = term is it.unibo.tuprolog.core.Var
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import it.unibo.tuprolog.core.Atom
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.SideEffect1

object Write : SideEffect1<ExecutionContext>("write") {
override fun accept(request: Solve.Request<ExecutionContext>, term: Term): Solve.Response {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.unibo.tuprolog.solve.stdlib.primitive

import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.primitive.UnaryPredicate
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TypeTestingUtils.assertCorrectResponse
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TypeTestingUtils.atomQueryToResult
import it.unibo.tuprolog.solve.stdlib.primitive.testutils.TypeTestingUtils.atomicQueryToResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException
import it.unibo.tuprolog.solve.exception.error.EvaluationError
import it.unibo.tuprolog.solve.exception.error.InstantiationError
import it.unibo.tuprolog.solve.primitive.ArithmeticRelation
import kotlin.reflect.KClass
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import it.unibo.tuprolog.solve.Solve
import it.unibo.tuprolog.solve.exception.TuPrologRuntimeException
import it.unibo.tuprolog.solve.exception.error.InstantiationError
import it.unibo.tuprolog.solve.exception.error.TypeError
import it.unibo.tuprolog.solve.primitive.UnaryPredicate
import it.unibo.tuprolog.solve.stdlib.primitive.*
import it.unibo.tuprolog.utils.squared
import kotlin.collections.List
Expand Down

0 comments on commit b8b1f42

Please sign in to comment.