bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does runtime stack work?


From: Peng Yu
Subject: Re: How does runtime stack work?
Date: Fri, 21 May 2021 08:07:45 -0500

OK. Thanks. I would like to understand how gawk is implemented internally.

So byte code implementation is slower than directly generating machine
code but is easier to implement?

On 5/21/21, arnold@skeeve.com <arnold@skeeve.com> wrote:
> Peng Yu <pengyu.ut@gmail.com> wrote:
>
>> Hi,
>>
>> I see a stack is used in gawk. I don't understand what this is used
>> for. Could anybody help explain? Thanks.
>
> Out of curiosity, why do you ask?
>
> To briefly answer the question, gawk reads the program and converts
> it into an internal form, often called "byte code". The internal form
> represents instructions for a "virtual machine" that is stack based.
> Operands are pushed onto the stack. Operators pop the operands, do the
> operation, and push the result back onto the stack. For example,
>
>       x = 3 + 5
>
> would turn into something like:
>
>       PUSH    3
>       PUSH    5
>       ADD             # 3 and 5 are popped off the stack, 8 is pushed on it
>       STORE   x       # 8 popped off the stack and stored into 'x'
>
> This is one of several standard mechanisms for implementing programming
> language interpreters.
>
> There have been hardware computers that are stack based as well,
> although I am not sure which modern architectures, if any, are
> stack based.
>
> HTH,
>
> Arnold
>


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]