Skip to main content.
IBAN   NL79 ABNA 0477 3565 08
EU-VAT NL170160656B01
Chamber of Commerce 32041148
http://www.compuphase.com
Eerste Industriestraat 19-21
1401VL  Bussum
tel. +31 35 693 9261
info@compuphase.com
CompuPhase

The Small language forum - message archive for 2000

 

The archive is sorted on date; the oldest messages appear first.


Welcome

Posted ByThiadmer Riemersma on July 20, 2000 at 07:44:49:

Welcome to the forum of the "Small scripting language".
I hope that in the future you will find a few tips and answers to your questions here.


Use a native C++ member function with amx:

Posted ByAndreas Lindmark on July 24, 2000 at 10:46:39:

my problem: I got a class called Tester this class have a member function declared as:

static cell printTHIS(AMX *amx, cell *params);

and then i register it like this:

AMX_NATIVE_INFO print_Natives[] = {
{ "printTHIS", printTHIS },
{ 0, 0 }
};
err=amx_Register(&amx, print_Natives, -1); //returns 0


The small program:
#include
native printTHIS();
main()
{
printTHIS();
}


The error i get is nr 20 (invalid symbol name\par)at row 5.

help...this is getting frustrating



Re: Use a native C++ member function with amx:

Posted ByThiadmer Riemersma on July 24, 2000 at 11:19:21:

In Reply to: Use a native C++ member function with amx: posted by Andreas Lindmark on July 24, 2000 at 10:46:39:

: The small program:
: #include
: native printTHIS();
: main()
: {
: printTHIS();
: }

:
: The error i get is nr 20 (invalid symbol name\par)at row 5.

