HLA中的類

program classDemo;

#include ("stdlib.hhf");

type
People: class
        
        var
            pName: string;

     procedure getName; @returns( "ebx" );
        
     procedure setName(myName:string);


    procedure create;

endclass;

    static

    procedure People.getName;
        begin getName;
            stdout.put("invoke getName", nl);
            mov(this.pName, ebx);
            stdout.put("invoke getName successfully", nl);
        end getName;
        
        
     procedure People.setName(myName:string);
        begin setName;
            stdout.put("invoke setName()", nl);
            mov(myName, this.pName);

            stdout.put("invoke setName() successfully!!", nl, nl);
        end setName;


    procedure People.create;
        begin create;
            push( eax );
            mem.alloc( @size( People ) );
            mov(eax, esi);
            stdout.put( "size People = ", (type uns32 eax), nl); 
            str.alloc( @size(char) * 100 );
            mov(eax, this.pName);
            pop(eax);
            stdout.put("this.pName = ", (type uns32 this.pName), nl);
            stdout.put("create successfully invoke!!", nl, nl);
        end create;

static
    iName: string;
    Me: People;
    pp: pointer to People;

begin classDemo;
    
    Me.create();
    mov(esi, pp);
    str.alloc(10);
    mov(eax, iName);
    str.put(iName, "yang");
    pp.setName(iName);
    pp.getName();

    stdout.put("Your name is ", (type string ebx) , nl);
    str.free(iName);

end classDemo;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章