ExternalFunction.st
author Claus Gittinger <cg@exept.de>
Fri, 12 Jul 1996 23:44:14 +0200
changeset 1545 01e11b46ca65
parent 1543 f687d50b978f
child 1547 fa7cc4070fc0
permissions -rw-r--r--
more possible argument types
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
	      All Rights Reserved
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
ExecutableFunction subclass:#ExternalFunction
1542
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    14
	instanceVariableNames:'name moduleHandle'
1184
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	classVariableNames:'InvalidCustomFunctionSignal'
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	poolDictionaries:''
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	category:'System-Support'
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!ExternalFunction primitiveFunctions!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
%{
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
/*
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
 * given an ST-object, make something useful for C
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 * cast it to an int
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 *
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 * CAVEAT: floats are not allowed.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 */
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
int
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
convertST_to_C(stObj) 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
    OBJ stObj;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
{
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    33
	int flags, nInst;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    34
	OBJ *oP;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    35
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
	if (__isString(stObj) || __isSymbol(stObj)) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
	    return (int)(__stringVal(stObj));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
	}
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    39
	if (__isByteArray(stObj)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    40
	    return (int)(__ByteArrayInstPtr(stObj)->ba_element);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    41
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    42
	if (__isExternalBytes(stObj)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    43
	    return (int)(__externalBytesAddress(stObj));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    44
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    45
	if (__isExternalAddress(stObj)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    46
	    return (int)(__externalAddressVal(stObj));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    47
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    48
	if (__isExternalFunction(stObj)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    49
	    return (int)(__externalFunctionVal(stObj));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    50
	}
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
	if (__isSmallInteger(stObj)) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
	    return (int)(__intVal(stObj));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
	}
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    54
	if (__isLargeInteger(stObj)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    55
	    return (int)(__signedLongIntVal(stObj));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    56
	}
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
	if (__isCharacter(stObj)) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
	    return (int)(__intVal(__characterVal(stObj)));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
	}
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    60
	if (stObj == nil) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    61
	    return 0;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    62
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    63
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    64
	if (__qClass(stObj) == @global(ShortFloat)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    65
	    return (int)(__shortFloatVal(stObj));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    66
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    67
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    68
        flags = __intVal(__ClassInstPtr(__qClass(stObj))->c_flags) & ARRAYMASK;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    69
	nInst = __intVal(__ClassInstPtr(__qClass(stObj))->c_ninstvars);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    70
	oP = (OBJ *)__InstPtr(stObj)->i_instvars[nInst];
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    71
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    72
	if (flags & FLOATARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    73
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    74
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    75
	if (flags & DOUBLEARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    76
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    77
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    78
	if (flags & DOUBLEARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    79
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    80
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    81
	if (flags & BYTEARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    82
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    83
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    84
	if (flags & WORDARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    85
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    86
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    87
	if (flags & LONGARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    88
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    89
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    90
	if (flags & SWORDARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    91
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    92
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    93
	if (flags & SLONGARRAY) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    94
	    return (int)(oP);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    95
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    96
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
	if (stObj == true) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
	    return 1;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
	}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
	if (stObj == false) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
	    return 0;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
	}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
	return 0;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
%}   
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!ExternalFunction class methodsFor:'documentation'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
copyright
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
 COPYRIGHT (c) 1994 by Claus Gittinger
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
	      All Rights Reserved
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
 This software is furnished under a license and may be used
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
 only in accordance with the terms of that license and with the
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
 inclusion of the above copyright notice.   This software may not
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
 be provided or otherwise made available to, or used by, any
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
 other person.  No title to or ownership of the software is
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
 hereby transferred.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
documentation
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
"
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    Instances of this class represent external (non-Smalltalk) functions.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    Also, the class provides access to custom functions 
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   130
    These custom functions enable you to call c functions 
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   131
    even if no stc compiler is available 
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   132
    (they are kind of what user-primitives are in ST-80).
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   133
    You can register your own custom C-functions in a private main.c
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   134
    and relink ST/X from the binaries.
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    (see the demo functions provided in main.c).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   137
    If you have the stc compiler, we recommend using inline primitive
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   138
    code: its much easier to enter, compile, debug and maintain.
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   139
    (especially, to maintain, since the primitive code is contained
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   140
     in the classes source/object file - while custom functions are 
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   141
     external to the classLibraries).
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   143
    Non custom externalFunctions are created, when a non-ST shared library is loaded, 
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   144
    and returned by the ObjectFileHandles>>getFunction: method.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   145
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   146
    The C functions contained in that lib are callable (instances of myself)
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   147
    with the call / callWith: methods.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   148
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   149
    ST-arguments are converted to C as follows:
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   150
	ST class	    C argument
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   151
	------------------------------
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   152
	SmallInteger	    int
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   153
	LargeInteger	    int	(must be 4-byte unsigned largeInteger)
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   154
	String		    char *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   155
	Symbol		    char *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   156
	Character	    int
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   157
	ExternalBytes	    char *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   158
	ExternalAddress	    char *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   159
	ExternalFunction    char *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   160
	FloatArray	    float *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   161
	DoubleArray	    double *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   162
	ByteArray	    char *
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   163
	ShortFloat	    float
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   164
	true		    1
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   165
	false		    0
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   166
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   167
    The returned value is converted to an unsigned integer (smallInteger or largeInteger).
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   168
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   169
    Notice, that no doubles can be passed; the reason is that the calling
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   170
    conventions (on stack, in registers, in FPU registers etc.) are so different among
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   171
    machines (and even compilers), that a general solution is not possible (difficult) 
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   172
    to program here. To pass doubles, either use shortFloats, or pack them into a DoubleArray.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   173
    For functions with up to 2 double arguments, specialized call methods are provided.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   174
    Sorry for that inconvenience.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   175
    
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   176
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   177
    - This is still in construction and NOT yet published for 
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   178
      general use. For now, either use inline C-code, or use the customFunction call
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   179
      mechanism.
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
   180
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
   181
    [author:]
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1267
diff changeset
   182
        Claus Gittinger
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   183
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   184
    [see also:]
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   185
        ExternalAddress ExternalBytes
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
   186
        ( how to write primitive code :html: programming/primitive.html )
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
"
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   188
!
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   189
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   190
examples
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   191
"
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   192
    see a sample demo c file in doc/coding/cModules;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   193
    compile and link (shared) it to an object module.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   194
    Load it into the system:
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   195
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   196
	handle := ObjectFileLoader loadDynamicObject:'demo1.o'.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   197
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   198
    get a C-function (an instance of ExternalFunction):
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   199
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   200
	f := handle getFunction:'function1'.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   201
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   202
    call it:
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   203
	
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   204
	f callWith:999
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   205
"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
!ExternalFunction class methodsFor:'initialization'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
initialize
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   211
    "create signals"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   212
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    InvalidCustomFunctionSignal isNil ifTrue:[
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   214
        InvalidCustomFunctionSignal := ExecutionErrorSignal newSignalMayProceed:true.
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   215
        InvalidCustomFunctionSignal nameClass:self message:#invalidCustomFunctionSignal.
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   216
        InvalidCustomFunctionSignal notifierString:'attempt to execute unknown custom function'.
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    ]
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   218
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   219
    "Modified: 22.4.1996 / 18:08:55 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
!ExternalFunction class methodsFor:'Signal constants'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
invalidCustomFunctionSignal
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "return the signal raised when a non existent custom function is
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
     called for."
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    ^ InvalidCustomFunctionSignal
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   231
!ExternalFunction class methodsFor:'calling custom functions'!
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
callCustomFunction:nr
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   234
    "call the custom function #nr without arguments"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   235
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    ^ self callCustomFunction:nr withArguments:#()
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
     ExternalFunction callCustomFunction:0
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
     ExternalFunction callCustomFunction:999 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    "
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   242
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   243
    "Modified: 22.4.1996 / 18:06:52 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
callCustomFunction:nr with:arg
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   247
    "call the custom function #nr with a single argument"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   248
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    ^ self callCustomFunction:nr withArguments:(Array with:arg)
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
     ExternalFunction callCustomFunction:1 with:'hello world'
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    "
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   254
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   255
    "Modified: 22.4.1996 / 18:07:03 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
callCustomFunction:nr with:arg1 with:arg2
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   259
    "call the custom function #nr with two arguments"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   260
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    ^ self callCustomFunction:nr withArguments:(Array with:arg1 with:arg2)
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
     ExternalFunction callCustomFunction:2 with:(Float pi) with:1.0
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    "
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   266
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   267
    "Modified: 22.4.1996 / 18:07:11 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
callCustomFunction:nr with:arg1 with:arg2 with:arg3
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   271
    "call the custom function #nr with three arguments"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   272
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    ^ self callCustomFunction:nr 
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   274
                withArguments:(Array with:arg1 with:arg2 with:arg3)
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   275
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   276
    "Modified: 22.4.1996 / 18:07:18 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
callCustomFunction:nr withArguments:argArray
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   280
    "call the custom function #nr with arguments from argArray"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   281
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
    |retVal called|
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
%{
917
57dd3973f35f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   285
#ifndef __stxNCustomFunctions__
856
d2c9f9ecedcf renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents: 848
diff changeset
   286
    extern int __stxNCustomFunctions__;
d2c9f9ecedcf renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents: 848
diff changeset
   287
    extern CUSTOMFUNCTION __stxCustomFunctions__[];
917
57dd3973f35f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   288
#endif
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    int (* func)();
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    called = false;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
    if (__isSmallInteger(nr) && __isArray(argArray)) {
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   293
        int nargs = __arraySize(argArray);
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   294
        int functionNr;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   296
        functionNr = __intVal(nr);
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   297
        if ((functionNr >= 0) && (functionNr < __stxNCustomFunctions__)) {
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   298
            /*
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   299
             * now, call the function; passing nargs and arg-vector
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   300
             */
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   301
            func = __stxCustomFunctions__[functionNr].func;
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   302
            if (func) {
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   303
                int ok;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   305
                retVal = self;
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   306
                ok = (*func)(nargs, &retVal, __ArrayInstPtr(argArray)->a_element);
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   307
                if (ok) {
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   308
                    RETURN (retVal);
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   309
                }
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   310
                called = true;
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   311
            }
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   312
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
    called ifTrue:[
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   316
        "
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   317
         the customFunction returned 0 (failure)
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   318
        "
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   319
        ^ self primitiveFailed
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
    ].
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
     an invalid customFunction-nr was given,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
    InvalidCustomFunctionSignal raise
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
     ExternalFunction callCustomFunction:2 withArguments:#(1.0 1.0)
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
     ExternalFunction callCustomFunction:999 withArguments:#(1.0 1.0)
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
callCustomFunctionNamed:name withArguments:argArray
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   335
    "call a custom function by name with arguments from argArray"
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   336
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
    |index|
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
    index := self indexOfCustomFunctionNamed:name.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    index notNil ifTrue:[
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   341
        ^ self callCustomFunction:index withArguments:argArray
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
    ].
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
     no such function exists
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
    InvalidCustomFunctionSignal raise
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
     ExternalFunction callCustomFunctionNamed:'demoFunction0'
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   350
                                withArguments:#()
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    "
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   352
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   353
    "Modified: 22.4.1996 / 18:08:09 / cg"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
indexOfCustomFunctionNamed:functionName
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   357
    "return the index of a named custom function"
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
%{  /* NOCONTEXT */
917
57dd3973f35f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   360
#ifndef __stxNCustomFunctions__
856
d2c9f9ecedcf renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents: 848
diff changeset
   361
    extern int __stxNCustomFunctions__;
d2c9f9ecedcf renamed customFunction-globals
Claus Gittinger <cg@exept.de>
parents: 848
diff changeset
   362
    extern CUSTOMFUNCTION __stxCustomFunctions__[];
917
57dd3973f35f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   363
#endif
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    if (__isString(functionName)) {
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   366
        char *nm;
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   367
        int i;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
1257
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   369
        nm = __stringVal(functionName);
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   370
        for (i=0; i < __stxNCustomFunctions__; i++) {
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   371
           if (strcmp(__stxCustomFunctions__[i].name, nm) == 0) {
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   372
                RETURN (__MKSMALLINT(i));
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   373
           }
f98014b76dd1 commentary
Claus Gittinger <cg@exept.de>
parents: 1184
diff changeset
   374
        }
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    ^ nil
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
     ExternalFunction indexOfCustomFunctionNamed:'demoFunction0'  
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
     ExternalFunction indexOfCustomFunctionNamed:'fooBar' 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
1184
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   385
!ExternalFunction class methodsFor:'queries'!
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   386
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   387
isBuiltInClass
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1257
diff changeset
   388
    "return true if this class is known by the run-time-system.
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1257
diff changeset
   389
     Here, true is returned for myself, false for subclasses."
1184
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   390
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   391
    ^ self == ExternalFunction
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   392
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   393
    "Created: 16.4.1996 / 11:24:50 / cg"
1267
e285a3a94d9e commentary
Claus Gittinger <cg@exept.de>
parents: 1257
diff changeset
   394
    "Modified: 23.4.1996 / 15:58:55 / cg"
1184
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   395
! !
e15a6702c812 subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   396
1542
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   397
!ExternalFunction methodsFor:'accessing'!
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   398
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   399
moduleHandle
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   400
    "return the functions moduleHandle (nil if not loaded dynamically)"
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   401
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   402
    ^ moduleHandle
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   403
!
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   404
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   405
name
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   406
    "return the functions name"
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   407
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   408
    ^ name
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   409
! !
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   410
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   411
!ExternalFunction methodsFor:'private loader access'!
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   412
1543
f687d50b978f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1542
diff changeset
   413
setName:aString moduleHandle:aHandle
f687d50b978f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1542
diff changeset
   414
    "set the name & moduleHandle.
1542
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   415
     This is a private interface for the objectFileLoader; not for public use."
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   416
1543
f687d50b978f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1542
diff changeset
   417
    name := aString.
1542
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   418
    moduleHandle := aHandle
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   419
! !
cdcf4ad7556f need name & moduleHandle for the ObjectFileLoader to be able to recreate
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   420
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
!ExternalFunction methodsFor:'function calling'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
call
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
    "call the underlying C function, passing no argument.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
     The return value is interpreted as an integer 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
     (and must be converted to an externalBytes object,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
      if it is a pointer to something).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
     DANGER alert: This is an unprotected low-level entry.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
     Not for normal application usage.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
%{
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
    INTFUNC func;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    int retVal;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   436
    func = (INTFUNC) __INST(code_);
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   437
    if (func) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   438
        retVal = (*func)();
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   439
        RETURN (__MKINT(retVal));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   440
    }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   441
%}.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   442
    self primitiveFailed
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
callWith:arg
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
    "call the underlying C function, passing a single argument.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
     The argument arg is converted to a corresponding C data type,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
     as defined in the convertST_to_C() function.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
     The return value is interpreted as an integer 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
     (and must be converted to an externalBytes object,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
      if it is a pointer to something).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
     DANGER alert: This is an unprotected low-level entry.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
     Not for normal application usage.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
%{
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
    INTFUNC func;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
    int retVal;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   460
    func = (INTFUNC) __INST(code_);
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   461
    if (func) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   462
        retVal = (*func)(convertST_to_C(arg));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   463
        RETURN (__MKINT(retVal));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   464
    }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   465
%}.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   466
    self primitiveFailed
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
callWithArguments:argArray
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
    "call the underlying C function, passing up to 10 arguments.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
     The arguments are converted to a corresponding C data type,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
     as defined in the convertST_to_C() function.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
     The return value is interpreted as an integer 
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
     (and must be converted to an externalBytes object,
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
      if it is a pointer to something).
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
     DANGER alert: This is an unprotected low-level entry.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
     Not for normal application usage.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
    "
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
%{
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
    INTFUNC func;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
#   define NUMARGS 10
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
    int args[NUMARGS];
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
    int retVal;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
    OBJ *ap;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   487
    func = (INTFUNC) __INST(code_);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   488
    if (func && __isArray(argArray)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   489
	int n = __arraySize(argArray);
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
	int i;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
	if (n <= 10) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 917
diff changeset
   493
	    ap = __ArrayInstPtr(argArray)->a_element;
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
	    for (i=0; i<NUMARGS; i++) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
		args[i] = convertST_to_C(*ap++);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
	    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
	}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
	switch (n) {
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
	    case 0:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
		retVal = (*func)();
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
	    case 1:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
		retVal = (*func)(args[0]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
	    case 2:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
		retVal = (*func)(args[0], args[1]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
	    case 3:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
		retVal = (*func)(args[0], args[1], args[2]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
	    case 4:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
		retVal = (*func)(args[0], args[1], args[2], args[3]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
	    case 5:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
		retVal = (*func)(args[0], args[1], args[2], args[3],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
				 args[4]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
	    case 6:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
		retVal = (*func)(args[0], args[1], args[2], args[3],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
				 args[4], args[5]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
	    case 7:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
		retVal = (*func)(args[0], args[1], args[2], args[3],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
				 args[4], args[5], args[6]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
	    case 8:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
		retVal = (*func)(args[0], args[1], args[2], args[3],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
				 args[4], args[5], args[6], args[7]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
	    case 9:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
		retVal = (*func)(args[0], args[1], args[2], args[3],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
				 args[4], args[5], args[6], args[7],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
				 args[8]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
	    case 10:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
		retVal = (*func)(args[0], args[1], args[2], args[3],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
				 args[4], args[5], args[6], args[7],
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
				 args[8], args[9]);
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
		break;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
	    default:
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
		goto err;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
	}
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
	RETURN (__MKINT(retVal));
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
    }
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
  err: ;
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
%}.
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
    self primitiveFailed
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   548
!
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   549
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   550
callWithDouble:aFloatArg returnsDouble:doubleFlag
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   551
    "call the underlying C function, passing a single double argument.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   552
     The returnsDouble flag specifies if the returnValue is a double; if false,
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   553
     an integer returnValue is assumed."
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   554
%{
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   555
    typedef double  (*DOUBLEFUNC)();
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   556
    INTFUNC func;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   557
    DOUBLEFUNC dfunc;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   558
    double arg, dretVal;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   559
    int retVal;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   560
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   561
    func = (INTFUNC) __INST(code_);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   562
    if (func) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   563
        if (__isFloat(aFloatArg)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   564
	    arg = __floatVal(aFloatArg);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   565
	} else if (__isShortFloat(aFloatArg)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   566
	    arg = (double)(__shortFloatVal(aFloatArg));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   567
	} else {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   568
	    arg = (double)(__signedLongIntVal(aFloatArg));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   569
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   570
	if (doubleFlag == true) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   571
	    dfunc = (DOUBLEFUNC)func;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   572
	    dretVal = (*dfunc)(arg);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   573
	    RETURN (__MKFLOAT(dretVal));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   574
	} else {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   575
	    retVal = (*func)(arg);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   576
	    RETURN (__MKINT(retVal));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   577
	}
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   578
    }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   579
%}.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   580
    self primitiveFailed
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   581
!
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   582
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   583
callWithDouble:aFloatArg1 withDouble:aFloatArg2 returnsDouble:doubleFlag
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   584
    "call the underlying C function, passing two double arguments.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   585
     The returnsDouble flag specifies if the returnValue is a double; if false,
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   586
     an integer returnValue is assumed."
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   587
%{
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   588
    typedef double  (*DOUBLEFUNC)();
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   589
    INTFUNC func;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   590
    DOUBLEFUNC dfunc;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   591
    double arg1, arg2, dretVal;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   592
    int retVal;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   593
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   594
    func = (INTFUNC) __INST(code_);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   595
    if (func) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   596
        if (__isFloat(aFloatArg1)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   597
            arg1 = __floatVal(aFloatArg1);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   598
        } else if (__isShortFloat(aFloatArg1)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   599
            arg1 = (double)(__shortFloatVal(aFloatArg1));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   600
        } else {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   601
            arg1 = (double)(__signedLongIntVal(aFloatArg1));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   602
        }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   603
        if (__isFloat(aFloatArg2)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   604
            arg2 = __floatVal(aFloatArg2);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   605
        } else if (__isShortFloat(aFloatArg2)) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   606
            arg2 = (double)(__shortFloatVal(aFloatArg2));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   607
        } else {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   608
            arg2 = (double)(__signedLongIntVal(aFloatArg2));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   609
        }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   610
        if (doubleFlag == true) {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   611
            dfunc = (DOUBLEFUNC)func;
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   612
            dretVal = (*dfunc)(arg1, arg2);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   613
            RETURN (__MKFLOAT(dretVal));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   614
        } else {
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   615
            retVal = (*func)(arg1, arg2);
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   616
            RETURN (__MKINT(retVal));
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   617
        }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   618
    }
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   619
%}.
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   620
    self primitiveFailed
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
!ExternalFunction class methodsFor:'documentation'!
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
version
1545
01e11b46ca65 more possible argument types
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
   626
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunction.st,v 1.12 1996-07-12 21:44:14 cg Exp $'
848
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
! !
76a83f34c26a moved ExtBytes & ExtFunc from libbasic2
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
ExternalFunction initialize!