00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #include "main.h"
00029
00030
00031
00032
00033
00034
00035 #if defined _WIN32 || defined __WIN32__
00036 cbmachine ww;
00037 #endif
00038 mmachine mm;
00039
00101 int sc_increment (mmachine m)
00102 {
00103 int mnumber;
00104
00105 MMechostr (MSKDEBUG, "sc_increment : entering\n");
00106
00107 mnumber = MTOI (MMget (m, 0));
00108 mnumber++;
00109 MMset (m, 0, ITOM (mnumber));
00110 return 0;
00111 }
00112
00113
00114
00127 int sc_hello (mmachine m)
00128 {
00129 int menter;
00130 char * enter = NULL;
00131 char * result = NULL;
00133 MMechostr (MSKDEBUG, "sc_hello : entering\n");
00134
00135 menter = MTOP (MMpull (m));
00136 enter = MMstartstr (m, menter);
00138 result = (char *) malloc (sizeof (char) * (strlen (enter) +7));
00139 sprintf (result, "%s %s", "Hello", enter);
00140
00141 Mpushstrbloc (m, result);
00142 free (result);
00143 return 0;
00144 }
00145
00146
00190 int sc_division (mmachine m)
00191 {
00192 int mtuple, mdividende, mdiviseur;
00193 int quotient, reste;
00194
00195 MMechostr (MSKDEBUG, "sc_division : entering\n");
00196
00197 mtuple = MTOI (MMpull (m));
00198 mdividende = MTOI (MMfetch (m, mtuple, 0));
00199 mdiviseur = MTOI (MMfetch (m, mtuple, 1));
00200
00201 if (mdiviseur == 0)
00202 return MMpush (m, NIL);
00203
00204 quotient = mdividende / mdiviseur;
00205 reste = mdividende % mdiviseur;
00206
00207 MMpush (m, ITOM (quotient));
00208 MMpush (m, ITOM (reste));
00209 MMpush (m, ITOM (2));
00210 return MBdeftab (m);
00211 }
00212
00306 int sc_calcul_list (mmachine m)
00307 {
00308 int mlist_enter, mnumber, mflag;
00309 int element_list, i, compteur = 0;
00310
00311 MMechostr (MSKDEBUG, "sc_calcul_list : entering\n");
00312
00313 mflag = MTOI (MMpull (m));
00314 mnumber = MTOI (MMpull (m));
00315 mlist_enter = MMpull (m)>>1;
00316
00317 while (mlist_enter != NIL)
00318 {
00319 element_list = MTOI (MMfetch (m, mlist_enter, 0));
00320 if (element_list != NIL)
00321 {
00322 MMpush (m, ITOM (element_list + (mnumber * mflag)));
00323 compteur++;
00324 }
00325 mlist_enter = MTOI (MMfetch(m, mlist_enter, 1));
00326 }
00327
00328 MMpush (m, NIL);
00329
00330 for (i = 0; i < compteur; i++)
00331 {
00332 MMpush (m, ITOM (2));
00333 MBdeftab (m);
00334 }
00335 return 0;
00336 }
00337
00338
00339
00340
00341
00342
00343
00353 char* example_name[EXAMPLE_PKG_NB] =
00354 {
00355
00356 "example_increment",
00357 "example_hello",
00358 "example_calcul",
00359 "example_list",
00360
00361
00362 "EXAMPLE_MOINS",
00363 "EXAMPLE_PLUS"
00364 };
00365
00379 int (*example_fun[EXAMPLE_PKG_NB]) (mmachine m) =
00380 {
00381 sc_increment,
00382 sc_hello,
00383 sc_division,
00384 sc_calcul_list,
00385
00386 (void*) ((-1)*2),
00387 (void*) (1*2)
00388 };
00389
00397 int example_narg[EXAMPLE_PKG_NB] =
00398 {
00399 1,
00400 1,
00401 1,
00402 3,
00403
00404 TYPVAR,
00405 TYPVAR
00406 };
00407
00413 char* example_type[EXAMPLE_PKG_NB] =
00414 {
00415 "fun [I] I",
00416 "fun [S] S",
00417 "fun [[I I]] [I I]",
00418 "fun [[I r1] I I] [I r1]",
00419
00420 "I",
00421 "I"
00422 };
00423
00424
00471 int SCOLinitEXAMPLEclass (mmachine m)
00472 {
00473 int k = 0;
00474
00475 MMechostr (MSKDEBUG, "SCOLinitEXAMPLEclass library : loading\n");
00476
00477 k = PKhardpak (m, "EXAMPLEengine", EXAMPLE_PKG_NB, example_name, example_fun, example_narg, example_type);
00478 return k;
00479 }
00480
00481
00482
00483
00484
00507 #if defined _WIN32 || defined __WIN32__
00508 __declspec (dllexport) int SCOLloadEXAMPLE (mmachine m, cbmachine w)
00509 {
00510 int k = 0;
00511
00512
00513
00514 ww = w;
00515 mm = m;
00516
00517 MMechostr (0, "EXAMPLE library : loading\n");
00518
00519 if ((k = SCOLinitEXAMPLEclass (m))) return k;
00520
00521 MMechostr (0, "\nEXAMPLE library loaded !\n");
00522 return k;
00523 }
00524
00525
00526 #elif defined linux || defined __linux
00527 int SCOLloadEXAMPLE (mmachine m)
00528 {
00529 int k = 0;
00530
00531
00532
00533 mm = m;
00534
00535 MMechostr (0, "EXAMPLE library : loading\n");
00536
00537 if ((k = SCOLinitEXAMPLEclass (m))) return k;
00538
00539 MMechostr (0, "\nEXAMPLE library loaded !\n");
00540 return k;
00541 }
00542
00543
00544 #else
00545 #error no platform supported
00546 #endif
00547
00548
00549
00560 #if defined linux || defined __linux
00561 int SCOLfreeEXAMPLE ()
00562
00563 #elif defined _WIN32 || defined __WIN32__
00564 __declspec (dllexport) int SCOLfreeEXAMPLE ()
00565
00566 #else
00567 #error no platform supported
00568 #endif
00569
00570 {
00571 MMechostr(MSKDEBUG, "\nEXAMPLE library release !\n");
00572 return 0;
00573 }