flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > LISP compiler

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 20 Oct 2003, 12:10
lisp compiler written in fasm,
is this possible?

--
Rolling Eyes

--
PS: on the contrary, someone try assembler on lisp ;^)
http://lasm.sourceforge.net/ (look cvs)
Post 20 Oct 2003, 12:10
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates 21 Oct 2003, 17:24
Possible? Probably yes. But I think it's really hard to do. How to manipulate on itself? LISP can modify itself. With compiled languages its really hard.
As you probably know, first LISP interpreter was writen... on the paper Smile That was function in LISP which was operating on lists. If you would like to do comiled version of LISP you should compile interpreter inside.
Is it worth to do?
Are you sure you want to do it (fully) in asm? It would be slow, so why to use asm. You can use any HLL to help yourself writing compiler.
But if you are as crazy as me... you would do all this yourself in asm Smile Good luck!
Post 21 Oct 2003, 17:24
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
mr_luc



Joined: 15 Jun 2005
Posts: 3
mr_luc 29 Jun 2005, 02:37
I am seriously considering this as a laid-back kind of personal project to help me get at ease in assembler, and more at ease with the underpinnings of Lisp. (Obviously, not CL. Dynamic scope and the basic operations).

I think it would be interesting to combine my interest in the highest-level language with my interest in the lowest-level language in this way.
Post 29 Jun 2005, 02:37
View user's profile Send private message Reply with quote
wbk



Joined: 29 Jun 2005
Posts: 1
wbk 29 Jun 2005, 17:39
the vast majority of lisp compilers and interpreters written in the 60s-80s were written in assembly.
Post 29 Jun 2005, 17:39
View user's profile Send private message Reply with quote
mr_luc



Joined: 15 Jun 2005
Posts: 3
mr_luc 29 Jun 2005, 22:45
wbk wrote:
the vast majority of lisp compilers and interpreters written in the 60s-80s were written in assembly.

Absolutely. Hell, two of lisp's basic operators, car and cdr, mean something like "Contents of Address Register" and "Contents of Decrement Register".

My ignorance about how to accomplish most simple tasks in fasm is really my limiter here. I know for a fact that a naive, ugly lisp <1.5 implementation could potentially be quite simple, even in assembler.

I need to play around with it more. To give you an idea -- I am stumped on how I would go about creating new procedures at runtime. That sort of thing must be done all of the time, but I don't know how.

However, I want to keep this a simple, NAIVE project, so I don't want to go back to The Dragon Book and essentially copy the way other people have done it.

I think it would be a really interesting project to see how much a true novice like me could do on a problem of this nature, with a BARE minimum of knowledge.

Does the fasm community have an irc channel where I can ask simple (but hopefully not stupid) questions?

The biggest question I have is:

"How might I make a procedure at runtime, and then call it?"

The answer to that question will determine what my next question will be. Very Happy Of course, if I ask the wrong question, I am likely to get the answer "Use C--", but as I understand it they don't allow procedures that take a variable number of arguments, because they say it interferes with tail-calls. Which is an intelligent point, but I just want to dick around right now; if it makes the result unusable, that's fine with me!
Post 29 Jun 2005, 22:45
View user's profile Send private message Reply with quote
Kain



Joined: 26 Oct 2003
Posts: 108
Kain 30 Jun 2005, 01:35
If you look in the "High Level Languages" forum, you'll find some other ongoing projects involving fasm, particularily Forth compilers which may help you in your own project.
Post 30 Jun 2005, 01:35
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 01 Jul 2005, 18:32
LISP seems like an old and weird language. However, AFAIK, it has always been an interpreted language. Some languages just can't be compiled very well, such as Perl, Forth, and LISP.
Post 01 Jul 2005, 18:32
View user's profile Send private message AIM Address Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 01 Jul 2005, 18:49
Forth is both an interpreted and a compiled language. It compiles quite well, thank you.
Post 01 Jul 2005, 18:49
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 01 Jul 2005, 20:32
Lisp can be (and these days often is) compiled. Take a look at sbcl for an example of this.
Post 01 Jul 2005, 20:32
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 01 Jul 2005, 22:21
I must say that I'm quite curious to know why you consider Forth to be a language that can't be compiled very well.
Post 01 Jul 2005, 22:21
View user's profile Send private message Visit poster's website Reply with quote
ezanahka



