@@ -12,6 +12,7 @@ import callisto.compiler;
1212import callisto.language;
1313
1414private struct Word {
15+ bool raw;
1516 bool inline;
1617 Node[] inlineNodes;
1718}
@@ -132,20 +133,38 @@ class BackendLinux86 : CompilerBackend {
132133 }
133134
134135 override string [] GetVersions () => [
135- " Linux86" , " Linux" , " LittleEndian" , " 16Bit" , " 32Bit" , " 64Bit"
136+ // platform
137+ " Linux86" , " Linux" , " LittleEndian" , " 16Bit" , " 32Bit" , " 64Bit" ,
138+ // features
139+ " IO" , " Exit" , " Time" , " File"
136140 ];
137141
138- override string [] FinalCommands () => [
139- format(" mv %s %s.asm" , compiler.outFile, compiler.outFile),
140- useDebug?
141- format(
142- " nasm -f elf64 %s.asm -o %s.o -F dwarf -g" , compiler.outFile,
143- compiler.outFile
144- ) :
145- format(" nasm -f elf64 %s.asm -o %s.o" , compiler.outFile, compiler.outFile),
146- format(" ld %s.o -o %s" , compiler.outFile, compiler.outFile),
147- format(" rm %s.asm %s.o" , compiler.outFile, compiler.outFile)
148- ];
142+ override string [] FinalCommands () {
143+ string [] ret = [
144+ format(" mv %s %s.asm" , compiler.outFile, compiler.outFile),
145+ useDebug?
146+ format(
147+ " nasm -f elf64 %s.asm -o %s.o -F dwarf -g" , compiler.outFile,
148+ compiler.outFile
149+ ) :
150+ format(" nasm -f elf64 %s.asm -o %s.o" , compiler.outFile, compiler.outFile)
151+ ];
152+
153+ string linkCommand = format(" ld %s.o -o %s" , compiler.outFile, compiler.outFile);
154+
155+ foreach (ref lib ; link) {
156+ linkCommand ~= format(" -l%s" , lib);
157+ }
158+
159+ if (! link.empty()) {
160+ // idk if this is correct on all linux systems but whatever
161+ linkCommand ~= " -dynamic-linker /lib64/ld-linux-x86-64.so.2" ;
162+ }
163+
164+ ret ~= linkCommand;
165+
166+ return ret ~ format(" rm %s.asm %s.o" , compiler.outFile, compiler.outFile);
167+ }
149168
150169 override void BeginMain () {
151170 output ~= " __calmain:\n " ;
@@ -258,7 +277,12 @@ class BackendLinux86 : CompilerBackend {
258277 }
259278 }
260279 else {
261- output ~= format(" call __func__%s\n " , node.name.Sanitise());
280+ if (word.raw) {
281+ output ~= format(" call %s\n " , node.name);
282+ }
283+ else {
284+ output ~= format(" call __func__%s\n " , node.name.Sanitise());
285+ }
262286 }
263287 }
264288 else if (VariableExists(node.name)) {
@@ -307,13 +331,13 @@ class BackendLinux86 : CompilerBackend {
307331 thisFunc = node.name;
308332
309333 if (node.inline) {
310- words[node.name] = Word(true , node.nodes);
334+ words[node.name] = Word(false , true , node.nodes);
311335 }
312336 else {
313337 assert (! inScope);
314338 inScope = true ;
315339
316- words[node.name] = Word(false , []);
340+ words[node.name] = Word(false , false , []);
317341
318342 if (exportSymbols) {
319343 output ~= format(" global __func__%s\n " , node.name.Sanitise());
@@ -707,4 +731,14 @@ class BackendLinux86 : CompilerBackend {
707731 types[node.to] = types[node.from];
708732 NewConst(format(" %s.sizeof" , node.to), cast (long ) types[node.to].size);
709733 }
734+
735+ override void CompileExtern (ExternNode node) {
736+ Word word;
737+ word.raw = node.raw;
738+ words[node.func] = word;
739+
740+ if (word.raw) {
741+ output ~= format(" extern %s\n " , node.func);
742+ }
743+ }
710744}
0 commit comments