The Artima Developer Community
Sponsored Link

Java Buzz Forum
Stack Frames as First Class Objects

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Stack Frames as First Class Objects Posted: Feb 25, 2004 2:01 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Stack Frames as First Class Objects
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

I had a fun idea chatting in #groovy -- make stack frames first class objects and accessible in the runtime context. Allow the twiddling of variables in the stack frames, allow the setting of a continuation in place of the continuation waiting for the return from the stack.

Some pseudo-ruby-java-code for concepts:


def functionOne()
    binding = Thread.current.frame.parent.binding()
    binding["foo"] = "goodbye"
end

foo = "hello"
functionOne()
puts foo

--> "goodbye"

Taking it a step further:



def functionTwo()
    puts "au revoir"
end

def functionThree()
    cont = new Continuation(functionTwo)
    old_next = Thread.current.frame.parent.replaceNext(cont)
    binding["foo"] = "goodbye"
end

foo = "hello"
functionThree()
puts foo

--> "au revoir"

I suspect stackless python does something like this now, where it just keeps a continuation waiting for the function return, not a real stack frame -- or more likely, plugs a call to the continuation in place of the "return" statement, with the returned value as an argument. I have only heard of stackless python though, so no clue if that is what they actually do. If they don't do something like this, it could be fun to play with.

This runtime-hackery is probably far worse than globals or GOTO, but the ideas are still pretty cool.

Read: Stack Frames as First Class Objects

Topic: London Java Meetup tonight Previous Topic   Next Topic Topic: jknowles@bmc.com

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use