This appears unrelated to how the native function was implemented. I copied the code snippet and compiled it, which worked (after completing the #include directive at line 1).

There once was a version of the Small compiler that had problems with upper case in letters, but I assume that you are using a recent version.


AMX usage

Posted ByJohn W. Ratcliff on July 26, 2000 at 16:42:38:

I'm a little unclear on how the virtual machine is meant to be used...

Can you instantiate multiple instances of a virtual machine at a time?

Can you load up a program into the virtual machine, and then call down into different functions in that coee?

Can you load up multiple programs into a single virtual machine? How do they do link resolution, etc?

Thanks,

John


Small Virtual Machine in C++

Posted ByJohn W. Ratcliff on July 26, 2000 at 23:41:09:

I'm considering re-writing the Small Virtual Machine in C++ so that Small programs can be executed in an objected oriented manner. (Meaning lots of instnaces of the same piece of Small code). I also want to have a real loader and linker so that you can dynamically link and execute lots of these Small base classes.

I'm also going to write a pre-parser for Small to adapt an object oriented event driven scripting langauge to be compiled and executed on the Small virtual machine.

Does anyone know if anyone has ever ported the Small Virtual Machine to C++ already?

Thanks,

John


Re: AMX usage

Posted ByThiadmer Riemersma on July 27, 2000 at 05:12:07:

In Reply to: AMX usage posted by John W. Ratcliff on July 26, 2000 at 16:42:38:

: Can you instantiate multiple instances of a virtual machine at a time?

Yes. All data related to a "virtual machine" is in the memory block that amx_Init() initializes for you. The only "shared" data between virtual machines is the optional linked list of "property" functions (native functions in amxcore.c)

: Can you load up a program into the virtual machine, and then call down into different functions in that code?

Yes, as long as those functions are exported. The main() function is always exported and it is also the default entry point, but you can export more functions and call them explicitly.

: Can you load up multiple programs into a single virtual machine? How do they do link resolution, etc?

No, one virtual machine can only hold one program. (So there is no linkage either). You may make a native function that, when call from one virtual machine, jumps to a function in another virtual machine, but that is as far as it goes.


Re: Small Virtual Machine in C++

Posted ByThiadmer Riemersma on July 27, 2000 at 05:26:50:

In Reply to: Small Virtual Machine in C++ posted by John W. Ratcliff on July 26, 2000 at 23:41:09:

: [...] I also want to have a real loader and linker so that you can dynamically link and execute lots of these Small base classes.

For a real linker/locater, the file format that is output by the compiler must probably change, as it currently holds no relocation information. That is, the copde refers directly to hard addresses in both code (jumps/calls) and data (variables).

One easy option out (sorry to bring it up again) might be to load all those tiny scripts into separate virtual machines. On the other hand, this incurs an overhead (each script has a header) and calling functions accross virtual machines becomes a hassle.

: I'm also going to write a pre-parser for Small to adapt an object oriented event driven scripting langauge to be compiled and executed on the Small virtual machine.

Do you want me to make any changes to the compiler to better support this? What I can think of right now is to introduce some "#line" directive (just like C) so that the Small debugger could refer to the original source.

: Does anyone know if anyone has ever ported the Small Virtual Machine to C++ already?

The virtual machine should compile in C++ (so you can rename the .C extension to .CPP without trouble. I do not know whether a C++ class wrapper exists, but it should be fairly easy. What I tried to do is to store all information in a structure that is referenced via the AMX type. Most "amx" functions take a parameter of that type. You could make a class that has an "AMX*" field as a private data member and strip it off all "amx" functions (which you implement as members). amx_Init() becomes a constructor; no destructor is needed.

(Hope this helps.)


Re: Small Virtual Machine in C++

Posted ByJohn W. Ratcliff on July 27, 2000 at 10:51:40:

In Reply to: Re: Small Virtual Machine in C++ posted byThiadmer Riemersma on July 27, 2000 at 05:26:50:

Yes, this helps. I spent quite some time looking at the virtual machine code last night and I think I have a handle on the problem.

Here's what I plan to do. Each 'class' operates on it's own virtual machine. Each 'instance' of a class will make a private copy of it's data space so that multiple 'instances' can be executed. Each time an instance is executed, his private data space is copied to and from the virtual machine.

To allow classes to talk between one another I will just implement that via the native methods, so it vectors through my wapper layer.

I was dissapointed that Small didn't support structs, but I just figure I can store the dataspace as globals relative to a single instantiation of a class. However, there is not currently any distinction between static data and dynamic data. In fact, I'm not sure Small makes a distinction.

However, since the dataspace is clearly defined, it will be easy for me to manage copies of them.

Thanks, the abstract machine is a really nice piece of work!

John


Re: Small Virtual Machine in C++

Posted ByThiadmer Riemersma on July 27, 2000 at 11:59:36:

In Reply to: Re: Small Virtual Machine in C++ posted byJohn W. Ratcliff on July 27, 2000 at 10:51:40:

: I was dissapointed that Small didn't support structs [...]

I understand that quite well, but for a typeless language, structures seem not to be very useful (all fields would have the same type). You can mimic some features of a struct by using an "enum" to declare the fields and to define an array with the size of that enum. The indices to the array will now be "tag checked", which catches most indexing mistakes.

: However, there is not currently any distinction between static data and dynamic data. In fact, I'm not sure Small makes a distinction.

Small has global variables (like the "external" class in C) and local variables (like the "auto" class). Local variables are stored on the stack. The (global) data section, the heap and the stack might be seen as one big data area.


Re: Use a native C++ member function with amx:

Posted ByAndreas Lindmark on July 27, 2000 at 23:44:20:

In Reply to: Re: Use a native C++ member function with amx: posted byThiadmer Riemersma on July 24, 2000 at 11:19:21:

I use the Loadprogram function from the manual to load my prg, but when it call the amx_Init it returns error 19(AMX_ERR_NOTFOUND, /* function not found */ according to the amx.h?)

small source:

native printthis();
main()
{
new a = 0, b= 1;
printthis(); //without this line it works fine...
}

It compiles ok, but the amx_Init doesn't like it.
Why?..


Re: Use a native C++ member function with amx:

Posted ByThiadmer Riemersma on July 28, 2000 at 03:30:42:

In Reply to: Re: Use a native C++ member function with amx: posted byAndreas Lindmark on July 27, 2000 at 23:44:20:

: I use the Loadprogram function from the manual to load my prg, but when it call the amx_Init it returns error 19(AMX_ERR_NOTFOUND, /* function not found */ according to the amx.h?)

I do not see (from the source) how amx_Init() can return error value AMX_ERR_NOTFOUND. Possible return values are AMX_ERR_FORMAT and AMX_ERR_VERSION (and AMX_ERR_NONE).

However, amx_Register() does return AMX_ERR_NOTFOUND if there is at least one unresolved native function. Can you make sure that you called amx_Register() on the new native function that you added?


libs

Posted ByFelix Kollmann on September 02, 2000 at 12:19:12:

I want to create a console using "small" but for this I have to dynamicly load other .amx files. In the header are some variables for that stuff, I believe.
But I'm unable to find sth. about it in the docs.
So... how does I load other .amx files as libs?


Re: libs

Posted ByThiadmer Riemersma on September 06, 2000 at 12:56:40:

In Reply to: libs posted byFelix Kollmann on September 02, 2000 at 12:19:12:

: So... how does I load other .amx files as libs?

One option is to load several .AMX files into separate "AMX" variables. To have one function call another function that is in a different AMX requires the help of a native function. You may also look at the question by John W. Ratcliff and the replies (see the link).

Thiadmer


GetPubVar

Posted ByDavid Burgess on October 04, 2000 at 05:49:06:

Does the AMX GetPubVar allow the "C" side of the
application to set the the values of Small public
variables? If so, do you have a sample?

rephrased
Is there anyway that the "C" program can set values
of variables?

Finally has anyone tried piping small console output
via WIN32 pipe?


Re: GetPubVar

In Reply to: GetPubVar posted byDavid Burgess on October 04, 2000 at 05:49:06:

: Does the AMX GetPubVar allow the "C" side of the
: application to set the the values of Small public
: variables? If so, do you have a sample?

That is exactly its purpose. I made the following "Small" program:
#include

public abc
main()
printf("abc=%d^n", abc)

Then, I added the following code to the sample program SRUN.C (before the call to amx_Exec):

cell amx_addr, *native_addr;
err = amx_FindPubVar(&amx, "abc", &amx_addr);
if (err == AMX_ERR_NONE) {
err = amx_GetAddr(&amx, amx_addr, &native_addr);
assert(err == AMX_ERR_NONE);
*native_addr = 42;
} /* if */

When running the Small program with the modified SRUN.C, it prints "42".

Note that I used amx_FindPubVar() rather than amx_GetPubVar(), to be able to search for a variable name.

: rephrased
: Is there anyway that the "C" program can set values
: of variables?

Before public variables, one had to do this via the debugger interface, which is still functional (and offers a little more control).

: Finally has anyone tried piping small console output
: via WIN32 pipe?

Not that I am aware of. But since Small is written in ANSI C as much as possible, I do not expect any problems.


Re: GetPubVar

Posted ByDavid Burgess on October 04, 2000 at 20:45:43:

In Reply to: Re: GetPubVar posted byThiadmer Riemersma on October 04, 2000 at 09:29:55:

: : Does the AMX GetPubVar allow the "C" side of the
: : application to set the the values of Small public
: : variables? If so, do you have a sample?

: That is exactly its purpose. I made the following "Small" program:
: #include

: public abc
: main()
: printf("abc=%d^n", abc)

: Then, I added the following code to the sample program SRUN.C (before the call to amx_Exec):

: cell amx_addr, *native_addr;
: err = amx_FindPubVar(&amx, "abc", &amx_addr);
: if (err == AMX_ERR_NONE) {
: err = amx_GetAddr(&amx, amx_addr, &native_addr);
: assert(err == AMX_ERR_NONE);
: *native_addr = 42;
: } /* if */

: When running the Small program with the modified SRUN.C, it prints "42".

: Note that I used amx_FindPubVar() rather than amx_GetPubVar(), to be able to search for a variable name.

: : rephrased
: : Is there anyway that the "C" program can set values
: : of variables?

: Before public variables, one had to do this via the debugger interface, which is still functional (and offers a little more control).

: : Finally has anyone tried piping small console output
: : via WIN32 pipe?

: Not that I am aware of. But since Small is written in ANSI C as much as possible, I do not expect any problems.


Is there anyway of doing this with a string array?


Re: GetPubVar

Posted ByThiadmer Riemersma on October 05, 2000 at 02:43:15:

In Reply to: Re: GetPubVar posted byDavid Burgess on October 04, 2000 at 20:45:43:

: Is there anyway of doing this with a string array?

Unfortunately not. Arrays cannot be made "public" variables. To set a string, a Small program must provide a public function that sets the global variable.

Alternatively, the Small program calls a native function to get a string.


Small being used in products?

Posted ByKurt Miller on October 11, 2000 at 11:22:59:

Is the Small language being used in any commercial products at the moment? If so, have you considered putting a web page up that lists these products? I believe such a list may help potential users decide if their type of software might benefit from using a scripting language such as Small. Anyway, keep up the good work.


Re: Small being used in products?

Posted ByThiadmer Riemersma on October 12, 2000 at 02:57:15:

In Reply to: Small being used in products? posted byKurt Miller on October 11, 2000 at 11:22:59:

: [...] have you considered putting a web page up that lists these products?

This is a good suggestion. However, I depend on other parties to keep this list up to date. I will try to build an initial list based on e-mails that I have received.


Floating point support

Posted BySascha Salevsky on October 13, 2000 at 06:57:53:

Will there be any floating point support in future versions of the language?


API Question

Posted BySylvain Rochette on October 13, 2000 at 14:41:46:

I have some question about the API... And before I read the 109 pages from the PDF :)

Is this is possible to execute a script line by line, I mean, I decide when I want to continue to execute the next line or a part of the script?

I'm not sure if I read correclty but is the script can be like pre-compilated before the use to make the execution faster?

Best Regards,
Corrosif


Re: Floating point support

Posted ByThiadmer Riemersma on October 15, 2000 at 11:24:54:

In Reply to: Floating point support posted bySascha Salevsky on October 13, 2000 at 06:57:53:

: Will there be any floating point support in future versions of the language?

I do not intent to add it as a native "type" in Small. I am considering to implement some limited form of operator overloading in Small, which in combination with a set of native functions, would make expressions with floating point operations more readable. However, at this point, I am not sure that this is feasible.

In the mean time, there is the floating point extension module written (contributed by Greg Garner from Artran, Inc.), which you can find among the other "downloads" (or use the link below).

Thiadmer


Re: API Question

Posted ByThiadmer Riemersma on October 15, 2000 at 11:28:48:

In Reply to: API Question posted bySylvain Rochette on October 13, 2000 at 14:41:46:

: Is this is possible to execute a script line by line, I mean, I decide when I want to continue to execute the next line or a part of the script?

Yes, using the debugger interface.

: I'm not sure if I read correclty but is the script can be like pre-compilated before the use to make the execution faster?

The script is _always_ compiled before it can run. There are two components in the Small kit: the compiler and the abstract machine (or "virtual machine"). This approach is comparable to that of Java.


Re: API Question

Posted BySylvain Rochette on October 15, 2000 at 18:11:37:

In Reply to: Re: API Question posted byThiadmer Riemersma on October 15, 2000 at 11:28:48:

ok thanks

basicly i want add your scripting into my game, so i can define script function and like your API will raise some 'callback' function i have defined?

can i handle the execution of multiple script at the same time?

Anyway your script sound like very cool, good job! :)

