Skip to content

Commit 3a156d0

Browse files
committed
add consts and Array
1 parent 015328b commit 3a156d0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

source/backends/rm86.d

+18-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ class BackendRM86 : CompilerBackend {
6060
foreach (name, ref type ; types) {
6161
NewConst(format("%s.sizeof", name), cast(long) type.size);
6262
}
63+
64+
// struct Array
65+
// usize length
66+
// usize memberSize
67+
// addr elements
68+
// end
69+
NewConst("Array.length", 0);
70+
NewConst("Array.memberSize", 2);
71+
NewConst("Array.elements", 4);
6372
}
6473

6574
void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) {
@@ -120,6 +129,9 @@ class BackendRM86 : CompilerBackend {
120129
output ~= format("mov word [si], __global_%s\n", node.name.Sanitise());
121130
output ~= "add si, 2\n";
122131
}
132+
else if (node.name in consts) {
133+
compiler.CompileNode(consts[node.name].value);
134+
}
123135
else {
124136
Error(node.error, "Undefined identifier '%s'", node.name);
125137
}
@@ -142,6 +154,8 @@ class BackendRM86 : CompilerBackend {
142154
assert(!inScope);
143155
inScope = true;
144156

157+
words[node.name] = Word(false, []);
158+
145159
output ~= format("jmp __func_end__%s\n", node.name.Sanitise());
146160
output ~= format("__func__%s:\n", node.name.Sanitise());
147161

@@ -157,12 +171,10 @@ class BackendRM86 : CompilerBackend {
157171
}
158172
output ~= format("add sp, %d\n", scopeSize);
159173

160-
output ~= "ret\n";
161-
output ~= format("__func_end__%s:\n", node.name.Sanitise());
162-
163-
words[node.name] = Word(false, []);
164-
variables = [];
165-
inScope = false;
174+
output ~= "ret\n";
175+
output ~= format("__func_end__%s:\n", node.name.Sanitise());
176+
variables = [];
177+
inScope = false;
166178
}
167179
}
168180

0 commit comments

Comments
 (0)