![]() |
|
SPONSORED LINKS BY GOOGLE |
|
SPONSORED LINKS BY GOOGLE |
|
7
20th August 09:41
External User
Posts: 1
|
"funkyj" <funkyj@gmail.com> writes:
See: http://www.cl-user.net/asp/search?search=assembler Paolo -- Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film The Common Lisp Directory: http://www.cl-user.net |
|
|
10
20th August 09:41
External User
Posts: 1
|
"funkyj" <funkyj@gmail.com> writes:
Writting an assembler is Lisp is easy. You benefit immediately of Lisp macros, and can use any lisp function at macro-expansion / assembly time. You may have to be careful not to mixup the phases however. Just provide a driver to read and process at (CL) run-time the LAP forms and "assemble" with an explicit macro-expansion phase. There are various examples of sexpified java too: http://www.franz.com/support/documen....2/doc/jil.htm There are already some options for sexps to C. For example, gcl and CLiCC. http://www.cliki.net/CLiCC CLiCC starts from: ;;--------------------------------------------------------------------- ;; TAILP sublist list ;;--------------------------------------------------------------------- (defun tailp (sublist list) (cond ((eql sublist list) t) ((atom list) nil) (t (tailp sublist (cdr list))))) and generates: void Ftailp(CL_FORM *base) { M1_1:; if(EQL(ARG(0), ARG(1))) { LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(0)); /* T */ } else { if(CL_ATOMP(ARG(1))) { LOAD_NIL(ARG(0)); } else { COPY(GET_CDR(ARG(1)), ARG(2)); COPY(ARG(2), ARG(1)); goto M1_1; } } goto RETURN1; RETURN1:; } However, I wouldn't say that the generated C source is entirely human readable or maintenable (even if it's one objective of CLiCC, contrarily to gcl). At least, it couldn't pass for C code to a customer... I'd want it to generate something more like: /*---------------------------------------------------------------------*/ /* TAILP sublist list */ /*---------------------------------------------------------------------*/ bool tailp(object_t* sublist,object_t* list){ if(sublist==list){ return(true); }else if(atom(list)){ return(false); }else{ return(tailp(sublist,list_rest((list_t*)list))); }} I started such a project, but could work on it only two days in the past year. The most tedious part is to collect the processor CodOps. If you can copy-and-paste from some computer readable reference, all the better. Beware that often the description of the codops in the processor reference manuals display _less_ orthogonality than exist really in the processor instruction sets. So you may need to process manually these descriptions. An good alternative would be to get them from gcc. Next, you have to streamline and sexpify the assembler instruction syntax. Instead of writing: cntr eql -16(a5) offset eql 4 flag eql -12 fnc1: move.l offset(a0),d3 move.b d3,flag(a7) asr.l #8,d3 move.w d3,cntr ret You'd write: (define cntr (-16 a5) (define offset 4) (define flag -12) (deflap fnc1 (move.l (a0 offset) d3) (move.b d3 (a5 flag)) label (asr.l (imm 8) d3) ; or you could have a reader macro for #immediate (move.w d3 cntr) (bne.s label) (ret)) Once you have sexps, anything else can be done with lisp macros and functions. No. It's simplier to have a ASSEMBLE function similar to COMPILE. It would read the assembler source file forms, macroexpand them, and If your lisp implementation allows you to insert in the system new executable code (at worse, you could copy the assembled bytes to a FFI allocated buffer and call a FFI C function to execute them), then you could have a macro to assemble in core, and to call these functions. (defasm <lisp-function-name> (<lisp-arguments>) "some doc" (move.l (a0 offset) d3) (move.b d3 (a5 flag)) label (asr.l (imm 8) d3) ; or you could have a reader macro for #immediate (move.w d3 cntr) (bne.s label) (ret)) But this defasm is a lisp macro easily written. It would call the assembler, store the bytes, keep a map of the function name to the bytes, and generate a lisp function to call it. -- __Pascal Bourguignon__ http://www.informatimago.com/ This universe shipped by weight, not volume. Some expansion may have occurred during shipment. |
|
|
|