Skip to content

Commit 9cb7d5f

Browse files
committed
Merge branch 'main' into 1.19
2 parents 8c6f3f7 + bb808f2 commit 9cb7d5f

File tree

11 files changed

+217
-89
lines changed

11 files changed

+217
-89
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Pydantic's HISTORY.md](https://github.com/pydantic/pydantic/blob/main/HISTORY.md), and this project *mostly* adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [UNRELEASED]
8+
9+
### Changed
10+
11+
- A message is now displayed if attempting to use an Evaluator when not debugging, instead of silently failing.
12+
- Evaluators are now prevented from evaluating patterns after an Uncaught Mishap breakpoint is hit.
13+
14+
### Fixed
15+
16+
- Evaluators were unable to cast any spells requiring media.
17+
- When debugging, spells requiring media would fail if a Debugger was not in the hand that the debug session was started with.
18+
- Evaluator mishaps were unintentionally caught by the Uncaught Mishaps option, and did not apply side effects to the stack.
19+
720
## 0.2.0+1.19.2
821

922
### Added

Common/src/main/kotlin/gay/object/hexdebug/adapter/DebugAdapter.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gay.`object`.hexdebug.adapter
22

33
import at.petrak.hexcasting.api.spell.SpellList
4+
import at.petrak.hexcasting.api.spell.casting.CastingContext
45
import at.petrak.hexcasting.api.spell.casting.ControllerInfo
56
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType
67
import at.petrak.hexcasting.api.spell.iota.Iota
@@ -107,22 +108,21 @@ open class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
107108
})
108109
}
109110

110-
fun evaluate(pattern: HexPattern) = evaluate(PatternIota(pattern))
111+
fun evaluate(env: CastingEnvironment, pattern: HexPattern) = evaluate(env, PatternIota(pattern))
111112

112-
fun evaluate(iota: Iota) = evaluate(SpellList.LList(listOf(iota)))
113+
fun evaluate(env: CastingEnvironment, iota: Iota) = evaluate(env, SpellList.LList(listOf(iota)))
113114

