sys.nanosleep(0, 48000000)
# Keyboard input
- while stdin.poll_in do
- if stdin.eof then return
- var c = stdin.read_char
+ while sys.stdin.poll_in do
+ if sys.stdin.eof then return
+ var c = sys.stdin.read_char
if c == 'q'.ascii then
self.exists = false
return
redef class Object
protected fun debug_a_star: Bool do return false
private fun debug(msg: String) do if debug_a_star then
- stderr.write "a_star debug: {msg}\n"
+ sys.stderr.write "a_star debug: {msg}\n"
end
end
var filepath = args.shift
var text
if filepath == "-" then
- text = stdin.read_all
+ text = sys.stdin.read_all
else if filepath == "-e" then
if args.is_empty then
print "Error: -e need a text"
# Print `objects` on the standard output (`stdout`).
protected fun printn(objects: Object...)
do
- stdout.write(objects.to_s)
+ sys.stdout.write(objects.to_s)
end
# Print an `object` on the standard output (`stdout`) and add a newline.
protected fun print(object: Object)
do
- stdout.write(object.to_s)
- stdout.write("\n")
+ sys.stdout.write(object.to_s)
+ sys.stdout.write("\n")
end
# Read a character from the standard input (`stdin`).
protected fun getc: Char
do
- return stdin.read_char.ascii
+ return sys.stdin.read_char.ascii
end
# Read a line from the standard input (`stdin`).
protected fun gets: String
do
- return stdin.read_line
+ return sys.stdin.read_line
end
# Return the working (current) directory
new native_stderr is extern "file_NativeFileCapable_NativeFileCapable_native_stderr_0"
end
-# Standard input.
-fun stdin: Stdin do return once new Stdin
+redef class Sys
-# Standard output.
-fun stdout: OFStream do return once new Stdout
+ # Standard input
+ var stdin: PollableIStream protected writable = new Stdin
-# Standard output for error.
-fun stderr: OFStream do return once new Stderr
+ # Standard output
+ var stdout: OStream protected writable = new Stdout
+
+ # Standard output for errors
+ var stderr: OStream protected writable = new Stderr
+
+end
private fun fatal(v: NaiveInterpreter, message: String)
do
if v.modelbuilder.toolcontext.opt_no_color.value == true then
- stderr.write("Runtime error: {message} ({location.file.filename}:{location.line_start})\n")
+ sys.stderr.write("Runtime error: {message} ({location.file.filename}:{location.line_start})\n")
else
- stderr.write("{location}: Runtime error: {message}\n{location.colored_line("0;31")}\n")
- stderr.write(v.stack_trace)
- stderr.write("\n")
+ sys.stderr.write("{location}: Runtime error: {message}\n{location.colored_line("0;31")}\n")
+ sys.stderr.write(v.stack_trace)
+ sys.stderr.write("\n")
end
exit(1)
end
var pname = mpropdef.mproperty.name
var cname = mpropdef.mclassdef.mclass.name
if pname == "native_stdout" then
- return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, stdout)
+ return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, sys.stdout)
else if pname == "native_stdin" then
- return new PrimitiveInstance[IStream](mpropdef.mclassdef.mclass.mclass_type, stdin)
+ return new PrimitiveInstance[IStream](mpropdef.mclassdef.mclass.mclass_type, sys.stdin)
else if pname == "native_stderr" then
- return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, stderr)
+ return new PrimitiveInstance[OStream](mpropdef.mclassdef.mclass.mclass_type, sys.stderr)
else if pname == "io_open_read" then
var a1 = args[1].val.as(Buffer)
return new PrimitiveInstance[IStream](mpropdef.mclassdef.mclass.mclass_type, new IFStream.open(a1.to_s))
fun prompt do
printn ">> "
- search(stdin.read_line)
+ search(sys.stdin.read_line)
end
fun search(entry: String) do
loop
printn prompt
printn " "
- var s = stdin.read_line
+ var s = sys.stdin.read_line
if s == "" then continue
if s.chars.first == ':' then
var res = new TString
for m in messages do
if opt_no_color.value then
- stderr.write("{m}\n")
+ sys.stderr.write("{m}\n")
else
- stderr.write("{m.to_color_string}\n")
+ sys.stderr.write("{m.to_color_string}\n")
end
end