@@ -13,25 +13,17 @@ module Crystal::Playground
13
13
@tag = 0
14
14
end
15
15
16
- def run (source, tag)
17
- @logger .info " Request to run code (session=#{ @session_key } , tag=#{ tag } ).\n #{ source } "
18
-
19
- @tag = tag
20
- begin
21
- ast = Parser .new(source).parse
22
- rescue ex : Crystal ::Exception
23
- send_exception ex, tag
24
- return
25
- end
16
+ def self.instrument_and_prelude (session_key, port, tag, source, logger)
17
+ ast = Parser .new(source).parse
26
18
27
19
instrumented = Playground ::AgentInstrumentorTransformer .transform(ast).to_s
28
- @ logger .info " Code instrumentation (session=#{ @ session_key} , tag=#{ tag } ).\n #{ instrumented } "
20
+ logger.info " Code instrumentation (session=#{ session_key } , tag=#{ tag } ).\n #{ instrumented } "
29
21
30
22
prelude = %(
31
23
require "compiler/crystal/tools/playground/agent"
32
24
33
25
class Crystal::Playground::Agent
34
- @@instance = Crystal::Playground::Agent.new("ws://localhost:#{@ port}/agent/#{@ session_key}/#{tag}", #{tag})
26
+ @@instance = Crystal::Playground::Agent.new("ws://localhost:#{port}/agent/#{session_key}/#{tag}", #{tag})
35
27
36
28
def self.instance
37
29
@@instance
@@ -43,10 +35,23 @@ module Crystal::Playground
43
35
end
44
36
)
45
37
46
- sources = [
38
+ [
47
39
Compiler ::Source .new(" playground_prelude" , prelude),
48
40
Compiler ::Source .new(" play" , instrumented),
49
41
]
42
+ end
43
+
44
+ def run (source, tag)
45
+ @logger .info " Request to run code (session=#{ @session_key } , tag=#{ tag } ).\n #{ source } "
46
+
47
+ @tag = tag
48
+ begin
49
+ sources = self .class.instrument_and_prelude(@session_key , @port , tag, source, @logger )
50
+ rescue ex : Crystal ::Exception
51
+ send_exception ex, tag
52
+ return
53
+ end
54
+
50
55
output_filename = tempfile " play-#{ @session_key } -#{ tag } "
51
56
compiler = Compiler .new
52
57
compiler.color = false
0 commit comments