Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-10 Thread Nicolas Oury
On Tue, Aug 10, 2010 at 12:43 AM, Jules julesjac...@gmail.com wrote:
 It is impossible (undecidable) to tell precisely which functions a
 function will call. Therefore you will need to consider not exactly
 set of functions that a function will call, but some superset of that.
 Why not take as your superset all functions? That is, always compile
 all functions.


There is a smaller decidable superset: all functions occurring in the
static call graph for a function.
But, I agree, most compilers would just compile everything and it's
probably a better idea.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread CuppoJava
Hello everyone,
Just for educational purposes, I'm writing a simple lisp compiler and
am stuck on a small problem.

I'm trying to write a function called (compile-function), which will
take a function as input and compile it.

If that function calls other functions, I would like (compile-
function) to automatically compile the called functions as well.

But I'm stuck on how to tell whether a function will be called or not.
Particularly when functions are passed around as objects.

So the question is this: Given a function f, how can I find all the
functions that f depends on?

Thanks a lot for your help
  -Patrick

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Jarkko Oranen


On Aug 9, 7:54 pm, CuppoJava patrickli_2...@hotmail.com wrote:
 Hello everyone,
 Just for educational purposes, I'm writing a simple lisp compiler and
 am stuck on a small problem.

 I'm trying to write a function called (compile-function), which will
 take a function as input and compile it.

 If that function calls other functions, I would like (compile-
 function) to automatically compile the called functions as well.

 But I'm stuck on how to tell whether a function will be called or not.
 Particularly when functions are passed around as objects.

 So the question is this: Given a function f, how can I find all the
 functions that f depends on?

I don't think that's feasible, if it's even possible in the first
place.

Functions that the parent function calls directly you can of course
try to compile whatever you encounter in a function call form; just
check if the operator is a known global function, and compile it.
However, if the operator is a local variable (ie. a function passed as
a parameter) there's no reliable way to find out what function it is.
It might even be a runtime-generated function (by eval)

Since you can't know what functions will be called, the generated code
must somehow verify that it's calling a function in the first place,
perhaps invoke the compiler (if all functions must be compiled), and
then execute it.

--
Jarkko

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread CuppoJava
Thanks for the reply Jarkko. That helps quite a lot. I have some hacks
in place that works most of the time, but was stuck trying to figure
out a general solution. Knowing that there isn't one puts my mind at
ease.
  -Patrick

On Aug 9, 1:56 pm, Jarkko Oranen chous...@gmail.com wrote:
 On Aug 9, 7:54 pm, CuppoJava patrickli_2...@hotmail.com wrote:

  Hello everyone,
  Just for educational purposes, I'm writing a simple lisp compiler and
  am stuck on a small problem.

  I'm trying to write a function called (compile-function), which will
  take a function as input and compile it.

  If that function calls other functions, I would like (compile-
  function) to automatically compile the called functions as well.

  But I'm stuck on how to tell whether a function will be called or not.
  Particularly when functions are passed around as objects.

  So the question is this: Given a function f, how can I find all the
  functions that f depends on?

 I don't think that's feasible, if it's even possible in the first
 place.

 Functions that the parent function calls directly you can of course
 try to compile whatever you encounter in a function call form; just
 check if the operator is a known global function, and compile it.
 However, if the operator is a local variable (ie. a function passed as
 a parameter) there's no reliable way to find out what function it is.
 It might even be a runtime-generated function (by eval)

 Since you can't know what functions will be called, the generated code
 must somehow verify that it's calling a function in the first place,
 perhaps invoke the compiler (if all functions must be compiled), and
 then execute it.

 --
 Jarkko

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Daniel Gagnon
As far as I know, the book Lisp In Small Pieces should be a tremendous
help for anyone who builds a Lisp interpreter or compiler. You might want to
check it out.

On Mon, Aug 9, 2010 at 2:21 PM, CuppoJava patrickli_2...@hotmail.comwrote:

 Thanks for the reply Jarkko. That helps quite a lot. I have some hacks
 in place that works most of the time, but was stuck trying to figure
 out a general solution. Knowing that there isn't one puts my mind at
 ease.
  -Patrick

 On Aug 9, 1:56 pm, Jarkko Oranen chous...@gmail.com wrote:
  On Aug 9, 7:54 pm, CuppoJava patrickli_2...@hotmail.com wrote:
 
   Hello everyone,
   Just for educational purposes, I'm writing a simple lisp compiler and
   am stuck on a small problem.
 
   I'm trying to write a function called (compile-function), which will
   take a function as input and compile it.
 
   If that function calls other functions, I would like (compile-
   function) to automatically compile the called functions as well.
 
   But I'm stuck on how to tell whether a function will be called or not.
   Particularly when functions are passed around as objects.
 
   So the question is this: Given a function f, how can I find all the
   functions that f depends on?
 
  I don't think that's feasible, if it's even possible in the first
  place.
 
  Functions that the parent function calls directly you can of course
  try to compile whatever you encounter in a function call form; just
  check if the operator is a known global function, and compile it.
  However, if the operator is a local variable (ie. a function passed as
  a parameter) there's no reliable way to find out what function it is.
  It might even be a runtime-generated function (by eval)
 
  Since you can't know what functions will be called, the generated code
  must somehow verify that it's calling a function in the first place,
  perhaps invoke the compiler (if all functions must be compiled), and
  then execute it.
 
  --
  Jarkko

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Jules
It is impossible (undecidable) to tell precisely which functions a
function will call. Therefore you will need to consider not exactly
set of functions that a function will call, but some superset of that.
Why not take as your superset all functions? That is, always compile
all functions.

On Aug 9, 6:54 pm, CuppoJava patrickli_2...@hotmail.com wrote:
 Hello everyone,
 Just for educational purposes, I'm writing a simple lisp compiler and
 am stuck on a small problem.

 I'm trying to write a function called (compile-function), which will
 take a function as input and compile it.

 If that function calls other functions, I would like (compile-
 function) to automatically compile the called functions as well.

 But I'm stuck on how to tell whether a function will be called or not.
 Particularly when functions are passed around as objects.

 So the question is this: Given a function f, how can I find all the
 functions that f depends on?

 Thanks a lot for your help
   -Patrick

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en