Joined: 10 Jul 2005
Posts: 3
ezanahka 10 Jul 2005, 15:15
fasm9 wrote:

PS: on the contrary, someone try assembler on lisp ;^)
http://lasm.sourceforge.net/ (look cvs)


Actually having an assembler in Lisp was just an early milestone in the project plan. The project is dead btw... All the developers left the project :p

The aim was to provide a framework for generating assembly programs in Common Lisp. I think that they would have been better off using FASM as a backend instead of generating raw binary.
Post 10 Jul 2005, 15:15
View user's profile Send private message Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias 10 Jul 2005, 18:56
At the time of this topic's first appearance, the FASM board did not include, as it does today, a section for High Level Languages. I believe that any questions about Lisp, Forth, etc, should be consigned to the pertinant sector of the forum which addresses those aspects of programming, since these issues are fundamentally unrelated to problems with, or limitations/features of FASM, topics pertinant to MAIN. Smile
Post 10 Jul 2005, 18:56
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 11 Jul 2005, 19:19
FORTH can be compiled, I suppose, but it seems like it's easier to interpret it. Some languages I prefer to be interpreted, FORTH is one of them. You know, BASIC used to be interpreted but Micro$oft QuickBasic and a newer one, FreeBasic (which is 32-bit), among others, are compilers. However, I don't think LISP could be compiled very easily.

BTW, I am kind of interested in LISP but I've never been able to find any information about it. Does anyone know of a good tutorial or something online?
Post 11 Jul 2005, 19:19
View user's profile Send private message AIM Address Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 11 Jul 2005, 20:31
Actually, Forth is both interpreted and compiled. Download Reva and play with it, and go through the tutorial provided.

The words are all compiled. What you type in or what you "include" is interpreted - but any new words you created are compiled.
Post 11 Jul 2005, 20:31
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
jvff



Joined: 05 Jul 2005
Posts: 5
Location: Brazil
jvff 11 Jul 2005, 23:33
Quote:

"How might I make a procedure at runtime, and then call it?"



The only way I see this is possible is to allocate memory for that procedure, just in time compile it and jump to the procedure. Not an easy job. Hope this helps,

JVFF
Post 11 Jul 2005, 23:33
View user's profile Send private message MSN Messenger Reply with quote
ezanahka



Joined: 10 Jul 2005
Posts: 3
ezanahka 14 Oct 2005, 10:56
ezanahka wrote:
The aim was to provide a framework for generating assembly programs in Common Lisp. I think that they would have been better off using FASM as a backend instead of generating raw binary.


I whipped this one up this morning in half an hour because I couldn't figure out how to do something with FASM macros. I'm more comfortable with doing things like this with Common Lisp. So this essentially just extends CL with a function and a macro character so that I can mix asm and Lisp together and uses FASM as a backend for assembling.