114-
fun evaluate(list: SpellList) = debugger?.let {
115-
val result = it.evaluate(list)
116-
if (result?.startedEvaluating == true) {
115+
fun evaluate(env: CastingEnvironment, list: SpellList) = debugger?.let {
116+
val result = it.evaluate(env, list)
117+
if (result.startedEvaluating) {
117118
setEvaluatorState(ItemEvaluator.EvalState.MODIFIED)
118119
}
119120
handleDebuggerStep(result)
120121
}
121122

122123
fun resetEvaluator() {
123124
setEvaluatorState(ItemEvaluator.EvalState.DEFAULT)
124-
debugger?.also {
125-
it.resetEvaluator()
125+
if (debugger?.resetEvaluator() == true) {
126126
sendStoppedEvent("step")
127127
}
128128
}
@@ -141,12 +141,12 @@ open class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
141141
?: ResponseError(ResponseErrorCode.InternalError, e.toString(), e.stackTraceToString())
142142
}
143143

144-
private fun handleDebuggerStep(result: DebugStepResult?): ControllerInfo? {
145-
val view = debugger?.getClientView()?.also {
144+
private fun handleDebuggerStep(result: DebugStepResult): ControllerInfo? {
145+
val view = result.clientInfo?.also {
146146
IXplatAbstractions.INSTANCE.sendPacketToPlayer(player, MsgNewSpellPatternAck(it, -1))
147147
}
148148

149-
if (result == null) {
149+
if (result.isDone) {
150150
terminate(null)
151151
return view
152152
}
@@ -158,7 +158,7 @@ open class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
158158
})
159159
}
160160

161-
sendStoppedEvent(result.reason)
161+
sendStoppedEvent(result.reason.value)
162162
return view
163163
}
164164

@@ -233,29 +233,29 @@ open class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
233233

234234
override fun configurationDone(args: ConfigurationDoneArguments?): CompletableFuture<Void> {
235235
knownPlayers.add(player.uuid)
236-
handleDebuggerStep(debugger?.start())
236+
debugger?.start()?.also(::handleDebuggerStep)
237237
return futureOf()
238238
}
239239

240240
// stepping
241241

242242
override fun next(args: NextArguments?): CompletableFuture<Void> {
243-
handleDebuggerStep(debugger?.executeUntilStopped(RequestStepType.OVER))
243+
debugger?.executeUntilStopped(RequestStepType.OVER)?.also(::handleDebuggerStep)
244244
return futureOf()
245245
}
246246

247247
override fun continue_(args: ContinueArguments?): CompletableFuture<ContinueResponse> {
248-
handleDebuggerStep(debugger?.executeUntilStopped())
248+
debugger?.executeUntilStopped()?.also(::handleDebuggerStep)
249249
return futureOf()
250250
}
251251

252252
override fun stepIn(args: StepInArguments?): CompletableFuture<Void> {
253-
handleDebuggerStep(debugger?.executeOnce())
253+
debugger?.executeOnce()?.also(::handleDebuggerStep)
254254
return futureOf()
255255
}
256256

257257
override fun stepOut(args: StepOutArguments?): CompletableFuture<Void> {
258-
handleDebuggerStep(debugger?.executeUntilStopped(RequestStepType.OUT))
258+
debugger?.executeUntilStopped(RequestStepType.OUT)?.also(::handleDebuggerStep)
259259
return futureOf()
260260
}
261261

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package gay.`object`.hexdebug.casting.eval
2+
3+
import at.petrak.hexcasting.api.casting.castables.Action
4+
import at.petrak.hexcasting.api.casting.eval.env.PackagedItemCastEnv
5+
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect
6+
import gay.`object`.hexdebug.debugger.DebugStepType
7+
import gay.`object`.hexdebug.utils.findMediaHolderInHand
8+
import gay.`object`.hexdebug.utils.otherHand
9+
import net.minecraft.network.chat.Component
10+
import net.minecraft.server.level.ServerPlayer
11+
import net.minecraft.world.InteractionHand
12+
13+
class DebuggerCastEnv(
14+
caster: ServerPlayer,
15+
castingHand: InteractionHand,
16+
) : PackagedItemCastEnv(caster, castingHand), IDebugCastEnv {
17+
private val item = caster.getItemInHand(castingHand).item
18+
19+
override var lastEvaluatedAction: Action? = null
20+
override var lastDebugStepType: DebugStepType? = null
21+
22+
override fun printMessage(message: Component) {
23+
super.printMessage(message)
24+
printDebugMessage(caster, message)
25+
}
26+
27+
override fun sendMishapMsgToPlayer(mishap: OperatorSideEffect.DoMishap) {
28+
super.sendMishapMsgToPlayer(mishap)
29+
printDebugMishap(this, caster, mishap)
30+
}
31+
32+
override fun extractMediaEnvironment(cost: Long): Long {
33+
if (caster.isCreative) return 0
34+
35+
var costLeft = cost
36+
37+
// allow extracting from a debugger item in either hand, preferring the one we started casting with
38+
// NOTE: if holding two debuggers and the first is empty, this will take the empty one, not the other one
39+
val casterMediaHolder = caster.findMediaHolderInHand(castingHand, item)
40+
?: caster.findMediaHolderInHand(castingHand.otherHand, item)
41+
42+
// The contracts on the AD and on this function are different.
43+
// ADs return the amount extracted, this wants the amount left
44+
if (casterMediaHolder != null) {
45+
val extracted = casterMediaHolder.withdrawMedia(costLeft.toInt().toLong(), false)
46+
costLeft -= extracted
47+
}
48+
49+
// debugger can always extract from inventory
50+
if (costLeft > 0) {
51+
costLeft = extractMediaFromInventory(costLeft, canOvercast())
52+
}
53+
54+
return costLeft
55+
}
56+
}

Common/src/main/kotlin/gay/object/hexdebug/casting/eval/IMixinCastingContext.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,15 @@ fun printDebugMessage(
2727
) {
2828
DebugAdapterManager[caster]?.print(message.string + "\n", category, withSource)
2929
}
30+
31+
fun printDebugMishap(
32+
env: CastingContext,
33+
caster: ServerPlayer,
34+
mishap: OperatorSideEffect.DoMishap,
35+
) {
36+
mishap.mishap.errorMessageWithName(env, mishap.errorCtx)?.also {
37+
printDebugMessage(caster, it, OutputEventArgumentsCategory.STDERR)
38+
}
39+
}
40+
41+
val CastingVM.debugCastEnv get() = ctx as IMixinCastingContext

Common/src/main/kotlin/gay/object/hexdebug/debugger/DebugStepResult.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package gay.`object`.hexdebug.debugger
22

3+
import at.petrak.hexcasting.api.casting.eval.ExecutionClientView
34
import org.eclipse.lsp4j.debug.Source
45
import org.eclipse.lsp4j.debug.LoadedSourceEventArgumentsReason as LoadedSourceReason
56

67
data class DebugStepResult(
7-
val reason: String,
8+
val reason: StopReason,
89
val type: DebugStepType? = null,
10+
val clientInfo: ExecutionClientView? = null,
911
val loadedSources: Map<Source, LoadedSourceReason> = mapOf(),
1012
val startedEvaluating: Boolean = false,
1113
) {
14+
val isDone = reason == StopReason.TERMINATED
15+
16+
fun done() = copy(reason = StopReason.TERMINATED)
17+
1218
operator fun plus(other: DebugStepResult) = copy(
1319
loadedSources = loadedSources + other.loadedSources,
1420
)
Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
package gay.`object`.hexdebug.debugger
22

3+
enum class StopReason(val value: String, val stopImmediately: Boolean) {
4+
STEP("step", false),
5+
BREAKPOINT("breakpoint", true),
6+
EXCEPTION("exception", true),
7+
STARTED("entry", true),
8+
TERMINATED("terminated", true),
9+
}
10+
311
enum class DebugStepType {
412
IN,
513
OUT,
614
JUMP,
715
ESCAPE,
816
}
917

10-
enum class SourceBreakpointMode {
11-
EVALUATED,
12-
ESCAPED,
13-
ALL;
14-
15-
val label get() = when (this) {
16-
EVALUATED -> "Evaluated"
17-
ESCAPED -> "Escaped"
18-
ALL -> "All"
19-
}
20-
21-
val description get() = when (this) {
22-
EVALUATED -> "Stop if this iota would be evaluated. (default)"
23-
ESCAPED -> "Stop if this iota would be escaped."
24-
ALL -> "Always stop at this iota."
25-
}
18+
enum class SourceBreakpointMode(val label: String, val description: String) {
19+
EVALUATED("Evaluated", "Stop if this iota would be evaluated. (default)"),
20+
ESCAPED("Escaped", "Stop if this iota would be escaped."),
21+
ALL("All", "Always stop at this iota."),
2622
}
2723

28-
enum class ExceptionBreakpointType {
29-
UNCAUGHT_MISHAPS;
30-
31-
val label get() = when (this) {
32-
UNCAUGHT_MISHAPS -> "Uncaught Mishaps"
33-
}
34-
35-
val isDefault get() = when (this) {
36-
UNCAUGHT_MISHAPS -> true
37-
}
24+
enum class ExceptionBreakpointType(val label: String, val isDefault: Boolean) {
25+
UNCAUGHT_MISHAPS("Uncaught Mishaps", true),
3826
}

0 commit comments

Comments
 (0)