Skip to content

Commit 82b4cc7

Browse files
committed
Feature/Parity: Type checking for inspection prims
1 parent 7242420 commit 82b4cc7

5 files changed

Lines changed: 58 additions & 43 deletions

File tree

compiler/shared/src/main/scala/SimplePrims.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ object SimplePrims {
302302
case _: prim.etc._importpcolorsrgb => imperfect(c, "import-pcolors-rgb")
303303
case _: prim.etc._importworld => imperfect(c, "import-world")
304304

305+
case _: prim.etc._stopinspectingdeadagents => "InspectionPrims.clearDead"
306+
305307
}
306308
}
307309

@@ -310,16 +312,15 @@ object SimplePrims {
310312
PartialFunction.condOpt(c) {
311313

312314
// Turtle
313-
case _: prim.etc._setxy => "PrimChecks.turtle.setXY"
314-
315+
case _: prim.etc._setxy => "PrimChecks.turtle.setXY"
315316
// Random
316-
case _: prim.etc._randomseed => "PrimChecks.math.randomSeed"
317-
317+
case _: prim.etc._randomseed => "PrimChecks.math.randomSeed"
318318
// Other
319-
case _: prim.etc._error => s"PrimChecks.errorPrim"
320-
319+
case _: prim.etc._error => "PrimChecks.errorPrim"
321320
// World
322321
case _: prim.etc._setpatchsize => "PrimChecks.world.setPatchSize"
322+
// Inspection
323+
case _: prim.etc._inspect => "PrimChecks.inspection.inspect"
323324

324325
}
325326
}
@@ -341,6 +342,9 @@ object SimplePrims {
341342
case _: prim.etc._watch => "world.observer.watch"
342343
case _: prim.etc._resetperspective => "world.observer.resetPerspective"
343344

345+
// Inspection
346+
case _: prim.etc._stopinspecting => "InspectionPrims.stopInspecting"
347+
344348
}
345349
}
346350

@@ -414,11 +418,6 @@ object SimplePrims {
414418
case _: prim.etc._setupplots => "plotManager.setupPlots"
415419
case _: prim.etc._updateplots => "plotManager.updatePlots"
416420

417-
// Inspection
418-
case _: prim.etc._inspect => "InspectionPrims.inspect"
419-
case _: prim.etc._stopinspecting => "InspectionPrims.stopInspecting"
420-
case _: prim.etc._stopinspectingdeadagents => "InspectionPrims.clearDead"
421-
422421
// Misc.
423422
case _: prim.etc._clearall => "world.clearAll"
424423
case _: prim.etc._clearallandresetticks => "world.clearAllAndResetTicks"

engine/src/main/coffee/engine/prim-checks/checker.coffee

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,41 @@
55
{ checks } = require('../core/typechecker')
66
{ exceptionFactory: exceptions } = require('util/exception')
77

8-
AgentSetChecks = require('./agentset-checks')
9-
ColorChecks = require('./color-checks')
10-
ControlChecks = require('./control-checks')
11-
LinkChecks = require('./link-checks')
12-
ListChecks = require('./list-checks')
13-
MathChecks = require('./math-checks')
14-
PatchChecks = require('./patch-checks')
15-
ProcedureChecks = require('./procedure-checks')
16-
TaskChecks = require('./task-checks')
17-
TurtleChecks = require('./turtle-checks')
18-
WorldChecks = require('./world-checks')
19-
Validator = require('./validator')
8+
AgentSetChecks = require('./agentset-checks')
9+
ColorChecks = require('./color-checks')
10+
ControlChecks = require('./control-checks')
11+
LinkChecks = require('./link-checks')
12+
ListChecks = require('./list-checks')
13+
MathChecks = require('./math-checks')
14+
PatchChecks = require('./patch-checks')
15+
ProcedureChecks = require('./procedure-checks')
16+
TaskChecks = require('./task-checks')
17+
TurtleChecks = require('./turtle-checks')
18+
InspectionChecks = require('./inspection-checks')
19+
WorldChecks = require('./world-checks')
20+
Validator = require('./validator')
2021

2122
class Checker
2223

2324
constructor: ( i18nBundle, dumper, miscPrims, listPrims, randomPrims, stringPrims
24-
, procedurePrims, selfPrims, world) ->
25+
, procedurePrims, selfPrims, inspectionPrims, world) ->
2526

