From: Jean-Christophe Beaupré Date: Tue, 16 Dec 2014 15:20:04 +0000 (-0500) Subject: brainfuck: Remove warnings. X-Git-Tag: v0.7~28^2 X-Git-Url: http://nitlanguage.org brainfuck: Remove warnings. Signed-off-by: Jean-Christophe Beaupré --- diff --git a/contrib/brainfuck/brainfuck.nit b/contrib/brainfuck/brainfuck.nit index b614776..c35b08a 100644 --- a/contrib/brainfuck/brainfuck.nit +++ b/contrib/brainfuck/brainfuck.nit @@ -16,7 +16,7 @@ module brainfuck # Interpreter for Brainfuck source code. -class BFInterpret +class BFInterpreter # Data cells var dr = new Array[Char] # Data pointer @@ -28,16 +28,19 @@ class BFInterpret var program: String # Contains the set of valid instructions, used in next - var valid_instr: Set[Char] + var valid_instr: Set[Char] is noinit - # Starts interpretation of file `filename` - init(filename: String) do - var ifs = new IFStream.open(filename.simplify_path) + # Create an interpreter for `program`. + init do valid_instr = new HashSet[Char] valid_instr.add_all "><[].,+-".chars dr.add 0.ascii - program = ifs.read_all - start + end + + # Create an interpreter for the file located at `path`. + init from_file(path: String) do + var ifs = new IFStream.open(path) + init(ifs.read_all) end # Starts the interpretation of the loaded program @@ -131,4 +134,4 @@ class BFInterpret end end -var i = new BFInterpret(args[0]) +new BFInterpreter.from_file(args[0]).start