Regards,
Corrosif


Re: API Question

Posted ByThiadmer Riemersma on October 16, 2000 at 11:50:02:

In Reply to: Re: API Question posted bySylvain Rochette on October 15, 2000 at 18:11:37:

: basicly i want add your scripting into my game, so i can define script function and like your API will raise some 'callback' function i have defined?

The script contains "public" functions that your application (in C/C++) can call (via amx_Exec()). Your C/C++ application can also provide "native" functions that the script can call.

: can i handle the execution of multiple script at the same time?

Yes, each script is loaded in its own virtual machine. The virtual machines can run concurrently. If synchronization between the synchronization is required, your application should provide this (e.g., via "native" functions).

Thiadmer


Re: API Question

Posted BySylvain Rochette on October 16, 2000 at 16:51:43:

In Reply to: Re: API Question posted byThiadmer Riemersma on October 16, 2000 at 11:50:02:

Perfect, so it's seam that the script can do all i want...

The last question :) is can I compile in realtime a script like i read a non-compilated script and compile the script myself from my application and use'it after?

Best Regards,
Corrosif


Re: API Question

Posted ByThiadmer Riemersma on October 17, 2000 at 11:44:53:

In Reply to: Re: API Question posted bySylvain Rochette on October 16, 2000 at 16:51:43:

