On Wed, Sep 16, 2009 at 3:30 AM, john skaller <skal...@users.sourceforge.net> wrote: >> >> Unfortunately, branching only works inside functions. > > Why is that unfortunate? Code only lives inside functions. > > In the C generator there's a hack to allow gcc to do "long jumps" > across functions.
Oh, it's just unfortunate because how the JIT is implemented. I just haven't figured out some basic things with llvm yet. For instance, LLVM requires every basic block to have a terminating instruction, but I haven't figured out yet how to the implicit return at the end of procedures. Since each toplevel statement is executed in their own procedure, llvm bails because it has incorrect IR. The second problem is I'm not sure how to do gotos in this situation. LLVM supports longjmp style, but I'm essentially throwing away the jitted function after I execute it, so I'm not sure how I'd be able to restart execution back where ever we jump to. > However this is needed only because gcc is pretty brain dead > handling large functions. Ideally Felix (and other C code generators) > would generate all code as a single massive function, since this then > allow unrestricted flow control. Unfortunately this can't be done since > gcc can't handle it so we have to generate multiple small functions and > then hack long jumps. > > Procedural jumps can also be done by a fiddling the spaghetti stack > and then doing a return to the driver code, which then "resumes" the > target function which itself starts off with a switch (or computed > goto). > Clearly this is less efficient than a direct jump. Oh well.. the real > problem > is that C can't handle control exchange. Ideally you'd have a function > with > multiple entry points and do a tail call to one of those points (which > is > equivalent to a jump). > > LLVM probably doesn't have this restriction since it is an assembler > and should be able to assemble a whole program as a single function > without any problem. That's true. I'll look into that when I start work on the ahead-of-time compiler backend. I wonder if I could use the spaghetti stack for the repl. Each toplevel llvm function just is added to an execution tree, and a goto is just a return into the driver that lets it know where to resume execution from, and the driver calls functions in order until it finds a leaf node. ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language