Re: Dragonflame 0.3a is out!

Hi robjoy,
This is directly concerning DFE because I would like to discuss the compiler and how its going to work. there are a few things you must know in order to write a compiler.
[list=#]
[#]You must know assembly language. For instance, you must know what a very simple program is in assembly language. This is a very simple file that does nothing, but contains the code
int main()
{
}
in assembly language. If you want to write a compiler, you must know what the following assembly source does
    .file    "asmtst.c"
    .def    ___main;    .scl    2;    .type    32;    .endef
    .text
.globl _main
    .def    _main;    .scl    2;    .type    32;    .endef
_main:
    leal    4(%esp), %ecx
    andl&nb sp;   $-16, %esp
    pushl    -4(%ecx)
    pushl    %ebp
    movl    %esp, %ebp
    pushl    %ecx
    subl    $4, %esp
    call    ___main
    addl    $4, %esp
    popl    %ecx
    popl    %ebp
    leal    -4(%ecx), %esp
    ret
Now this might seem easy, just paste it in! But there are a few things you must also know in order to do anything useful. Here is a simple hello world program in C, then assembly language:
C:
#include <stdio.h>

int main(int argc, const char* argv[])
{
printf ("Hello world!\n");
}

Assembly language:
    .file    "asmtst.c"
    .def    ___main;    .scl    2;&n bsp;   .type    32;    .endef
    .section .rdata,"dr"
LC0:
    .ascii "Hello world!\0"
    .text
.globl _main
    .def    _main;    .scl    2;    .type    32;    .endef
_main:
    leal    4(%esp), %ecx
    andl    $-16, %esp
    pushl    -4(%ecx)
    pushl    %ebp
    movl    %esp, %ebp
    pushl    %ecx
    subl    $4, %esp
    call    ___main
    movl    $LC0, (%esp)
    call    _printf
    addl    $4, %esp
    popl    %ecx
    popl    %ebp
    leal    -4(%ecx ), %esp
    ret
    .def    _printf;    .scl    2;    .type    32;    .endef
This does the exact thing in C as the assembler source does. Both do the same thing.
[#]You cannot convert source code to assembly language in lua. That requires another compiler like Gcc.[/#]
[#]You must know another high level language like C, C++, fortran, go, objective C, objective C++ or ada. This is a definite requirement.[/#]
[#]you must know the registers of the computers CpU architecture. For instance, a 32 bit CPU has eax, ax, etc, while a 64 bit system has rax, rbx etc.[/#]
[#]You need to know machine language, or a way to convert the binary created by your compiler into executable, machine language code that can be executed directly without going through an interpreter. Maybe GNU bison would be another, better choice?[/#]
[/list]
You should study these things before even t hinking about writing a compiler.

URL: http://forum.audiogames.net/viewtopic.php?pid=160369#p160369

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
http://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

Reply via email to