: The last question :) is can I compile in realtime a script like i read a non-compilated script and compile the script myself from my application and use'it after?

That is now (finally) possible, but it requires some work. What you need to do is link the compiler to your application. When doing that, you must also implement a few functions that the compiler calls, such as functions to read from the source file and to write to the output file. The README.TXT file in the "Small kit" gives the details.


Re: API Question

Posted BySylvain Rochette on October 17, 2000 at 14:40:42:

In Reply to: Re: API Question posted byThiadmer Riemersma on October 17, 2000 at 11:44:53:

> That is now (finally) possible, but it requires >some work. What you need to do is link the >compiler to your application. When doing that, >you must also implement a few functions that the >compiler calls, such as functions to read from >the source file and to write to the output file. >The README.TXT file in the "Small kit" gives the >details.

Perfect thanks



Small Call

Posted ByDavid Burgess on October 25, 2000 at 21:39:56:

Where do I find an example of calling a
Small Function (other than main()) from C?


Re: Small Call

Posted ByThiadmer Riemersma on October 26, 2000 at 03:19:24:

In Reply to: Small Call posted byDavid Burgess on October 25, 2000 at 21:39:56:

: Where do I find an example of calling a
: Small Function (other than main()) from C?

I was at the point of directing you to "PluginMaker", when I realized that I had not put up the source code for it. So below is a snippet of code that I extracted from it.


