-
Notifications
You must be signed in to change notification settings - Fork 0
/
standart_library.rb
185 lines (150 loc) · 4.36 KB
/
standart_library.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
require_relative 'generator/generator'
class StandartLibrary
attr_reader :functions
def initialize
@functions = {}
add_definition('void', 'print', ['string'])
add_definition('string', 'get_input', [])
add_definition('string', 'int_to_string', ['int'])
add_definition('int', 'string_to_int', ['string'])
add_definition('string', 'float_to_string', ['float'])
add_definition('pointer', 'allocate', ['int'], true)
add_definition('void', 'sleep', ['int'])
add_definition('void', 'clear', [])
add_definition('bool', 'left_key', [])
add_definition('bool', 'right_key', [])
add_definition('void', 'set_color', ['int'])
add_definition('bool', 'r_key', [])
add_definition('string', 'ascii_to_char', ['int'])
add_definition('void', 'rblc', ['string'])
add_definition('void', 'bblc', ['string'])
end
def add_definition(return_type, name, params, r_any_pointer = false)
@functions[name] = {'type' => return_type, 'params' => params, 'r_any_pointer' => r_any_pointer}
end
def generate(gen)
generate_print(gen)
generate_get_input(gen)
generate_int_to_string(gen)
generate_string_to_int(gen)
generate_float_to_string(gen)
generate_allocate(gen)
generate_sleep(gen)
generate_clear(gen)
generate_left_key(gen)
generate_right_key(gen)
generate_set_color(gen)
generate_r_key(gen)
generate_ascii_to_char(gen)
generate_rblc(gen)
generate_bblc(gen)
end
def generate_print(gen)
gen.label_function('print')
gen.set_current_function('print')
gen.add_variable(TypeString.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:PRINT)
gen.write(:RET)
end
def generate_get_input(gen)
gen.label_function('get_input')
gen.set_current_function('get_input')
gen.write(:GINP)
gen.write(:RET_V)
end
def generate_int_to_string(gen)
gen.label_function('int_to_string')
gen.set_current_function('int_to_string')
gen.add_variable(TypeInt.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:ITS)
gen.write(:RET_V)
end
def generate_string_to_int(gen)
gen.label_function('string_to_int')
gen.set_current_function('string_to_int')
gen.add_variable(TypeString.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:STI)
gen.write(:RET_V)
end
def generate_float_to_string(gen)
gen.label_function('float_to_string')
gen.set_current_function('float_to_string')
gen.add_variable(TypeFloat.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:FTS)
gen.write(:RET_V)
end
def generate_allocate(gen)
gen.label_function('allocate')
gen.set_current_function('allocate')
gen.add_variable(TypeInt.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:ALLOC)
gen.write(:RET_V)
end
def generate_sleep(gen)
gen.label_function('sleep')
gen.set_current_function('sleep')
gen.add_variable(TypeInt.new, '0', 0)
gen.write(:SLEEP, 0)
gen.write(:RET)
end
def generate_clear(gen)
gen.label_function('clear')
gen.set_current_function('clear')
gen.write(:CLEAR)
gen.write(:RET)
end
def generate_left_key(gen)
gen.label_function('left_key')
gen.set_current_function('left_key')
gen.write(:LEFT_KEY)
gen.write(:RET_V)
end
def generate_right_key(gen)
gen.label_function('right_key')
gen.set_current_function('right_key')
gen.write(:RIGHT_KEY)
gen.write(:RET_V)
end
def generate_set_color(gen)
gen.label_function('set_color')
gen.set_current_function('set_color')
gen.add_variable(TypeInt.new, '0', 0)
gen.write(:SETCOLOR)
gen.write(:RET)
end
def generate_r_key(gen)
gen.label_function('r_key')
gen.set_current_function('r_key')
gen.write(:R_KEY)
gen.write(:RET_V)
end
def generate_ascii_to_char(gen)
gen.label_function('ascii_to_char')
gen.set_current_function('ascii_to_char')
gen.add_variable(TypeInt.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:ATC)
gen.write(:RET_V)
end
def generate_rblc(gen)
gen.label_function('rblc')
gen.set_current_function('rblc')
gen.add_variable(TypeString.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:RBLC)
gen.write(:RET)
end
def generate_bblc(gen)
gen.label_function('bblc')
gen.set_current_function('bblc')
gen.add_variable(TypeString.new, '0', 0)
gen.write(:PEEK, 0)
gen.write(:BBLC)
gen.write(:RET)
end
end