/*
: doub dup + ;
: quad doub doub ;
: swap ( a b -- b a ) ;
: dup ( a -- a a ) ;
: pop ( a -- ) ;
: + ( int int -- int ) ;
int doub(int a)
{
    return a + a;
}
int quad(int a)
{
    return doub(doub(a));
}
*/
#include <iostream>
#include <vector>
#include <string>
struct Object
{
};
typedef Object* ObjectPtr;
struct Int : public Object
{
    int val;
};
typedef Int* IntPtr;
#define DEREF_Int(x) (*static_cast<IntPtr>(x))
std::ostream& operator<<(std::ostream& os, Int const& i)
{
    os<<i.val;
    return os;
}
struct String : public Object
{
    std::string val;
};
typedef String* StringPtr;
#define DEREF_String(x) (*static_cast<StringPtr>(x))
std::ostream& operator<<(std::ostream& os, String const& i)
{
    os<<i.val;
    return os;
}
int main()
{
    std::vector<ObjectPtr> vec;
    Int i;
    i.val = 42;
    vec.push_back(&i);
    String s;
    s.val = "hello world!";
    vec.push_back(&s);
    std::cout<<DEREF_Int(vec[0])<<std::endl
        <<DEREF_String(vec[1])<<std::endl;
    return 0;
}
Friday, April 17, 2009
Labels:
forth
Subscribe to:
Comments (Atom)