1 # coding: utf-8
2 # frozen_string_literal: true
3
4
5
6 module Umu
7
8 module Value
9
10 module Core
11
12 class Device < Top
13 define_class_method(
14 :meth_make_stdin,
15 :stdin, [],
16 [], VC::IO::Input
17 )
18 def self.meth_make_stdin(_loc, _env, _event)
19 VC.make_input ::STDIN
20 end
21
22
23 define_class_method(
24 :meth_make_stdout,
25 :stdout, [],
26 [], VC::IO::Output
27 )
28 def self.meth_make_stdout(_loc, _env, _event)
29 VC.make_output ::STDOUT
30 end
31
32
33 define_class_method(
34 :meth_make_stderr,
35 :stderr, [],
36 [], VC::IO::Output
37 )
38 def self.meth_make_stderr(_loc, _env, _event)
39 VC.make_output ::STDERR
40 end
41
42
43 define_class_method(
44 :meth_see,
45 :see, [],
46 [VCA::String], VC::IO::Input
47 )
48 def self.meth_see(_loc, _env, _event, file_path)
49 ASSERT.kind_of file_path, VCA::String
50
51 file = ::File.open file_path.val, "r"
52
53 VC.make_input file
54 end
55
56
57 define_class_method(
58 :meth_see_with,
59 :'see-with', [],
60 [VCA::String, VC::Fun], VC::Unit
61 )
62 def self.meth_see_with(loc, env, event, file_path, func)
63 ASSERT.kind_of file_path, VCA::String
64 ASSERT.kind_of func, VC::Fun
65
66 ::File.open(file_path.val, "r") do |file|
67 func.apply VC.make_input(file), [], loc, env.enter(event)
68 end
69
70 VC.make_unit
71 end
72
73
74 define_class_method(
75 :meth_see_dir,
76 :'see-dir', [],
77 [VCA::String], VC::Dir
78 )
79 def self.meth_see_dir(_loc, _env, _event, file_path)
80 ASSERT.kind_of file_path, VCA::String
81
82 dir = ::Dir.open file_path.val
83
84 VC.make_dir dir
85 end
86
87 define_class_method(
88 :meth_see_dir_with,
89 :'see-dir-with', [],
90 [VCA::String, VC::Fun], VC::Unit
91 )
92 def self.meth_see_dir_with(loc, env, event, file_path, func)
93 ASSERT.kind_of file_path, VCA::String
94 ASSERT.kind_of func, VC::Fun
95
96 ::Dir.open(file_path.val) do |dir|
97 func.apply VC.make_dir(dir), [], loc, env.enter(event)
98 end
99
100 VC.make_unit
101 end
102
103
104 define_class_method(
105 :meth_tell,
106 :tell, [],
107 [VCA::String], VC::IO::Output
108 )
109 def self.meth_tell(_loc, _env, _event, file_path)
110 ASSERT.kind_of file_path, VCA::String
111
112 file = ::File.open file_path.val, "a"
113
114 VC.make_output file
115 end
116
117
118 define_class_method(
119 :meth_tell_with,
120 :'tell-with', [],
121 [VCA::String, VC::Fun], VC::Unit
122 )
123 def self.meth_tell_with(loc, env, event, file_path, func)
124 ASSERT.kind_of file_path, VCA::String
125 ASSERT.kind_of func, VC::Fun
126
127 ::File.open(file_path.val, "a") do |file|
128 func.apply VC.make_output(file), [], loc, env.enter(event)
129 end
130
131 VC.make_unit
132 end
133 end
134 Device.freeze
135
136 end # Umu::Value::Core
137
138 end # Umu::Value
139
140 end # Umu