Permalink
Browse files

Get rid of the weird ass "Main" module which made no sense, factoring…

… it into

the System module. Oh, and "string".puts() is now officially the way you should be printing strings in Reia. If someone asks you for a Reia hello world and you tell them System.puts("Hello, World!") you're DOING IT WRONG
  • Loading branch information...
1 parent d73897d commit 09b1c4c383344cb6f1efbcbf94a77a89e000241b Tony Arcieri committed Sep 22, 2010
Showing with 37 additions and 42 deletions.
  1. +2 −2 examples/fibonacci.re
  2. +1 −1 examples/hello_world.re
  3. +24 −0 lib/system.re
  4. +0 −29 src/core/main.re
  5. +10 −10 test/runner.re
@@ -45,7 +45,7 @@ module Fibonacci
end
n = 42
-Main.puts("Fibonacci number #{n}: #{Fibonacci.optimized(n)}")
+"Fibonacci number #{n}: #{Fibonacci.optimized(n)}".puts()
n = 10
-Main.puts("First #{n} Fibonacci numbers: #{Fibonacci.optimized_list(n)}")
+"First #{n} Fibonacci numbers: #{Fibonacci.optimized_list(n)}".puts()
@@ -2,4 +2,4 @@
#
# From the toplevel Reia directory, run: bin/reia examples/hello_world.re
-"Hello, world!\n".print()
+"Hello, world!".puts()
View
@@ -1,4 +1,28 @@
module System
+ # Display a string to the user (with appended newline)
+ def puts(value)
+ erl.io.format("~s~n".to_list(), [value.to_s().to_binary()])
+ nil
+ end
+
+ # Display a string to the user (without any additional characters)
+ def print(value)
+ erl.io.format("~s".to_list(), [value.to_s().to_binary()])
+ nil
+ end
+
+ # Load a Reia source code file
+ def load(filename)
+ case erl.reia.load(filename.to_s().to_list())
+ when (:ok, _, _)
+ true
+ when (:error, :enoent)
+ throw(FileNotFound, "No such file or directory - #{filename}")
+ when (:error, error)
+ throw(LoadError, error)
+ end
+ end
+
# Argument list as passed in from the command line
def args
erl.init.get_plain_arguments().map { |arg| arg.to_string() }
View
@@ -1,29 +0,0 @@
-#
-# main.re: Methods available in all scopes
-# Copyright (C)2009-10 Tony Arcieri
-#
-# Redistribution is permitted under the MIT license. See LICENSE for details.
-#
-
-module Main
- def puts(value)
- erl.io.format("~s~n".to_list(), [value.to_s().to_binary()])
- nil
- end
-
- def print(value)
- erl.io.format("~s".to_list(), [value.to_s().to_binary()])
- nil
- end
-
- def load(filename)
- case erl.reia.load(filename.to_s().to_list())
- when (:ok, _, _)
- true
- when (:error, :enoent)
- throw(FileNotFound, "No such file or directory - #{filename}")
- when (:error, error)
- throw(LoadError, error)
- end
- end
-end
View
@@ -6,7 +6,7 @@
#
started_at = erl.now()
-Main.load("test/test_helper.re")
+System.load("test/test_helper.re")
tests = [
("builtins", [
@@ -23,38 +23,38 @@ tests = [
results = tests.map do |(group, modules)|
modules.map do |name|
try
- Main.load("test/#{group}/#{name}_test.re")
+ System.load("test/#{group}/#{name}_test.re")
mod = "#{name.capitalize()}Test".to_module()
mod.run()
catch ex
- Main.print("E")
+ System.print("E")
(:error, "#{group}/#{name}.re", ex)
end
end
end.flatten()
-Main.puts("\n")
+"\n".puts()
failures = [error for error = (:error, _, _, _, _) in results]
failures.each do |(:error, group, description, expected, actual)|
- Main.puts("'#{group} #{description}' FAILED")
- Main.puts("expected #{expected.inspect()}, actual #{actual.inspect()}\n")
+ "'#{group} #{description}' FAILED".puts()
+ "expected #{expected.inspect()}, actual #{actual.inspect()}\n".puts()
end
errors = [error for error = (:error, _, _) in results]
errors.each do |(:error, test, ex)|
case ex
when (:exception,(:throw, msg))
- Main.puts("#{test} ERROR: #{msg.to_s()}")
+ "#{test} ERROR: #{msg.to_s()}".puts()
when _
- Main.puts("#{test} ERROR: #{ex}\n")
+ "#{test} ERROR: #{ex}\n".puts()
end
end
finished_at = erl.now()
duration = TestHelper.duration(started_at, finished_at)
-Main.puts("Finished in #{duration} seconds\n")
-Main.puts("#{results.size()} assertions, #{failures.size()} failures, #{errors.size()} errors")
+"Finished in #{duration} seconds\n".puts()
+"#{results.size()} assertions, #{failures.size()} failures, #{errors.size()} errors".puts()
System.halt(1) if failures.size() > 0 or errors.size() > 0

0 comments on commit 09b1c4c

Please sign in to comment.