Question for Mark

BlitzMax Forums/BlitzMax Programming/Question for Mark

DStastny(Posted 2008) [#1]
I have been working on a custom module Math module that exposes my own customs types directly into BlitzMax written in purely in C and using SSE.

The new modificiations to BMK that Brucey has added have allowed me to drop the overhead of stack-frames and control GCC which is huge help as GCC doesnt generate the fastest code by default.

I have been successful in following the implementations of the String and Array Objects in Blitz_String.c and Blitz_Array.c and have been pleased with the performance improvments that I can make over pure BlitzMax code.

My only issue is the only way I can get them introduced into MAX is by adding my defintions to the Blitz_Classes.i file which is not the ideal way.

Is there something I am missing to get the Bltiz compiler to pick up my own .I file without having to resort to modifiying Blitz_Classes.i or BMK to append my defintions to the generated .i files

Thanks
Doug


Blueapples(Posted 2008) [#2]
Maybe I'm missing something but I don't see why you'd want to append your definitions to a different module's .i file.

Since you're writing C code, you have to provide a stub .bmx file with the name of your module that imports all your C files. When you build this it will get it's own .a and .i files.
For example, look at \mod\brl.mod\blitz.mod\blitz.bmx. Pretty much all it does is provide ModuleInfo and import C files (and a few function aliases and exception types, but that's peripheral). That's what you need to do - but in your own module stub.

I haven't actually done this myself so I might be missing some detail.


DStastny(Posted 2008) [#3]
The point of the excersise is no bmx code. To introduce a BlitzMax object written in C to Max Code it needs to be defined by the .i file so the bcc.exe can deal with it. The linker(LD.exe does the rest).

It works much better than I expected other than having to deal with the .i file. hack.

Yeah I have been down the Extern wrap route but I am writting fast math routines and I am trying remove the overhead of the stack frame that is setup by blitzmax and C by default.

It works just great this .i issue is my problem.

To understand all this you need to look at the assembly output generated by the BMax or a C compiler.

Doug



Doug


Blueapples(Posted 2008) [#4]
It doesn't matter what your C code does, this is the only way to get your own module.

"Extern" is pretty much just a compiler notation that puts lines into the .i file. For instance, from from stdc.bmx:

Import "stdc.c"

Extern "c"

Const SEEK_SET_=0,SEEK_CUR_=1,SEEK_END_=2
Const S_IFMT_=$f000,S_IFIFO_=$1000,S_IFCHR_=$2000,S_IFBLK_=$3000,S_IFDIR_=$4000,S_IFREG_=$8000

Global stdin_="stdin_"
Global stdout_="stdout_"
Global stderr_="stderr_"

Function putenv_( str$z )="putenv_"
Function getenv_$z( evar$z )="getenv"

Function getchar_()="getchar"
Function puts_( str$z )="puts"

Function fopen_( fname$z,fmode$z )="fopen"
.
.
.


Then look at stdc.release.win32.x86.i:
SEEK_SET_%=0
SEEK_CUR_%=1
SEEK_END_%=2
S_IFMT_%=61440
S_IFIFO_%=4096
S_IFCHR_%=8192
S_IFBLK_%=12288
S_IFDIR_%=16384
S_IFREG_%=32768
putenv_%(str$z)="putenv_"
getenv_$z(evar$z)="getenv"
getchar_%()="getchar"
puts_%(str$z)="puts"
fopen_%(fname$z,fmode$z)="fopen"


Extern is just a more handy way to do it, and is where all of the .i files that you see in your mod folder came from in the first place. You don't have to put any actual runtime code in the BMX file unless you want to - all the file has to do in your case is store the extern lines that you want to go into your own .i file.

This is what Mark will say, if he answers this. Maybe Brucey can chime in, I know he's done this kind of thing before.


DStastny(Posted 2008) [#5]
@Blueapple

I dont think your getting what I am doing.

This is what the what my .i looks like

TVector3^Object{
.X#&
.Y#&
.Z#&
-New()="dbsTVector3Ctor"
-Delete()="dbsTVector3Dtor"
-Add:TVector3(v1:TVector3,v2:TVector3)="dbsTVector3Add"
}="dbsTVector3Class"



You see its an OBJECT not a function. I am well aware of how blitzmax works and Extern statement works. It does not do what I need.

This code works like a "STRING" or "ARRAY" not functions or EXTERN classes. These this is a true BlitzMax object that you can use the new operator on.

I dont think you read my first post.


Blueapples(Posted 2008) [#6]
Ah, types. Yeah I guess I missed that part.

If that's all it takes to make C types work in BM, I would expect Extern to allow you to define Type blocks within it. I guess you probably tried that already though. Looks like BMK needs an extension. :-/ Which you said you don't want to do.

p.s. My name is plural. ;-p