int result,index;
cell ret;
/* some more code */
result=amx_FindPublic(&amx, "@run", &index);
if (result == AMX_ERR_NONE) {
result = amx_Exec(&amx, &ret, index, 0);
if (amx_checkresult(hwnd,&amx,result)) {
/* some more code */
} /* if */
} else {
MessageBox(hwnd, "Function \"@run\" is"
"missing.", Caption,
MB_OK|MB_ICONEXCLAMATION);
} /* if */

Hope this helps.
Thiadmer


When run with /D "ASM32" in MSVC++6 it doesn't work, but it works without it.

Posted ByJim Bellinger on November 05, 2000 at 00:27:32:

Why would this occur, exactly? Is there something specifically I have to do to make the ASM32 ver work? I already used MASM on that one asmexec.asm thang...


Re: When run with /D "ASM32" in MSVC++6 it doesn't work, but it works without it.

Posted ByThiadmer Riemersma on November 06, 2000 at 09:58:28:

In Reply to: When run with /D "ASM32" in MSVC++6 it doesn't work, but it works without it. posted byJim Bellinger on November 05, 2000 at 00:27:32:

I think that I just fixed that problem today.

There was a "syntax problem" in the ASMEXEC.ASM file, which TASM and WASM accepted but MASM rejected. Marc Peter and I fixed this a long time ago, but apparently in a way that the new Microsoft Incremental Linker did not like. Anyway, I got it compiling again with Microsoft Visual C/C++ 6.0.

Thiadmer


Re: When run with /D "ASM32" in MSVC++6 it doesn't work, but it works without it.

Posted ByJim Bellinger on November 07, 2000 at 00:48:15:

In Reply to: Re: When run with /D "ASM32" in MSVC++6 it doesn't work, but it works without it. posted byThiadmer Riemersma on November 06, 2000 at 09:58:28:

: I think that I just fixed that problem today.

: There was a "syntax problem" in the ASMEXEC.ASM file, which TASM and WASM accepted but MASM rejected. Marc Peter and I fixed this a long time ago, but apparently in a way that the new Microsoft Incremental Linker did not like. Anyway, I got it compiling again with Microsoft Visual C/C++ 6.0.

: Thiadmer

