Thanks Charles, I got it working, now I will study and play with it. Will write more in the future after some playing.
Hi Kent,
I've given this code a thorough workover and shaken a out a few bugs. The main issue remaining is that you can't really make floating point operations transparent at this level. - the FPU is a totally different beast. - we will have to speak to it in Reverse Polish or hide it in a floating point library.
This is Test_oop1.tbasic - working with the latest version: I hope it makes sense enough to play with. - There's more work to do on the manual.
[code=thinbasic]
uses "OXYGEN"
uses "FILE"
dim vv as single
dim src as string ="
; test_oop1
; 13:30 21/06/2008
initialise:
;-----------
; ebx holds address of runtime functions table
; assume esi edi and ebx are preserved
esi=getmemory 1000 ; pass address of sz holding length
; this replaces the previous varbase in esi
call testclasses
freememory esi
ret
;==========================
; classes
;==========================
;------------------
;GENERIC OOP MACROS
;------------------
def class type
def context
(
indexers `ecx` offset 0 ascending var %1 this
)
def params
(
def parambytes %1
indexers `ebp` offset 8 ascending
)
def locals
(
indexers `ebp` offset 0 descending
push ebp
mov ebp,esp
sub esp,%1
)
def release
(
mov esp,ebp
pop ebp
ret parambytes
)
def create
(
var %1 %2
%1_methods %2
)
def method
(
lea ecx, %1
proc )
;------------------
;define classes
;------------------
class class0
(
4 u 4 v 4 w
)
class class1
(
class0, 4 a 4 b 4 c
)
class class2
(
class1, 4 d 4 e
)
;define methods
;---------------
.init
(
context class0
params 0
locals 0
release
)
.put
(
context class1
params 4
var 4 aa
locals 16
var 4 i j
mov eax,aa
mov this.a,eax
mov eax,0
release
)
.get
(
context class1
params 0
locals 16
mov eax,this.a
release
)
.clear
(
context class2
params 0
locals 16
mov this.u,0
mov this.v,0
mov this.w,0
mov this.a,0
mov this.b,0
mov this.c,0
mov this.d,0
mov this.e,0
release
)
;define method calls
;-------------------
def class0_methods
(
def %1_init method %1 init
)
def class1_methods
(
class0_methods %1
def %1_get method %1 get
def %1_put method %1 put
)
def class2_methods
(
class1_methods %1
def %1_clear method %1 clear
)
'------------
testclasses:
'------------
(
indexers `esi` offset 100 ascending
def Result [#vv]
create class2 obj
obj_init
;using 32 bit floating point
;inline table of single constants
edx=data (ns 42.125 ns 0.61803 ns 3.14159)
obj_put [edx+4]
Result=obj_get
obj_clear
;Result=obj_get
ret
)
;=========================
; end classes
;=========================
"
' record o2 listing
file_save ("t.txt",o2_view(src))
O2_ASMO src
if len(O2_ERROR)>0 then
msgbox 0, O2_ERROR+$crlf+"Program will end now"
stop
end if
O2_EXEC
msgbox 0, vv
[/code]
http://community.thinbasic.com/index.php?topic=1637.0
Thanks Charles, I got it working, now I will study and play with it. Will write more in the future after some playing.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
A lurid description of Asmosphere macros
Technical descriptions can be quite hard to follow so I thought of a way to describe these in more graphic terms which are easier to conceptualise.
Imagine a macro word as an amoeba. It can eat words both ahead of it and behind it. If the macro contains any %1s in its body, it will consume the first word to the right of it. If a %2 is present then it will consume the second word to the right and so forth. If there is a %0 then the word to the left is taken. If there is a %b in the macro body then it consumes all the words from the beginning of the line. If there is a %e then the macro will devour the rest of the line or even an entire block if a left bracket is encountered.
The macro substitutes all the %params in its body with the words it has swallowed, then bursts disgorging its contents into the script.
Macros may contain other macros - These are resolved recursively. If the macro contains itself or any of its progeny contains itself then the script will recursively inflate - in theory until the computer runs out of memory but the preprocessor imposes a limit to this source code inflation. If the source script inflates due to macro recursion by a factor of 10 then assembly is halted. In addition to this protection, recursive cycles are limited to 256 loops per word - so macros like def def def will not lock the assembler into a perpetual (non inflationary) loop.
Macros may also contain definitions of other macros - so it is possible to generate an entire vocabulary with a single word - to create a domain-specific mini-language.
If macros are defined between brackets then they have local scope within those brackets and do not affect code elsewhere. So it is possible to have several mini languages in the same script - all using similar words but for different purposes, without causing name conflicts.
The amoeba is confined by brackets.
Hi Charles,
I was for 3 days out and once back you advanced again
May I ask you to make "The Asmosphere Assembler" topic with help + DLL + samples as a sticky one, with date of last update in thread name? ( like "The Asmosphere Assembler [UPDATED 18-Jun-2k8]")
Thanks a lot,
for nice new shiny toys to play with
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Hi Petr,
Welcome back! That is a good idea but I don't have the option available to create sticky topics - only locked ones. Is there a magic switch Eros can throw somewhere?
PS
The preprocessor layer feels nearly complete but am tempted to add a few more runtime string functions - like str$ hex$ val - these are a bore to code up from scratch when they are so readily accessible.
I've created a dedicated forum for all your code and projects, Charles.
You should be able to add sticky and moderate posts in there.
I've also moved all posts and subforum regarding ASM.
Hope this is ok or ... let me know if you need other setup or subforums.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thank you Eros. I will now set up the sticky topic for the downloads.
PS: This is our first day of warmish weather. No need for gloves but I am still keeping my hat and furs on
I liked the lurid description for asmosphere macros. It is going to take me some time to get my head around this stuff. But it is nice to get a glimpse of all our computers do for us behind the scenes. It is easy to forget with high level languages the work that goes on at the lowest levels.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
First day !? I am BURNING here for a month. I need an igloo desperately...This is our first day of warmish weather. No need for gloves but I am still keeping my hat and furs on
Thanks for all the updates,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Stretching the syntax
With some very small tweaks it is now possible to define macros and variables with multisymbol and multiword names. This takes us into uncharted territory, but to give a flavour of what is possible this is all valid Asmosphere preprocessor:
def `@-/\-@` nop
def `++` inc
def `--` dec
def `<>` cmp eax,edx
def `` mov eax,1
def `` mov eax,2
def `` mov eax,3
def `` mov eax,-1
def `bye bye` ret
var 4 `the meaning of life`
@-/\-@
++ eax
-- eax
<>
mov the meaning of life,42
bye bye
http://community.thinbasic.com/index.php?topic=1845
Bookmarks