Code:
;;;; carrot.lisp (don't ask me why this name... the file just needed any name)
;;;; Using CommonLisp as a macro preprocessor for an assembler
;;;; Written for and used with CLISP (version 2.34 or newer)

;; check command line argument count
(unless (= (length ext:*args*) 1)
  (format t "clisp carrot.lisp <LASM>.lasm ; processes Lisp-Assembly file and produces an .asm file.~%")
  (ext:bye))

;; check that the LASM file exists
(unless (probe-file (first ext:*args*))
  (format t "Specified LASM file does not exist.~%"))

;; compute the name of the output file
(defvar *output-file*
  (concatenate 'string (subseq (first ext:*args*)
    0 (position #\. (first ext:*args*) :from-end t)) ".asm"))

;; a list of generated lines of code
(defvar *asm* ())

(defun asm (&rest s)
  (setf *asm* (append *asm* (list
    (apply #'concatenate (cons 'string (mapcar #'princ-to-string s)))))))

;; syntax extensions:
;; % mov eax, edx % ; generates the specified block of assembly code
;; \\ ; generates a newline (only usable inside a block of assembly code)
(set-macro-character #\%
  #'(lambda (s c)
    (let ((str "") char)
      (loop until (char= #\% (setf char (read-char s)))
        do (if (char= #\# char)
            (setf str (concatenate 'string str (princ-to-string (eval (read-preserving-whitespace s))) " "))
            (setf str (concatenate 'string str (string char)))))
      (read-char s)
      `(setf *asm* (append *asm* ',(regexp:regexp-split "\\\\\\\\" str))))))

;; processes the LASM file
(load (first ext:*args*))

;; write the generated code into the output file
(with-open-file
    (s *output-file* :direction :output :if-exists :supersede)
  (dolist (i *asm*)
    (princ i s)
    (terpri s)))

;; attempt assembling the file
(ext:execute "/usr/bin/fasm" *output-file*)
    


Implementing a one way linked list dictionary for a Forth was pretty easy with this. Yeah I know its easy with FASM macros too but I needed an extra feature which I couldn't pull off.

With this:

Code:
(defvar *_prev* 0)

(defun _entry (name body)
  (let ((here (gensym)))
    (asm here ":")
    (asm "dd " *_prev*)
    (asm "dd " name)
    (asm "db 0")
    (asm "cstr '" name "'")
    (setf *_prev* here)
    (asm name ":")
    (asm body)))
    


This code:

Code:
%use32%
(_entry "foo"
"mov eax, esi
xor esi, esi")
(_entry "foo2"
"mov eax, esi
xor esi, esi")
    


Generated the following output:

Code:
G4091:
dd 0
dd foo
db 0
cstr 'foo'
foo:
mov eax, esi
xor esi, esi
G4092:
dd G4091
dd foo2
db 0
cstr 'foo2'
foo2:
mov eax, esi
xor esi, esi
    


This is not a big system but it pretty much does what that LASM project at Sourceforge was supposed to achieve.
Post 14 Oct 2005, 10:56
View user's profile Send private message Reply with quote
james



Joined: 07 Sep 2005
Posts: 45
Location: Australia
james 15 Oct 2005, 05:01
Im writing a LISP implementation in FASM right now.
Seriously, I am.
Post 15 Oct 2005, 05:01
View user's profile Send private message MSN Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 15 Oct 2005, 08:25
james: looking forward to see the result
Post 15 Oct 2005, 08:25
View user's profile Send private message Visit poster's website Reply with quote
james



Joined: 07 Sep 2005
Posts: 45
Location: Australia
james 15 Oct 2005, 22:10
Keep an eye on mylisp.com !
I put it up today so that people could see what I was doing and get involved.

If you cant see the site right now, then its flowing through the dns.

Rgs, James.
Post 15 Oct 2005, 22:10
View user's profile Send private message MSN Messenger Reply with quote
eiforall



Joined: 21 Sep 2005
Posts: 5
eiforall 07 Nov 2005, 16:55
It seems like mylisp.com does have only one forum message...

thoughts on list complier:
because lisp is high level the compiled code will look more or less like:

call CreateList
push 2
call AddToList
...
so on lost of
push's and call's to higher level functions

because your lisp compiler would already make this kind of code structures it would not be too complex to include the compiler in the program image to just-in-time compile newly defined functions because you will not be dealing with all the hundreds of instructions of the x80 just the push's and call's.

Other thing it would be wise to have both compiler(for final) and interpriter (for debugging) because remember in order for people to use your lisp it needs to be easy to use and debuger is a must.

Again interpriter is just a compiler that compiles and runs one line at a time and with a jit compiler that is easy to do.

Why not reread the The Dragon Book? It will help.
Post 07 Nov 2005, 16:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.