Re: Questions about anonymous functions and classes/functions declarations

Louis Paul Santillan <lsantil@calstatela.edu>
6 Oct 2003 21:27:09 -0400

          From comp.compilers

Related articles
Questions about anonymous functions and classes/functions declarations mrfaro@libero.it (Gabriele Farina) (2003-10-04)
Re: Questions about anonymous functions and classes/functions declarat derkgwen@HotPOP.com (Derk Gwen) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat lsantil@calstatela.edu (Louis Paul Santillan) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat haberg@matematik.su.se (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat joachim.durchholz@web.de (Joachim Durchholz) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat geoff@wozniak.ca (Geoff Wozniak) (2003-10-08)
Re: Questions about anonymous functions and classes/functions declarat joachim.durchholz@web.de (Joachim Durchholz) (2003-10-08)
Re: Questions about anonymous functions and classes/functions declarat witness@t-online.de (Uli Kusterer) (2003-10-13)
Re: Questions about anonymous functions and classes/functions declarat marcov@stack.nl (Marco van de Voort) (2003-10-13)
| List of all articles for this month |
From: Louis Paul Santillan <lsantil@calstatela.edu>
Newsgroups: comp.compilers
Date: 6 Oct 2003 21:27:09 -0400
Organization: CSUnet
References: 03-10-004
Keywords: code, design
Posted-Date: 06 Oct 2003 21:27:09 EDT

You can investigate how JavaScript implements this
<http://www.mozilla.org/js/> in C and Java. Both implementations use
stack-based, byte code interpreters/VMs and use an object property
lookup byte code to find what property is actually being requested. I
pasted examples below.


Louis
---------test.js-------------
function test( x )
{
      if( x > 0 )
      {
            this.x = method1;
      }
      else
      {
            this.x = method2;
      }
}
---------test.js-------------


--------execution------------
js> load("test.js");
js> dissrc( test )
;------------------------- 3: if( x > 0 )
00000: 3 getarg 0
00003: 3 zero
00004: 3 gt
00005: 3 ifeq 19 (14)
;------------------------- 4: {
;------------------------- 5: this.x = method1;
00008: 5 this
00009: 5 name "method1"
00012: 5 setprop "x"
00015: 5 pop
00016: 5 goto 27 (11)
;------------------------- 6: }
;------------------------- 7: else
;------------------------- 8: {
;------------------------- 9: this.x = method2;
00019: 9 this
00020: 9 name "method2"
00023: 9 setprop "x"
00026: 9 pop
js> quit()
--------execution------------


On 4 Oct 2003, Gabriele Farina wrote:
> Hi guys,
[SNIP]
> test = class()
> input value
>
> if value == 10
> test.a_new_method = function(a) print a
> else
> test.a_new_method = function(a) print 'Your wrong the number, you
> inserted'.append(a)
>
> instance = new test()
> instance.a_new_method(value)
>
[SNIP]
> bye
> [The only way I know to handle anonymous functions is to give each on a
> secret private name at compile time. As far as adding new methods at
> runtime, it's doable but it means that you have to keep most of the
> compiler symbol table at runtime and possibly the whole compiler if
> you're adding new code on the fly. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.