2627
getSelf = world.selfManager.self
2728

28-
@validator = new Validator(i18nBundle, dumper)
29-
@agentset = new AgentSetChecks(@validator, dumper, miscPrims, getSelf)
30-
@color = new ColorChecks(@validator)
31-
@list = new ListChecks(@validator, dumper, listPrims, stringPrims)
32-
@math = new MathChecks(@validator, randomPrims)
33-
@procedure = new ProcedureChecks(@validator, procedurePrims)
34-
@turtle = new TurtleChecks( @validator, getSelf, world.turtleManager
29+
@validator = new Validator(i18nBundle, dumper)
30+
@agentset = new AgentSetChecks(@validator, dumper, miscPrims, getSelf)
31+
@color = new ColorChecks(@validator)
32+
@list = new ListChecks(@validator, dumper, listPrims, stringPrims)
33+
@math = new MathChecks(@validator, randomPrims)
34+
@procedure = new ProcedureChecks(@validator, procedurePrims)
35+
@turtle = new TurtleChecks( @validator, getSelf, world.turtleManager
3536
, world.breedManager)
36-
@patch = new PatchChecks(@validator, getSelf)
37-
@link = new LinkChecks(@validator, getSelf, selfPrims)
38-
@task = new TaskChecks(@validator)
39-
@control = new ControlChecks(@validator)
40-
@world = new WorldChecks(@validator, world)
37+
@patch = new PatchChecks(@validator, getSelf)
38+
@link = new LinkChecks(@validator, getSelf, selfPrims)
39+
@task = new TaskChecks(@validator)
40+
@control = new ControlChecks(@validator)
41+
@inspection = new InspectionChecks(@validator, inspectionPrims)
42+
@world = new WorldChecks(@validator, world)
4143

4244
@turtleOrLink = {
4345
getVariable: (sourceStart, sourceEnd, name) =>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# (C) Uri Wilensky. https://github.com/NetLogo/Tortoise
2+
3+
{ Something } = require('brazier/maybe')
4+
{ exceptionFactory: exceptions } = require('util/exception')
5+
6+
class InspectionChecks
7+
8+
constructor: (@validator, @prims) ->
9+
10+
# (Int, Int, Agent) => Unit
11+
inspect: (sourceStart, sourceEnd, agent) ->
12+
if agent.isDead()
13+
throw exceptions.runtime("That #{agent.getBreedNameSingular()} is dead.", "inspect", Something(sourceStart), Something(sourceEnd))
14+
else
15+
@prims.inspect(agent)
16+
return
17+
18+
module.exports = InspectionChecks

engine/src/main/coffee/engine/prim/inspectionprims.coffee

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ module.exports.Config =
1010
module.exports.Prims =
1111
class InspectionPrims
1212
# (InspectionConfig) => InspectionPrims
13-
constructor: ({ inspect, @stopInspecting, @clearDead }) ->
14-
@inspect = (agent) ->
15-
if not agent.isDead()
16-
inspect(agent)
17-
else
18-
throw exceptions.runtime("That #{agent.getBreedNameSingular()} is dead.", "inspect")
13+
constructor: ({ @inspect, @stopInspecting, @clearDead }) ->
14+
return

engine/src/main/coffee/engine/workspace.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module.exports =
112112

113113
i18nBundle = new I18nBundle()
114114
primChecks = new PrimChecks( i18nBundle, dump, prims, listPrims, randomPrims
115-
, stringPrims, procedurePrims, selfPrims, world)
115+
, stringPrims, procedurePrims, selfPrims, inspectionPrims, world)
116116

117117
importWorldFromCSV = (csvText) ->
118118

0 commit comments

Comments
 (0)