Skip to content

Commit 63ca374

Browse files
committed
spooky jumpscares
1 parent e1c95d4 commit 63ca374

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ COPY ./build.sh /compiler
1717
WORKDIR /compiler
1818
RUN /compiler/build.sh
1919
RUN ln -s /compiler/_build/spooky.native /usr/local/bin/compile
20-
ENTRYPOINT [ "compile" ]
20+
ENTRYPOINT [ "compile", "-j" ]

compiler/bytecodeInterpreter.ml

+9-2
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,17 @@ class virtual_machine = object(self)
318318
val mutable registers = ((Array.create ~len:0 (Void)): spookyval array)
319319
val mutable op_stack = ([] : spookyval list)
320320
val mutable debug = false
321+
val mutable jumpscares = false
321322
val mutable context = Void
322323
val mutable returning = false
323324

324325
method enable_debug =
325326
debug <- true
326327

328+
method enable_jumpscares =
329+
JumpScares.initialize;
330+
jumpscares <- true
331+
327332
method print_and_then_scream =
328333
match op_stack with
329334
| [] -> print_endline "AHHHHHHHHHHHH!"
@@ -515,7 +520,8 @@ class virtual_machine = object(self)
515520
self#try_loop loop_statement
516521
);
517522

518-
method interpret_opcodes opcodes =
523+
method interpret_opcodes opcodes =
524+
JumpScares.try_jump_scare;
519525
match Stream.peek opcodes, op_stack with
520526
| None, [] -> ()
521527
| None, result :: tl -> ()
@@ -873,11 +879,12 @@ let rec opcodes ?d:(debug=false) bytes =
873879
)
874880
in Stream.from(next_opcode)
875881

876-
let interpret ?d:(debug=false) bytestream =
882+
let interpret ?j:(jumpscares=false) ?d:(debug=false) bytestream =
877883
if debug then (
878884
print_endline "DEBUGGING BYTECODE: ";
879885
print_newline()
880886
);
881887
let vm = new virtual_machine in
882888
if debug then vm#enable_debug;
889+
if jumpscares then vm#enable_jumpscares;
883890
vm#interpret_opcodes (opcodes ~d:debug bytestream)

compiler/jumpScares.ml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
open Core
2+
3+
let initialize =
4+
Random.self_init()
5+
6+
let try_jump_scare =
7+
if (Random.float 1.0) <. 0.001 then (
8+
print_endline " BOO! AHHHHHHHHHHHHHHHHH!";
9+
print_endline(" _.---._\n .' `.\n :) (:\n \\ (@) (@) /\n \\ A /\n ) (\n \\\"\"\"\"\"/\n `._.'\n .=.\n .---._.-.=.-._.---.\n / ':-(_.-: :-._)-:` \\\n / /' (__.-: :-.__) `\\ \\\n / / (___.-` '-.___) \\ \\\n / / (___.-'^`-.___) \\ \\\n / / (___.-'=`-.___) \\ \\\n / / (____.'=`.____) \\ \\\n / / (___.'=`.___) \\ \\\n (_.; `---'.=.`---' ;._)\n ;|| __ _.=._ __ ||;\n ;|| ( `.-.=.-.' ) ||;\n ;|| \\ `.=.' / ||;\n ;|| \\ .=. / ||;\n ;|| .-`.`-._.-'.'-. ||;\n.:::\\ ( ,): O O :(, ) /:::.\n|||| ` / /'`--'--'`\\ \\ ' ||||\n'''' / / \\ \\ ''''\n / / \\ \\\n / / \\ \\\n / / \\ \\\n / / \\ \\\n / / \\ \\\n /.' `.\\\n (_)' `(_)\n \\\\. .//\n \\\\. .//\n \\\\. .//\n \\\\. .//\n \\\\. .//\n \\\\. .//\n jgs \\\\. .//\n ///) (\\\\\\\n ,///' `\\\\\\,\n ///' `\\\\\\\n \"\"' '\"\"\n")
10+
)

compiler/spooky.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ and compile_key_value_assignment key_val symbol_table =
249249
let key_val_expr = List.append key_expression value_expression in
250250
List.append key_opcode key_val_expr
251251

252-
let compile debug filename =
252+
let compile debug jumpscares filename =
253253
let input = open_in filename in
254254
let filebuf = Lexing.from_channel input in
255255
try
@@ -267,7 +267,7 @@ let compile debug filename =
267267
print_newline();
268268
print_newline();
269269
);
270-
BytecodeInterpreter.interpret ~d:debug (Stream.of_list (add_main_call st (compile_ast st ast)));
270+
BytecodeInterpreter.interpret ~j:jumpscares ~d:debug (Stream.of_list (add_main_call st (compile_ast st ast)));
271271
if debug then print_endline "🐛 🐞 🐜 🦋 🕷️ 🐝 🐛 🦋 🐞 🐛 🐞 🐜 🐝 🦋 🕷️ 🐛 🐝 🦋 🐞 🕷️ 🐛 🦋 🐝 🐞 🐛 🐞 🐜 🦋 🐞 🐝 🕷️ 🐛 🦋 🐞"
272272
with
273273
| Scarerrors.Error msg ->
@@ -287,14 +287,15 @@ let spec =
287287
let open Command.Spec in
288288
empty
289289
+> flag "-d" no_arg ~doc:"run with scary de'bug'ging output"
290+
+> flag "-j" no_arg ~doc:"run with jumpscares"
290291
+> anon("filename" %: file)
291292

292293
let command =
293294
Command.basic
294295
~summary:"The Spooky language compiler"
295296
~readme:(fun () -> "The world's first scary-complete language.")
296297
spec
297-
(fun debug filename () -> compile debug filename)
298+
(fun jumpscares debug filename () -> compile jumpscares debug filename)
298299

299300
let () =
300301
Command.run ~version:"0.10" ~build_info:"RWO" command

0 commit comments

Comments
 (0)