Abstract forms

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Abstract forms

Vlad Dumitrescu-3
Hi again...

I have been playing a lot with code, erl_parse, beam_lib and the likes, and things go pretty well. There is one thing that I can't do and I'd like to: obtain an abstract form for a function, compile it and run it. Obtaining isn't a problem now, but trying to compile it fails miserabily...

Is it the right abstract form format that is returned from beam_lib:chunks(abstract_form) that can be fed into compile:forms?

thanks.
Vlad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20010115/7623902d/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Abstract forms

Richard Carlsson-4

On Mon, 15 Jan 2001, Vlad Dumitrescu wrote:

> I have been playing a lot with code, erl_parse, beam_lib and the
> likes, and things go pretty well. There is one thing that I can't do
> and I'd like to: obtain an abstract form for a function, compile it
> and run it. Obtaining isn't a problem now, but trying to compile it
> fails miserabily...
>
> Is it the right abstract form format that is returned from
> beam_lib:chunks(abstract_form) that can be fed into compile:forms?

The result from beam_lib:chunks(File, [abstract_code]) is indeed (at least
currently) on basically the same format as that returned from erl_parse.
(It has been expanded by the compiler, so you won't find records or
function imports in that code. Look in sys_pre_expand for details.)

It could be fed into compile:forms, but you'd have to modify it a bit
first:
        - add a module declaration form at the top of the list:
            {attribute,Line,module,ModuleName}

        - remove the auto-generated code for "module_info" functions:
            {function,Line,module_info,0,Clauses}
            {function,Line,module_info,1,Clauses}

but keep in mind that the compiler only accepts complete modules as input,
even if you use compile:forms.

        /Richard Carlsson


Richard Carlsson (richardc)   (This space intentionally left blank.)
E-mail: Richard.Carlsson WWW: http://www.csd.uu.se/~richardc/