Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: "BartC" Newsgroups: comp.lang.java.programmer,comp.programming Subject: Re: Creating a new stack from an exisiting one. Date: Sat, 3 Nov 2012 18:58:22 -0000 Organization: A noiseless patient Spider Lines: 1 Message-ID: References: <0.73472d82415d5353822e.20121103155132GMT.87mwyyvg57.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit Injection-Date: Sat, 3 Nov 2012 18:59:03 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="834da54ce43f3ee3a7b5a28b138be74f"; logging-data="5566"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/M3oWiVxDF5oJuXxWfO++" X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726 In-Reply-To: X-Antivirus-Status: Clean X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726 Importance: Normal X-Antivirus: avast! (VPS 121103-0, 03/11/2012), Outbound message Cancel-Lock: sha1:/rdW+cOzMKkD0y6ILpEra6rBv2w= X-Priority: 3 X-MSMail-Priority: Normal Xref: csiph.com comp.lang.java.programmer:19610 comp.programming:2452 "Chad" wrote in message news:b227ba50-ccbc-4da0-9f6a-31bb809f329d@ah9g2000pbd.googlegroups.com... > That what I thought. However, I don't think so. Let me elaborate. This > is part of a much much larger software project. The part is question > is the RunTimeStack module. In this module, we have one stack which is > called runStack. This is an ArrayList that is supposed to hold the > data pushed onto the stack. In other words, after I push the numbers > onto the stack, it would look something like.. > > [1, 4, 10, 20] > > There is another stack, of type Stack, that is called framePointers. > This holds the current offset. So this is some sort of language where you can have a stack of frame pointers (presumably due to nested functions)? (Instead of the ones I'm used to where there only one frame pointer is visible at any time, and usually kept in a register.) So you have two stacks; why shouldn't that be enough? (Normally only one is used.) >So if I have something like f(3) in the > source code, the corresponding runTimeStack is supposed to go > something like > > LIT 3 //private machine code > [1, 4, 10, 20, 3] > > ARGS 1 //ditto > [1, 4, 10, 20] [3] > > CALL F<<20>> > [1, 4, 10, 20] [3] > I don't see how to create the new "stack" when I'm only given one > stack to hold the data and another to hold the offsets. It's not clear what you're trying to do. You haven't shown the stack of frame pointers. I would guess that when F is called, it has to create some space on the data stack (for its local data), create a new frame pointer to point to that space, and push that frame pointer onto the frame pointer stack (or maybe it keeps the current one off the stack). But if you are implementing something to do with such a language, then you need to find out a bit more about how these things are done. (BTW what's the difference between .add and .push in your OP?) -- Bartc