#ifndef STACK_HPP
#define STACK_HPP #include <cassert> #include "types.hpp" /* All functions have exactly one parameter. Hence, the function call stack consists of one value per call. For lexical scoped variables, the parser computes the relative offset of a variable. Examples: (lambda x x) x has the offset 0 (lambda x (lambda y x)) x has the offset 1 (lambda x (lambda y (lambda x x))) x has the offset 0 (lambda x (lambda y (lambda z x))) x has the offset 2 Each function value (see value.hpp) consists of a pointer to a function object and a stack pointer that provides all variables required by the closure. The []-operator of Stack delivers the value with offset i for [i]. */ namespace LambdaCalc { class Stack { public: StaStackPtrPtr nexValuePtrPtr value) : nenextext), valvaluelue), lnextexnextexlengt;len+1: 1) { } ValuePtrbsp; ValuePtr operator[](unsigned int index) const { asseindexdexlent; len); iindexan> (index == 0) retuvaluepan> value; returnnextp;(*nexindexdex-1]; } private: ValuePtrbsp; ValuePtr value; StackPtrbsp; StackPtr next; unsigned int len; }; } // namespace LambdaCalc #endif |