Author Topic: HJWasm 2.25 Object Orientation Guide  (Read 2955 times)

johnsa

  • Member
  • ****
  • Posts: 893
    • Uasm
HJWasm 2.25 Object Orientation Guide
« on: April 06, 2017, 06:08:42 AM »

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: HJWasm 2.25 Object Orientation Guide
« Reply #1 on: April 06, 2017, 01:34:06 PM »
Interesting, although too C++ for my taste  ;)

Code: [Select]
METHOD Person, Init, age:BYTE
LOCAL isAlive:DWORD
; Internally the METHOD forms a traditional procedure, so anything that you can
; do in a PROC you can do in a method.
; On entry into any method RCX is a pointer to the instance
; and the correct reference type is assumed.
mov [rcx].human, 1 ; Hence this is possible.
mov (Person PTR [rcx]).human, 1 ; Alternative forms of reference.
mov [rcx].Person.human, 1 ; " "
mov isAlive,0
mov al,age
mov [rcx].age,al
.if( age < 100 )
  mov isAlive,1
.endif
; Constructor MUST return thisPtr in rax (the implicit self reference
; passed in RCX).
mov rax,thisPtr
ret
ENDMETHOD

Are this just examples how to do it, or does the library provide some of them? Could you use more assembly-style code like this?
Code: [Select]
and isAlive,0
mov al,age
mov [rcx].age,al
.if age < 100
   inc isAlive
.endif

johnsa

  • Member
  • ****
  • Posts: 893
    • Uasm
Re: HJWasm 2.25 Object Orientation Guide
« Reply #2 on: April 06, 2017, 05:55:16 PM »
Hey,

That was just an example.

Inside a method you can code it however you like :) It's really just a PROC behind the scenes with this sort of structure :

MyClass_MyMethod PROC FRAME thisPtr:QWORD, <args>
asssume rcx:PTR MyClass
.
.

So you can do whatever you want :) follow the rules, break the rules.. make up new rules lol

mabdelouahab

  • Member
  • ****
  • Posts: 537
Re: HJWasm 2.25 Object Orientation Guide
« Reply #3 on: April 07, 2017, 09:13:18 AM »
How I can use it?
Code: [Select]
... Error A2260: Missing .ENDPROLOG: _Person_Release  ENDCLASS(11)[....

johnsa

  • Member
  • ****
  • Posts: 893
    • Uasm
Re: HJWasm 2.25 Object Orientation Guide
« Reply #4 on: April 07, 2017, 07:47:59 PM »
There was a small bug in the $DELETE implementation which I've fixed. The new packages are up on the site and Git, dated 7th April.
The packages now include a new sample oo1.asm which demonstrates a few of the new features and using the OO layer.

mabdelouahab

  • Member
  • ****
  • Posts: 537
Re: HJWasm 2.25 Object Orientation Guide
« Reply #5 on: April 07, 2017, 09:33:23 PM »
Thank you johnsa