Skip to content

Commit 5484cec

Browse files
committed
add raw functions
1 parent 00cb242 commit 5484cec

File tree

7 files changed

+51
-13
lines changed

7 files changed

+51
-13
lines changed

editors/micro_callisto.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ detect:
66
rules:
77
- statement: "\\b(func|end|begin|asm|include|inline|if|then|elseif|else|while|do)\\b"
88
- statement: "\\b(let|enable|requires|struct|version|return|const|enum|restrict)\\b"
9-
- statement: "\\b(continue|break|union|alias|overwrite|error)\\b"
9+
- statement: "\\b(continue|break|union|alias|overwrite|error|extern|call|raw)\\b"
1010
- type: "\\b(addr|void|u8|i8|u16|i16|u32|i32|u64|i64|size|usize|cell|array)\\b"
1111

1212
- constant.string:

examples/rawFunction.cal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
func raw test begin
2+
3+
end
4+
5+
test

source/backends/linux86.d

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,16 @@ class BackendLinux86 : CompilerBackend {
339339
assert(!inScope);
340340
inScope = true;
341341

342-
words[node.name] = Word(false, false, []);
342+
words[node.name] = Word(node.raw, false, []);
343+
344+
string symbol =
345+
node.raw? node.name : format("__func__%s", node.name.Sanitise());
343346

344347
if (exportSymbols) {
345-
output ~= format("global __func__%s\n", node.name.Sanitise());
348+
output ~= format("global %s\n", symbol);
346349
}
347350

348-
output ~= format("__func__%s:\n", node.name.Sanitise());
351+
output ~= format("%s:\n", symbol);
349352

350353
foreach (ref inode ; node.nodes) {
351354
compiler.CompileNode(inode);
@@ -755,7 +758,10 @@ class BackendLinux86 : CompilerBackend {
755758
Error(node.error, "Function '%s' doesn't exist");
756759
}
757760

758-
output ~= format("mov rax, __func__%s\n", node.func.Sanitise());
761+
auto word = words[node.func];
762+
string symbol = word.raw? node.func : format("__func__%s", node.func.Sanitise());
763+
764+
output ~= format("mov rax, %s\n", symbol);
759765
output ~= "mov [r15], rax\n";
760766
output ~= "add r15, 8\n";
761767
}

source/backends/rm86.d

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,12 @@ class BackendRM86 : CompilerBackend {
249249
assert(!inScope);
250250
inScope = true;
251251

252-
words[node.name] = Word(false, false, []);
252+
words[node.name] = Word(node.raw, false, []);
253253

254-
output ~= format("__func__%s:\n", node.name.Sanitise());
254+
string symbol =
255+
node.raw? node.name : format("__func__%s", node.name.Sanitise());
256+
257+
output ~= format("%s:\n", symbol);
255258

256259
foreach (ref inode ; node.nodes) {
257260
compiler.CompileNode(inode);
@@ -664,7 +667,11 @@ class BackendRM86 : CompilerBackend {
664667
Error(node.error, "Function '%s' doesn't exist");
665668
}
666669

667-
output ~= format("mov ax, __func__%s\n", node.func.Sanitise());
670+
auto word = words[node.func];
671+
string symbol =
672+
word.raw? node.func : format("__func__%s", node.func.Sanitise());
673+
674+
output ~= format("mov ax, %s\n", symbol);
668675
output ~= "mov [si], ax\n";
669676
output ~= "add si, 2\n";
670677
}

source/backends/uxn.d

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class BackendUXN : CompilerBackend {
148148

149149
override void Init() {
150150
output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2\n";
151+
output ~= "|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2\n";
151152
output ~= "|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1\n";
152153
output ~= "|100\n";
153154
output ~= "@on-reset\n";
@@ -250,9 +251,12 @@ class BackendUXN : CompilerBackend {
250251
assert(!inScope);
251252
inScope = true;
252253

253-
words[node.name] = Word(false, false, []);
254+
words[node.name] = Word(node.raw, false, []);
254255

255-
output ~= format("@func__%s\n", node.name.Sanitise());
256+
string symbol =
257+
node.raw? node.name : format("func__%s", node.name.Sanitise());
258+
259+
output ~= format("@%s\n", symbol);
256260

257261
foreach (ref inode ; node.nodes) {
258262
compiler.CompileNode(inode);
@@ -651,6 +655,10 @@ class BackendUXN : CompilerBackend {
651655
Error(node.error, "Function '%s' doesn't exist");
652656
}
653657

654-
output ~= format(";func__%s\n", node.func.Sanitise());
658+
auto word = words[node.func];
659+
string symbol =
660+
word.raw? node.func : format("func__%s", node.func.Sanitise());
661+
662+
output ~= format(";%s\n", symbol);
655663
}
656664
}

source/backends/y32.d

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,12 @@ class BackendY32 : CompilerBackend {
204204
assert(!inScope);
205205
inScope = true;
206206

207-
words[node.name] = Word(false, false, []);
208-
output ~= format("__func__%s:\n", node.name.Sanitise());
207+
words[node.name] = Word(node.raw, false, []);
208+
209+
string symbol =
210+
node.raw? node.name : format("__func__%s", node.name.Sanitise());
211+
212+
output ~= format("%s:\n", symbol);
209213

210214
foreach (ref inode ; node.nodes) {
211215
compiler.CompileNode(inode);

source/parser.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class FuncDefNode : Node {
7979
string name;
8080
Node[] nodes;
8181
bool inline;
82+
bool raw;
8283

8384
this(ErrorInfo perror) {
8485
type = NodeType.FuncDef;
@@ -470,6 +471,13 @@ class Parser {
470471

471472
Next();
472473
Expect(TokenType.Identifier);
474+
475+
if (tokens[i].contents == "raw") {
476+
ret.raw = true;
477+
Next();
478+
Expect(TokenType.Identifier);
479+
}
480+
473481
ret.name = tokens[i].contents;
474482

475483
Next();

0 commit comments

Comments
 (0)