Is this also the case with the Just In Time compiler, or did it work already (I hadn't tried it)?


Re: When run with /D

Posted ByThiadmer Riemersma on November 08, 2000 at 12:48:17:

In Reply to: Re: When run with /D posted byJim Bellinger on November 07, 2000 at 00:48:15:

: Is this also the case with the Just In Time compiler, or did it work already (I hadn't tried it)?

I have not fixed the JIT yet. Actually, I think that the JIT has never been tested with Microsoft Visual C/C++.

Note that the JIT currently still has a few rough edges: the size of the "compiled" program is estimated, rather than calculated (meaning that there may exist programs for which the estimate is wrong), and the debugger hook is not supported.

Thiadmer


controlled run of amx

Posted ByHan Cicimen on November 22, 2000 at 04:55:00:

We manufacture control systems in Turkey. For one of our new desgin we decided to add on site programmabality but we want it self contained. I mean everything will be inside the controller including interpreter or pcode compiler. Since this project contains many features I could not be able to do everything by my self because of common problem: lack of time. So I started to look for simple reliable, easy to use and feature rich interpreter library and found SMALL. I think it is a incredibly well thougt and sophisticated. I think it is an excellent work. But I have few questions below.

I plan to use BC 5.0 LARGE model 16 Bit. I downloaded AMX and compiled compiler and AMX. They are working with my memory model.

1. I plan to use AMX with a realtime kernel (From On time) I plan to work cooperative mode not preemptive mode. My equipment has 4 comm ports , 1 ethernet port with TCP/IP. I wanted to give more priority to hardware than the software. So I wanted to stop running of AMX and give control to my tasker program. Let say every AMX will work for 20 Ms than I want to pause it. Or maybe pause it when it run 200 instruction. Somehow I ve to stop it and give control to my tasker. And when I want to make it work I want it to resume again. Is there an easy way to do it?
2. My application will work 24 hour 365 day. Any problem with AMX?
3. What else I have to take into consider?

Regards,
HAN


Need a way to break out of AMX if it has executed over, say, 100K instructions.

Posted ByJim Bellinger on November 26, 2000 at 13:45:29:

Need a way to prevent bad code from locking everything up. Any ideas? Thanks. :)


Re: controlled run of amx

Posted ByThiadmer Riemersma on November 27, 2000 at 03:12:33:

In Reply to: controlled run of amx posted byHan Cicimen on November 22, 2000 at 04:55:00:

: 1. [...] So I wanted to stop running of AMX and give control to my tasker program. Let say every AMX will work for 20 Ms than I want to pause it. Or maybe pause it when it run 200 instruction. Somehow I ve to stop it and give control to my tasker. And when I want to make it work I want it to resume again. Is there an easy way to do it?

Not to my knowledge. The AMX does not count instructions. You can switch tasks at any native function (by modifying the central function that interfaces between Small and the native functions). I do not have an option to break out of the AMX after an number of instructions. I will have to consider this.

: 2. My application will work 24 hour 365 day. Any problem with AMX?

No. Small does not use dynamic memory (other than local variables allocated from the stack). So memory leaks are practically impossible. There is no garbage collection. The core functions of the AMX do not allocate memory or other system resources (with the exception of the "property functions" that call malloc).

: 3. What else I have to take into consider?

The Small compiler is not re-entrant. I believe that the AMX is re-entrant.

Thiadmer


Re: Need a way to break out of AMX if it has executed over, say, 100K instructions.

Posted ByThiadmer Riemersma on November 27, 2000 at 03:18:35:

In Reply to: Need a way to break out of AMX if it has executed over, say, 100K instructions. posted byJim Bellinger on November 26, 2000 at 13:45:29:

: Need a way to prevent bad code from locking everything up.

A native function can abort a Small program (using amx_Raise()). The debugger interface allows you to monitor how many "lines" of source code are executed.

There was another request for calling a native function after some limit of pseudo-code instructions was executed. I must consider this (I do not know whether it is feasible at a low cost).

Thiadmer


Re: controlled run of amx

Posted ByHan Cicimen on November 27, 2000 at 09:10:53:

In Reply to: Re: controlled run of amx posted byThiadmer Riemersma on November 27, 2000 at 03:12:33:

Dear Sir,

I played and checked your code more intensively and I want to say it is very good. I am novice programmer but I learned so many thing from your code. I found a simple way to count instructions. Just added a simple counter in the for next loop and let say every 1000 instruction I just switch to my tasker. And it seems it works.

I wanted to ask another question. GNU version use label adress to run the code faster. (As far as I understand) It sees like Borland omplier does not support this. But way do not you use pointers to the functions instead of case switch? I feel like function pointers will run faster than case- switch. May be I am wrong, just an opinion.
Regards,
HAN



Re: controlled run of amx

Posted ByThiadmer Riemersma on November 28, 2000 at 04:24:57:

In Reply to: Re: controlled run of amx posted byHan Cicimen on November 27, 2000 at 09:09:08:

:I found a simple way to count instructions. Just added a simple counter in the for next loop and let say every 1000 instruction I just switch to my tasker. And it seems it works.

Perhaps a simple solution is the best. I will use this suggestion to implement it in the "official" version of the toolkit.

: GNU version use label adress to run the code faster. (As far as I understand) It sees like Borland omplier does not support this.

Labels as pointers is a GCC extension. No other compiler that I know supports it.

: But why do not you use pointers to the functions instead of case switch? I feel like function pointers will run faster than case-switch.

Although I have not timed it, from the generated assembler code, I had the impression that the switch statement would be faster (the compiler generates a jump table). That the GCC label solution is faster than a switch is mostly because it removes the overhead of the loop around the switch, not because a jump table is quicker than a switch.

Thiadmer


Re: #pragma pack

Posted ByThiadmer Riemersma on November 30, 2000 at 03:45:02:

In Reply to: #pragma pack posted byLinus Nuber on November 29, 2000 at 08:45:01:

: I would like to access a single character with [], even if #pragma pack 1 is used!

: Is it possible to change not only the meaning of the !"" - syntax for stringconstants but also the meaning of the index operator [] and {}?

Actually, I consider the "#pragma pack" (and the compiler option) a mistake: now you cannot simply look at a routine and "know" the memory layout of strings, unless you also know the compiler options and earlier pragmas.

Changing the semantics of an operator based on a pragma or a compiler option is worse: making general purpose functions that operate on an array would be a pain. None of the example routines in the Small manual that work on arrays would still work correctly.

To answer your question, yes it is possible, but I will not make that change.

Thiadmer


Re: Need a way to break out of AMX if it has executed over, say, 100K instructions.

Posted BySøren Hannibal on December 01, 2000 at 07:13:27:

In Reply to: Re: Need a way to break out of AMX if it has executed over, say, 100K instructions. posted byThiadmer Riemersma on November 27, 2000 at 03:18:35:

: There was another request for calling a native function after some limit of pseudo-code instructions was executed. I must consider this (I do not know whether it is feasible at a low cost).

: Thiadmer

I also vote for the proposition of having some kind of check to avoid the script locking up the whole program. (and if you won't do it I will demand a recount :-)

Just an idea: If you want to put in a counter only to avoid infinite loops, it does not have to increment and test the counter for every instruction, just for all the branch opcodes, as these are the only ones that will cause it to loop forever


Re: Suggestion: native variables

Posted ByHan Cicimen on December 05, 2000 at 19:45:09:

In Reply to: Re: Suggestion: native variables posted byThiadmer Riemersma on December 04, 2000 at 04:14:35:

I have same problem. I want to give possibility to Small programmer to reach C variables (or system variables of control system) from Small. I plan to use public variables. But my some variables in C is planned to be read only (also it must be). So somehow I have to prevent the user from changing it. If there was an option for const it would be usefull. Let say like
public const s_variable

In fact s_variable should be just an ordinary public variable but compiler just prevents it's value to be written inside the Small. But since it's memory address can be got by native fuctions it can be written from C. I just wonder how people solve this probllem before?

Regards,

HAN


Re: Suggestion: native variables

Posted ByThiadmer Riemersma on December 06, 2000 at 02:50:38:

In Reply to: Re: Suggestion: native variables posted byHan Cicimen on December 05, 2000 at 19:45:09:

: If there was an option for const it would be usefull. Let say like
: public const s_variable

This is exactly the major reason for me to introduce the "const" keyword in Small.

: I just wonder how people solve this probllem before?

They didn't, probably ;-)

Thiadmer


Re: Suggestion: native variables

Posted BySoren Hannibal on December 06, 2000 at 05:32:21:

In Reply to: Re: Suggestion: native variables posted bySøren Hannibal on December 04, 2000 at 06:37:55:

One more thought (and more stuff on your todo list :-) is that accessing arrays of native variables can be useful:

"nativeVar[4]=10"

which would then call the native function "setnativeVar(10,4)"


Re: Suggestion: native variables

Posted ByHan Cicimen on December 06, 2000 at 07:12:39:

In Reply to: Re: Suggestion: native variables posted byThiadmer Riemersma on December 06, 2000 at 02:50:38:

But we can not reach the const values outside the Small program. Can we reach them?

Regards,

HAN


Re: Suggestion: native variables

Posted ByThiadmer Riemersma on December 07, 2000 at 02:56:25:

In Reply to: Re: Suggestion: native variables posted byHan Cicimen on December 06, 2000 at 07:12:39:

: But we can not reach the const values outside the Small program. Can we reach them?

A Small program cannot reach data outside its abstract machine. The application that embeds the AMX can only reach variables in the Small program via the debugger interface, and it can reach public variables.

The "native variables" suggestion is to translate accesses to a variable to function calls; calls to "native functions" to be precise.

Thiadmer


Re: Suggestion: native variables

Posted ByThiadmer Riemersma on December 08, 2000 at 03:50:09:

In Reply to: Re: Suggestion: native variables posted bySoren Hannibal on December 06, 2000 at 05:32:21:

: One more thought (and more stuff on your todo list :-) is that accessing arrays of native variables can be useful:

And the same goes for public variables. At the moment these can only be simple variables, not arrays.

Thiadmer


prevent initialize of Public variables

Posted ByHan Cicimen on December 08, 2000 at 12:49:18:

Is there any way to prevent the initialisation of oublic variables. I create some pointers in C. Then I assign their address to the Small public variable address with amx_GetPubVar and amx_GetAddr. When I run small program it initialize pubilc variables to 0 so my variables in C as well.
Is there any way to do:
1. No initialiazation as startup.
2. Prevent initialiazation of public variables.
3. May be a better solution when the Small amx file loaded to the memory and initialize with amx_init I think all the initialize operation will be completed up to main function. (Just an idea)
4. Is there any way to learn where the program after main() starts? Let say if number of opcodes So I could simply stop the small program and can initialize my values.

5. Any other idea?
Best Regards,
HAN


Re: prevent initialize of Public variables

Posted ByHan Cicimen on December 09, 2000 at 05:44:36:

In Reply to: prevent initialize of Public variables posted byHan Cicimen on December 08, 2000 at 12:49:18:

I solved my problem. Before I assign a my C pointer to the pointer of Smal variable I just assign value of my variable first. Then assign addresses.
Let say
cell *Smallpointer; (I know the address of small variable pointer with the help of (getpubvar and getaddr functions)
cell *cpointer;

first
*Smallpointer=*cpointer;
then
cpointer=Smallpointer;

it solves my problem.

Regards,
HAN




native callbacks with user-defined data

Posted ByBao Nguyen on December 10, 2000 at 21:50:13:

At the zip file link I have a modified version of Small that adds a couple minor features. It's not the current version of Small, however, it's one of the older ones. All changes are enclosed in // BAO{ and // }BAO.

Changes
- native functions can now be passed callback data that's specified when the native function is added
- larger symbol names

Compiler Changes
- visual c++ style errors
- more auto-extensions when including headers
- headers are included from the directory the parent header is in. this way headers can be in different directories and include more headers w/o problems. this is like C compilers

That's all. It would be nice if at least the native callback data improvement makes it into the next release.



Re: native callbacks with user-defined data

Posted ByThiadmer Riemersma on December 11, 2000 at 06:42:39:

In Reply to: native callbacks with user-defined data posted byBao Nguyen on December 10, 2000 at 21:50:13:

: At the zip file link I have a modified version of Small that adds a couple minor features.

Thank you. I will look at it.


sprintf() exists?

Posted ByKirk Bratvold on December 19, 2000 at 13:48:33:

Is there any sort of sprintf()-style functionality for Small?


re-entrancy

Posted ByKirk Bratvold on December 19, 2000 at 16:53:33:

Is it possible for a Small function to call a native function that calls a Small function?


Re: sprintf() exists?

Posted ByThiadmer Riemersma on December 20, 2000 at 03:06:17:

In Reply to: sprintf() exists? posted byKirk Bratvold on December 19, 2000 at 13:48:33:

: Is there any sort of sprintf()-style functionality for Small?

No such functionality is implemented right now. It could be done, without much trouble, by taking printf() as an example.

In Small, I tried to minimize the number of "standard" functions to keep the abstract machine as little as possible. As the Small abstract machine is embedded into a host application, the functions that you need in a Small script depend largely on the host.

Thiadmer


Re: re-entrancy

Posted ByThiadmer Riemersma on December 20, 2000 at 03:07:57:

In Reply to: re-entrancy posted byKirk Bratvold on December 19, 2000 at 16:53:33:

: Is it possible for a Small function to call a native function that calls a Small function?

Yes. Or rather, it "should" be possible. The Small abstract machine was designed to support this, but I have not tested it in a long while.

Thiadmer