Initial commit, Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
commit
a4c804b49e
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,158 @@
|
|||
# Microsoft Developer Studio Project File - Name="CBot" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=CBot - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CBot.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CBot.mak" CFG="CBot - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "CBot - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "CBot - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "CBot - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD BASE RSC /l 0x40c /d "NDEBUG"
|
||||
# ADD RSC /l 0x40c /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "CBot - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD BASE RSC /l 0x40c /d "_DEBUG"
|
||||
# ADD RSC /l 0x40c /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
|
||||
# Begin Custom Build
|
||||
InputPath=.\Debug\CBot.dll
|
||||
SOURCE=$(InputPath)
|
||||
|
||||
".\TestCBot\CBot.dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
copy .\Debug\CBot.dll .\TestCBot\CBot.dll
|
||||
copy .\Debug\CBot.dll "C:\Program Files\Colobot\CBot.dll"
|
||||
_Copy.bat
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "CBot - Win32 Release"
|
||||
# Name "CBot - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBot.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBot.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBot.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotClass.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotDll.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotFunction.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotIf.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotProgram.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotStack.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotString.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotToken.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotToken.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotTwoOpExpr.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotVar.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotWhile.cpp
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
|
@ -0,0 +1,44 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 5.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "CBot"=".\CBot.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "TestCBot"=".\TestCBot\TestCBot.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name CBot
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,61 @@
|
|||
--------------------Configuration: CBot - Win32 Release--------------------
|
||||
Begining build with project "D:\Robot\projet1\CBot\CBot.dsp", at root.
|
||||
Active configuration is Win32 (x86) Dynamic-Link Library (based on Win32 (x86) Dynamic-Link Library)
|
||||
|
||||
Project's tools are:
|
||||
"32-bit C/C++ Compiler for 80x86" with flags "/nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR"Release/" /Fp"Release/CBot.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c "
|
||||
"OLE Type Library Maker" with flags "/nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 "
|
||||
"Win32 Resource Compiler" with flags "/l 0x40c /fo"Release/CBot.res" /d "NDEBUG" "
|
||||
"Browser Database Maker" with flags "/nologo /o"Release/CBot.bsc" "
|
||||
"COFF Linker for 80x86" with flags "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /incremental:no /pdb:"Release/CBot.pdb" /machine:I386 /out:"Release/CBot.dll" /implib:"Release/CBot.lib" "
|
||||
"Custom Build" with flags ""
|
||||
"<Component 0xa>" with flags ""
|
||||
|
||||
Creating command line "rc.exe /l 0x40c /fo"Release/CBot.res" /d "NDEBUG" "D:\Robot\projet1\CBot\CBot.rc""
|
||||
Creating temp file "C:\DOCUME~1\ROUXDA~1\LOCALS~1\Temp\RSP9.tmp" with contents </nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR"Release/" /Fp"Release/CBot.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
|
||||
"D:\Robot\projet1\CBot\CBot.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotClass.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotFunction.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotIf.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotProgram.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotStack.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotString.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotToken.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotTwoOpExpr.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotVar.cpp"
|
||||
"D:\Robot\projet1\CBot\CBotWhile.cpp"
|
||||
>
|
||||
Creating command line "cl.exe @C:\DOCUME~1\ROUXDA~1\LOCALS~1\Temp\RSP9.tmp"
|
||||
Creating temp file "C:\DOCUME~1\ROUXDA~1\LOCALS~1\Temp\RSPA.tmp" with contents <kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /incremental:no /pdb:"Release/CBot.pdb" /machine:I386 /out:"Release/CBot.dll" /implib:"Release/CBot.lib"
|
||||
.\Release\CBot.obj
|
||||
.\Release\CBotClass.obj
|
||||
.\Release\CBotFunction.obj
|
||||
.\Release\CBotIf.obj
|
||||
.\Release\CBotProgram.obj
|
||||
.\Release\CBotStack.obj
|
||||
.\Release\CBotString.obj
|
||||
.\Release\CBotToken.obj
|
||||
.\Release\CBotTwoOpExpr.obj
|
||||
.\Release\CBotVar.obj
|
||||
.\Release\CBotWhile.obj
|
||||
.\Release\CBot.res>
|
||||
Creating command line "link.exe @C:\DOCUME~1\ROUXDA~1\LOCALS~1\Temp\RSPA.tmp"
|
||||
Compiling resources...
|
||||
Compiling...
|
||||
CBot.cpp
|
||||
CBotClass.cpp
|
||||
CBotFunction.cpp
|
||||
CBotIf.cpp
|
||||
CBotProgram.cpp
|
||||
CBotStack.cpp
|
||||
CBotString.cpp
|
||||
CBotToken.cpp
|
||||
CBotTwoOpExpr.cpp
|
||||
CBotVar.cpp
|
||||
CBotWhile.cpp
|
||||
Linking...
|
||||
Creating library Release/CBot.lib and object Release/CBot.exp
|
||||
|
||||
|
||||
|
||||
CBot.dll - 0 error(s), 0 warning(s)
|
|
@ -0,0 +1,279 @@
|
|||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// French (France) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_IF "if"
|
||||
ID_ELSE "else"
|
||||
ID_WHILE "while"
|
||||
ID_DO "do"
|
||||
ID_FOR "for"
|
||||
ID_BREAK "break"
|
||||
ID_CONTINUE "continue"
|
||||
ID_SWITCH "switch"
|
||||
ID_CASE "case"
|
||||
ID_DEFAULT "default"
|
||||
ID_TRY "try"
|
||||
ID_THROW "throw"
|
||||
ID_CATCH "catch"
|
||||
ID_FINALLY "finally"
|
||||
ID_TXT_AND "and"
|
||||
ID_TXT_OR "or"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_DEBUGDD "STARTDEBUGDD"
|
||||
ID_INT "int"
|
||||
ID_FLOAT "float"
|
||||
ID_BOOLEAN "boolean"
|
||||
ID_STRING "string"
|
||||
ID_VOID "void"
|
||||
ID_BOOL "bool"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_TXT_NOT "not"
|
||||
ID_RETURN "return"
|
||||
ID_CLASS "class"
|
||||
ID_EXTENDS "extends"
|
||||
ID_SYNCHO "synchronized"
|
||||
ID_NEW "new"
|
||||
ID_PUBLIC "public"
|
||||
ID_EXTERN "extern"
|
||||
ID_FINAL "final"
|
||||
ID_STATIC "static"
|
||||
ID_PROTECTED "protected"
|
||||
ID_PRIVATE "private"
|
||||
ID_REPEAT "repeat"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_OPENPAR "Il manque une parenthèse ouvrante."
|
||||
TX_CLOSEPAR "Il manque une parenthèse fermante."
|
||||
TX_NOTBOOL "L'expression doit être un boolean."
|
||||
TX_UNDEFVAR "Variable non déclarée."
|
||||
TX_BADLEFT "Assignation impossible."
|
||||
TX_ENDOF "Terminateur point-virgule non trouvé."
|
||||
TX_OUTCASE "Instruction ""case"" hors d'un bloc ""switch""."
|
||||
TX_NOTERM "Instructions après la fin."
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_CLOSEBLK "Il manque la fin du bloc."
|
||||
TX_ELSEWITHOUTIF "Instruction ""else"" sans ""if"" correspondant."
|
||||
TX_OPENBLK "Début d'un bloc attendu."
|
||||
TX_BADTYPE "Mauvais type de résultat pour l'assignation."
|
||||
TX_REDEFVAR "Redéfinition d'une variable."
|
||||
TX_BAD2TYPE "Les deux opérandes ne sont pas de types compatibles."
|
||||
TX_UNDEFCALL "Routine inconnue."
|
||||
TX_MISDOTS "Séparateur "" : "" attendu."
|
||||
TX_WHILE "Manque le mot ""while""."
|
||||
TX_BREAK "Instruction ""break"" en dehors d'une boucle."
|
||||
TX_LABEL "Un label ne peut se placer que devant un ""for"", un ""while"" ou un ""do""."
|
||||
TX_NOLABEL "Cette étiquette n'existe pas"
|
||||
TX_NOCASE "Manque une instruction ""case""."
|
||||
TX_BADNUM "Un nombre est attendu."
|
||||
TX_VOID "Paramètre void."
|
||||
TX_NOTYP "Déclaration de type attendu."
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_DIVZERO "Division par zéro."
|
||||
TX_NOTINIT "Variable non initialisée."
|
||||
TX_BADTHROW "Valeur négative refusée pour ""throw""."
|
||||
TX_NORETVAL "La fonction n'a pas retourné de résultat"
|
||||
TX_NORUN "Pas de fonction en exécution"
|
||||
TX_NOCALL "Appel d'une fonction inexistante"
|
||||
TX_NOCLASS "Cette classe n'existe pas"
|
||||
TX_NULLPT "Pointeur nul."
|
||||
TX_OPNAN "Opération sur un ""nan"""
|
||||
TX_OUTARRAY "Accès hors du tableau"
|
||||
TX_STACKOVER "Dépassement de la pile"
|
||||
TX_DELETEDPT "Pointeur à un objet détruit"
|
||||
TX_FILEOPEN "Ouverture du fichier impossible"
|
||||
TX_NOTOPEN "Fichier pas ouvert"
|
||||
TX_ERRREAD "Erreur de lecture"
|
||||
TX_ERRWRITE "Erreur d'écriture"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_NOVAR "Nom d'une variable attendu."
|
||||
TX_NOFONC "Nom de la fonction attendu."
|
||||
TX_OVERPARAM "Trop de paramètres."
|
||||
TX_REDEF "Cette fonction existe déjà."
|
||||
TX_LOWPARAM "Pas assez de paramètres."
|
||||
TX_BADPARAM "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramètre(s)."
|
||||
TX_NUMPARAM "Aucune fonction de ce nom n'accepte ce nombre de paramètres."
|
||||
TX_NOITEM "Cet élément n'existe pas dans cette classe."
|
||||
TX_DOT "L'objet n'est pas une instance d'une classe."
|
||||
TX_NOCONST "Il n'y a pas de constructeur approprié."
|
||||
TX_REDEFCLASS "Cette classe existe déjà."
|
||||
TX_CLBRK """ ] "" attendu."
|
||||
TX_RESERVED "Ce mot est réservé."
|
||||
TX_BADNEW "Mauvais argument pour ""new""."
|
||||
TX_OPBRK """ [ "" attendu."
|
||||
TX_BADSTRING "Une chaîne de caractère est attendue."
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_BADINDEX "Mauvais type d'index"
|
||||
TX_PRIVATE "Membre privé de la classe"
|
||||
TX_NOPUBLIC """public"" manque"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_OPENPAR "("
|
||||
ID_CLOSEPAR ")"
|
||||
ID_OPBLK "{"
|
||||
ID_CLBLK "}"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_SEP ";"
|
||||
ID_COMMA ","
|
||||
ID_DOTS ":"
|
||||
ID_DOT "."
|
||||
ID_OPBRK "["
|
||||
ID_CLBRK "]"
|
||||
ID_DBLDOTS "::"
|
||||
ID_LOGIC "?"
|
||||
ID_ADD "+"
|
||||
ID_SUB "-"
|
||||
ID_MUL "*"
|
||||
ID_DIV "/"
|
||||
ID_ASS "="
|
||||
ID_ASSADD "+="
|
||||
ID_ASSSUB "-="
|
||||
ID_ASSMUL "*="
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_TRUE "true"
|
||||
ID_FALSE "false"
|
||||
ID_NULL "null"
|
||||
ID_NAN "nan"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_ASSDIV "/="
|
||||
ID_ASSOR "|="
|
||||
ID_ASSAND "&="
|
||||
ID_ASSXOR "^="
|
||||
ID_ASSSL "<<="
|
||||
ID_ASSSR ">>>="
|
||||
ID_ASSASR ">>="
|
||||
ID_SL "<<"
|
||||
ID_SR ">>>"
|
||||
ID_ASR ">>"
|
||||
ID_INC "++"
|
||||
ID_DEC "--"
|
||||
ID_LO "<"
|
||||
ID_HI ">"
|
||||
ID_LS "<="
|
||||
ID_HS ">="
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_EQ "=="
|
||||
ID_NE "!="
|
||||
ID_AND "&"
|
||||
ID_XOR "^"
|
||||
ID_OR "|"
|
||||
ID_LOG_AND "&&"
|
||||
ID_LOG_OR "||"
|
||||
ID_LOG_NOT "!"
|
||||
ID_NOT "~"
|
||||
ID_MODULO "%"
|
||||
ID_POWER "**"
|
||||
ID_ASSMODULO "%="
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_UNDEF "undefined"
|
||||
TX_NAN "not a number"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_SUPER "super"
|
||||
END
|
||||
|
||||
#endif // French (France) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 + Opérande2
|
||||
// Opérande1 - Opérande2
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotAddExpr::CBotAddExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
||||
name = "CBotAddExpr"; // debug
|
||||
}
|
||||
|
||||
CBotAddExpr::~CBotAddExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
|
||||
// compile une instruction de type A + B
|
||||
|
||||
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
||||
{
|
||||
CBotStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
||||
|
||||
// cherche des instructions qui peuvent convenir à gauche de l'opération + ou -
|
||||
|
||||
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B à gauche
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
||||
|
||||
// est-ce qu'on a le token + ou - ensuite ?
|
||||
|
||||
if ( p->GetType() == ID_ADD ||
|
||||
p->GetType() == ID_SUB) // plus ou moins
|
||||
{
|
||||
CBotAddExpr* inst = new CBotAddExpr(); // élément pour opération
|
||||
inst->SetToken(p); // mémorise l'opération
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStack->GetType(); // de quel type le premier opérande ?
|
||||
|
||||
p = p->Next(); // saute le token de l'opération
|
||||
|
||||
// cherche des instructions qui peuvent convenir à droite
|
||||
|
||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) à droite
|
||||
{
|
||||
// il y a un second opérande acceptable
|
||||
|
||||
type2 = pStack->GetType(); // de quel type le résultat ?
|
||||
|
||||
if ( type1 == type2 ) // les résultats sont-ils compatibles
|
||||
{
|
||||
// si ok, enregistre l'opérande dans l'objet
|
||||
inst->m_leftop = left;
|
||||
// et rend l'object à qui l'a demandé
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// en cas d'erreur, libère les éléments
|
||||
delete left;
|
||||
delete inst;
|
||||
// et transmet l'erreur qui se trouve sur la pile
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// si on n'a pas affaire à une opération + ou -
|
||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
||||
// à la place de l'objet "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// fait l'opération d'addition ou de soustraction
|
||||
|
||||
BOOL CBotAddExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
// if ( pSk1 == EOX ) return TRUE;
|
||||
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
|
||||
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
|
||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
// passe à l'étape suivante
|
||||
pStk1->SetState(1); // prêt pour la suite
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
// qui se trouve sur la pile, justement.
|
||||
|
||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
|
||||
// 2e état, évalue l'opérande de droite
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
|
||||
int type1 = pStk1->GetType(); // de quels types les résultats ?
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
// crée une variable temporaire pour y mettre le résultat
|
||||
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
||||
|
||||
// fait l'opération selon la demande
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_ADD:
|
||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
|
||||
break;
|
||||
case ID_SUB:
|
||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
|
||||
break;
|
||||
}
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
|
||||
pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,867 @@
|
|||
///////////////////////////////////////////////////////////////////////
|
||||
// Gestion des variables de type classe
|
||||
//
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
|
||||
CBotClass* CBotClass::m_ExClass = NULL;
|
||||
|
||||
CBotClass::CBotClass(const char* name, CBotClass* pPapa, BOOL bIntrinsic)
|
||||
{
|
||||
m_pParent = pPapa;
|
||||
m_name = name;
|
||||
m_pVar = NULL;
|
||||
m_next = NULL;
|
||||
m_pCalls = NULL;
|
||||
m_pMethod = NULL;
|
||||
m_rMaj = NULL;
|
||||
m_IsDef = TRUE;
|
||||
m_bIntrinsic= bIntrinsic;
|
||||
m_cptLock = 0;
|
||||
m_cptOne = 0;
|
||||
m_nbVar = m_pParent == NULL ? 0 : m_pParent->m_nbVar;
|
||||
|
||||
for ( int j= 0; j< 5 ; j++ )
|
||||
{
|
||||
m_ProgInLock[j] = NULL;
|
||||
}
|
||||
|
||||
|
||||
// se place tout seul dans la liste
|
||||
if (m_ExClass) m_ExClass->m_ExPrev = this;
|
||||
m_ExNext = m_ExClass;
|
||||
m_ExPrev = NULL;
|
||||
m_ExClass = this;
|
||||
|
||||
}
|
||||
|
||||
CBotClass::~CBotClass()
|
||||
{
|
||||
// retire la classe de la liste
|
||||
if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext;
|
||||
else m_ExClass = m_ExNext;
|
||||
|
||||
if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev;
|
||||
m_ExPrev = NULL;
|
||||
m_ExNext = NULL;
|
||||
|
||||
delete m_pVar;
|
||||
delete m_pCalls;
|
||||
delete m_pMethod;
|
||||
|
||||
delete m_next; // libère toutes celle de ce niveau
|
||||
}
|
||||
|
||||
|
||||
void CBotClass::Free()
|
||||
{
|
||||
while ( m_ExClass != NULL )
|
||||
{
|
||||
delete m_ExClass;
|
||||
}
|
||||
}
|
||||
|
||||
void CBotClass::Purge()
|
||||
{
|
||||
if ( this == NULL ) return;
|
||||
|
||||
delete m_pVar;
|
||||
m_pVar = NULL;
|
||||
delete m_pCalls;
|
||||
m_pCalls = NULL;
|
||||
delete m_pMethod;
|
||||
m_pMethod = NULL;
|
||||
m_IsDef = FALSE;
|
||||
|
||||
m_nbVar = m_pParent == NULL ? 0 : m_pParent->m_nbVar;
|
||||
|
||||
m_next->Purge();
|
||||
m_next = NULL; // n'appartient plus à cette chaîne
|
||||
}
|
||||
|
||||
BOOL CBotClass::Lock(CBotProgram* p)
|
||||
{
|
||||
int i = m_cptLock++;
|
||||
|
||||
if ( i == 0 )
|
||||
{
|
||||
m_cptOne = 1;
|
||||
m_ProgInLock[0] = p;
|
||||
return TRUE;
|
||||
}
|
||||
if ( p == m_ProgInLock[0] )
|
||||
{
|
||||
m_cptOne++;
|
||||
m_cptLock--; // a déjà été compté
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for ( int j = 1 ; j <= i ; j++)
|
||||
{
|
||||
if ( p == m_ProgInLock[j] )
|
||||
{
|
||||
m_cptLock--;
|
||||
return FALSE; // déjà en attente
|
||||
}
|
||||
}
|
||||
|
||||
if ( i < 5 ) // maxi 5 en attente
|
||||
{
|
||||
m_ProgInLock[i] = p; // se place dans la queue
|
||||
}
|
||||
else
|
||||
m_cptLock--;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CBotClass::Unlock()
|
||||
{
|
||||
if ( --m_cptOne > 0 ) return ;
|
||||
|
||||
int i = --m_cptLock;
|
||||
if ( i<0 )
|
||||
{
|
||||
m_cptLock = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int j= 0; j< i ; j++ )
|
||||
{
|
||||
m_ProgInLock[j] = m_ProgInLock[j+1];
|
||||
}
|
||||
m_ProgInLock[i] = 0;
|
||||
}
|
||||
|
||||
void CBotClass::FreeLock(CBotProgram* p)
|
||||
{
|
||||
CBotClass* pClass = m_ExClass;
|
||||
|
||||
while ( pClass != NULL )
|
||||
{
|
||||
if ( p == pClass->m_ProgInLock[0] )
|
||||
{
|
||||
pClass->m_cptLock -= pClass->m_cptOne;
|
||||
pClass->m_cptOne = 0;
|
||||
}
|
||||
|
||||
for ( int j = 1; j < 5 ; j++ )
|
||||
if ( p == pClass->m_ProgInLock[j] )
|
||||
pClass->m_cptLock--;
|
||||
|
||||
pClass = pClass->m_ExNext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOL CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate)
|
||||
{
|
||||
CBotToken token(name, CBotString());
|
||||
CBotClass* pClass = type.GivClass();
|
||||
|
||||
CBotVar* pVar = CBotVar::Create( name, type );
|
||||
/// pVar->SetUniqNum(CBotVar::NextUniqNum());
|
||||
pVar->SetPrivate( mPrivate );
|
||||
|
||||
if ( pClass != NULL )
|
||||
{
|
||||
// pVar->SetClass(pClass);
|
||||
if ( type.Eq(CBotTypClass) )
|
||||
{
|
||||
// ajoute une instruction new pour initialiser l'object
|
||||
pVar->m_InitExpr = new CBotNew() ;
|
||||
CBotToken nom( pClass->GivName() );
|
||||
pVar->m_InitExpr->SetToken(&nom);
|
||||
}
|
||||
}
|
||||
return AddItem( pVar );
|
||||
}
|
||||
|
||||
|
||||
BOOL CBotClass::AddItem(CBotVar* pVar)
|
||||
{
|
||||
pVar->SetUniqNum(++m_nbVar);
|
||||
|
||||
if ( m_pVar == NULL ) m_pVar = pVar;
|
||||
else m_pVar->AddNext(pVar);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CBotClass::AddNext(CBotClass* pClass)
|
||||
{
|
||||
CBotClass* p = this;
|
||||
while (p->m_next != NULL) p = p->m_next;
|
||||
|
||||
p->m_next = pClass;
|
||||
}
|
||||
|
||||
CBotString CBotClass::GivName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
CBotClass* CBotClass::GivParent()
|
||||
{
|
||||
if ( this == NULL ) return NULL;
|
||||
return m_pParent;
|
||||
}
|
||||
|
||||
BOOL CBotClass::IsChildOf(CBotClass* pClass)
|
||||
{
|
||||
CBotClass* p = this;
|
||||
while ( p != NULL )
|
||||
{
|
||||
if ( p == pClass ) return TRUE;
|
||||
p = p->m_pParent;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
CBotVar* CBotClass::GivVar()
|
||||
{
|
||||
return m_pVar;
|
||||
}
|
||||
|
||||
CBotVar* CBotClass::GivItem(const char* name)
|
||||
{
|
||||
CBotVar* p = m_pVar;
|
||||
|
||||
while ( p != NULL )
|
||||
{
|
||||
if ( p->GivName() == name ) return p;
|
||||
p = p->GivNext();
|
||||
}
|
||||
if ( m_pParent != NULL ) return m_pParent->GivItem(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBotVar* CBotClass::GivItemRef(int nIdent)
|
||||
{
|
||||
CBotVar* p = m_pVar;
|
||||
|
||||
while ( p != NULL )
|
||||
{
|
||||
if ( p->GivUniqNum() == nIdent ) return p;
|
||||
p = p->GivNext();
|
||||
}
|
||||
if ( m_pParent != NULL ) return m_pParent->GivItemRef(nIdent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL CBotClass::IsIntrinsic()
|
||||
{
|
||||
return m_bIntrinsic;
|
||||
}
|
||||
|
||||
CBotClass* CBotClass::Find(CBotToken* &pToken)
|
||||
{
|
||||
return Find(pToken->GivString());
|
||||
}
|
||||
|
||||
CBotClass* CBotClass::Find(const char* name)
|
||||
{
|
||||
CBotClass* p = m_ExClass;
|
||||
|
||||
while ( p != NULL )
|
||||
{
|
||||
if ( p->GivName() == name ) return p;
|
||||
p = p->m_ExNext;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL CBotClass::AddFunction(const char* name,
|
||||
BOOL rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
|
||||
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
|
||||
{
|
||||
// mémorise les pointeurs aux deux fonctions
|
||||
CBotCallMethode* p = m_pCalls;
|
||||
CBotCallMethode* pp = NULL;
|
||||
|
||||
while ( p != NULL )
|
||||
{
|
||||
if ( name == p->GivName() )
|
||||
{
|
||||
if ( pp == NULL ) m_pCalls = p->m_next;
|
||||
else pp->m_next = p->m_next;
|
||||
delete p;
|
||||
break;
|
||||
}
|
||||
pp = p;
|
||||
p = p->m_next;
|
||||
}
|
||||
|
||||
p = new CBotCallMethode(name, rExec, rCompile);
|
||||
|
||||
if (m_pCalls == NULL) m_pCalls = p;
|
||||
else m_pCalls->AddNext(p); // ajoute à la liste
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) )
|
||||
{
|
||||
m_rMaj = rMaj;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compile une méthode associée à une instance de classe
|
||||
// la méthode peut être déclarée par AddFunction ou par l'utilisateur
|
||||
|
||||
CBotTypResult CBotClass::CompileMethode(const char* name,
|
||||
CBotVar* pThis, CBotVar** ppParams,
|
||||
CBotCStack* pStack, long& nIdent)
|
||||
{
|
||||
nIdent = 0; // oublie le précédent s'il y a lieu
|
||||
|
||||
// recherche dans les méthodes déclarées par AddFunction
|
||||
|
||||
CBotTypResult r = m_pCalls->CompileCall(name, pThis, ppParams, pStack, nIdent);
|
||||
if ( r.GivType() >= 0) return r;
|
||||
|
||||
// recherche dans les méthodes déclarées par l'utilisateur
|
||||
|
||||
r = m_pMethod->CompileCall(name, ppParams, nIdent);
|
||||
if ( r.Eq(TX_UNDEFCALL) && m_pParent != NULL )
|
||||
return m_pParent->m_pMethod->CompileCall(name, ppParams, nIdent);
|
||||
return r;
|
||||
}
|
||||
|
||||
// exécute une méthode
|
||||
|
||||
BOOL CBotClass::ExecuteMethode(long& nIdent, const char* name,
|
||||
CBotVar* pThis, CBotVar** ppParams,
|
||||
CBotVar* &pResult, CBotStack* &pStack,
|
||||
CBotToken* pToken)
|
||||
{
|
||||
int ret = m_pCalls->DoCall(nIdent, name, pThis, ppParams, pResult, pStack, pToken);
|
||||
if (ret>=0) return ret;
|
||||
|
||||
ret = m_pMethod->DoCall(nIdent, name, pThis, ppParams, pStack, pToken, this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// rétabli la pile d'exécution
|
||||
|
||||
void CBotClass::RestoreMethode(long& nIdent, const char* name, CBotVar* pThis,
|
||||
CBotVar** ppParams, CBotStack* &pStack)
|
||||
{
|
||||
m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOL CBotClass::SaveStaticState(FILE* pf)
|
||||
{
|
||||
if (!WriteWord( pf, CBOTVERSION*2)) return FALSE;
|
||||
|
||||
// sauve l'état des variables statiques dans les classes
|
||||
CBotClass* p = m_ExClass;
|
||||
|
||||
while ( p != NULL )
|
||||
{
|
||||
if (!WriteWord( pf, 1)) return FALSE;
|
||||
// enregistre le nom de la classe
|
||||
if (!WriteString( pf, p->GivName() )) return FALSE;
|
||||
|
||||
CBotVar* pv = p->GivVar();
|
||||
while( pv != NULL )
|
||||
{
|
||||
if ( pv->IsStatic() )
|
||||
{
|
||||
if (!WriteWord( pf, 1)) return FALSE;
|
||||
if (!WriteString( pf, pv->GivName() )) return FALSE;
|
||||
|
||||
if ( !pv->Save0State(pf)) return FALSE; // entête commune
|
||||
if ( !pv->Save1State(pf) ) return FALSE; // sauve selon la classe fille
|
||||
if ( !WriteWord( pf, 0)) return FALSE;
|
||||
}
|
||||
pv = pv->GivNext();
|
||||
}
|
||||
|
||||
if (!WriteWord( pf, 0)) return FALSE;
|
||||
p = p->m_ExNext;
|
||||
}
|
||||
|
||||
if (!WriteWord( pf, 0)) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CBotClass::RestoreStaticState(FILE* pf)
|
||||
{
|
||||
CBotString ClassName, VarName;
|
||||
CBotClass* pClass;
|
||||
WORD w;
|
||||
|
||||
if (!ReadWord( pf, w )) return FALSE;
|
||||
if ( w != CBOTVERSION*2 ) return FALSE;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!ReadWord( pf, w )) return FALSE;
|
||||
if ( w == 0 ) return TRUE;
|
||||
|
||||
if (!ReadString( pf, ClassName )) return FALSE;
|
||||
pClass = Find(ClassName);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!ReadWord( pf, w )) return FALSE;
|
||||
if ( w == 0 ) break;
|
||||
|
||||
CBotVar* pVar = NULL;
|
||||
CBotVar* pv = NULL;
|
||||
|
||||
if (!ReadString( pf, VarName )) return FALSE;
|
||||
if ( pClass != NULL ) pVar = pClass->GivItem(VarName);
|
||||
|
||||
if (!CBotVar::RestoreState(pf, pv)) return FALSE; // la variable temp
|
||||
|
||||
if ( pVar != NULL ) pVar->Copy(pv);
|
||||
delete pv;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
CBotClassInst::CBotClassInst()
|
||||
{
|
||||
m_next = NULL;
|
||||
m_var = NULL;
|
||||
m_Parameters = NULL;
|
||||
m_expr = NULL;
|
||||
m_hasParams = FALSE;
|
||||
m_nMethodeIdent = 0;
|
||||
name = "CBotClassInst";
|
||||
}
|
||||
|
||||
CBotClassInst::~CBotClassInst()
|
||||
{
|
||||
delete m_var;
|
||||
// delete m_next; // fait par le destructeur de la classe de base ~CBotInstr()
|
||||
}
|
||||
|
||||
// définition de pointeur(s) à un objet
|
||||
// du style
|
||||
// CPoint A, B ;
|
||||
|
||||
CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass)
|
||||
{
|
||||
// cherche la classe correspondante
|
||||
if ( pClass == NULL )
|
||||
{
|
||||
pStack->SetStartError(p->GivStart());
|
||||
pClass = CBotClass::Find(p);
|
||||
if ( pClass == NULL )
|
||||
{
|
||||
// pas trouvé ? c'est bizare
|
||||
pStack->SetError(TX_NOCLASS, p);
|
||||
return NULL;
|
||||
}
|
||||
p = p->GivNext();
|
||||
}
|
||||
|
||||
BOOL bIntrinsic = pClass->IsIntrinsic();
|
||||
CBotTypResult
|
||||
type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer,
|
||||
pClass );
|
||||
CBotClassInst* inst = (CBotClassInst*)CompileArray(p, pStack, type);
|
||||
if ( inst != NULL || !pStack->IsOk() ) return inst;
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
inst = new CBotClassInst();
|
||||
|
||||
inst->SetToken(&pClass->GivName(), p->GivStart(), p->GivEnd());
|
||||
CBotToken* vartoken = p;
|
||||
|
||||
if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
|
||||
{
|
||||
((CBotLeftExprVar*)inst->m_var)->m_typevar = type;
|
||||
if (pStk->CheckVarLocal(vartoken)) // redéfinition de la variable
|
||||
{
|
||||
pStk->SetStartError(vartoken->GivStart());
|
||||
pStk->SetError(TX_REDEFVAR, vartoken->GivEnd());
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (IsOfType(p, ID_OPBRK)) // avec des indices ?
|
||||
{
|
||||
delete inst; // n'est pas de type CBotInt
|
||||
p = vartoken; // revient sur le nom de la variable
|
||||
|
||||
// compile une déclaration de tableau
|
||||
|
||||
inst = (CBotClassInst*)CBotInstArray::Compile( p, pStk, type );
|
||||
|
||||
if (!pStk->IsOk() )
|
||||
{
|
||||
pStk->SetError(TX_CLBRK, p->GivStart());
|
||||
goto error;
|
||||
}
|
||||
goto suite; // pas d'assignation, variable déjà créée
|
||||
}
|
||||
|
||||
|
||||
CBotVar* var;
|
||||
var = CBotVar::Create(vartoken->GivString(), type); // crée l'instance
|
||||
// var->SetClass(pClass);
|
||||
var->SetUniqNum(
|
||||
((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
|
||||
// lui attribut un numéro unique
|
||||
pStack->AddVar(var); // la place sur la pile
|
||||
|
||||
// regarde s'il y a des paramètres
|
||||
inst->m_hasParams = (p->GivType() == ID_OPENPAR);
|
||||
|
||||
CBotVar* ppVars[1000];
|
||||
inst->m_Parameters = CompileParams(p, pStk, ppVars);
|
||||
if ( !pStk->IsOk() ) goto error;
|
||||
|
||||
// s'il y a des paramètres, fait l'équivalent de l'instruction new
|
||||
// CPoint A ( 0, 0 ) est équivalent à
|
||||
// CPoint A = new CPoint( 0, 0 )
|
||||
|
||||
// if ( NULL != inst->m_Parameters )
|
||||
if ( inst->m_hasParams )
|
||||
{
|
||||
// le constructeur existe-il ?
|
||||
// CBotString noname;
|
||||
CBotTypResult r = pClass->CompileMethode(pClass->GivName(), var, ppVars, pStk, inst->m_nMethodeIdent);
|
||||
delete pStk->TokenStack(); // libère le supplément de pile
|
||||
int typ = r.GivType();
|
||||
|
||||
if (typ == TX_UNDEFCALL)
|
||||
{
|
||||
// si le constructeur n'existe pas
|
||||
if (inst->m_Parameters != NULL) // avec des paramètres
|
||||
{
|
||||
pStk->SetError(TX_NOCONST, vartoken);
|
||||
goto error;
|
||||
}
|
||||
typ = 0;
|
||||
}
|
||||
|
||||
if (typ>20)
|
||||
{
|
||||
pStk->SetError(typ, vartoken->GivEnd());
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (IsOfType(p, ID_ASS)) // avec une assignation ?
|
||||
{
|
||||
if (inst->m_hasParams)
|
||||
{
|
||||
pStk->SetError(TX_ENDOF, p->GivStart());
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
CBotClass* result = pStk->GivClass();
|
||||
if ( !pStk->GivTypResult(1).Eq(CBotTypNullPointer) &&
|
||||
( !pStk->GivTypResult(1).Eq(CBotTypPointer) ||
|
||||
( result != NULL && !pClass->IsChildOf(result) ))) // type compatible ?
|
||||
{
|
||||
pStk->SetError(TX_BADTYPE, p->GivStart());
|
||||
goto error;
|
||||
}
|
||||
// if ( !bIntrinsic ) var->SetPointer(pStk->GivVar()->GivPointer());
|
||||
if ( !bIntrinsic )
|
||||
{
|
||||
// n'utilise pas le résultat sur la pile, pour imposer la classe
|
||||
CBotVar* pvar = CBotVar::Create("", pClass);
|
||||
var->SetPointer( pvar ); // var déjà déclarée pointe l'instance
|
||||
delete pvar; // supprime le second pointeur
|
||||
}
|
||||
var->SetInit(TRUE); // marque le pointeur comme init
|
||||
}
|
||||
else if (inst->m_hasParams)
|
||||
{
|
||||
// crée l'objet sur le "tas"
|
||||
// avec un pointeur sur cet objet
|
||||
if ( !bIntrinsic )
|
||||
{
|
||||
CBotVar* pvar = CBotVar::Create("", pClass);
|
||||
var->SetPointer( pvar ); // var déjà déclarée pointe l'instance
|
||||
delete pvar; // supprime le second pointeur
|
||||
}
|
||||
var->SetInit(2); // marque le pointeur comme init
|
||||
}
|
||||
suite:
|
||||
if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
|
||||
{
|
||||
if ( NULL != ( inst->m_next = CBotClassInst::Compile(p, pStk, pClass) )) // compile la suivante
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsOfType(p, ID_SEP)) // instruction terminée
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
|
||||
pStk->SetError(TX_ENDOF, p->GivStart());
|
||||
}
|
||||
|
||||
error:
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// déclaration de l'instance d'une classe, par exemple:
|
||||
// CPoint A, B;
|
||||
|
||||
BOOL CBotClassInst::Execute(CBotStack* &pj)
|
||||
{
|
||||
CBotVar* pThis = NULL;
|
||||
|
||||
CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
|
||||
// if ( pile == EOX ) return TRUE;
|
||||
|
||||
CBotToken* pt = &m_token;
|
||||
CBotClass* pClass = CBotClass::Find(pt);
|
||||
|
||||
BOOL bIntrincic = pClass->IsIntrinsic();
|
||||
|
||||
// crée la variable de type pointeur à l'objet
|
||||
|
||||
if ( pile->GivState()==0)
|
||||
{
|
||||
CBotString name = m_var->m_token.GivString();
|
||||
if ( bIntrincic )
|
||||
{
|
||||
pThis = CBotVar::Create(name, CBotTypResult( CBotTypIntrinsic, pClass ));
|
||||
}
|
||||
else
|
||||
{
|
||||
pThis = CBotVar::Create(name, CBotTypResult( CBotTypPointer, pClass ));
|
||||
}
|
||||
|
||||
pThis->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent); // lui attribut un numéro unique
|
||||
pile->AddVar(pThis); // la place sur la pile
|
||||
pile->IncState();
|
||||
}
|
||||
|
||||
if ( pThis == NULL ) pThis = pile->FindVar(((CBotLeftExprVar*)m_var)->m_nIdent);
|
||||
|
||||
if ( pile->GivState()<3)
|
||||
{
|
||||
// y a-t-il une assignation ou des paramètres (constructeur)
|
||||
|
||||
// CBotVarClass* pInstance = NULL;
|
||||
|
||||
if ( m_expr != NULL )
|
||||
{
|
||||
// évalue l'expression pour l'assignation
|
||||
if (!m_expr->Execute(pile)) return FALSE;
|
||||
|
||||
if ( bIntrincic )
|
||||
{
|
||||
CBotVar* pv = pile->GivVar();
|
||||
if ( pv == NULL || pv->GivPointer() == NULL )
|
||||
{
|
||||
pile->SetError(TX_NULLPT, &m_token);
|
||||
return pj->Return(pile);
|
||||
}
|
||||
pThis->Copy(pile->GivVar(), FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
CBotVarClass* pInstance;
|
||||
pInstance = ((CBotVarPointer*)pile->GivVar())->GivPointer(); // valeur pour l'assignation
|
||||
pThis->SetPointer(pInstance);
|
||||
}
|
||||
pThis->SetInit(TRUE);
|
||||
}
|
||||
|
||||
else if ( m_hasParams )
|
||||
{
|
||||
// évalue le constructeur d'une instance
|
||||
|
||||
if ( !bIntrincic && pile->GivState() == 1)
|
||||
{
|
||||
CBotToken* pt = &m_token;
|
||||
CBotClass* pClass = CBotClass::Find(pt);
|
||||
|
||||
// crée une instance de la classe demandée
|
||||
|
||||
CBotVarClass* pInstance;
|
||||
pInstance = (CBotVarClass*)CBotVar::Create("", pClass);
|
||||
pThis->SetPointer(pInstance);
|
||||
delete pInstance;
|
||||
|
||||
pile->IncState();
|
||||
}
|
||||
|
||||
CBotVar* ppVars[1000];
|
||||
CBotStack* pile2 = pile;
|
||||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_Parameters;
|
||||
// évalue les paramètres
|
||||
// et place les valeurs sur la pile
|
||||
// pour pouvoir être interrompu n'importe quand
|
||||
|
||||
if ( p != NULL) while ( TRUE )
|
||||
{
|
||||
pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats
|
||||
if ( pile2->GivState() == 0 )
|
||||
{
|
||||
if (!p->Execute(pile2)) return FALSE; // interrompu ici ?
|
||||
pile2->SetState(1);
|
||||
}
|
||||
ppVars[i++] = pile2->GivVar();
|
||||
p = p->GivNext();
|
||||
if ( p == NULL) break;
|
||||
}
|
||||
ppVars[i] = NULL;
|
||||
|
||||
// crée une variable pour le résultat
|
||||
CBotVar* pResult = NULL; // constructeurs toujours void
|
||||
|
||||
if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(),
|
||||
pThis, ppVars,
|
||||
pResult, pile2, GivToken())) return FALSE; // interrompu
|
||||
|
||||
pThis->SetInit(TRUE);
|
||||
pThis->ConstructorSet(); // signale que le constructeur a été appelé
|
||||
pile->Return(pile2); // libère un bout de pile
|
||||
|
||||
// pInstance = pThis->GivPointer();
|
||||
|
||||
}
|
||||
|
||||
// if ( !bIntrincic ) pThis->SetPointer(pInstance); // le fait pointer l'instance
|
||||
|
||||
pile->SetState(3); // fini cette partie
|
||||
}
|
||||
|
||||
if ( pile->IfStep() ) return FALSE;
|
||||
|
||||
if ( m_next2b != NULL &&
|
||||
!m_next2b->Execute(pile)) return FALSE; // autre(s) définition(s)
|
||||
|
||||
return pj->Return( pile ); // transmet en dessous
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CBotClassInst::RestoreState(CBotStack* &pj, BOOL bMain)
|
||||
{
|
||||
CBotVar* pThis = NULL;
|
||||
|
||||
CBotStack* pile = pj;
|
||||
if ( bMain ) pile = pj->RestoreStack(this);
|
||||
if ( pile == NULL ) return;
|
||||
|
||||
// crée la variable de type pointeur à l'objet
|
||||
{
|
||||
CBotString name = m_var->m_token.GivString();
|
||||
pThis = pile->FindVar(name);
|
||||
pThis->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent); // lui attribut un numéro unique
|
||||
}
|
||||
|
||||
CBotToken* pt = &m_token;
|
||||
CBotClass* pClass = CBotClass::Find(pt);
|
||||
BOOL bIntrincic = pClass->IsIntrinsic();
|
||||
|
||||
if ( bMain && pile->GivState()<3)
|
||||
{
|
||||
// y a-t-il une assignation ou des paramètres (constructeur)
|
||||
|
||||
// CBotVarClass* pInstance = NULL;
|
||||
|
||||
if ( m_expr != NULL )
|
||||
{
|
||||
// évalue l'expression pour l'assignation
|
||||
m_expr->RestoreState(pile, bMain);
|
||||
return;
|
||||
}
|
||||
|
||||
else if ( m_hasParams )
|
||||
{
|
||||
// évalue le constructeur d'une instance
|
||||
|
||||
if ( !bIntrincic && pile->GivState() == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CBotVar* ppVars[1000];
|
||||
CBotStack* pile2 = pile;
|
||||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_Parameters;
|
||||
// évalue les paramètres
|
||||
// et place les valeurs sur la pile
|
||||
// pour pouvoir être interrompu n'importe quand
|
||||
|
||||
if ( p != NULL) while ( TRUE )
|
||||
{
|
||||
pile2 = pile2->RestoreStack(); // de la place sur la pile pour les résultats
|
||||
if ( pile2 == NULL ) return;
|
||||
|
||||
if ( pile2->GivState() == 0 )
|
||||
{
|
||||
p->RestoreState(pile2, bMain); // interrompu ici ?
|
||||
return;
|
||||
}
|
||||
ppVars[i++] = pile2->GivVar();
|
||||
p = p->GivNext();
|
||||
if ( p == NULL) break;
|
||||
}
|
||||
ppVars[i] = NULL;
|
||||
|
||||
// crée une variable pour le résultat
|
||||
CBotVar* pResult = NULL; // constructeurs toujours void
|
||||
|
||||
pClass->RestoreMethode(m_nMethodeIdent, pClass->GivName(), pThis, ppVars, pile2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_next2b != NULL )
|
||||
m_next2b->RestoreState(pile, bMain); // autre(s) définition(s)
|
||||
}
|
||||
|
||||
|
||||
// test si un nom de procédure est déjà défini quelque part
|
||||
|
||||
BOOL CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
|
||||
{
|
||||
CBotString name = pToken->GivString();
|
||||
|
||||
if ( CBotCall::CheckCall(name) ) return TRUE;
|
||||
|
||||
CBotFunction* pp = m_pMethod;
|
||||
while ( pp != NULL )
|
||||
{
|
||||
if ( pToken->GivString() == pp->GivName() )
|
||||
{
|
||||
// les paramètres sont-ils exactement les mêmes ?
|
||||
if ( pp->CheckParam( pParam ) )
|
||||
return TRUE;
|
||||
}
|
||||
pp = pp->Next();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 > Opérande2
|
||||
// Opérande1 != Opérande2
|
||||
// etc.
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotCompExpr::CBotCompExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL;
|
||||
name = "CBotCompExpr";
|
||||
}
|
||||
|
||||
CBotCompExpr::~CBotCompExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
fichier plus utilise;
|
||||
|
||||
// compile une instruction de type A < B
|
||||
|
||||
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->AddStack();
|
||||
|
||||
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B à gauche
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // erreur
|
||||
|
||||
if ( p->GetType() == ID_HI ||
|
||||
p->GetType() == ID_LO ||
|
||||
p->GetType() == ID_HS ||
|
||||
p->GetType() == ID_LS ||
|
||||
p->GetType() == ID_EQ ||
|
||||
p->GetType() == ID_NE) // les diverses comparaisons
|
||||
{
|
||||
CBotCompExpr* inst = new CBotCompExpr(); // élément pour opération
|
||||
inst->SetToken(p); // mémorise l'opération
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStack->GetType();
|
||||
|
||||
p = p->Next();
|
||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B à droite
|
||||
{
|
||||
type2 = pStack->GetType();
|
||||
// les résultats sont-ils compatibles
|
||||
if ( type1 == type2 )
|
||||
{
|
||||
inst->m_leftop = left;
|
||||
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
||||
// le résultat est un boolean
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
delete left;
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
// fait l'opération
|
||||
|
||||
BOOL CBotCompExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this);
|
||||
// if ( pStk1 == EOX ) return TRUE;
|
||||
|
||||
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
pStk1->SetState(1); // opération terminée
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
CBotStack* pStk2 = pStk1->AddStack();
|
||||
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
|
||||
int type1 = pStk1->GetType();
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
|
||||
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_LO:
|
||||
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
|
||||
break;
|
||||
case ID_HI:
|
||||
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
|
||||
break;
|
||||
case ID_LS:
|
||||
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
|
||||
break;
|
||||
case ID_HS:
|
||||
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
|
||||
break;
|
||||
case ID_EQ:
|
||||
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
|
||||
break;
|
||||
case ID_NE:
|
||||
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
|
||||
break;
|
||||
}
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
|
||||
pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,145 @@
|
|||
///////////////////////////////////////////////////////////////////////
|
||||
// instruction if (condition) opération1 else opération2;
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// les divers constructeurs / destructeurs
|
||||
CBotIf::CBotIf()
|
||||
{
|
||||
m_Condition =
|
||||
m_Block =
|
||||
m_BlockElse = NULL; // NULL pour pouvoir faire delete directement
|
||||
name = "CBotIf"; // debug
|
||||
}
|
||||
|
||||
CBotIf::~CBotIf()
|
||||
{
|
||||
delete m_Condition; // libère la condition
|
||||
delete m_Block; // libère le bloc d'instruction1
|
||||
delete m_BlockElse; // libère le bloc d'instruction2
|
||||
}
|
||||
|
||||
// compilation (routine statique)
|
||||
// appelé lorsque le token "if" a été trouvé
|
||||
|
||||
CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p; // conserve le ^au token (début instruction)
|
||||
|
||||
if (!IsOfType(p, ID_IF)) return NULL; // ne doit jamais arriver
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
||||
|
||||
CBotIf* inst = new CBotIf(); // crée l'object
|
||||
inst->SetToken( pp );
|
||||
|
||||
if ( NULL != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
|
||||
{
|
||||
// la condition existe bel et bien
|
||||
|
||||
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
|
||||
if ( pStk->IsOk() )
|
||||
{
|
||||
// le bloc d'instruction est ok (peut être vide)
|
||||
|
||||
// regarde si l'instruction suivante est le token "else"
|
||||
if (IsOfType(p, ID_ELSE))
|
||||
{
|
||||
// si oui, compile le bloc d'instruction qui suit
|
||||
inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
|
||||
if (!pStk->IsOk())
|
||||
{
|
||||
// il n'y a pas de bloc correct après le else
|
||||
// libère l'objet, et transmet l'erreur qui est sur la pile
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// rend l'object correct à qui le demande.
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// erreur, libère l'objet
|
||||
delete inst;
|
||||
// et transmet l'erreur qui se trouve sur la pile.
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
|
||||
// exécution de l'instruction
|
||||
|
||||
BOOL CBotIf :: Execute(CBotStack* &pj)
|
||||
{
|
||||
CBotStack* pile = pj->AddStack(this); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
// if ( pile == EOX ) return TRUE;
|
||||
|
||||
if ( pile->IfStep() ) return FALSE;
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
if( pile->GivState() == 0 )
|
||||
{
|
||||
// évalue la condition
|
||||
if ( !m_Condition->Execute(pile) ) return FALSE; // interrompu ici ?
|
||||
|
||||
// termine s'il y a une erreur
|
||||
if ( !pile->IsOk() )
|
||||
{
|
||||
return pj->Return(pile); // transmet le résultat et libère la pile
|
||||
}
|
||||
|
||||
// passe dans le second état
|
||||
if (!pile->SetState(1)) return FALSE; // prêt pour la suite
|
||||
}
|
||||
|
||||
// second état, évalue les instructions associées
|
||||
// le résultat de la condition est sur la pile
|
||||
|
||||
if ( pile->GivVal() == TRUE ) // condition était vraie ?
|
||||
{
|
||||
if ( m_Block != NULL && // bloc peut être absent
|
||||
!m_Block->Execute(pile) ) return FALSE; // interrompu ici ?
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_BlockElse != NULL && // s'il existe un bloc alternatif
|
||||
!m_BlockElse->Execute(pile) ) return FALSE; // interrompu ici
|
||||
}
|
||||
|
||||
// transmet le résultat et libère la pile
|
||||
return pj->Return(pile);
|
||||
}
|
||||
|
||||
|
||||
void CBotIf :: RestoreState(CBotStack* &pj, BOOL bMain)
|
||||
{
|
||||
if ( !bMain ) return;
|
||||
|
||||
CBotStack* pile = pj->RestoreStack(this); // ajoute un élément à la pile
|
||||
if ( pile == NULL ) return;
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
if( pile->GivState() == 0 )
|
||||
{
|
||||
// évalue la condition
|
||||
m_Condition->RestoreState(pile, bMain); // interrompu ici !
|
||||
return;
|
||||
}
|
||||
|
||||
// second état, évalue les instructions associées
|
||||
// le résultat de la condition est sur la pile
|
||||
|
||||
if ( pile->GivVal() == TRUE ) // condition était vraie ?
|
||||
{
|
||||
if ( m_Block != NULL ) // bloc peut être absent
|
||||
m_Block->RestoreState(pile, bMain); // interrompu ici !
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_BlockElse != NULL ) // s'il existe un bloc alternatif
|
||||
m_BlockElse->RestoreState(pile, bMain); // interrompu ici !
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,588 @@
|
|||
/////////////////////////////////////////////////////
|
||||
// gestion de chaine
|
||||
// basé sur le CString de MFC
|
||||
// mais moins complet
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("Cbot.dll"); // comment le récupérer autrement ??
|
||||
|
||||
|
||||
CBotString::CBotString()
|
||||
{
|
||||
m_ptr = NULL; // chaine vide
|
||||
m_lg = 0;
|
||||
}
|
||||
|
||||
CBotString::~CBotString()
|
||||
{
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
}
|
||||
|
||||
|
||||
CBotString::CBotString(const char* p)
|
||||
{
|
||||
m_lg = lstrlen( p );
|
||||
|
||||
m_ptr = NULL;
|
||||
if (m_lg>0)
|
||||
{
|
||||
m_ptr = (char*)malloc(m_lg+1);
|
||||
lstrcpy(m_ptr, p);
|
||||
}
|
||||
}
|
||||
|
||||
CBotString::CBotString(const CBotString& srcString)
|
||||
{
|
||||
m_lg = srcString.m_lg;
|
||||
|
||||
m_ptr = NULL;
|
||||
if (m_lg>0)
|
||||
{
|
||||
m_ptr = (char*)malloc(m_lg+1);
|
||||
lstrcpy(m_ptr, srcString.m_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int CBotString::GivLength()
|
||||
{
|
||||
if ( m_ptr == NULL ) return 0;
|
||||
return lstrlen( m_ptr );
|
||||
}
|
||||
|
||||
|
||||
|
||||
CBotString CBotString::Left(int nCount) const
|
||||
{
|
||||
char chaine[2000];
|
||||
|
||||
int i;
|
||||
for (i = 0; i < m_lg && i < nCount && i < 1999; i++)
|
||||
{
|
||||
chaine[i] = m_ptr[i];
|
||||
}
|
||||
chaine[i] = 0 ;
|
||||
|
||||
return CBotString( chaine );
|
||||
}
|
||||
|
||||
CBotString CBotString::Right(int nCount) const
|
||||
{
|
||||
char chaine[2000];
|
||||
|
||||
int i = m_lg - nCount;
|
||||
if ( i < 0 ) i = 0;
|
||||
|
||||
for ( int j = 0; i < m_lg && i < 1999; i++)
|
||||
{
|
||||
chaine[j++] = m_ptr[i];
|
||||
}
|
||||
chaine[j] = 0 ;
|
||||
|
||||
return CBotString( chaine );
|
||||
}
|
||||
|
||||
CBotString CBotString::Mid(int nFirst, int nCount) const
|
||||
{
|
||||
char chaine[2000];
|
||||
|
||||
int i;
|
||||
|
||||
for ( i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; i++)
|
||||
{
|
||||
chaine[i] = m_ptr[i];
|
||||
}
|
||||
chaine[i] = 0 ;
|
||||
|
||||
return CBotString( chaine );
|
||||
}
|
||||
|
||||
CBotString CBotString::Mid(int nFirst) const
|
||||
{
|
||||
char chaine[2000];
|
||||
|
||||
int i;
|
||||
|
||||
for ( i = nFirst; i < m_lg && i < 1999 ; i++)
|
||||
{
|
||||
chaine[i] = m_ptr[i];
|
||||
}
|
||||
chaine[i] = 0 ;
|
||||
|
||||
return CBotString( chaine );
|
||||
}
|
||||
|
||||
|
||||
int CBotString::Find(const char c)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < m_lg; i++)
|
||||
{
|
||||
if (m_ptr[i] == c) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CBotString::Find(LPCTSTR lpsz)
|
||||
{
|
||||
int i, j;
|
||||
int l = lstrlen(lpsz);
|
||||
|
||||
for (i = 0; i <= m_lg-l; i++)
|
||||
{
|
||||
for (j = 0; j < l; j++)
|
||||
{
|
||||
if (m_ptr[i+j] != lpsz[j]) goto bad;
|
||||
}
|
||||
return i;
|
||||
bad:;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CBotString::ReverseFind(const char c)
|
||||
{
|
||||
int i;
|
||||
for (i = m_lg-1; i >= 0; i--)
|
||||
{
|
||||
if (m_ptr[i] == c) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CBotString::ReverseFind(LPCTSTR lpsz)
|
||||
{
|
||||
int i, j;
|
||||
int l = lstrlen(lpsz);
|
||||
|
||||
for (i = m_lg-l; i >= 0; i--)
|
||||
{
|
||||
for (j = 0; j < l; j++)
|
||||
{
|
||||
if (m_ptr[i+j] != lpsz[j]) goto bad;
|
||||
}
|
||||
return i;
|
||||
bad:;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
CBotString CBotString::Mid(int start, int lg)
|
||||
{
|
||||
CBotString res;
|
||||
if (start >= m_lg) return res;
|
||||
|
||||
if ( lg < 0 ) lg = m_lg - start;
|
||||
|
||||
char* p = (char*)malloc(m_lg+1);
|
||||
lstrcpy(p, m_ptr+start);
|
||||
p[lg] = 0;
|
||||
|
||||
res = p;
|
||||
free(p);
|
||||
return res;
|
||||
}
|
||||
|
||||
void CBotString::MakeUpper()
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < m_lg && i < 1999 ; i++)
|
||||
{
|
||||
char c = m_ptr[i];
|
||||
if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
|
||||
}
|
||||
}
|
||||
|
||||
void CBotString::MakeLower()
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < m_lg && i < 1999 ; i++)
|
||||
{
|
||||
char c = m_ptr[i];
|
||||
if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define MAXSTRING 256
|
||||
|
||||
BOOL CBotString::LoadString(UINT id)
|
||||
{
|
||||
char buffer[MAXSTRING];
|
||||
|
||||
m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING );
|
||||
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
|
||||
m_ptr = NULL;
|
||||
if (m_lg > 0)
|
||||
{
|
||||
m_ptr = (char*)malloc(m_lg+1);
|
||||
lstrcpy(m_ptr, buffer);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
const CBotString& CBotString::operator=(const CBotString& stringSrc)
|
||||
{
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
|
||||
m_lg = stringSrc.m_lg;
|
||||
m_ptr = NULL;
|
||||
|
||||
if (m_lg > 0)
|
||||
{
|
||||
m_ptr = (char*)malloc(m_lg+1);
|
||||
lstrcpy(m_ptr, stringSrc.m_ptr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CBotString operator+(const CBotString& string, LPCTSTR lpsz)
|
||||
{
|
||||
CBotString s ( string );
|
||||
s += lpsz;
|
||||
return s;
|
||||
}
|
||||
|
||||
const CBotString& CBotString::operator+(const CBotString& stringSrc)
|
||||
{
|
||||
char* p = (char*)malloc(m_lg+stringSrc.m_lg+1);
|
||||
|
||||
lstrcpy(p, m_ptr);
|
||||
char* pp = p + m_lg;
|
||||
lstrcpy(pp, stringSrc.m_ptr);
|
||||
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
m_ptr = p;
|
||||
m_lg += stringSrc.m_lg;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CBotString& CBotString::operator=(const char ch)
|
||||
{
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
|
||||
m_lg = 1;
|
||||
|
||||
m_ptr = (char*)malloc(2);
|
||||
m_ptr[0] = ch;
|
||||
m_ptr[1] = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CBotString& CBotString::operator=(const char* pString)
|
||||
{
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
m_ptr = NULL;
|
||||
|
||||
if ( pString != NULL )
|
||||
{
|
||||
m_lg = lstrlen(pString);
|
||||
|
||||
if (m_lg != 0)
|
||||
{
|
||||
m_ptr = (char*)malloc(m_lg+1);
|
||||
lstrcpy(m_ptr, pString);
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const CBotString& CBotString::operator+=(const char ch)
|
||||
{
|
||||
char* p = (char*)malloc(m_lg+2);
|
||||
|
||||
if (m_ptr!=NULL) lstrcpy(p, m_ptr);
|
||||
p[m_lg++] = ch;
|
||||
p[m_lg] = 0;
|
||||
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
|
||||
m_ptr = p;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const CBotString& CBotString::operator+=(const CBotString& str)
|
||||
{
|
||||
char* p = (char*)malloc(m_lg+str.m_lg+1);
|
||||
|
||||
lstrcpy(p, m_ptr);
|
||||
char* pp = p + m_lg;
|
||||
lstrcpy(pp, str.m_ptr);
|
||||
|
||||
m_lg = m_lg + str.m_lg;
|
||||
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
|
||||
m_ptr = p;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator==(const CBotString& str)
|
||||
{
|
||||
return Compare(str) == 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator==(const char* p)
|
||||
{
|
||||
return Compare(p) == 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator!=(const CBotString& str)
|
||||
{
|
||||
return Compare(str) != 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator!=(const char* p)
|
||||
{
|
||||
return Compare(p) != 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator>(const CBotString& str)
|
||||
{
|
||||
return Compare(str) > 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator>(const char* p)
|
||||
{
|
||||
return Compare(p) > 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator>=(const CBotString& str)
|
||||
{
|
||||
return Compare(str) >= 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator>=(const char* p)
|
||||
{
|
||||
return Compare(p) >= 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator<(const CBotString& str)
|
||||
{
|
||||
return Compare(str) < 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator<(const char* p)
|
||||
{
|
||||
return Compare(p) < 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator<=(const CBotString& str)
|
||||
{
|
||||
return Compare(str) <= 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::operator<=(const char* p)
|
||||
{
|
||||
return Compare(p) <= 0;
|
||||
}
|
||||
|
||||
BOOL CBotString::IsEmpty()
|
||||
{
|
||||
return (m_lg == 0);
|
||||
}
|
||||
|
||||
void CBotString::Empty()
|
||||
{
|
||||
if (m_ptr != NULL) free(m_ptr);
|
||||
m_ptr = NULL;
|
||||
m_lg = 0;
|
||||
}
|
||||
|
||||
static char nilstring[] = {0};
|
||||
|
||||
CBotString::operator LPCTSTR() const
|
||||
{
|
||||
if (this == NULL || m_ptr == NULL) return nilstring;
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
|
||||
int CBotString::Compare(LPCTSTR lpsz) const
|
||||
{
|
||||
char* p = m_ptr;
|
||||
if (lpsz == NULL) lpsz = nilstring;
|
||||
if (m_ptr == NULL) p = nilstring;
|
||||
return strcmp(p, lpsz); // wcscmp
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// tableaux de chaines
|
||||
|
||||
CBotStringArray::CBotStringArray()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_nSize = m_nMaxSize = 0;
|
||||
}
|
||||
|
||||
CBotStringArray::~CBotStringArray()
|
||||
{
|
||||
SetSize(0); // détruit les données !
|
||||
}
|
||||
|
||||
|
||||
int CBotStringArray::GivSize()
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
void CBotStringArray::Add(const CBotString& str)
|
||||
{
|
||||
SetSize(m_nSize+1);
|
||||
|
||||
m_pData[m_nSize-1] = str;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// routines utilitaires
|
||||
|
||||
static inline void ConstructElement(CBotString* pNewData)
|
||||
{
|
||||
memset(pNewData, 0, sizeof(CBotString));
|
||||
}
|
||||
|
||||
static inline void DestructElement(CBotString* pOldData)
|
||||
{
|
||||
pOldData->~CBotString();
|
||||
}
|
||||
|
||||
static inline void CopyElement(CBotString* pSrc, CBotString* pDest)
|
||||
{
|
||||
*pSrc = *pDest;
|
||||
}
|
||||
|
||||
static void ConstructElements(CBotString* pNewData, int nCount)
|
||||
{
|
||||
while (nCount--)
|
||||
{
|
||||
ConstructElement(pNewData);
|
||||
pNewData++;
|
||||
}
|
||||
}
|
||||
|
||||
static void DestructElements(CBotString* pOldData, int nCount)
|
||||
{
|
||||
while (nCount--)
|
||||
{
|
||||
DestructElement(pOldData);
|
||||
pOldData++;
|
||||
}
|
||||
}
|
||||
|
||||
static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount)
|
||||
{
|
||||
while (nCount--)
|
||||
{
|
||||
*pDest = *pSrc;
|
||||
++pDest;
|
||||
++pSrc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// sélect la taille du tableau
|
||||
|
||||
void CBotStringArray::SetSize(int nNewSize)
|
||||
{
|
||||
if (nNewSize == 0)
|
||||
{
|
||||
// shrink to nothing
|
||||
|
||||
DestructElements(m_pData, m_nSize);
|
||||
delete[] (BYTE*)m_pData;
|
||||
m_pData = NULL;
|
||||
m_nSize = m_nMaxSize = 0;
|
||||
}
|
||||
else if (m_pData == NULL)
|
||||
{
|
||||
// create one with exact size
|
||||
m_pData = (CBotString*) new BYTE[nNewSize * sizeof(CBotString)];
|
||||
|
||||
ConstructElements(m_pData, nNewSize);
|
||||
|
||||
m_nSize = m_nMaxSize = nNewSize;
|
||||
}
|
||||
else if (nNewSize <= m_nMaxSize)
|
||||
{
|
||||
// it fits
|
||||
if (nNewSize > m_nSize)
|
||||
{
|
||||
// initialize the new elements
|
||||
|
||||
ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize);
|
||||
|
||||
}
|
||||
|
||||
else if (m_nSize > nNewSize) // destroy the old elements
|
||||
DestructElements(&m_pData[nNewSize], m_nSize-nNewSize);
|
||||
|
||||
m_nSize = nNewSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise, grow array
|
||||
int nGrowBy;
|
||||
{
|
||||
// heuristically determine growth when nGrowBy == 0
|
||||
// (this avoids heap fragmentation in many situations)
|
||||
nGrowBy = min(1024, max(4, m_nSize / 8));
|
||||
}
|
||||
int nNewMax;
|
||||
if (nNewSize < m_nMaxSize + nGrowBy)
|
||||
nNewMax = m_nMaxSize + nGrowBy; // granularity
|
||||
else
|
||||
nNewMax = nNewSize; // no slush
|
||||
|
||||
CBotString* pNewData = (CBotString*) new BYTE[nNewMax * sizeof(CBotString)];
|
||||
|
||||
// copy new data from old
|
||||
memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
|
||||
|
||||
// construct remaining elements
|
||||
ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
|
||||
|
||||
|
||||
// Ret rid of old stuff (note: no destructors called)
|
||||
delete[] (BYTE*)m_pData;
|
||||
m_pData = pNewData;
|
||||
m_nSize = nNewSize;
|
||||
m_nMaxSize = nNewMax;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CBotString& CBotStringArray::operator[](int nIndex)
|
||||
{
|
||||
return ElementAt(nIndex);
|
||||
}
|
||||
|
||||
CBotString& CBotStringArray::ElementAt(int nIndex)
|
||||
{
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,540 @@
|
|||
//////////////////////////////////////////////////////////////////
|
||||
// Gestion des Tokens
|
||||
// le texte d'un programme est d'abord transformé
|
||||
// en une suite de tokens pour facilité l'interprétation
|
||||
|
||||
// il faudra traiter le seul cas d'erreur possible
|
||||
// qui est un caractère illégal dans une string
|
||||
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
CBotStringArray CBotToken::m_ListKeyWords;
|
||||
int CBotToken::m_ListIdKeyWords[200];
|
||||
CBotStringArray CBotToken::m_ListKeyDefine;
|
||||
long CBotToken::m_ListKeyNums[MAXDEFNUM];
|
||||
|
||||
// constructeurs
|
||||
CBotToken::CBotToken()
|
||||
{
|
||||
m_next = NULL;
|
||||
m_prev = NULL;
|
||||
|
||||
m_type = TokenTypVar; // à priori un nom d'une variable
|
||||
m_IdKeyWord = -1;
|
||||
}
|
||||
|
||||
CBotToken::CBotToken(const CBotToken* pSrc)
|
||||
{
|
||||
m_next = NULL;
|
||||
m_prev = NULL;
|
||||
|
||||
m_Text.Empty();
|
||||
m_Sep.Empty();
|
||||
|
||||
m_type = 0;
|
||||
m_IdKeyWord = 0;
|
||||
|
||||
m_start = 0;
|
||||
m_end = 0;
|
||||
|
||||
if ( pSrc != NULL )
|
||||
{
|
||||
m_Text = pSrc->m_Text;
|
||||
m_Sep = pSrc->m_Sep;
|
||||
|
||||
m_type = pSrc->m_type;
|
||||
m_IdKeyWord = pSrc->m_IdKeyWord;
|
||||
|
||||
m_start = pSrc->m_start;
|
||||
m_end = pSrc->m_end;
|
||||
}
|
||||
}
|
||||
|
||||
CBotToken::CBotToken(CBotString& mot, CBotString& sep, int start, int end)
|
||||
{
|
||||
m_Text = mot; // mot trouvé comme token
|
||||
m_Sep = sep; // séparateurs qui suivent
|
||||
m_next = NULL;
|
||||
m_prev = NULL;
|
||||
m_start = start;
|
||||
m_end = end;
|
||||
|
||||
m_type = TokenTypVar; // à priori un nom d'une variable
|
||||
m_IdKeyWord = -1;
|
||||
}
|
||||
|
||||
CBotToken::CBotToken(const char* mot, const char* sep)
|
||||
{
|
||||
m_Text = mot;
|
||||
if ( sep != NULL ) m_Sep = sep;
|
||||
m_next = NULL;
|
||||
m_prev = NULL;
|
||||
|
||||
m_type = TokenTypVar; // à priori un nom d'une variable
|
||||
m_IdKeyWord = -1;
|
||||
}
|
||||
|
||||
CBotToken::~CBotToken()
|
||||
{
|
||||
delete m_next; // récursif
|
||||
m_next = NULL;
|
||||
}
|
||||
|
||||
void CBotToken::Free()
|
||||
{
|
||||
m_ListKeyDefine.SetSize(0);
|
||||
}
|
||||
|
||||
const CBotToken& CBotToken::operator=(const CBotToken& src)
|
||||
{
|
||||
if (m_next != NULL) delete(m_next);
|
||||
m_next = NULL;
|
||||
m_prev = NULL;
|
||||
|
||||
m_Text = src.m_Text;
|
||||
m_Sep = src.m_Sep;
|
||||
|
||||
m_type = src.m_type;
|
||||
m_IdKeyWord = src.m_IdKeyWord;
|
||||
|
||||
m_start = src.m_start;
|
||||
m_end = src.m_end;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
int CBotToken::GivType()
|
||||
{
|
||||
if (this == NULL) return 0;
|
||||
if (m_type == TokenTypKeyWord) return m_IdKeyWord;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
long CBotToken::GivIdKey()
|
||||
{
|
||||
return m_IdKeyWord;
|
||||
}
|
||||
|
||||
CBotToken* CBotToken::GivNext()
|
||||
{
|
||||
if (this == NULL) return NULL;
|
||||
return m_next;
|
||||
}
|
||||
|
||||
CBotToken* CBotToken::GivPrev()
|
||||
{
|
||||
if (this == NULL) return NULL;
|
||||
return m_prev;
|
||||
}
|
||||
|
||||
void CBotToken::AddNext(CBotToken* p)
|
||||
{
|
||||
CBotToken* n = new CBotToken(p);
|
||||
CBotToken* pt = this;
|
||||
|
||||
while ( pt->m_next != NULL ) pt = pt->m_next;
|
||||
|
||||
pt->m_next = n;
|
||||
n->m_prev = pt;
|
||||
}
|
||||
|
||||
|
||||
CBotString& CBotToken::GivString()
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
|
||||
CBotString& CBotToken::GivSep()
|
||||
{
|
||||
return m_Sep;
|
||||
}
|
||||
|
||||
void CBotToken::SetString(const char* name)
|
||||
{
|
||||
m_Text = name;
|
||||
}
|
||||
|
||||
|
||||
int CBotToken::GivStart()
|
||||
{
|
||||
if (this == NULL) return -1;
|
||||
return m_start;
|
||||
}
|
||||
|
||||
int CBotToken::GivEnd()
|
||||
{
|
||||
if (this == NULL) return -1;
|
||||
return m_end;
|
||||
}
|
||||
|
||||
void CBotToken::SetPos(int start, int end)
|
||||
{
|
||||
m_start = start;
|
||||
m_end = end;
|
||||
}
|
||||
|
||||
BOOL CharInList(const char c, const char* list)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (c == list[i++]) return TRUE;
|
||||
if (list[i] == 0) return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL Char2InList(const char c, const char cc, const char* list)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (c == list[i++] &&
|
||||
cc == list[i++]) return TRUE;
|
||||
|
||||
if (list[i] == 0) return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static char* sep1 = " \r\n\t,:()[]{}-+*/=;><!~^|&%.";
|
||||
static char* sep2 = " \r\n\t"; // séparateurs pures
|
||||
static char* sep3 = ",:()[]{}-+*/=;<>!~^|&%."; // séparateurs opérationnels
|
||||
static char* num = "0123456789"; // le point (unique) est testé séparément
|
||||
static char* hexnum = "0123456789ABCDEFabcdef";
|
||||
static char* nch = "\"\r\n\t"; // refusé dans les chaines
|
||||
|
||||
//static char* duo = "+=-=*=/===!=<=>=++--///**/||&&";// les opérateurs doubles
|
||||
|
||||
// cherche le prochain token dans une phrase
|
||||
// ne doit pas commencer par des séparateurs
|
||||
// qui sont pris avec le token précédent
|
||||
CBotToken* CBotToken::NextToken(char* &program, int& error, BOOL first)
|
||||
{
|
||||
CBotString mot; // le mot trouvé
|
||||
CBotString sep; // les séparateurs qui le suivent
|
||||
char c;
|
||||
BOOL stop = first;
|
||||
|
||||
if (*program == 0) return NULL;
|
||||
|
||||
c = *(program++); // prochain caractère
|
||||
|
||||
if (!first)
|
||||
{
|
||||
mot = c; // construit le mot
|
||||
c = *(program++); // prochain caractère
|
||||
|
||||
// cas particulier pour les chaînes de caractères
|
||||
if ( mot[0] == '\"' )
|
||||
{
|
||||
while (c != 0 && !CharInList(c, nch))
|
||||
{
|
||||
mot += c;
|
||||
c = *(program++); // prochain caractère
|
||||
if ( c == '\\' )
|
||||
{
|
||||
c = *(program++); // prochain caractère
|
||||
if ( c == 'n' ) c = '\n';
|
||||
if ( c == 'r' ) c = '\r';
|
||||
if ( c == 't' ) c = '\t';
|
||||
mot += c;
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
}
|
||||
if ( c == '\"' )
|
||||
{
|
||||
mot += c; // chaîne complète
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
stop = TRUE;
|
||||
}
|
||||
|
||||
// cas particulier pour les nombres
|
||||
if ( CharInList(mot[0], num ))
|
||||
{
|
||||
BOOL bdot = FALSE; // trouvé un point ?
|
||||
BOOL bexp = FALSE; // trouvé un exposant ?
|
||||
|
||||
char* liste = num;
|
||||
if (mot[0] == '0' && c == 'x') // valeur hexadécimale ?
|
||||
{
|
||||
mot += c;
|
||||
c = *(program++); // prochain caractère
|
||||
liste = hexnum;
|
||||
}
|
||||
cw:
|
||||
while (c != 0 && CharInList(c, liste))
|
||||
{
|
||||
cc: mot += c;
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
if ( liste == num ) // pas pour les exadécimaux
|
||||
{
|
||||
if ( !bdot && c == '.' ) { bdot = TRUE; goto cc; }
|
||||
if ( !bexp && ( c == 'e' || c == 'E' ) )
|
||||
{
|
||||
bexp = TRUE;
|
||||
mot += c;
|
||||
c = *(program++); // prochain caractère
|
||||
if ( c == '-' ||
|
||||
c == '+' ) goto cc;
|
||||
goto cw;
|
||||
}
|
||||
|
||||
}
|
||||
stop = TRUE;
|
||||
}
|
||||
|
||||
if (CharInList(mot[0], sep3)) // un séparateur opérationnel ?
|
||||
{
|
||||
CBotString motc = mot;
|
||||
while (motc += c, c != 0 && GivKeyWords(motc)>0) // cherche l'opérande le plus long possible
|
||||
{
|
||||
mot += c; // construit le mot
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
|
||||
stop = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (stop || c == 0 || CharInList(c, sep1))
|
||||
{
|
||||
if (!first && mot.IsEmpty()) return NULL; // fin de l'analyse
|
||||
bis:
|
||||
while (CharInList(c, sep2))
|
||||
{
|
||||
sep += c; // tous les séparateurs qui suivent
|
||||
c = *(program++);
|
||||
}
|
||||
if (c == '/' && *program == '/') // un commentaire dans le tas ?
|
||||
{
|
||||
while( c != '\n' && c != 0 )
|
||||
{
|
||||
sep += c;
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
goto bis;
|
||||
}
|
||||
|
||||
if (c == '/' && *program == '*') // un commentaire dans le tas ?
|
||||
{
|
||||
while( c != 0 && (c != '*' || *program != '/'))
|
||||
{
|
||||
sep += c;
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
if ( c != 0 )
|
||||
{
|
||||
sep += c;
|
||||
c = *(program++); // prochain caractère
|
||||
sep += c;
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
goto bis;
|
||||
}
|
||||
|
||||
program--;
|
||||
|
||||
CBotToken* token = new CBotToken(mot, sep);
|
||||
|
||||
if (CharInList( mot[0], num )) token->m_type = TokenTypNum;
|
||||
if (mot[0] == '\"') token->m_type = TokenTypString;
|
||||
if (first) token->m_type = 0;
|
||||
|
||||
token->m_IdKeyWord = GivKeyWords(mot);
|
||||
if (token->m_IdKeyWord > 0) token->m_type = TokenTypKeyWord;
|
||||
else GivKeyDefNum(mot, token) ; // traite les DefineNum
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
mot += c; // construit le mot
|
||||
c = *(program++); // prochain caractère
|
||||
}
|
||||
}
|
||||
|
||||
CBotToken* CBotToken::CompileTokens(const char* program, int& error)
|
||||
{
|
||||
CBotToken *nxt, *prv, *tokenbase;
|
||||
char* p = (char*) program;
|
||||
int pos = 0;
|
||||
|
||||
error = 0;
|
||||
prv = tokenbase = NextToken(p, error, TRUE);
|
||||
|
||||
if (tokenbase == NULL) return NULL;
|
||||
|
||||
tokenbase->m_start = pos;
|
||||
pos += tokenbase->m_Text.GivLength();
|
||||
tokenbase->m_end = pos;
|
||||
pos += tokenbase->m_Sep.GivLength();
|
||||
|
||||
char* pp = p;
|
||||
while (NULL != (nxt = NextToken(p, error)))
|
||||
{
|
||||
prv->m_next = nxt; // ajoute à la suite
|
||||
nxt->m_prev = prv;
|
||||
prv = nxt; // avance
|
||||
|
||||
nxt->m_start = pos;
|
||||
/* pos += nxt->m_Text.GivLength(); // la chaîne peut être plus courte (BOA supprimés)
|
||||
nxt->m_end = pos;
|
||||
pos += nxt->m_Sep.GivLength();*/
|
||||
pos += (p - pp); // taille totale
|
||||
nxt->m_end = pos - nxt->m_Sep.GivLength();
|
||||
pp = p;
|
||||
}
|
||||
|
||||
// ajoute un token comme terminateur
|
||||
// ( utile pour avoir le précédent )
|
||||
nxt = new CBotToken();
|
||||
nxt->m_type = 0;
|
||||
prv->m_next = nxt; // ajoute à la suite
|
||||
nxt->m_prev = prv;
|
||||
|
||||
return tokenbase;
|
||||
}
|
||||
|
||||
void CBotToken::Delete(CBotToken* pToken)
|
||||
{
|
||||
delete pToken;
|
||||
}
|
||||
|
||||
|
||||
// recherche si un mot fait parti des mots clefs
|
||||
|
||||
int CBotToken::GivKeyWords(const char* w)
|
||||
{
|
||||
int i;
|
||||
int l = m_ListKeyWords.GivSize();
|
||||
|
||||
if (l == 0)
|
||||
{
|
||||
LoadKeyWords(); // prend la liste la première fois
|
||||
l = m_ListKeyWords.GivSize();
|
||||
}
|
||||
|
||||
for (i = 0; i < l; i++)
|
||||
{
|
||||
if (m_ListKeyWords[i] == w) return m_ListIdKeyWords[ i ];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
BOOL CBotToken::GivKeyDefNum(const char* w, CBotToken* &token)
|
||||
{
|
||||
int i;
|
||||
int l = m_ListKeyDefine.GivSize();
|
||||
|
||||
for (i = 0; i < l; i++)
|
||||
{
|
||||
if (m_ListKeyDefine[i] == w)
|
||||
{
|
||||
token->m_IdKeyWord = m_ListKeyNums[i];
|
||||
token->m_type = TokenTypDef;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// reprend la liste des mots clefs dans les ressources
|
||||
|
||||
void CBotToken::LoadKeyWords()
|
||||
{
|
||||
CBotString s;
|
||||
int i, n = 0;
|
||||
|
||||
i = TokenKeyWord;
|
||||
while (s.LoadString(i))
|
||||
{
|
||||
m_ListKeyWords.Add(s);
|
||||
m_ListIdKeyWords[n++] = i++;
|
||||
}
|
||||
|
||||
i = TokenKeyDeclare;
|
||||
while (s.LoadString(i))
|
||||
{
|
||||
m_ListKeyWords.Add(s);
|
||||
m_ListIdKeyWords[n++] = i++;
|
||||
}
|
||||
|
||||
|
||||
i = TokenKeyVal;
|
||||
while (s.LoadString(i))
|
||||
{
|
||||
m_ListKeyWords.Add(s);
|
||||
m_ListIdKeyWords[n++] = i++;
|
||||
}
|
||||
|
||||
i = TokenKeyOp;
|
||||
while (s.LoadString(i))
|
||||
{
|
||||
m_ListKeyWords.Add(s);
|
||||
m_ListIdKeyWords[n++] = i++;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CBotToken::DefineNum(const char* name, long val)
|
||||
{
|
||||
int i;
|
||||
int l = m_ListKeyDefine.GivSize();
|
||||
|
||||
for (i = 0; i < l; i++)
|
||||
{
|
||||
if (m_ListKeyDefine[i] == name) return FALSE;
|
||||
}
|
||||
if ( i == MAXDEFNUM ) return FALSE;
|
||||
|
||||
m_ListKeyDefine.Add( name );
|
||||
m_ListKeyNums[i] = val;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL IsOfType(CBotToken* &p, int type1, int type2)
|
||||
{
|
||||
if (p->GivType() == type1 ||
|
||||
p->GivType() == type2 )
|
||||
{
|
||||
p = p->GivNext();
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// idem avec un nombre indéfini d'arguments
|
||||
// il faut mettre un zéro comme dernier argument
|
||||
BOOL IsOfTypeList(CBotToken* &p, int type1, ...)
|
||||
{
|
||||
int i = type1;
|
||||
int max = 20;
|
||||
int type = p->GivType();
|
||||
|
||||
va_list marker;
|
||||
va_start( marker, type1 ); /* Initialize variable arguments. */
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (type == i)
|
||||
{
|
||||
p = p->GivNext();
|
||||
va_end( marker ); /* Reset variable arguments. */
|
||||
return TRUE;
|
||||
}
|
||||
if (--max == 0 || 0 == (i = va_arg( marker, int)))
|
||||
{
|
||||
va_end( marker ); /* Reset variable arguments. */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// interpréteur pour le language CBot du jeu COLOBOT
|
||||
|
||||
|
||||
// un programme écrit est tout d'abord transformé en une liste de tokens
|
||||
// avant d'aborder le compilateur proprement dit
|
||||
// par exemple
|
||||
// int var = 3 * ( pos.y + x )
|
||||
// est décomposé en (chaque ligne est un token)
|
||||
// int
|
||||
// var
|
||||
// =
|
||||
// 3
|
||||
// *
|
||||
// (
|
||||
// pos.y
|
||||
// +
|
||||
// x
|
||||
// )
|
||||
|
||||
|
||||
extern BOOL IsOfType(CBotToken* &p, int type1, int type2 = -1);
|
||||
extern BOOL IsOfTypeList(CBotToken* &p, int type1, ...);
|
|
@ -0,0 +1,302 @@
|
|||
///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 + Opérande2
|
||||
// Opérande1 > Opérande2
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotTwoOpExpr::CBotTwoOpExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
||||
name = "CBotTwoOpExpr"; // debug
|
||||
}
|
||||
|
||||
CBotTwoOpExpr::~CBotTwoOpExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
// type d'opérandes acceptés par les opérations
|
||||
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
||||
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
||||
#define BOOLEEN (1<<CBotTypBoolean)
|
||||
#define CHAINE (1<<CBotTypString)
|
||||
#define CLASSE (1<<CBotTypClass)
|
||||
|
||||
// liste des opérations (précéance)
|
||||
static int ListOp[] =
|
||||
{
|
||||
BOOLEEN, ID_LOG_OR, 0,
|
||||
BOOLEEN, ID_LOG_AND, 0,
|
||||
BOOLEEN|ENTIER, ID_OR, 0,
|
||||
ENTIER, ID_XOR, 0,
|
||||
BOOLEEN|ENTIER, ID_AND, 0,
|
||||
BOOLEEN|ENTIER|FLOTANT, ID_EQ,
|
||||
BOOLEEN|ENTIER|FLOTANT, ID_NE, 0,
|
||||
ENTIER|FLOTANT, ID_HI,
|
||||
ENTIER|FLOTANT, ID_LO,
|
||||
ENTIER|FLOTANT, ID_HS,
|
||||
ENTIER|FLOTANT, ID_LS, 0,
|
||||
ENTIER, ID_SR,
|
||||
ENTIER, ID_SL,
|
||||
ENTIER, ID_ASR, 0,
|
||||
ENTIER|FLOTANT|CHAINE, ID_ADD,
|
||||
ENTIER|FLOTANT, ID_SUB, 0,
|
||||
ENTIER|FLOTANT, ID_MUL,
|
||||
ENTIER|FLOTANT, ID_DIV,
|
||||
ENTIER|FLOTANT, ID_MODULO, 0,
|
||||
0,
|
||||
};
|
||||
|
||||
BOOL IsInList( int val, int* list, int& typemasque )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
if ( *list == 0 ) return FALSE;
|
||||
typemasque = *list++;
|
||||
if ( *list++ == val ) return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL TypeOk( int type, int test )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
if ( type == 0 ) return (test & 1);
|
||||
type--; test /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
// compile une instruction de type A op B
|
||||
|
||||
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
||||
{
|
||||
int typemasque;
|
||||
|
||||
if ( pOperations == NULL ) pOperations = ListOp;
|
||||
int* pOp = pOperations;
|
||||
while ( *pOp++ != 0 ); // suite de la table
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
||||
|
||||
// cherche des instructions qui peuvent convenir à gauche de l'opération
|
||||
CBotInstr* left = CBotParExpr::Compile( p, pStk ) ; // expression (...) à gauche
|
||||
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
||||
|
||||
|
||||
CBotToken* pp = p;
|
||||
int TypeOp = pp->GetType(); // type d'opération
|
||||
p = p->Next(); // saute le token de l'opération
|
||||
|
||||
// cherche des instructions qui peuvent convenir à droite
|
||||
|
||||
CBotInstr* right = (*pOp == 0) ?
|
||||
CBotParExpr::Compile( p, pStk ) : // expression (...) à droite
|
||||
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A op B à droite
|
||||
|
||||
if (right == NULL) return pStack->Return(left, pStk); // pas d'opérande à droite ?
|
||||
|
||||
// est-ce qu'on a l'opération prévue entre les deux ?
|
||||
if ( IsInList( TypeOp, pOperations, typemasque ) )
|
||||
{
|
||||
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // élément pour opération
|
||||
inst->SetToken(pp); // mémorise l'opération
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStk->GetType(); // de quel type le premier opérande ?
|
||||
|
||||
inst->m_rightop = right;
|
||||
{
|
||||
// il y a un second opérande acceptable
|
||||
|
||||
type2 = pStk->GetType(); // de quel type le résultat ?
|
||||
|
||||
// quel est le type du résultat ?
|
||||
int TypeRes = MAX( type1, type2 );
|
||||
if (!TypeOk( TypeRes, typemasque )) type1 = 99; // erreur de type
|
||||
|
||||
switch ( TypeOp )
|
||||
{
|
||||
case ID_LOG_OR:
|
||||
case ID_LOG_AND:
|
||||
case ID_EQ:
|
||||
case ID_NE:
|
||||
case ID_HI:
|
||||
case ID_LO:
|
||||
case ID_HS:
|
||||
case ID_LS:
|
||||
TypeRes = CBotTypBoolean;
|
||||
}
|
||||
if ( TypeCompatible (type1, type2) || // les résultats sont-ils compatibles
|
||||
// cas particulier pour les concaténation de chaînes
|
||||
(TypeOp == ID_ADD && (type1 == CBotTypString || type2 == CBotTypString)))
|
||||
{
|
||||
// si ok, enregistre l'opérande dans l'objet
|
||||
inst->m_leftop = left;
|
||||
// met une variable sur la pile pour avoir le type de résultat
|
||||
pStk->SetVar(new CBotVar(NULL, TypeRes));
|
||||
// et rend l'object à qui l'a demandé
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
|
||||
}
|
||||
|
||||
// en cas d'erreur, libère les éléments
|
||||
delete left;
|
||||
delete inst;
|
||||
// et transmet l'erreur qui se trouve sur la pile
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// si on n'a pas affaire à une opération + ou -
|
||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
||||
// à la place de l'objet "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// fait l'opération d'addition ou de soustraction
|
||||
|
||||
BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
// if ( pStk1 == EOX ) return TRUE;
|
||||
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
|
||||
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
|
||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
// passe à l'étape suivante
|
||||
pStk1->SetState(1); // prêt pour la suite
|
||||
|
||||
// pour les OU et ET logique, n'évalue pas la seconde expression si pas nécessaire
|
||||
if ( GetTokenType() == ID_LOG_AND && pStk1->GetVal() == FALSE )
|
||||
{
|
||||
CBotVar* res = CBotVar::Create( NULL, CBotTypBoolean);
|
||||
res->SetValInt(FALSE);
|
||||
pStk1->SetVar(res);
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
if ( GetTokenType() == ID_LOG_OR && pStk1->GetVal() == TRUE )
|
||||
{
|
||||
CBotVar* res = CBotVar::Create( NULL, CBotTypBoolean);
|
||||
res->SetValInt(TRUE);
|
||||
pStk1->SetVar(res);
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
// qui se trouve sur la pile, justement.
|
||||
|
||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
|
||||
// 2e état, évalue l'opérande de droite
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
|
||||
int type1 = pStk1->GetType(); // de quels types les résultats ?
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
// crée une variable temporaire pour y mettre le résultat
|
||||
// quel est le type du résultat ?
|
||||
int TypeRes = MAX(type1, type2);
|
||||
switch ( GetTokenType() )
|
||||
{
|
||||
case ID_LOG_OR:
|
||||
case ID_LOG_AND:
|
||||
case ID_EQ:
|
||||
case ID_NE:
|
||||
case ID_HI:
|
||||
case ID_LO:
|
||||
case ID_HS:
|
||||
case ID_LS:
|
||||
TypeRes = CBotTypBoolean;
|
||||
}
|
||||
CBotVar* result = CBotVar::Create( NULL, TypeRes);
|
||||
CBotVar* temp = CBotVar::Create( NULL, MAX(type1, type2) );
|
||||
|
||||
int err = 0;
|
||||
// fait l'opération selon la demande
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_ADD:
|
||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
|
||||
break;
|
||||
case ID_SUB:
|
||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
|
||||
break;
|
||||
case ID_MUL:
|
||||
result->Mul(pStk1->GetVar(), pStk2->GetVar()); // multiplie
|
||||
break;
|
||||
case ID_DIV:
|
||||
err = result->Div(pStk1->GetVar(), pStk2->GetVar());// divise
|
||||
break;
|
||||
case ID_MODULO:
|
||||
err = result->Modulo(pStk1->GetVar(), pStk2->GetVar());// reste de division
|
||||
break;
|
||||
case ID_LO:
|
||||
temp->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_HI:
|
||||
temp->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_LS:
|
||||
temp->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_HS:
|
||||
temp->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_EQ:
|
||||
temp->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_NE:
|
||||
temp->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_LOG_AND:
|
||||
case ID_AND:
|
||||
result->And(pStk1->GetVar(), pStk2->GetVar()); // ET
|
||||
break;
|
||||
case ID_LOG_OR:
|
||||
case ID_OR:
|
||||
result->Or(pStk1->GetVar(), pStk2->GetVar()); // OU
|
||||
break;
|
||||
case ID_XOR:
|
||||
result->XOr(pStk1->GetVar(), pStk2->GetVar()); // OU exclusif
|
||||
break;
|
||||
case ID_ASR:
|
||||
result->ASR(pStk1->GetVar(), pStk2->GetVar());
|
||||
break;
|
||||
case ID_SR:
|
||||
result->SR(pStk1->GetVar(), pStk2->GetVar());
|
||||
break;
|
||||
case ID_SL:
|
||||
result->SL(pStk1->GetVar(), pStk2->GetVar());
|
||||
break;
|
||||
default:
|
||||
__asm int 3;
|
||||
}
|
||||
delete temp;
|
||||
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
if ( err ) pStk2->SetError(err, &m_token); // et l'erreur éventuelle (division par zéro)
|
||||
|
||||
pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,552 @@
|
|||
///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 + Opérande2
|
||||
// Opérande1 > Opérande2
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotTwoOpExpr::CBotTwoOpExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
||||
name = "CBotTwoOpExpr"; // debug
|
||||
}
|
||||
|
||||
CBotTwoOpExpr::~CBotTwoOpExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
CBotLogicExpr::CBotLogicExpr()
|
||||
{
|
||||
m_condition =
|
||||
m_op1 =
|
||||
m_op2 = NULL; // NULL pour pouvoir faire delete sans autre
|
||||
name = "CBotLogicExpr"; // debug
|
||||
}
|
||||
|
||||
CBotLogicExpr::~CBotLogicExpr()
|
||||
{
|
||||
delete m_condition;
|
||||
delete m_op1;
|
||||
delete m_op2;
|
||||
}
|
||||
|
||||
|
||||
// type d'opérandes acceptés par les opérations
|
||||
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
||||
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
||||
#define BOOLEEN (1<<CBotTypBoolean)
|
||||
#define CHAINE (1<<CBotTypString)
|
||||
#define POINTER (1<<CBotTypPointer)
|
||||
#define INSTANCE (1<<CBotTypClass)
|
||||
|
||||
// liste des opérations (précéance)
|
||||
// type acceptable, opérande
|
||||
// le zéro termine un niveau de précéance
|
||||
|
||||
static int ListOp[] =
|
||||
{
|
||||
BOOLEEN, ID_LOGIC, 0,
|
||||
BOOLEEN, ID_TXT_OR,
|
||||
BOOLEEN, ID_LOG_OR, 0,
|
||||
BOOLEEN, ID_TXT_AND,
|
||||
BOOLEEN, ID_LOG_AND, 0,
|
||||
BOOLEEN|ENTIER, ID_OR, 0,
|
||||
BOOLEEN|ENTIER, ID_XOR, 0,
|
||||
BOOLEEN|ENTIER, ID_AND, 0,
|
||||
BOOLEEN|ENTIER|FLOTANT
|
||||
|CHAINE
|
||||
|POINTER
|
||||
|INSTANCE,ID_EQ,
|
||||
BOOLEEN|ENTIER|FLOTANT
|
||||
|CHAINE
|
||||
|POINTER
|
||||
|INSTANCE,ID_NE, 0,
|
||||
ENTIER|FLOTANT|CHAINE, ID_HI,
|
||||
ENTIER|FLOTANT|CHAINE, ID_LO,
|
||||
ENTIER|FLOTANT|CHAINE, ID_HS,
|
||||
ENTIER|FLOTANT|CHAINE, ID_LS, 0,
|
||||
ENTIER, ID_SR,
|
||||
ENTIER, ID_SL,
|
||||
ENTIER, ID_ASR, 0,
|
||||
ENTIER|FLOTANT|CHAINE, ID_ADD,
|
||||
ENTIER|FLOTANT, ID_SUB, 0,
|
||||
ENTIER|FLOTANT, ID_MUL,
|
||||
ENTIER|FLOTANT, ID_DIV,
|
||||
ENTIER|FLOTANT, ID_MODULO, 0,
|
||||
ENTIER|FLOTANT, ID_POWER, 0,
|
||||
0,
|
||||
};
|
||||
|
||||
BOOL IsInList( int val, int* list, int& typemasque )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
if ( *list == 0 ) return FALSE;
|
||||
typemasque = *list++;
|
||||
if ( *list++ == val ) return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL TypeOk( int type, int test )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
if ( type == 0 ) return (test & 1);
|
||||
type--; test /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
// compile une instruction de type A op B
|
||||
|
||||
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
||||
{
|
||||
int typemasque;
|
||||
|
||||
if ( pOperations == NULL ) pOperations = ListOp;
|
||||
int* pOp = pOperations;
|
||||
while ( *pOp++ != 0 ); // suite de la table
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
||||
|
||||
// cherche des instructions qui peuvent convenir à gauche de l'opération
|
||||
CBotInstr* left = (*pOp == 0) ?
|
||||
CBotParExpr::Compile( p, pStk ) : // expression (...) à gauche
|
||||
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B à gauche
|
||||
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
||||
|
||||
// est-ce qu'on a l'opérande prévu ensuite ?
|
||||
int TypeOp = p->GivType();
|
||||
if ( IsInList( TypeOp, pOperations, typemasque ) )
|
||||
{
|
||||
CBotTypResult type1, type2;
|
||||
type1 = pStk->GivTypResult(); // de quel type le premier opérande ?
|
||||
|
||||
if ( TypeOp == ID_LOGIC ) // cas spécial pour condition ? op1 : op2 ;
|
||||
{
|
||||
if ( !type1.Eq(CBotTypBoolean) )
|
||||
{
|
||||
pStk->SetError( TX_BADTYPE, p);
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
CBotLogicExpr* inst = new CBotLogicExpr();
|
||||
inst->m_condition = left;
|
||||
|
||||
p = p->GivNext(); // saute le token de l'opération
|
||||
inst->m_op1 = CBotExpression::Compile(p, pStk);
|
||||
CBotToken* pp = p;
|
||||
if ( inst->m_op1 == NULL || !IsOfType( p, ID_DOTS ) )
|
||||
{
|
||||
pStk->SetError( TX_MISDOTS, p->GivStart());
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
type1 = pStk->GivTypResult();
|
||||
|
||||
inst->m_op2 = CBotExpression::Compile(p, pStk);
|
||||
if ( inst->m_op2 == NULL )
|
||||
{
|
||||
pStk->SetError( TX_ENDOF, p->GivStart() );
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
type2 = pStk->GivTypResult();
|
||||
if (!TypeCompatible(type1, type2))
|
||||
{
|
||||
pStk->SetError( TX_BAD2TYPE, pp );
|
||||
delete inst;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
pStk->SetType(type1); // le plus grand des 2 types
|
||||
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
|
||||
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // élément pour opération
|
||||
inst->SetToken(p); // mémorise l'opération
|
||||
|
||||
|
||||
p = p->GivNext(); // saute le token de l'opération
|
||||
|
||||
// cherche des instructions qui peuvent convenir à droite
|
||||
|
||||
if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) )
|
||||
// expression (...) à droite
|
||||
{
|
||||
// il y a un second opérande acceptable
|
||||
|
||||
type2 = pStk->GivTypResult(); // de quel type le résultat ?
|
||||
|
||||
// quel est le type du résultat ?
|
||||
int TypeRes = MAX( type1.GivType(3), type2.GivType(3) );
|
||||
if ( TypeOp == ID_ADD && type1.Eq(CBotTypString) )
|
||||
{
|
||||
TypeRes = CBotTypString;
|
||||
type2 = type1; // tout type convertible en chaîne
|
||||
}
|
||||
else if ( TypeOp == ID_ADD && type2.Eq(CBotTypString) )
|
||||
{
|
||||
TypeRes = CBotTypString;
|
||||
type1 = type2; // tout type convertible en chaîne
|
||||
}
|
||||
else if (!TypeOk( TypeRes, typemasque )) type1.SetType(99);// erreur de type
|
||||
|
||||
switch ( TypeOp )
|
||||
{
|
||||
case ID_LOG_OR:
|
||||
case ID_LOG_AND:
|
||||
case ID_TXT_OR:
|
||||
case ID_TXT_AND:
|
||||
case ID_EQ:
|
||||
case ID_NE:
|
||||
case ID_HI:
|
||||
case ID_LO:
|
||||
case ID_HS:
|
||||
case ID_LS:
|
||||
TypeRes = CBotTypBoolean;
|
||||
}
|
||||
if ( TypeCompatible (type1, type2, TypeOp ) ) // les résultats sont-ils compatibles
|
||||
{
|
||||
// si ok, enregistre l'opérande dans l'objet
|
||||
inst->m_leftop = left;
|
||||
|
||||
// spécial pour évaluer les opérations de même niveau de gauche à droite
|
||||
while ( IsInList( p->GivType(), pOperations, typemasque ) ) // même(s) opération(s) suit ?
|
||||
{
|
||||
TypeOp = p->GivType();
|
||||
CBotTwoOpExpr* i = new CBotTwoOpExpr(); // élément pour opération
|
||||
i->SetToken(p); // mémorise l'opération
|
||||
i->m_leftop = inst; // opérande de gauche
|
||||
type1 = TypeRes;
|
||||
|
||||
p = p->GivNext(); // avance à la suite
|
||||
i->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp );
|
||||
type2 = pStk->GivTypResult();
|
||||
|
||||
if ( !TypeCompatible (type1, type2, TypeOp) ) // les résultats sont-ils compatibles
|
||||
{
|
||||
pStk->SetError(TX_BAD2TYPE, &i->m_token);
|
||||
delete i;
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
if ( TypeRes != CBotTypString )
|
||||
TypeRes = MAX(type1.GivType(), type2.GivType());
|
||||
inst = i;
|
||||
}
|
||||
|
||||
CBotTypResult t(type1);
|
||||
t.SetType(TypeRes);
|
||||
// met une variable sur la pile pour avoir le type de résultat
|
||||
pStk->SetVar(CBotVar::Create((CBotToken*)NULL, t));
|
||||
|
||||
// et rend l'object à qui l'a demandé
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
|
||||
}
|
||||
|
||||
// en cas d'erreur, libère les éléments
|
||||
delete left;
|
||||
delete inst;
|
||||
// et transmet l'erreur qui se trouve sur la pile
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// si on n'a pas affaire à une opération + ou -
|
||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
||||
// à la place de l'objet "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
BOOL IsNan(CBotVar* left, CBotVar* right, int* err = NULL)
|
||||
{
|
||||
if ( left ->GivInit() > IS_DEF || right->GivInit() > IS_DEF )
|
||||
{
|
||||
if ( err != NULL ) *err = TX_OPNAN ;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// fait l'opération sur 2 opérandes
|
||||
|
||||
BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
// if ( pStk1 == EOX ) return TRUE;
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
|
||||
if ( pStk1->GivState() == 0 ) // 1er état, évalue l'opérande de gauche
|
||||
{
|
||||
if (!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
// pour les OU et ET logique, n'évalue pas la seconde expression si pas nécessaire
|
||||
if ( (GivTokenType() == ID_LOG_AND || GivTokenType() == ID_TXT_AND ) && pStk1->GivVal() == FALSE )
|
||||
{
|
||||
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
|
||||
res->SetValInt(FALSE);
|
||||
pStk1->SetVar(res);
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
if ( (GivTokenType() == ID_LOG_OR||GivTokenType() == ID_TXT_OR) && pStk1->GivVal() == TRUE )
|
||||
{
|
||||
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
|
||||
res->SetValInt(TRUE);
|
||||
pStk1->SetVar(res);
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
// passe à l'étape suivante
|
||||
pStk1->SetState(1); // prêt pour la suite
|
||||
}
|
||||
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
// qui se trouve sur la pile, justement.
|
||||
|
||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
|
||||
// 2e état, évalue l'opérande de droite
|
||||
if ( pStk2->GivState() == 0 )
|
||||
{
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
pStk2->IncState();
|
||||
}
|
||||
|
||||
CBotTypResult type1 = pStk1->GivTypResult(); // de quels types les résultats ?
|
||||
CBotTypResult type2 = pStk2->GivTypResult();
|
||||
|
||||
CBotStack* pStk3 = pStk2->AddStack(this); // ajoute un élément à la pile
|
||||
if ( pStk3->IfStep() ) return FALSE; // montre l'opération si step by step
|
||||
|
||||
// crée une variable temporaire pour y mettre le résultat
|
||||
// quel est le type du résultat ?
|
||||
int TypeRes = MAX(type1.GivType(), type2.GivType());
|
||||
|
||||
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
|
||||
{
|
||||
TypeRes = CBotTypString;
|
||||
}
|
||||
|
||||
switch ( GivTokenType() )
|
||||
{
|
||||
case ID_LOG_OR:
|
||||
case ID_LOG_AND:
|
||||
case ID_TXT_OR:
|
||||
case ID_TXT_AND:
|
||||
case ID_EQ:
|
||||
case ID_NE:
|
||||
case ID_HI:
|
||||
case ID_LO:
|
||||
case ID_HS:
|
||||
case ID_LS:
|
||||
TypeRes = CBotTypBoolean;
|
||||
break;
|
||||
case ID_DIV:
|
||||
TypeRes = MAX(TypeRes, CBotTypFloat);
|
||||
}
|
||||
|
||||
// crée une variable pour le résultat
|
||||
CBotVar* result = CBotVar::Create( (CBotToken*)NULL, TypeRes);
|
||||
|
||||
// crée une variable pour effectuer le calcul dans le type adapté
|
||||
TypeRes = MAX(type1.GivType(), type2.GivType());
|
||||
|
||||
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
|
||||
{
|
||||
TypeRes = CBotTypString;
|
||||
}
|
||||
|
||||
CBotVar* temp;
|
||||
|
||||
if ( TypeRes == CBotTypPointer ) TypeRes = CBotTypNullPointer;
|
||||
if ( TypeRes == CBotTypClass ) temp = CBotVar::Create( (CBotToken*)NULL, CBotTypResult(CBotTypIntrinsic, type1.GivClass() ) );
|
||||
else temp = CBotVar::Create( (CBotToken*)NULL, TypeRes );
|
||||
|
||||
int err = 0;
|
||||
// fait l'opération selon la demande
|
||||
CBotVar* left = pStk1->GivVar();
|
||||
CBotVar* right = pStk2->GivVar();
|
||||
|
||||
switch (GivTokenType())
|
||||
{
|
||||
case ID_ADD:
|
||||
if ( !IsNan(left, right, &err) ) result->Add(left , right); // additionne
|
||||
break;
|
||||
case ID_SUB:
|
||||
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // soustrait
|
||||
break;
|
||||
case ID_MUL:
|
||||
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplie
|
||||
break;
|
||||
case ID_POWER:
|
||||
if ( !IsNan(left, right, &err) ) result->Power(left , right); // puissance
|
||||
break;
|
||||
case ID_DIV:
|
||||
if ( !IsNan(left, right, &err) ) err = result->Div(left , right);// divise
|
||||
break;
|
||||
case ID_MODULO:
|
||||
if ( !IsNan(left, right, &err) ) err = result->Modulo(left , right);// reste de division
|
||||
break;
|
||||
case ID_LO:
|
||||
if ( !IsNan(left, right, &err) )
|
||||
result->SetValInt(temp->Lo(left , right)); // inférieur
|
||||
break;
|
||||
case ID_HI:
|
||||
if ( !IsNan(left, right, &err) )
|
||||
result->SetValInt(temp->Hi(left , right)); // supérieur
|
||||
break;
|
||||
case ID_LS:
|
||||
if ( !IsNan(left, right, &err) )
|
||||
result->SetValInt(temp->Ls(left , right)); // inférieur ou égal
|
||||
break;
|
||||
case ID_HS:
|
||||
if ( !IsNan(left, right, &err) )
|
||||
result->SetValInt(temp->Hs(left , right)); // supérieur ou égal
|
||||
break;
|
||||
case ID_EQ:
|
||||
if ( IsNan(left, right) )
|
||||
result->SetValInt(left->GivInit() == right->GivInit()) ;
|
||||
else
|
||||
result->SetValInt(temp->Eq(left , right)); // égal
|
||||
break;
|
||||
case ID_NE:
|
||||
if ( IsNan(left, right) )
|
||||
result->SetValInt(left ->GivInit() != right->GivInit()) ;
|
||||
else
|
||||
result->SetValInt(temp->Ne(left , right)); // différent
|
||||
break;
|
||||
case ID_TXT_AND:
|
||||
case ID_LOG_AND:
|
||||
case ID_AND:
|
||||
if ( !IsNan(left, right, &err) ) result->And(left , right); // ET
|
||||
break;
|
||||
case ID_TXT_OR:
|
||||
case ID_LOG_OR:
|
||||
case ID_OR:
|
||||
if ( !IsNan(left, right, &err) ) result->Or(left , right); // OU
|
||||
break;
|
||||
case ID_XOR:
|
||||
if ( !IsNan(left, right, &err) ) result->XOr(left , right); // OU exclusif
|
||||
break;
|
||||
case ID_ASR:
|
||||
if ( !IsNan(left, right, &err) ) result->ASR(left , right);
|
||||
break;
|
||||
case ID_SR:
|
||||
if ( !IsNan(left, right, &err) ) result->SR(left , right);
|
||||
break;
|
||||
case ID_SL:
|
||||
if ( !IsNan(left, right, &err) ) result->SL(left , right);
|
||||
break;
|
||||
default:
|
||||
__asm int 3;
|
||||
}
|
||||
delete temp;
|
||||
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
if ( err ) pStk2->SetError(err, &m_token); // et l'erreur éventuelle (division par zéro)
|
||||
|
||||
// pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk2); // transmet le résultat
|
||||
}
|
||||
|
||||
void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, BOOL bMain)
|
||||
{
|
||||
if ( !bMain ) return;
|
||||
CBotStack* pStk1 = pStack->RestoreStack(this); // ajoute un élément à la pile
|
||||
if ( pStk1 == NULL ) return;
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
|
||||
if ( pStk1->GivState() == 0 ) // 1er état, évalue l'opérande de gauche
|
||||
{
|
||||
m_leftop->RestoreState(pStk1, bMain); // interrompu ici !
|
||||
return;
|
||||
}
|
||||
|
||||
CBotStack* pStk2 = pStk1->RestoreStack(); // ajoute un élément à la pile
|
||||
if ( pStk2 == NULL ) return;
|
||||
|
||||
// 2e état, évalue l'opérande de droite
|
||||
if ( pStk2->GivState() == 0 )
|
||||
{
|
||||
m_rightop->RestoreState(pStk2, bMain); // interrompu ici !
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOL CBotLogicExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
// if ( pStk1 == EOX ) return TRUE;
|
||||
|
||||
if ( pStk1->GivState() == 0 )
|
||||
{
|
||||
if ( !m_condition->Execute(pStk1) ) return FALSE;
|
||||
if (!pStk1->SetState(1)) return FALSE;
|
||||
}
|
||||
|
||||
if ( pStk1->GivVal() == TRUE )
|
||||
{
|
||||
if ( !m_op1->Execute(pStk1) ) return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !m_op2->Execute(pStk1) ) return FALSE;
|
||||
}
|
||||
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
void CBotLogicExpr::RestoreState(CBotStack* &pStack, BOOL bMain)
|
||||
{
|
||||
if ( !bMain ) return;
|
||||
|
||||
CBotStack* pStk1 = pStack->RestoreStack(this); // ajoute un élément à la pile
|
||||
if ( pStk1 == NULL ) return;
|
||||
|
||||
if ( pStk1->GivState() == 0 )
|
||||
{
|
||||
m_condition->RestoreState(pStk1, bMain);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( pStk1->GivVal() == TRUE )
|
||||
{
|
||||
m_op1->RestoreState(pStk1, bMain);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_op2->RestoreState(pStk1, bMain);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void t()
|
||||
{
|
||||
int x,y;
|
||||
1>0 ? x = 0 : y = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 01
|
||||
void t(BOOL t)
|
||||
{
|
||||
int x;
|
||||
x = 1 + t ? 1 : 3 + 4 * 2 ;
|
||||
t ? 0 : "test";
|
||||
}
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,412 @@
|
|||
// ClassFile.cpp
|
||||
//
|
||||
// définition des méthodes pour la classe FILE
|
||||
|
||||
|
||||
|
||||
// Variables statiques
|
||||
|
||||
static CBotClass* m_pClassFILE;
|
||||
static CBotProgram* m_pFuncFile;
|
||||
static int m_CompteurFileOpen = 0;
|
||||
|
||||
|
||||
|
||||
// Prépare un nom de fichier.
|
||||
|
||||
void PrepareFilename(CBotString &filename) //DD!
|
||||
{
|
||||
int pos;
|
||||
|
||||
pos = filename.ReverseFind('\\');
|
||||
if ( pos > 0 )
|
||||
{
|
||||
filename = filename.Mid(pos+1); // enlève les dossiers
|
||||
}
|
||||
|
||||
pos = filename.ReverseFind('/');
|
||||
if ( pos > 0 )
|
||||
{
|
||||
filename = filename.Mid(pos+1); // aussi ceux avec /
|
||||
}
|
||||
|
||||
pos = filename.ReverseFind(':');
|
||||
if ( pos > 0 )
|
||||
{
|
||||
filename = filename.Mid(pos+1); // enlève aussi la lettre d'unité C:
|
||||
}
|
||||
|
||||
filename = CBotString("files\\") + filename;
|
||||
}
|
||||
|
||||
|
||||
// constructeur de la classe
|
||||
// reçois le nom du fichier en paramètre
|
||||
|
||||
// exécution
|
||||
BOOL rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
CBotString mode;
|
||||
|
||||
// accepte sans paramètre
|
||||
if ( pVar == NULL ) return TRUE;
|
||||
|
||||
// qui doit être une chaîne de caractères
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
||||
|
||||
CBotString filename = pVar->GivValString();
|
||||
PrepareFilename(filename); //DR
|
||||
|
||||
// il peut y avoir un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar != NULL )
|
||||
{
|
||||
// récupère le mode
|
||||
mode = pVar->GivValString();
|
||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
}
|
||||
|
||||
// enregistre le nom du fichier
|
||||
pVar = pThis->GivItem("filename");
|
||||
pVar->SetValString(filename);
|
||||
|
||||
if ( ! mode.IsEmpty() )
|
||||
{
|
||||
// ouvre le ficher demandé
|
||||
FILE* pFile = fopen( filename, mode );
|
||||
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return FALSE; }
|
||||
|
||||
m_CompteurFileOpen ++;
|
||||
|
||||
// enregiste le canal du fichier
|
||||
pVar = pThis->GivItem("handle");
|
||||
pVar->SetValInt((long)pFile);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compilation
|
||||
CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// accepte sans paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( 0 );
|
||||
|
||||
// qui doit être une chaine
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( CBotErrBadString );
|
||||
|
||||
// il peut y avoir un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar != NULL )
|
||||
{
|
||||
// qui doit être une chaine
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( CBotErrBadString );
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
}
|
||||
|
||||
// le résultat est de type void (constructeur)
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
|
||||
// destructeur de la classe
|
||||
|
||||
// exécution
|
||||
BOOL rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// récupère l'élément "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
// pas ouvert ? pas de problème
|
||||
if ( pVar->GivInit() != IS_DEF) return TRUE;
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
fclose(pFile);
|
||||
m_CompteurFileOpen --;
|
||||
|
||||
pVar->SetInit(IS_NAN);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// méthode FILE :: open
|
||||
// reçois le mode r/w en paramètre
|
||||
|
||||
// exécution
|
||||
BOOL rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// il doit y avoir un paramètre
|
||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
||||
|
||||
// qui doit être une chaîne de caractères
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
||||
|
||||
// il peut y avoir un second paramètre
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
// dans ce cas le premier paramètre est le nom du fichier
|
||||
CBotString filename = pVar->GivValString();
|
||||
PrepareFilename(filename); //DR
|
||||
|
||||
// enregistre le nom du fichier
|
||||
CBotVar* pVar2 = pThis->GivItem("filename");
|
||||
pVar2->SetValString(filename);
|
||||
|
||||
// paramètre suivant est le mode
|
||||
pVar = pVar -> GivNext();
|
||||
}
|
||||
|
||||
CBotString mode = pVar->GivValString();
|
||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
|
||||
// récupère l'élément "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
// qui doit pas être initialisé
|
||||
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return FALSE; }
|
||||
|
||||
// reprend le nom du fichier
|
||||
pVar = pThis->GivItem("filename");
|
||||
CBotString filename = pVar->GivValString();
|
||||
|
||||
PrepareFilename(filename); //DD! (si le nom a été attribué par h.filename = "...";
|
||||
|
||||
// ouvre le ficher demandé
|
||||
FILE* pFile = fopen( filename, mode );
|
||||
if ( pFile == NULL ) //DR
|
||||
{
|
||||
pResult->SetValInt(FALSE); //DR
|
||||
return TRUE; //DR
|
||||
}
|
||||
|
||||
m_CompteurFileOpen ++;
|
||||
|
||||
// enregiste le canal du fichier
|
||||
pVar = pThis->GivItem("handle");
|
||||
pVar->SetValInt((long)pFile);
|
||||
|
||||
pResult->SetValInt(TRUE); //DR
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compilation
|
||||
CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// il doit y avoir un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
|
||||
|
||||
// qui doit être une chaine
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( CBotErrBadString );
|
||||
|
||||
// il peut y avoir un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar != NULL )
|
||||
{
|
||||
// qui doit être une chaine
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( CBotErrBadString );
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
}
|
||||
|
||||
// le résultat est de type bool
|
||||
return CBotTypResult(CBotTypBoolean); //DR
|
||||
}
|
||||
|
||||
|
||||
// méthode FILE :: close
|
||||
|
||||
// exécution
|
||||
BOOL rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// il ne doit pas y avoir de paramètre
|
||||
if ( pVar != NULL ) return CBotErrOverParam;
|
||||
|
||||
// récupère l'élément "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
fclose(pFile);
|
||||
m_CompteurFileOpen --;
|
||||
|
||||
pVar->SetInit(IS_NAN);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compilation
|
||||
CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// il ne doit pas y avoir de paramètre
|
||||
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
|
||||
// la fonction retourne un résultat "void"
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
// méthode FILE :: writeln
|
||||
|
||||
// exécution
|
||||
BOOL rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// il doit y avoir un paramètre
|
||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
||||
|
||||
// qui doit être une chaîne de caractères
|
||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
||||
|
||||
CBotString param = pVar->GivValString();
|
||||
|
||||
// récupère l'élément "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
|
||||
int res = fputs(param+"\n", pFile);
|
||||
|
||||
// en cas d'erreur génère une exception
|
||||
if ( res < 0 ) { Exception = CBotErrWrite; return FALSE; }
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compilation
|
||||
CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// il doit y avoir un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
|
||||
|
||||
// qui doit être une chaîne de caractères
|
||||
if ( pVar->GivType() != CBotTypString ) return CBotTypResult( CBotErrBadString );
|
||||
|
||||
// pas d'autre paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
|
||||
// la fonction retourne un résultat void
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
// méthode FILE :: readln
|
||||
|
||||
// exécution
|
||||
BOOL rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// il ne doit pas y avoir de paramètre
|
||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
|
||||
// récupère l'élément "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
|
||||
char chaine[2000];
|
||||
int i;
|
||||
for ( i = 0 ; i < 2000 ; i++ ) chaine[i] = 0;
|
||||
|
||||
fgets(chaine, 1999, pFile);
|
||||
|
||||
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
|
||||
|
||||
// en cas d'erreur génère une exception
|
||||
if ( ferror(pFile) ) { Exception = CBotErrRead; return FALSE; }
|
||||
|
||||
pResult->SetValString( chaine );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compilation
|
||||
CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// il ne doit pas y avoir de paramètre
|
||||
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
|
||||
// la fonction retourne un résultat "string"
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
// méthode FILE :: readln
|
||||
|
||||
|
||||
// exécution
|
||||
BOOL rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||
{
|
||||
// il ne doit pas y avoir de paramètre
|
||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
||||
|
||||
// récupère l'élément "handle"
|
||||
pVar = pThis->GivItem("handle");
|
||||
|
||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
||||
|
||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||
|
||||
pResult->SetValInt( feof( pFile ) );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// compilation
|
||||
CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// il ne doit pas y avoir de paramètre
|
||||
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||
|
||||
// la fonction retourne un résultat booleen
|
||||
return CBotTypResult( CBotTypBoolean );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void InitClassFILE()
|
||||
{
|
||||
// crée une classe pour la gestion des fichiers
|
||||
// l'utilisation en est la suivante:
|
||||
// file canal( "NomFichier.txt" )
|
||||
// canal.open( "r" ); // ouvre en lecture
|
||||
// s = canal.readln( ); // lit une ligne
|
||||
// canal.close(); // referme le fichier
|
||||
|
||||
// crée la classe FILE
|
||||
m_pClassFILE = new CBotClass("file", NULL);
|
||||
// ajoute le composant ".filename"
|
||||
m_pClassFILE->AddItem("filename", CBotTypString);
|
||||
// ajoute le composant ".handle"
|
||||
m_pClassFILE->AddItem("handle", CBotTypInt, PR_PRIVATE);
|
||||
|
||||
// défini un constructeur et un destructeur
|
||||
m_pClassFILE->AddFunction("file", rfconstruct, cfconstruct );
|
||||
m_pClassFILE->AddFunction("~file", rfdestruct, NULL );
|
||||
|
||||
// défini les méthodes associées
|
||||
m_pClassFILE->AddFunction("open", rfopen, cfopen );
|
||||
m_pClassFILE->AddFunction("close", rfclose, cfclose );
|
||||
m_pClassFILE->AddFunction("writeln", rfwrite, cfwrite );
|
||||
m_pClassFILE->AddFunction("readln", rfread, cfread );
|
||||
m_pClassFILE->AddFunction("eof", rfeof, cfeof );
|
||||
|
||||
m_pFuncFile = new CBotProgram( );
|
||||
CBotStringArray ListFonctions;
|
||||
m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
|
||||
m_pFuncFile->SetIdent(-2); // identificateur spécial pour RestoreState dans cette fonction
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// French (France) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_IF "if"
|
||||
ID_ELSE "else"
|
||||
ID_WHILE "while"
|
||||
ID_DO "do"
|
||||
ID_ADD "+"
|
||||
ID_SUB "-"
|
||||
ID_MUL "*"
|
||||
ID_DIV "/"
|
||||
ID_OPENPAR "("
|
||||
ID_CLOSEPAR ")"
|
||||
ID_SEP ";"
|
||||
ID_INT "int"
|
||||
ID_ASS "="
|
||||
ID_TRUE "true"
|
||||
ID_FALSE "false"
|
||||
ID_OPBLK "{"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_CLBLK "}"
|
||||
ID_FOR "for"
|
||||
ID_COMMA ","
|
||||
ID_LO "<"
|
||||
ID_HI ">"
|
||||
ID_LS "<="
|
||||
ID_HS ">="
|
||||
ID_EQ "=="
|
||||
ID_NE "!="
|
||||
ID_FLOAT "float"
|
||||
ID_STRING "String"
|
||||
ID_BOOLEAN "boolean"
|
||||
ID_AND "&"
|
||||
ID_XOR "^"
|
||||
ID_OR "|"
|
||||
ID_LOG_AND "&&"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_OPENPAR "Il manque une parenthèse ouvrante."
|
||||
TX_CLOSEPAR "Il manque une parenthèse fermante."
|
||||
TX_NOTBOOL "L'expression doit être un boolean."
|
||||
TX_UNDEFVAR "Variable non déclarée."
|
||||
TX_BADLEFT "Assignation impossible."
|
||||
TX_ENDOF "Instruction non terminée."
|
||||
TX_OUTCASE "Instruction ""case"" hors d'un bloc ""switch""."
|
||||
TX_NOTERM "Instructions après la fin."
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_CLOSEBLK "Il manque la fin du bloc."
|
||||
TX_ELSEWITHOUTIF "Instruction ""else"" sans ""if"" correspondant."
|
||||
TX_OPENBLK "Début d'un bloc attendu."
|
||||
TX_BADTYPE "Mauvais type de résultat pour l'assignation."
|
||||
TX_REDEFVAR "Redéfinition d'une variable."
|
||||
TX_BAD2TYPE "Les deux opérandes ne sont pas de types compatibles."
|
||||
TX_UNDEFCALL "Routine inconnue."
|
||||
TX_MISDOTS "Séparateur "" : "" attendu."
|
||||
TX_WHILE "Manque le mot ""while""."
|
||||
TX_BREAK "Instruction ""break"" en dehors d'une boucle."
|
||||
TX_LABEL "Un label ne peut se placer que devant un ""for"", un ""while"", un ""do"" ou un ""switch""."
|
||||
TX_NOLABEL "Cette étiquette n'existe pas"
|
||||
TX_NOCASE "Manque une instruction ""case""."
|
||||
TX_BADNUM "Un nombre est attendu."
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_DIVZERO "Division par zéro."
|
||||
TX_NOTINIT "Variable non initialisée."
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_LOG_OR "||"
|
||||
ID_LOG_NOT "!"
|
||||
ID_NOT "~"
|
||||
ID_ASSADD "+="
|
||||
ID_ASSSUB "-="
|
||||
ID_ASSMUL "*="
|
||||
ID_ASSDIV "/="
|
||||
ID_ASSOR "|="
|
||||
ID_ASSAND "&="
|
||||
ID_ASSXOR "^="
|
||||
ID_ASSSL "<<="
|
||||
ID_ASSSR ">>>="
|
||||
ID_ASSASR ">>="
|
||||
ID_SL "<<"
|
||||
ID_SR ">>>"
|
||||
ID_ASR ">>"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_INC "++"
|
||||
ID_DEC "--"
|
||||
ID_MODULO "%"
|
||||
ID_ASSMODULO "%="
|
||||
ID_LOGIC "?"
|
||||
ID_DOTS ":"
|
||||
ID_BREAK "break"
|
||||
ID_SWITCH "switch"
|
||||
ID_CASE "case"
|
||||
ID_CONTINUE "continue"
|
||||
ID_TRY "try"
|
||||
ID_CATCH "catch"
|
||||
ID_THROW "throw"
|
||||
ID_FINALLY "finally"
|
||||
ID_DEFAULT "default"
|
||||
END
|
||||
|
||||
#endif // French (France) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
|
@ -0,0 +1,295 @@
|
|||
///////////////////////////////////////////////////
|
||||
// expression du genre Opérande1 + Opérande2
|
||||
// Opérande1 > Opérande2
|
||||
|
||||
#include "CBot.h"
|
||||
|
||||
// divers constructeurs
|
||||
|
||||
CBotTwoOpExpr::CBotTwoOpExpr()
|
||||
{
|
||||
m_leftop =
|
||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
||||
name = "CBotTwoOpExpr"; // debug
|
||||
}
|
||||
|
||||
CBotTwoOpExpr::~CBotTwoOpExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
// type d'opérandes acceptés par les opérations
|
||||
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
||||
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
||||
#define BOOLEEN (1<<CBotTypBoolean)
|
||||
#define CHAINE (1<<CBotTypString)
|
||||
#define CLASSE (1<<CBotTypClass)
|
||||
|
||||
// liste des opérations (précéance)
|
||||
static int ListOp[] =
|
||||
{
|
||||
BOOLEEN, ID_LOG_OR, 0,
|
||||
BOOLEEN, ID_LOG_AND, 0,
|
||||
BOOLEEN|ENTIER, ID_OR, 0,
|
||||
ENTIER, ID_XOR, 0,
|
||||
BOOLEEN|ENTIER, ID_AND, 0,
|
||||
BOOLEEN|ENTIER|FLOTANT, ID_EQ,
|
||||
BOOLEEN|ENTIER|FLOTANT, ID_NE, 0,
|
||||
ENTIER|FLOTANT, ID_HI,
|
||||
ENTIER|FLOTANT, ID_LO,
|
||||
ENTIER|FLOTANT, ID_HS,
|
||||
ENTIER|FLOTANT, ID_LS, 0,
|
||||
ENTIER, ID_SR,
|
||||
ENTIER, ID_SL,
|
||||
ENTIER, ID_ASR, 0,
|
||||
ENTIER|FLOTANT|CHAINE, ID_ADD,
|
||||
ENTIER|FLOTANT, ID_SUB, 0,
|
||||
ENTIER|FLOTANT, ID_MUL,
|
||||
ENTIER|FLOTANT, ID_DIV,
|
||||
ENTIER|FLOTANT, ID_MODULO, 0,
|
||||
0,
|
||||
};
|
||||
|
||||
BOOL IsInList( int val, int* list, int& typemasque )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
if ( *list == 0 ) return FALSE;
|
||||
typemasque = *list++;
|
||||
if ( *list++ == val ) return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL TypeOk( int type, int test )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
if ( type == 0 ) return (test & 1);
|
||||
type--; test /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
// compile une instruction de type A op B
|
||||
|
||||
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
||||
{
|
||||
int typemasque;
|
||||
|
||||
if ( pOperations == NULL ) pOperations = ListOp;
|
||||
int* pOp = pOperations;
|
||||
while ( *pOp++ != 0 ); // suite de la table
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
||||
|
||||
// cherche des instructions qui peuvent convenir à gauche de l'opération
|
||||
CBotInstr* left = (*pOp == 0) ?
|
||||
CBotParExpr::Compile( p, pStk ) : // expression (...) à gauche
|
||||
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B à gauche
|
||||
|
||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
||||
|
||||
// est-ce qu'on a l'opérande prévu ensuite ?
|
||||
int TypeOp = p->GetType();
|
||||
if ( IsInList( TypeOp, pOperations, typemasque ) )
|
||||
{
|
||||
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // élément pour opération
|
||||
inst->SetToken(p); // mémorise l'opération
|
||||
|
||||
int type1, type2;
|
||||
type1 = pStk->GetType(); // de quel type le premier opérande ?
|
||||
|
||||
p = p->Next(); // saute le token de l'opération
|
||||
|
||||
// cherche des instructions qui peuvent convenir à droite
|
||||
|
||||
if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOperations )) )
|
||||
// expression (...) à droite
|
||||
{
|
||||
// il y a un second opérande acceptable
|
||||
|
||||
type2 = pStk->GetType(); // de quel type le résultat ?
|
||||
|
||||
// quel est le type du résultat ?
|
||||
int TypeRes = MAX( type1, type2 );
|
||||
if (!TypeOk( TypeRes, typemasque )) type1 = 99; // erreur de type
|
||||
|
||||
switch ( TypeOp )
|
||||
{
|
||||
case ID_LOG_OR:
|
||||
case ID_LOG_AND:
|
||||
case ID_EQ:
|
||||
case ID_NE:
|
||||
case ID_HI:
|
||||
case ID_LO:
|
||||
case ID_HS:
|
||||
case ID_LS:
|
||||
TypeRes = CBotTypBoolean;
|
||||
}
|
||||
if ( TypeCompatible (type1, type2) || // les résultats sont-ils compatibles
|
||||
// cas particulier pour les concaténation de chaînes
|
||||
(TypeOp == ID_ADD && (type1 == CBotTypString || type2 == CBotTypString)))
|
||||
{
|
||||
// si ok, enregistre l'opérande dans l'objet
|
||||
inst->m_leftop = left;
|
||||
// met une variable sur la pile pour avoir le type de résultat
|
||||
pStk->SetVar(new CBotVar(NULL, TypeRes));
|
||||
// et rend l'object à qui l'a demandé
|
||||
return pStack->Return(inst, pStk);
|
||||
}
|
||||
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
|
||||
}
|
||||
|
||||
// en cas d'erreur, libère les éléments
|
||||
delete left;
|
||||
delete inst;
|
||||
// et transmet l'erreur qui se trouve sur la pile
|
||||
return pStack->Return(NULL, pStk);
|
||||
}
|
||||
|
||||
// si on n'a pas affaire à une opération + ou -
|
||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
||||
// à la place de l'objet "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// fait l'opération d'addition ou de soustraction
|
||||
|
||||
BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||
{
|
||||
CBotStack* pStk1 = pStack->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
|
||||
// selon la reprise, on peut être dans l'un des 2 états
|
||||
|
||||
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
|
||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
||||
|
||||
// passe à l'étape suivante
|
||||
pStk1->SetState(1); // prêt pour la suite
|
||||
|
||||
// pour les OU et ET logique, n'évalue pas la seconde expression si pas nécessaire
|
||||
if ( GetTokenType() == ID_LOG_AND && pStk1->GetVal() == FALSE )
|
||||
{
|
||||
CBotVar* res = CBotVar::Create( NULL, CBotTypBoolean);
|
||||
res->SetValInt(FALSE);
|
||||
pStk1->SetVar(res);
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
if ( GetTokenType() == ID_LOG_OR && pStk1->GetVal() == TRUE )
|
||||
{
|
||||
CBotVar* res = CBotVar::Create( NULL, CBotTypBoolean);
|
||||
res->SetValInt(TRUE);
|
||||
pStk1->SetVar(res);
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
||||
// qui se trouve sur la pile, justement.
|
||||
|
||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
||||
// ou le retrouve en cas de reprise
|
||||
|
||||
// 2e état, évalue l'opérande de droite
|
||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
||||
|
||||
int type1 = pStk1->GetType(); // de quels types les résultats ?
|
||||
int type2 = pStk2->GetType();
|
||||
|
||||
// crée une variable temporaire pour y mettre le résultat
|
||||
// quel est le type du résultat ?
|
||||
int TypeRes = MAX(type1, type2);
|
||||
switch ( GetTokenType() )
|
||||
{
|
||||
case ID_LOG_OR:
|
||||
case ID_LOG_AND:
|
||||
case ID_EQ:
|
||||
case ID_NE:
|
||||
case ID_HI:
|
||||
case ID_LO:
|
||||
case ID_HS:
|
||||
case ID_LS:
|
||||
TypeRes = CBotTypBoolean;
|
||||
}
|
||||
CBotVar* result = CBotVar::Create( NULL, TypeRes);
|
||||
CBotVar* temp = CBotVar::Create( NULL, MAX(type1, type2) );
|
||||
|
||||
int err = 0;
|
||||
// fait l'opération selon la demande
|
||||
switch (GetTokenType())
|
||||
{
|
||||
case ID_ADD:
|
||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
|
||||
break;
|
||||
case ID_SUB:
|
||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
|
||||
break;
|
||||
case ID_MUL:
|
||||
result->Mul(pStk1->GetVar(), pStk2->GetVar()); // multiplie
|
||||
break;
|
||||
case ID_DIV:
|
||||
err = result->Div(pStk1->GetVar(), pStk2->GetVar());// divise
|
||||
break;
|
||||
case ID_MODULO:
|
||||
err = result->Modulo(pStk1->GetVar(), pStk2->GetVar());// reste de division
|
||||
break;
|
||||
case ID_LO:
|
||||
temp->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_HI:
|
||||
temp->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_LS:
|
||||
temp->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_HS:
|
||||
temp->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_EQ:
|
||||
temp->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_NE:
|
||||
temp->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
|
||||
result->SetValInt(temp->GetValInt()); // converti le résultat
|
||||
break;
|
||||
case ID_LOG_AND:
|
||||
case ID_AND:
|
||||
result->And(pStk1->GetVar(), pStk2->GetVar()); // ET
|
||||
break;
|
||||
case ID_LOG_OR:
|
||||
case ID_OR:
|
||||
result->Or(pStk1->GetVar(), pStk2->GetVar()); // OU
|
||||
break;
|
||||
case ID_XOR:
|
||||
result->XOr(pStk1->GetVar(), pStk2->GetVar()); // OU exclusif
|
||||
break;
|
||||
case ID_ASR:
|
||||
result->ASR(pStk1->GetVar(), pStk2->GetVar());
|
||||
break;
|
||||
case ID_SR:
|
||||
result->SR(pStk1->GetVar(), pStk2->GetVar());
|
||||
break;
|
||||
case ID_SL:
|
||||
result->SL(pStk1->GetVar(), pStk2->GetVar());
|
||||
break;
|
||||
default:
|
||||
__asm int 3;
|
||||
}
|
||||
delete temp;
|
||||
|
||||
pStk2->SetVar(result); // met le résultat sur la pile
|
||||
if ( err ) pStk2->SetError(err, &m_token); // et l'erreur éventuelle (division par zéro)
|
||||
|
||||
pStk1->Return(pStk2); // libère la pile
|
||||
return pStack->Return(pStk1); // transmet le résultat
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,420 @@
|
|||
// définition des fonctions sur les chaînes
|
||||
|
||||
|
||||
// donne la longueur d'une chaîne
|
||||
// exécution
|
||||
|
||||
BOOL rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// pas de second paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// met la longueur sur la pile
|
||||
pResult->SetValInt( s.GivLength() );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// int xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADPARAM );
|
||||
|
||||
// pas de second paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est un nombre entier
|
||||
return CBotTypResult( CBotTypInt );
|
||||
}
|
||||
|
||||
|
||||
// donne la partie gauche d'une chaîne
|
||||
// exécution
|
||||
|
||||
BOOL rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
|
||||
|
||||
// récupère ce nombre
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
// prend la partie intéressante
|
||||
s = s.Left( n );
|
||||
|
||||
// la met sur la pile
|
||||
pResult->SetValString( s );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// string xxx ( string, int )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est une string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
// donne la partie droite d'une chaîne
|
||||
// exécution
|
||||
|
||||
BOOL rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
|
||||
|
||||
// récupère ce nombre
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
// prend la partie intéressante
|
||||
s = s.Right( n );
|
||||
|
||||
// la met sur la pile
|
||||
pResult->SetValString( s );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// donne la partie centrale d'une chaîne
|
||||
// exécution
|
||||
|
||||
BOOL rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
|
||||
|
||||
// récupère ce nombre
|
||||
int n = pVar->GivValInt();
|
||||
|
||||
// 3e paramètre optionnel
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
|
||||
|
||||
// récupère ce nombre
|
||||
int l = pVar->GivValInt();
|
||||
|
||||
// mais pas de 4e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
// prend la partie intéressante
|
||||
s = s.Mid( n, l );
|
||||
}
|
||||
else
|
||||
{
|
||||
// prend la partie intéressante
|
||||
s = s.Mid( n );
|
||||
}
|
||||
|
||||
// la met sur la pile
|
||||
pResult->SetValString( s );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// donne la partie centrale d'une chaîne
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// 3e paramètre optionnel
|
||||
if ( pVar->GivNext() != NULL )
|
||||
{
|
||||
|
||||
pVar = pVar->GivNext();
|
||||
// qui doit être un nombre
|
||||
if ( pVar->GivType() > CBotTypDouble )
|
||||
return CBotTypResult( TX_BADNUM );
|
||||
|
||||
// pas de 4e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
}
|
||||
|
||||
// le résultat final est une string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
|
||||
// donne le nombre contenu dans une chaîne
|
||||
// exécution
|
||||
|
||||
BOOL rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// mais pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
float val = GivNumFloat(s);
|
||||
|
||||
// la met la valeur sur la pile
|
||||
pResult->SetValFloat( val );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// float xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est un nombre
|
||||
return CBotTypResult( CBotTypFloat );
|
||||
}
|
||||
|
||||
|
||||
// trouve une chaine dans une autre
|
||||
// exécution
|
||||
|
||||
BOOL rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// récupère ce nombre
|
||||
CBotString s2 = pVar->GivValString();
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
// met le résultat sur la pile
|
||||
int res = s.Find(s2);
|
||||
pResult->SetValInt( res );
|
||||
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// int xxx ( string, string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// il faut un second paramètre
|
||||
pVar = pVar->GivNext();
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// pas de 3e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est un nombre
|
||||
return CBotTypResult( CBotTypInt );
|
||||
}
|
||||
|
||||
// donne une chaine en majuscule
|
||||
// exécution
|
||||
|
||||
BOOL rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// mais pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
|
||||
s.MakeUpper();
|
||||
|
||||
// la met la valeur sur la pile
|
||||
pResult->SetValString( s );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// donne une chaine en minuscules
|
||||
// exécution
|
||||
|
||||
BOOL rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
|
||||
|
||||
// recupére le contenu de la string
|
||||
CBotString s = pVar->GivValString();
|
||||
|
||||
// mais pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
|
||||
|
||||
|
||||
s.MakeLower();
|
||||
|
||||
// la met la valeur sur la pile
|
||||
pResult->SetValString( s );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// string xxx ( string )
|
||||
// compilation
|
||||
|
||||
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
// il faut un paramètre
|
||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||
|
||||
// qui doit être une string
|
||||
if ( pVar->GivType() != CBotTypString )
|
||||
return CBotTypResult( TX_BADSTRING );
|
||||
|
||||
// pas de 2e paramètre
|
||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||
|
||||
// le résultat final est une string
|
||||
return CBotTypResult( CBotTypString );
|
||||
}
|
||||
|
||||
|
||||
void InitStringFunctions()
|
||||
{
|
||||
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
|
||||
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
|
||||
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
|
||||
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
|
||||
|
||||
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
|
||||
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
|
||||
|
||||
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
|
||||
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
float [ ] TEST2 ( int [ ] param )
|
||||
{
|
||||
float [ ] z;
|
||||
for ( int i = 0 ; i < sizeof( param ) ; i++ ) try { z [i] = param [i] / 3; }
|
||||
return z;
|
||||
}
|
||||
|
||||
extern public void T()
|
||||
{
|
||||
int a [4];
|
||||
for ( int i = 0 ; i < 3 ; i++ ) a[i] = 4*i;
|
||||
a [2] = 22;
|
||||
|
||||
float [] b ;
|
||||
b = TEST2 ( a ) ;
|
||||
show ( a, b );
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
object object :: TT ( int n )
|
||||
{
|
||||
object XX = radar();
|
||||
if ( n == 0 ) return null;
|
||||
|
||||
while ( null == XX ) XX = radar();
|
||||
return XX;
|
||||
}
|
||||
|
||||
extern void object::Attack( )
|
||||
{
|
||||
show ( TT ( 0 ) ) ;
|
||||
show ( TT ( 1 ) ) ;
|
||||
return;
|
||||
|
||||
int list[];
|
||||
int i;
|
||||
object p;
|
||||
float dist, prox;
|
||||
point dest;
|
||||
boolean advance = true;
|
||||
|
||||
TEST(0); // ne stoppe pas si erreur
|
||||
// while ( F () != 0 ) F(1);
|
||||
|
||||
i = 0;
|
||||
list[i++] = WingedGrabber;
|
||||
list[i++] = TrackedGrabber;
|
||||
list[i++] = WheeledGrabber;
|
||||
list[i++] = LeggedGrabber;
|
||||
list[i++] = WingedShooter;
|
||||
list[i++] = TrackedShooter;
|
||||
list[i++] = WheeledShooter;
|
||||
list[i++] = LeggedShooter;
|
||||
list[i++] = WingedOrgaShooter;
|
||||
list[i++] = TrackedOrgaShooter;
|
||||
list[i++] = WheeledOrgaShooter;
|
||||
list[i++] = LeggedOrgaShooter;
|
||||
list[i++] = WingedSniffer;
|
||||
list[i++] = TrackedSniffer;
|
||||
list[i++] = WheeledSniffer;
|
||||
list[i++] = LeggedSniffer;
|
||||
list[i++] = Thumper;
|
||||
list[i++] = PhazerShooter;
|
||||
list[i++] = Recycler;
|
||||
list[i++] = Shielder;
|
||||
list[i++] = Subber;
|
||||
list[i++] = Me;
|
||||
list[i++] = 3333;
|
||||
list[i++] = 3334;
|
||||
list[i++] = 3335;
|
||||
list[i++] = 3336;
|
||||
list[i++] = 3337;
|
||||
list[i++] = 3338;
|
||||
list[i++] = 3339;
|
||||
list[i++] = 3331;
|
||||
list[i++] = 3332;
|
||||
list[i++] = 3330;
|
||||
list[i++] = 1111;
|
||||
list[i++] = 1112;
|
||||
|
||||
F(F(0));
|
||||
|
||||
while ( true )
|
||||
{
|
||||
p = radar(list, 0, 360, 0, 1000);
|
||||
if ( p == null )
|
||||
{
|
||||
F(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = F(p.position, position);
|
||||
if ( dist <= 40 && !advance )
|
||||
{
|
||||
fire(p.position);
|
||||
advance = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//? if ( RetBaseDistance() > 20 )
|
||||
{
|
||||
prox = dist-(5+F()*5);
|
||||
if ( prox < 5 ) prox = 5;
|
||||
dest.x = (position.x-p.position.x)*prox/dist + p.position.x;
|
||||
dest.y = (position.y-p.position.y)*prox/dist + p.position.y;
|
||||
dest.z = (position.z-p.position.z)*prox/dist + p.position.z;
|
||||
goto(dest);
|
||||
advance = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calcule la distance jusqu'à la base.
|
||||
|
||||
float object::RetBaseDistance()
|
||||
{
|
||||
object p;
|
||||
float dist;
|
||||
|
||||
p = radar(4444, 0, 360, 0, 1000);
|
||||
if ( p == null ) return 1000;
|
||||
dist = F(p.position, position);
|
||||
return dist;
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
// CBotConsoleDlg.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestCBot.h"
|
||||
#include "CBotConsoleDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CBotConsoleDlg dialog
|
||||
|
||||
|
||||
CBotConsoleDlg::CBotConsoleDlg(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CBotConsoleDlg::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CBotConsoleDlg)
|
||||
// NOTE: the ClassWizard will add member initialization here
|
||||
//}}AFX_DATA_INIT
|
||||
m_pProg = NULL;
|
||||
m_threadinfo.m_bRun = FALSE;
|
||||
m_code = 0;
|
||||
}
|
||||
|
||||
|
||||
void CBotConsoleDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CBotConsoleDlg)
|
||||
DDX_Control(pDX, IDOK, m_cOK);
|
||||
DDX_Control(pDX, IDC_EDIT2, m_Edit2);
|
||||
DDX_Control(pDX, IDC_EDIT1, m_Edit1);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CBotConsoleDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(CBotConsoleDlg)
|
||||
ON_MESSAGE(WM_ENDPROG, EndProg)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CBotConsoleDlg message handlers
|
||||
|
||||
UINT ThreadProc(ThreadInfo *info)
|
||||
{
|
||||
CTime t0 = CTime::GetCurrentTime();
|
||||
int Cpt = 0;
|
||||
|
||||
info->m_pProg->Start("LaCommande");
|
||||
while ( !info->m_bStop && !info->m_pProg->Run() )
|
||||
{
|
||||
#if 0
|
||||
const char* FunctionName;
|
||||
const char* FN;
|
||||
int start, end;
|
||||
|
||||
info->m_pProg->GetRunPos(FunctionName, start, end);
|
||||
|
||||
if ( FunctionName != NULL )
|
||||
{
|
||||
info->m_pEditx->SetSel(start, end);
|
||||
|
||||
char buffer[200];
|
||||
sprintf( buffer, "step %s, %d, %d",FunctionName, start, end);
|
||||
AfxMessageBox( buffer );
|
||||
|
||||
int level = 0;
|
||||
do
|
||||
{
|
||||
CBotVar* t = info->m_pProg->GivStackVars(FN, level--);
|
||||
if ( FN != FunctionName ) break;
|
||||
if ( t != NULL )
|
||||
{
|
||||
CString s ;
|
||||
while ( t != NULL )
|
||||
{
|
||||
if (s.IsEmpty()) s+= "Stack -> ";
|
||||
else s+= " , ";
|
||||
s += t->GivValString();
|
||||
t = t->GivNext();
|
||||
}
|
||||
AfxMessageBox(s);
|
||||
}
|
||||
} while (TRUE);
|
||||
}
|
||||
#endif
|
||||
Cpt++;
|
||||
if ( Cpt%50 == 0 ) info->m_pEdit1->ReplaceSel(".");
|
||||
}
|
||||
|
||||
if ( info->m_bStop )
|
||||
{
|
||||
info->m_pEdit1->ReplaceSel("\r\nInterrompu\r\n");
|
||||
}
|
||||
else if (info->m_pProg->GivError() == 0)
|
||||
{
|
||||
CTime t = CTime::GetCurrentTime();
|
||||
CTimeSpan ts = t - t0;
|
||||
|
||||
char buffer[200];
|
||||
sprintf( buffer, "\r\nExécution terminée en %d secondes.\r\nInterrompue %d fois.\r\n",
|
||||
ts.GetTotalSeconds(), Cpt);
|
||||
|
||||
info->m_pEdit1->ReplaceSel(buffer);
|
||||
}
|
||||
|
||||
info->m_pWndMessage->SendMessage(WM_ENDPROG, 0, 0) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
LONG CBotConsoleDlg::EndProg(UINT wparam, LONG lparam)
|
||||
{
|
||||
m_threadinfo.m_bRun = FALSE;
|
||||
|
||||
if (m_pProg->GetError(m_code, m_start, m_end))
|
||||
{
|
||||
CBotString TextError;
|
||||
TextError = CBotProgram::GivErrorText(m_code);
|
||||
AfxMessageBox(TextError);
|
||||
CDialog::OnCancel();
|
||||
return 1;
|
||||
}
|
||||
delete m_pProg;
|
||||
m_pProg = NULL;
|
||||
|
||||
m_Edit2.EnableWindow(TRUE);
|
||||
m_cOK.EnableWindow(TRUE);
|
||||
|
||||
m_Edit2.SetWindowText("");
|
||||
m_Edit2.SetFocus();
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
void CBotConsoleDlg::OnOK()
|
||||
{
|
||||
CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp();
|
||||
pApp->m_pConsole = &m_Edit1;
|
||||
m_code = 0;
|
||||
|
||||
CString Commande;
|
||||
m_Edit2.GetWindowText(Commande);
|
||||
|
||||
CString s = "void LaCommande() { " + Commande + " ;}";
|
||||
m_pProg = new CBotProgram();
|
||||
CBotStringArray liste;
|
||||
m_pProg->Compile(s, liste);
|
||||
|
||||
int err, start, end;
|
||||
if ( m_pProg->GetError(err, start, end) )
|
||||
{
|
||||
CBotString TextError;
|
||||
TextError = CBotProgram::GivErrorText(err);
|
||||
AfxMessageBox(TextError);
|
||||
m_Edit2.SetSel(start-20, end-20);
|
||||
return;
|
||||
}
|
||||
|
||||
m_Edit1.ReplaceSel("\r\n" + Commande + " ->\r\n");
|
||||
|
||||
m_Edit2.SetWindowText("");
|
||||
m_Edit1.SetFocus();
|
||||
m_Edit2.EnableWindow(FALSE);
|
||||
m_cOK.EnableWindow(FALSE);
|
||||
|
||||
// lance un processus paralèle pour l'exécution
|
||||
m_threadinfo.m_pWndMessage = this ;
|
||||
|
||||
m_threadinfo.m_pEdit1 = &m_Edit1;
|
||||
m_threadinfo.m_pEditx = m_pEditx;
|
||||
m_threadinfo.m_pProg = m_pProg;
|
||||
m_threadinfo.m_bStop = FALSE;
|
||||
m_threadinfo.m_bRun = TRUE;
|
||||
|
||||
AfxBeginThread((AFX_THREADPROC)ThreadProc, &m_threadinfo) ;
|
||||
}
|
||||
|
||||
void CBotConsoleDlg::OnCancel()
|
||||
{
|
||||
if (!m_threadinfo.m_bRun) CDialog::OnCancel();
|
||||
m_threadinfo.m_bStop = TRUE ;
|
||||
}
|
||||
|
||||
|
||||
BOOL CBotConsoleDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
m_Edit1.ReplaceSel("Les fonctions suivantes sont disponibles:\r\n");
|
||||
for ( int i = 0; i < m_pListe->GivSize(); i++ )
|
||||
{
|
||||
CBotString x = (*m_pListe)[i] + "\r\n";
|
||||
m_Edit1.ReplaceSel(x);
|
||||
}
|
||||
m_Edit1.ReplaceSel("Entrez une commande ci-dessous.\r\n\r\n");
|
||||
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
#if !defined(AFX_BOTCONSOLEDLG_H__A11450A2_8E09_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_BOTCONSOLEDLG_H__A11450A2_8E09_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
// CBotConsoleDlg.h : header file
|
||||
//
|
||||
|
||||
struct ThreadInfo
|
||||
{
|
||||
CEdit* m_pEdit1 ;
|
||||
CEdit* m_pEditx ;
|
||||
CBotProgram* m_pProg;
|
||||
CWnd* m_pWndMessage;
|
||||
BOOL m_bStop;
|
||||
BOOL m_bRun;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CBotConsoleDlg dialog
|
||||
|
||||
class CBotConsoleDlg : public CDialog
|
||||
{
|
||||
// Construction
|
||||
public:
|
||||
CBotConsoleDlg(CWnd* pParent = NULL); // standard constructor
|
||||
|
||||
// Dialog Data
|
||||
//{{AFX_DATA(CBotConsoleDlg)
|
||||
enum { IDD = IDD_CONSOLE };
|
||||
CButton m_cOK;
|
||||
CEdit m_Edit2;
|
||||
CEdit m_Edit1;
|
||||
//}}AFX_DATA
|
||||
|
||||
CBotProgram* m_pProg;
|
||||
ThreadInfo m_threadinfo;
|
||||
|
||||
CBotStringArray*
|
||||
m_pListe;
|
||||
int m_code, m_start, m_end;
|
||||
CEdit* m_pEditx;
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CBotConsoleDlg)
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
protected:
|
||||
|
||||
// Generated message map functions
|
||||
//{{AFX_MSG(CBotConsoleDlg)
|
||||
virtual void OnOK();
|
||||
virtual void OnCancel();
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg LONG EndProg(UINT wparam, LONG lparam) ;
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_BOTCONSOLEDLG_H__A11450A2_8E09_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,58 @@
|
|||
// ChildFrm.cpp : implementation of the CChildFrame class
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestCBot.h"
|
||||
|
||||
#include "ChildFrm.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CChildFrame
|
||||
|
||||
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
|
||||
//{{AFX_MSG_MAP(CChildFrame)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CChildFrame construction/destruction
|
||||
|
||||
CChildFrame::CChildFrame()
|
||||
{
|
||||
}
|
||||
|
||||
CChildFrame::~CChildFrame()
|
||||
{
|
||||
}
|
||||
|
||||
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
|
||||
{
|
||||
return CMDIChildWnd::PreCreateWindow(cs);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CChildFrame diagnostics
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CChildFrame::AssertValid() const
|
||||
{
|
||||
CMDIChildWnd::AssertValid();
|
||||
}
|
||||
|
||||
void CChildFrame::Dump(CDumpContext& dc) const
|
||||
{
|
||||
CMDIChildWnd::Dump(dc);
|
||||
}
|
||||
|
||||
#endif //_DEBUG
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CChildFrame message handlers
|
|
@ -0,0 +1,50 @@
|
|||
// ChildFrm.h : interface of the CChildFrame class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CHILDFRM_H__4D1BB909_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_CHILDFRM_H__4D1BB909_8E74_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
class CChildFrame : public CMDIChildWnd
|
||||
{
|
||||
DECLARE_DYNCREATE(CChildFrame)
|
||||
public:
|
||||
CChildFrame();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CChildFrame)
|
||||
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CChildFrame();
|
||||
#ifdef _DEBUG
|
||||
virtual void AssertValid() const;
|
||||
virtual void Dump(CDumpContext& dc) const;
|
||||
#endif
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CChildFrame)
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_CHILDFRM_H__4D1BB909_8E74_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,23 @@
|
|||
public extern void object :: ESSAI()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
if ( true )
|
||||
{
|
||||
goto(12);
|
||||
break;
|
||||
}
|
||||
}
|
||||
object x = null ;
|
||||
|
||||
while ( x == null ) x = radar();
|
||||
|
||||
show ( x.position ) ;
|
||||
|
||||
TEST(5, x);
|
||||
|
||||
if ( x == null ) show ( "DELETED" );
|
||||
|
||||
show ( x.position ) ;
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
class MaClass
|
||||
{
|
||||
int a = 1 ;
|
||||
MaClass pointeur ;
|
||||
MaClass next = null ;
|
||||
CPoint autre = new CPoint( 1 , 1 ) ;
|
||||
}
|
||||
|
||||
extern public void Test ( )
|
||||
{
|
||||
MaClass x () ;
|
||||
x.next = new MaClass ( ) ;
|
||||
println ( x ) ;
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
// MainFrm.cpp : implementation of the CMainFrame class
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestCBot.h"
|
||||
|
||||
#include "MainFrm.h"
|
||||
#include "TestCBotDoc.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame
|
||||
|
||||
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
|
||||
//{{AFX_MSG_MAP(CMainFrame)
|
||||
ON_WM_CREATE()
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
static UINT indicators[] =
|
||||
{
|
||||
ID_SEPARATOR, // status line indicator
|
||||
ID_INDICATOR_CAPS,
|
||||
ID_INDICATOR_NUM,
|
||||
ID_INDICATOR_SCRL,
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame construction/destruction
|
||||
|
||||
CMainFrame::CMainFrame()
|
||||
{
|
||||
}
|
||||
|
||||
CMainFrame::~CMainFrame()
|
||||
{
|
||||
}
|
||||
|
||||
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
||||
{
|
||||
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
|
||||
return -1;
|
||||
|
||||
if (!m_wndToolBar.Create(this) ||
|
||||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
|
||||
{
|
||||
TRACE0("Failed to create toolbar\n");
|
||||
return -1; // fail to create
|
||||
}
|
||||
|
||||
if (!m_wndStatusBar.Create(this) ||
|
||||
!m_wndStatusBar.SetIndicators(indicators,
|
||||
sizeof(indicators)/sizeof(UINT)))
|
||||
{
|
||||
TRACE0("Failed to create status bar\n");
|
||||
return -1; // fail to create
|
||||
}
|
||||
|
||||
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
|
||||
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
|
||||
|
||||
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
|
||||
EnableDocking(CBRS_ALIGN_ANY);
|
||||
DockControlBar(&m_wndToolBar);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
|
||||
{
|
||||
return CMDIFrameWnd::PreCreateWindow(cs);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame diagnostics
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CMainFrame::AssertValid() const
|
||||
{
|
||||
CMDIFrameWnd::AssertValid();
|
||||
}
|
||||
|
||||
void CMainFrame::Dump(CDumpContext& dc) const
|
||||
{
|
||||
CMDIFrameWnd::Dump(dc);
|
||||
}
|
||||
|
||||
#endif //_DEBUG
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame message handlers
|
||||
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
// MainFrm.h : interface of the CMainFrame class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_MAINFRM_H__4D1BB907_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_MAINFRM_H__4D1BB907_8E74_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
class CMainFrame : public CMDIFrameWnd
|
||||
{
|
||||
DECLARE_DYNAMIC(CMainFrame)
|
||||
public:
|
||||
CMainFrame();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CMainFrame)
|
||||
public:
|
||||
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CMainFrame();
|
||||
#ifdef _DEBUG
|
||||
virtual void AssertValid() const;
|
||||
virtual void Dump(CDumpContext& dc) const;
|
||||
#endif
|
||||
|
||||
protected: // control bar embedded members
|
||||
CStatusBar m_wndStatusBar;
|
||||
CToolBar m_wndToolBar;
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CMainFrame)
|
||||
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_MAINFRM_H__4D1BB907_8E74_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,4 @@
|
|||
class MaClass
|
||||
{
|
||||
int t = 12;
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Voici encore du texte
|
||||
et une seconde ligne
|
|
@ -0,0 +1,4 @@
|
|||
public extern void Nop()
|
||||
{
|
||||
while ( true ) {}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
void object :: T ( )
|
||||
{
|
||||
show ( position ) ;
|
||||
}
|
||||
|
||||
public extern void object :: POS()
|
||||
{
|
||||
for ( int i = 0; i < 10 ; i++ )
|
||||
{
|
||||
if ( i == 2 ) TEST ( 12 ) ;
|
||||
// show ( position );
|
||||
T ( ) ;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
// PerformDlg.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "testcbot.h"
|
||||
#include "PerformDlg.h"
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <sys/timeb.h>
|
||||
//#include <time.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPerformDlg dialog
|
||||
|
||||
|
||||
CPerformDlg::CPerformDlg(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CPerformDlg::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CPerformDlg)
|
||||
// NOTE: the ClassWizard will add member initialization here
|
||||
//}}AFX_DATA_INIT
|
||||
}
|
||||
|
||||
|
||||
void CPerformDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CPerformDlg)
|
||||
DDX_Control(pDX, IDC_EDIT3, m_Edit3);
|
||||
DDX_Control(pDX, IDC_EDIT1, m_Edit1);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CPerformDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(CPerformDlg)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPerformDlg message handlers
|
||||
|
||||
/* Pauses for a specified number of milliseconds. */
|
||||
|
||||
/*void sleep( double waitseconds )
|
||||
{
|
||||
clock_t wait = (clock_t)(waitseconds * CLOCKS_PER_SEC);
|
||||
clock_t goal;
|
||||
goal = wait + clock();
|
||||
while( goal > clock() )
|
||||
;
|
||||
}*/
|
||||
|
||||
void sleep( clock_t wait )
|
||||
{
|
||||
clock_t goal;
|
||||
goal = wait + clock();
|
||||
while( goal > clock() )
|
||||
TRACE("%d \n", clock() );
|
||||
}
|
||||
|
||||
void sleep2( clock_t wait )
|
||||
{
|
||||
struct _timeb timebuffer;
|
||||
char *timeline;
|
||||
|
||||
_ftime( &timebuffer );
|
||||
timeline = ctime( & ( timebuffer.time ) );
|
||||
long x = timebuffer.millitm;
|
||||
while( x == timebuffer.millitm ) _ftime( &timebuffer );
|
||||
}
|
||||
|
||||
#define NBLP 20
|
||||
|
||||
UINT ThreadProc2(ThreadInfo2 *info)
|
||||
{
|
||||
int lp = NBLP;
|
||||
int i;
|
||||
clock_t start = clock();
|
||||
|
||||
while ( !info->m_bStop )
|
||||
{
|
||||
for ( i = 0; i< info->m_nbscripts; i++ )
|
||||
{
|
||||
info->m_pProg[i]->Run();
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
sleep2( 1 );
|
||||
#else
|
||||
CString s ( "xx" );
|
||||
for ( long z = 0x5000; z>0; z-- ) s = s.Left(1);
|
||||
#endif
|
||||
if ( --lp == 0 )
|
||||
{
|
||||
clock_t finish = clock();
|
||||
double n = (double)NBLP / (double)(finish-start) * CLOCKS_PER_SEC;
|
||||
char b[30];
|
||||
sprintf( b, "%f", n);
|
||||
info->m_pEdit->SetWindowText(b);
|
||||
|
||||
n = n * 1100 / 200; // performances
|
||||
sprintf( b, "%f", n);
|
||||
info->m_pEdit3->SetWindowText(b);
|
||||
start = finish;
|
||||
lp = NBLP;
|
||||
}
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
BOOL CPerformDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
|
||||
CBotStringArray liste;
|
||||
// crée les scripts pour les tests
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
m_pProg[i] = new CBotProgram();
|
||||
m_pProg[i]->Compile(m_Script, liste);
|
||||
m_pProg[i]->Start(liste[0]);
|
||||
}
|
||||
|
||||
// lance un processus paralèle pour l'exécution
|
||||
// m_threadinfo2.m_pWndMessage = this ;
|
||||
|
||||
m_threadinfo2.m_pEdit = &m_Edit1;
|
||||
m_threadinfo2.m_pEdit3 = &m_Edit3;
|
||||
m_threadinfo2.m_pProg = m_pProg;
|
||||
m_threadinfo2.m_bStop = FALSE;
|
||||
m_threadinfo2.m_nbscripts = 30;
|
||||
|
||||
|
||||
AfxBeginThread((AFX_THREADPROC)ThreadProc2, &m_threadinfo2) ;
|
||||
// TODO: Add extra initialization here
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
void CPerformDlg::OnCancel()
|
||||
{
|
||||
m_threadinfo2.m_bStop = TRUE;
|
||||
sleep ( 2000 );
|
||||
|
||||
CDialog::OnCancel();
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
delete m_pProg[i];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
#if !defined(AFX_PERFORMDLG_H__EAF2D560_97D8_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_PERFORMDLG_H__EAF2D560_97D8_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
// PerformDlg.h : header file
|
||||
//
|
||||
|
||||
struct ThreadInfo2
|
||||
{
|
||||
CEdit* m_pEdit ;
|
||||
CEdit* m_pEdit3 ;
|
||||
|
||||
CBotProgram** m_pProg;
|
||||
BOOL m_bStop;
|
||||
int m_nbscripts;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPerformDlg dialog
|
||||
|
||||
class CPerformDlg : public CDialog
|
||||
{
|
||||
// Construction
|
||||
public:
|
||||
CPerformDlg(CWnd* pParent = NULL); // standard constructor
|
||||
|
||||
// Dialog Data
|
||||
//{{AFX_DATA(CPerformDlg)
|
||||
enum { IDD = IDD_DIALOG1 };
|
||||
CEdit m_Edit3;
|
||||
CEdit m_Edit1;
|
||||
//}}AFX_DATA
|
||||
|
||||
CBotProgram* m_pProg[100];
|
||||
ThreadInfo2 m_threadinfo2;
|
||||
CString m_Script;
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CPerformDlg)
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
protected:
|
||||
|
||||
// Generated message map functions
|
||||
//{{AFX_MSG(CPerformDlg)
|
||||
virtual BOOL OnInitDialog();
|
||||
virtual void OnCancel();
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_PERFORMDLG_H__EAF2D560_97D8_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,139 @@
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// routine show()
|
||||
// utilisable depuis le programme écrit en CBot
|
||||
|
||||
// exécution
|
||||
BOOL rShow( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser )
|
||||
{
|
||||
CString s;
|
||||
|
||||
while ( pVar != NULL )
|
||||
{
|
||||
CString ss;
|
||||
ss.LoadString( TX_TYPENAMES + pVar->GivType() );
|
||||
s += ss + " ";
|
||||
|
||||
ss = pVar->GivName();
|
||||
if (ss.IsEmpty()) ss = "<sans nom>";
|
||||
s += ss + " = ";
|
||||
|
||||
s += pVar->GivValString();
|
||||
s += "\n";
|
||||
pVar = pVar->GivNext();
|
||||
}
|
||||
|
||||
AfxMessageBox(s, MB_OK|MB_ICONINFORMATION);
|
||||
|
||||
return TRUE; // pas d'interruption
|
||||
}
|
||||
|
||||
CBotTypResult cShow( CBotVar* &pVar, void* pUser)
|
||||
{
|
||||
if ( pVar == NULL ) return CBotTypResult(5028);
|
||||
return CBotTypResult(0); // tous paramètres acceptés, void en retour
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// routine print()
|
||||
// utilisable depuis le programme écrit en CBot
|
||||
|
||||
// exécution
|
||||
BOOL rPrintLn( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser )
|
||||
{
|
||||
CString s;
|
||||
|
||||
CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp();
|
||||
CEdit* pEdit = pApp->m_pConsole;
|
||||
|
||||
if (pEdit == NULL) return TRUE;
|
||||
pEdit->GetWindowText(s);
|
||||
|
||||
while ( pVar != NULL )
|
||||
{
|
||||
if ( !s.IsEmpty() ) s += " ";
|
||||
s += pVar->GivValString();
|
||||
pVar = pVar->GivNext();
|
||||
}
|
||||
s += "\r\n";
|
||||
|
||||
pEdit->SetWindowText(s);
|
||||
pEdit->SetSel(s.GetLength(), s.GetLength());
|
||||
pEdit->SetFocus();
|
||||
return TRUE; // pas d'interruption
|
||||
}
|
||||
|
||||
BOOL rPrint( CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser )
|
||||
{
|
||||
CString s;
|
||||
|
||||
CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp();
|
||||
CEdit* pEdit = pApp->m_pConsole;
|
||||
|
||||
if (pEdit == NULL) return TRUE;
|
||||
pEdit->GetWindowText(s);
|
||||
|
||||
while ( pVar != NULL )
|
||||
{
|
||||
if ( !s.IsEmpty() ) s += " ";
|
||||
s += pVar->GivValString();
|
||||
pVar = pVar->GivNext();
|
||||
}
|
||||
|
||||
pEdit->SetWindowText(s);
|
||||
pEdit->SetSel(s.GetLength(), s.GetLength());
|
||||
pEdit->SetFocus();
|
||||
return TRUE; // pas d'interruption
|
||||
}
|
||||
|
||||
CBotTypResult cPrint( CBotVar* &pVar, void* pUser)
|
||||
{
|
||||
return CBotTypResult(0); // tous paramètres acceptés, un entier en retour
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// class CPoint pour essayer
|
||||
|
||||
// exécution
|
||||
BOOL rCPoint( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception )
|
||||
{
|
||||
CString s;
|
||||
|
||||
if ( pVar == NULL )return TRUE; // constructeur sans paramètres est ok
|
||||
|
||||
CBotVar* pX = pThis->GivItem("x");
|
||||
pX->SetValFloat( pVar->GivValFloat() );
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
CBotVar* pY = pThis->GivItem("y");
|
||||
pY->SetValFloat( pVar->GivValFloat() );
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
return TRUE; // pas d'interruption
|
||||
}
|
||||
|
||||
CBotTypResult cCPoint( CBotVar* pThis, CBotVar* &pVar)
|
||||
{
|
||||
// ok si aucun paramètres !
|
||||
if ( pVar == NULL ) return CBotTypResult(0);
|
||||
|
||||
// paramètre de type numérique svp
|
||||
if ( pVar->GivType() > CBotTypDouble ) return CBotTypResult(5011);
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
// il doit y avoir un second paramètre
|
||||
if ( pVar == NULL ) return 5028;
|
||||
// également de type numérique
|
||||
if ( pVar->GivType() > CBotTypDouble )return CBotTypResult(5011);
|
||||
pVar = pVar->GivNext();
|
||||
|
||||
// et pas plus de 2 paramètres svp
|
||||
if ( pVar != NULL ) return CBotTypResult(5026);
|
||||
|
||||
return CBotTypResult(0); // cette fonction retourne void
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// TestCBot.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#if !defined(AFX_STDAFX_H__4D1BB905_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_STDAFX_H__4D1BB905_8E74_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
#include <afxwin.h> // MFC core and standard components
|
||||
#include <afxext.h> // MFC extensions
|
||||
#include <afxdisp.h> // MFC OLE automation classes
|
||||
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
||||
#include <afxcmn.h> // MFC support for Windows Common Controls
|
||||
#endif // _AFX_NO_AFXCMN_SUPPORT
|
||||
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_STDAFX_H__4D1BB905_8E74_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,4 @@
|
|||
public extern int T ( float n )
|
||||
{
|
||||
return n * 1.1;
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
int T ( int z )
|
||||
{
|
||||
return 45 + z ;
|
||||
}
|
||||
|
||||
class toto
|
||||
{
|
||||
int val = 3 ;
|
||||
int x = 3 * 3 ;
|
||||
void toto( int n )
|
||||
{ val = n + 3 ; }
|
||||
int retval ( int param )
|
||||
{ int r = val + param + x ;
|
||||
val = param ;
|
||||
return r ; }
|
||||
}
|
||||
|
||||
public extern void object :: Chose( )
|
||||
{
|
||||
int z [ 6 ];
|
||||
for ( int i = 0 ; i < 6 ; ) z [ i++ ] = 3 - i ;
|
||||
show ( z ) ;
|
||||
return;
|
||||
|
||||
// test des tableaux
|
||||
int [ ] a [ 3 ] ;
|
||||
// a = null;
|
||||
if ( a == null ) show ( "NULL" );
|
||||
|
||||
a [ 2 / 2 ] [ 2 ]= 5 ;
|
||||
int [ ] b ; b = a [1] ;
|
||||
b [ 0 ] = -4;
|
||||
a [ 4 / 2 ] [ 1 ]= 1 ;
|
||||
show ( a , b ) ;
|
||||
return ;
|
||||
{
|
||||
toto chose = new toto (5 ) ;
|
||||
toto truc = chose ;
|
||||
show ( chose, chose.retval( 100 ) ,
|
||||
truc, truc.retval (40 ) ) ;
|
||||
|
||||
return;
|
||||
}
|
||||
{
|
||||
point A = new
|
||||
point ( 4 * 4 , 2 ) ;
|
||||
show ( A ) ;
|
||||
return;
|
||||
}
|
||||
{
|
||||
show ( T ( 1 ) , T ( 3.7 ) ) ;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
point A ( 3, 4 ) ,
|
||||
B = A ;
|
||||
|
||||
int n = -4;
|
||||
show ( n );
|
||||
|
||||
show ( A, B ) ;
|
||||
|
||||
boolean a = false;
|
||||
boolean b = a or true;
|
||||
if ( not a and b ) ;
|
||||
return;
|
||||
}
|
||||
{
|
||||
// test try
|
||||
float x = nan ; int z = 0 ;
|
||||
try {
|
||||
// throw ( 3 * 4 + 33 ) ;
|
||||
int zz ; goto ( 12 ) ; z = 1 ; z = 0 / 0 ; z = 2 ;
|
||||
}
|
||||
catch ( 45 + 0 * 6000 )
|
||||
{
|
||||
show( "Exception 6000", z ) ;
|
||||
}
|
||||
catch ( x == 0 ) { show( "x nul" ) ; }
|
||||
finally { show ( "fini" ) ; }
|
||||
show ( "continue" );
|
||||
return;
|
||||
}
|
||||
{
|
||||
// test des if
|
||||
int a = 3;
|
||||
if ( a == 3 ) show ( "33");
|
||||
else show ( "44");
|
||||
if ( a != 3 ) show ( "333");
|
||||
else show ( "444");
|
||||
return;
|
||||
}
|
||||
{
|
||||
int a = 0;
|
||||
// test break
|
||||
un:
|
||||
while ( true )
|
||||
{
|
||||
deux:
|
||||
while ( true )
|
||||
{
|
||||
a++;
|
||||
if ( a == 2 ) continue;
|
||||
if ( a == 3 ) break deux;
|
||||
show ( a ) ;
|
||||
if ( a == 5 ) break un;
|
||||
}
|
||||
show ( "DEUX" );
|
||||
}
|
||||
return;
|
||||
}
|
||||
{
|
||||
// test switch
|
||||
int a = 0;
|
||||
|
||||
switch ( a )
|
||||
{
|
||||
case 1 : show( "un" ) ; break;
|
||||
case 2 : show( "deux" ) ; // break;
|
||||
case 3 : show( "trois" ) ; break;
|
||||
case 4 : show( "quatre" ) ; // break;
|
||||
default : show( "par défaut" ) ;
|
||||
}
|
||||
return;
|
||||
}
|
||||
{
|
||||
// test boucle while
|
||||
float z = 3.3;
|
||||
while ( z > 0 )
|
||||
{ show ( z-- ) ; }
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
// test boucle do
|
||||
float y = 3.3;
|
||||
do { int x = 0; show(y); y++; } while ( y < 7 ) ;
|
||||
return;
|
||||
}
|
||||
// test boucle for
|
||||
int j = -7; show ( j );
|
||||
for ( int ii = 3, j = 31; ii < 6 ; ++ii, j = j -3 )
|
||||
{
|
||||
j = 10 * j;
|
||||
show ( ii, j );
|
||||
}
|
||||
return;
|
||||
{
|
||||
// déclarations de variables
|
||||
int a; int b = 3; int c = 4*b, d = 1, e;
|
||||
float x; float y = 3.3; float z = y / 2, u = 1, v;
|
||||
boolean t; boolean tt = true or false; boolean ttt = false, tttt = true, t5;
|
||||
string s; string ss = "hello"; string s2 = ss + " plus", s3 = "s3", s4;
|
||||
|
||||
show( b, c, d );
|
||||
show( y, z, u );
|
||||
show( tt, ttt, tttt );
|
||||
show( ss, s2, s3 );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
extern public void toto()
|
||||
{
|
||||
print( "hello" ) ;
|
||||
print( fac(5) );
|
||||
print( t() ) ;
|
||||
}
|
||||
|
||||
public int fac(int n)
|
||||
{
|
||||
if ( n<2 ) return 1;
|
||||
return n * fac(n-1);
|
||||
}
|
||||
|
||||
point t()
|
||||
{
|
||||
point a(1,2);
|
||||
return a;
|
||||
}
|
|
@ -0,0 +1,316 @@
|
|||
; CLW file contains information for the MFC ClassWizard
|
||||
|
||||
[General Info]
|
||||
Version=1
|
||||
LastClass=CPerformDlg
|
||||
LastTemplate=CDialog
|
||||
NewFileInclude1=#include "stdafx.h"
|
||||
NewFileInclude2=#include "testcbot.h"
|
||||
LastPage=0
|
||||
|
||||
ClassCount=8
|
||||
Class1=CBotConsoleDlg
|
||||
Class2=CChildFrame
|
||||
Class3=CMainFrame
|
||||
Class4=CTestCBotApp
|
||||
Class5=CAboutDlg
|
||||
Class6=CTestCBotDoc
|
||||
Class7=CTestCBotView
|
||||
|
||||
ResourceCount=12
|
||||
Resource1=IDD_CONSOLE
|
||||
Resource2=IDR_TESTCBTYPE (French (France))
|
||||
Resource3=IDD_ABOUTBOX (French (France))
|
||||
Resource4=IDR_MAINFRAME (French (France))
|
||||
Resource5=IDR_MAINFRAME
|
||||
Resource6=IDR_TESTCBTYPE
|
||||
Resource7=IDD_ABOUTBOX
|
||||
Resource8=IDD_CONSOLE (French (Switzerland))
|
||||
Class8=CPerformDlg
|
||||
Resource9=IDD_DIALOG1
|
||||
Resource10=IDD_DIALOG2
|
||||
Resource11=IDD_DIALOG1 (French (Switzerland))
|
||||
Resource12=IDD_DIALOG2 (French (France))
|
||||
|
||||
[CLS:CBotConsoleDlg]
|
||||
Type=0
|
||||
BaseClass=CDialog
|
||||
HeaderFile=CBotConsoleDlg.h
|
||||
ImplementationFile=CBotConsoleDlg.cpp
|
||||
LastObject=IDC_EDIT1
|
||||
|
||||
[CLS:CChildFrame]
|
||||
Type=0
|
||||
BaseClass=CMDIChildWnd
|
||||
HeaderFile=ChildFrm.h
|
||||
ImplementationFile=ChildFrm.cpp
|
||||
|
||||
[CLS:CMainFrame]
|
||||
Type=0
|
||||
BaseClass=CMDIFrameWnd
|
||||
HeaderFile=MainFrm.h
|
||||
ImplementationFile=MainFrm.cpp
|
||||
Filter=T
|
||||
VirtualFilter=fWC
|
||||
LastObject=CMainFrame
|
||||
|
||||
[CLS:CTestCBotApp]
|
||||
Type=0
|
||||
BaseClass=CWinApp
|
||||
HeaderFile=TestCBot.h
|
||||
ImplementationFile=TestCBot.cpp
|
||||
Filter=N
|
||||
VirtualFilter=AC
|
||||
LastObject=ID_TEST
|
||||
|
||||
[CLS:CAboutDlg]
|
||||
Type=0
|
||||
BaseClass=CDialog
|
||||
HeaderFile=TestCBot.cpp
|
||||
ImplementationFile=TestCBot.cpp
|
||||
LastObject=CAboutDlg
|
||||
|
||||
[CLS:CTestCBotDoc]
|
||||
Type=0
|
||||
BaseClass=CDocument
|
||||
HeaderFile=TestCBotDoc.h
|
||||
ImplementationFile=TestCBotDoc.cpp
|
||||
LastObject=CTestCBotDoc
|
||||
Filter=N
|
||||
VirtualFilter=DC
|
||||
|
||||
[CLS:CTestCBotView]
|
||||
Type=0
|
||||
BaseClass=CView
|
||||
HeaderFile=TestCBotView.h
|
||||
ImplementationFile=TestCBotView.cpp
|
||||
LastObject=CTestCBotView
|
||||
Filter=C
|
||||
VirtualFilter=VWC
|
||||
|
||||
[DLG:IDD_CONSOLE]
|
||||
Type=1
|
||||
Class=CBotConsoleDlg
|
||||
ControlCount=4
|
||||
Control1=IDC_STATIC,static,1342308352
|
||||
Control2=IDC_EDIT2,edit,1350631552
|
||||
Control3=IDOK,button,1342242817
|
||||
Control4=IDC_EDIT1,edit,1352734724
|
||||
|
||||
[DLG:IDD_ABOUTBOX]
|
||||
Type=1
|
||||
Class=CAboutDlg
|
||||
ControlCount=7
|
||||
Control1=IDC_STATIC,static,1342177283
|
||||
Control2=IDC_STATIC,static,1342308480
|
||||
Control3=IDC_STATIC,static,1342308352
|
||||
Control4=IDOK,button,1342373889
|
||||
Control5=IDC_STATIC,static,1342308352
|
||||
Control6=IDC_STATIC,static,1342308352
|
||||
Control7=IDC_STATIC,static,1342308352
|
||||
|
||||
[TB:IDR_MAINFRAME (French (France))]
|
||||
Type=1
|
||||
Class=?
|
||||
Command1=ID_FILE_NEW
|
||||
Command2=ID_FILE_OPEN
|
||||
Command3=ID_FILE_SAVE
|
||||
Command4=ID_EDIT_CUT
|
||||
Command5=ID_EDIT_COPY
|
||||
Command6=ID_EDIT_PASTE
|
||||
Command7=ID_FILE_PRINT
|
||||
Command8=ID_RUN
|
||||
Command9=ID_APP_ABOUT
|
||||
CommandCount=9
|
||||
|
||||
[MNU:IDR_MAINFRAME (French (France))]
|
||||
Type=1
|
||||
Class=?
|
||||
Command1=ID_FILE_NEW
|
||||
Command2=ID_FILE_OPEN
|
||||
Command3=ID_FILE_MRU_FILE1
|
||||
Command4=ID_APP_EXIT
|
||||
Command5=ID_VIEW_TOOLBAR
|
||||
Command6=ID_VIEW_STATUS_BAR
|
||||
Command7=ID_APP_ABOUT
|
||||
CommandCount=7
|
||||
|
||||
[MNU:IDR_TESTCBTYPE (French (France))]
|
||||
Type=1
|
||||
Class=?
|
||||
Command1=ID_FILE_NEW
|
||||
Command2=ID_FILE_OPEN
|
||||
Command3=ID_FILE_CLOSE
|
||||
Command4=ID_FILE_SAVE
|
||||
Command5=ID_FILE_SAVE_AS
|
||||
Command6=ID_FILE_MRU_FILE1
|
||||
Command7=ID_APP_EXIT
|
||||
Command8=ID_EDIT_UNDO
|
||||
Command9=ID_EDIT_CUT
|
||||
Command10=ID_EDIT_COPY
|
||||
Command11=ID_EDIT_PASTE
|
||||
Command12=ID_VIEW_TOOLBAR
|
||||
Command13=ID_VIEW_STATUS_BAR
|
||||
Command14=ID_WINDOW_NEW
|
||||
Command15=ID_WINDOW_CASCADE
|
||||
Command16=ID_WINDOW_TILE_HORZ
|
||||
Command17=ID_WINDOW_ARRANGE
|
||||
Command18=ID_APP_ABOUT
|
||||
CommandCount=18
|
||||
|
||||
[ACL:IDR_MAINFRAME (French (France))]
|
||||
Type=1
|
||||
Class=?
|
||||
Command1=ID_EDIT_COPY
|
||||
Command2=ID_FILE_NEW
|
||||
Command3=ID_FILE_OPEN
|
||||
Command4=ID_FILE_SAVE
|
||||
Command5=ID_EDIT_PASTE
|
||||
Command6=ID_EDIT_UNDO
|
||||
Command7=ID_EDIT_CUT
|
||||
Command8=ID_RUN
|
||||
Command9=ID_NEXT_PANE
|
||||
Command10=ID_PREV_PANE
|
||||
Command11=ID_RUN
|
||||
Command12=ID_TEST
|
||||
Command13=ID_EDIT_COPY
|
||||
Command14=ID_EDIT_PASTE
|
||||
Command15=ID_EDIT_CUT
|
||||
Command16=ID_EDIT_UNDO
|
||||
CommandCount=16
|
||||
|
||||
[DLG:IDD_ABOUTBOX (French (France))]
|
||||
Type=1
|
||||
Class=CAboutDlg
|
||||
ControlCount=7
|
||||
Control1=IDC_STATIC,static,1342177283
|
||||
Control2=IDC_STATIC,static,1342308480
|
||||
Control3=IDC_STATIC,static,1342308352
|
||||
Control4=IDOK,button,1342373889
|
||||
Control5=IDC_STATIC,static,1342308352
|
||||
Control6=IDC_STATIC,static,1342308352
|
||||
Control7=IDC_STATIC,static,1342308352
|
||||
|
||||
[ACL:IDR_MAINFRAME]
|
||||
Type=1
|
||||
Command1=ID_EDIT_COPY
|
||||
Command2=ID_FILE_NEW
|
||||
Command3=ID_FILE_OPEN
|
||||
Command4=ID_FILE_SAVE
|
||||
Command5=ID_EDIT_PASTE
|
||||
Command6=ID_EDIT_UNDO
|
||||
Command7=ID_EDIT_CUT
|
||||
Command8=ID_RUN
|
||||
Command9=ID_NEXT_PANE
|
||||
Command10=ID_PREV_PANE
|
||||
Command11=ID_RUN
|
||||
Command12=ID_TEST
|
||||
Command13=ID_EDIT_COPY
|
||||
Command14=ID_EDIT_PASTE
|
||||
Command15=ID_EDIT_CUT
|
||||
Command16=ID_EDIT_UNDO
|
||||
CommandCount=16
|
||||
|
||||
[TB:IDR_MAINFRAME]
|
||||
Type=1
|
||||
Command1=ID_FILE_NEW
|
||||
Command2=ID_FILE_OPEN
|
||||
Command3=ID_FILE_SAVE
|
||||
Command4=ID_EDIT_CUT
|
||||
Command5=ID_EDIT_COPY
|
||||
Command6=ID_EDIT_PASTE
|
||||
Command7=ID_FILE_PRINT
|
||||
Command8=ID_RUN
|
||||
Command9=ID_APP_ABOUT
|
||||
CommandCount=9
|
||||
|
||||
[MNU:IDR_MAINFRAME]
|
||||
Type=1
|
||||
Command1=ID_FILE_NEW
|
||||
Command2=ID_FILE_OPEN
|
||||
Command3=ID_FILE_MRU_FILE1
|
||||
Command4=ID_APP_EXIT
|
||||
Command5=ID_VIEW_TOOLBAR
|
||||
Command6=ID_VIEW_STATUS_BAR
|
||||
Command7=ID_APP_ABOUT
|
||||
CommandCount=7
|
||||
|
||||
[MNU:IDR_TESTCBTYPE]
|
||||
Type=1
|
||||
Command1=ID_FILE_NEW
|
||||
Command2=ID_FILE_OPEN
|
||||
Command3=ID_FILE_CLOSE
|
||||
Command4=ID_FILE_SAVE
|
||||
Command5=ID_FILE_SAVE_AS
|
||||
Command6=ID_FILE_MRU_FILE1
|
||||
Command7=ID_APP_EXIT
|
||||
Command8=ID_EDIT_UNDO
|
||||
Command9=ID_EDIT_CUT
|
||||
Command10=ID_EDIT_COPY
|
||||
Command11=ID_EDIT_PASTE
|
||||
Command12=ID_VIEW_TOOLBAR
|
||||
Command13=ID_VIEW_STATUS_BAR
|
||||
Command14=ID_WINDOW_NEW
|
||||
Command15=ID_WINDOW_CASCADE
|
||||
Command16=ID_WINDOW_TILE_HORZ
|
||||
Command17=ID_WINDOW_ARRANGE
|
||||
Command18=ID_APP_ABOUT
|
||||
CommandCount=18
|
||||
|
||||
[DLG:IDD_CONSOLE (French (Switzerland))]
|
||||
Type=1
|
||||
Class=CBotConsoleDlg
|
||||
ControlCount=4
|
||||
Control1=IDC_STATIC,static,1342308352
|
||||
Control2=IDC_EDIT2,edit,1350631552
|
||||
Control3=IDOK,button,1342242817
|
||||
Control4=IDC_EDIT1,edit,1352734724
|
||||
|
||||
[DLG:IDD_DIALOG1]
|
||||
Type=1
|
||||
Class=CPerformDlg
|
||||
ControlCount=9
|
||||
Control1=IDC_STATIC,static,1342308352
|
||||
Control2=IDC_EDIT1,edit,1350633600
|
||||
Control3=IDC_STATIC,static,1342308352
|
||||
Control4=IDC_EDIT2,edit,1350631552
|
||||
Control5=IDC_SPIN1,msctls_updown32,1342177312
|
||||
Control6=IDC_COMBO1,combobox,1344339971
|
||||
Control7=IDC_STATIC,static,1342308352
|
||||
Control8=IDC_STATIC,static,1342308352
|
||||
Control9=IDC_EDIT3,edit,1350633600
|
||||
|
||||
[CLS:CPerformDlg]
|
||||
Type=0
|
||||
HeaderFile=PerformDlg.h
|
||||
ImplementationFile=PerformDlg.cpp
|
||||
BaseClass=CDialog
|
||||
Filter=D
|
||||
VirtualFilter=dWC
|
||||
LastObject=IDC_EDIT3
|
||||
|
||||
[DLG:IDD_DIALOG2]
|
||||
Type=1
|
||||
ControlCount=2
|
||||
Control1=IDOK,button,1342242817
|
||||
Control2=IDCANCEL,button,1342242816
|
||||
|
||||
[DLG:IDD_DIALOG1 (French (Switzerland))]
|
||||
Type=1
|
||||
ControlCount=9
|
||||
Control1=IDC_STATIC,static,1342308352
|
||||
Control2=IDC_EDIT1,edit,1350633600
|
||||
Control3=IDC_STATIC,static,1342308352
|
||||
Control4=IDC_EDIT2,edit,1350631552
|
||||
Control5=IDC_SPIN1,msctls_updown32,1342177312
|
||||
Control6=IDC_COMBO1,combobox,1344339971
|
||||
Control7=IDC_STATIC,static,1342308352
|
||||
Control8=IDC_STATIC,static,1342308352
|
||||
Control9=IDC_EDIT3,edit,1350633600
|
||||
|
||||
[DLG:IDD_DIALOG2 (French (France))]
|
||||
Type=1
|
||||
ControlCount=2
|
||||
Control1=IDOK,button,1342242817
|
||||
Control2=IDCANCEL,button,1342242816
|
||||
|
|
@ -0,0 +1,253 @@
|
|||
// TestCBot.cpp : Defines the class behaviors for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestCBot.h"
|
||||
|
||||
#include "MainFrm.h"
|
||||
#include "ChildFrm.h"
|
||||
#include "TestCBotDoc.h"
|
||||
#include "TestCBotView.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotApp
|
||||
|
||||
BEGIN_MESSAGE_MAP(CTestCBotApp, CWinApp)
|
||||
//{{AFX_MSG_MAP(CTestCBotApp)
|
||||
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
|
||||
//}}AFX_MSG_MAP
|
||||
// Standard file based document commands
|
||||
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
|
||||
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotApp construction
|
||||
|
||||
CTestCBotApp::CTestCBotApp()
|
||||
{
|
||||
m_pConsole = NULL;
|
||||
m_LastActive = NULL;
|
||||
m_pClassPoint= NULL;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// The one and only CTestCBotApp object
|
||||
|
||||
CTestCBotApp theApp;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotApp initialization
|
||||
|
||||
#include "Routines.cpp"
|
||||
|
||||
|
||||
static char BASED_CODE szSection[] = "Recent File List";
|
||||
static char BASED_CODE szFilename[] = "File1";
|
||||
|
||||
|
||||
#include "../ClassFILE.cpp"
|
||||
|
||||
// routine pour mettre à jour l'instance de la classe Bot courante
|
||||
void rMajObject( CBotVar* pThis, void* pUser )
|
||||
{
|
||||
if (!pThis->IsElemOfClass("object"))
|
||||
return ;
|
||||
CBotVar* pPos = pThis->GivItem("position");
|
||||
CBotVar* pX = pPos->GivItem("x");
|
||||
CBotVar* pY = pPos->GivItem("y");
|
||||
CBotVar* pZ = pPos->GivItem("z");
|
||||
// CBotVar* pPt = pThis->GivItem("transport");
|
||||
|
||||
CBotString p = pX->GivValString();
|
||||
|
||||
// pX->SetValFloat( pUser == (void*)1 ? (float)12.5 : (float)44.4 );
|
||||
pZ->SetValFloat( (float)0 );
|
||||
pY->SetValFloat( (float)-3.33 );
|
||||
pX->SetValFloat( pX->GivValFloat() + 10 ) ;
|
||||
|
||||
// pX = pThis->GivItem( "xx" );
|
||||
// pX->SetValFloat( (float)22 );
|
||||
|
||||
// crée une instance sur une classe object
|
||||
// CBotVar* pAutre = CBotVar::Create("autre", CBotTypClass, "object");
|
||||
// pAutre->SetUserPtr( (void*)3 );
|
||||
// pPt->SetPointer( pAutre );
|
||||
// pPt->SetPointer( NULL );
|
||||
// delete pAutre;
|
||||
}
|
||||
|
||||
|
||||
BOOL CTestCBotApp::InitInstance()
|
||||
{
|
||||
//////////////////////////////////////////////
|
||||
// défini les mots clefs supplémentaires
|
||||
// -------------------------------------------
|
||||
|
||||
CBotProgram::Init();
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// défini les fonctions "show()" et "print()"
|
||||
// -------------------------------------------
|
||||
|
||||
CBotProgram::AddFunction("show", rShow, cShow);
|
||||
CBotProgram::AddFunction("print", rPrint, cPrint);
|
||||
CBotProgram::AddFunction("println", rPrintLn, cPrint);
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// définie la classe globale CPoint
|
||||
// --------------------------------
|
||||
|
||||
m_pClassPoint = new CBotClass("CPoint", NULL);
|
||||
// ajoute le composant ".x"
|
||||
m_pClassPoint->AddItem("x", CBotTypFloat);
|
||||
// ajoute le composant ".y"
|
||||
m_pClassPoint->AddItem("y", CBotTypFloat);
|
||||
|
||||
// ajoute le constructeur pour cette classe
|
||||
m_pClassPoint->AddFunction("CPoint", rCPoint, cCPoint);
|
||||
|
||||
m_pClassPointIntr = new CBotClass("point", NULL, TRUE);
|
||||
// ajoute le composant ".x"
|
||||
m_pClassPointIntr->AddItem("x", CBotTypFloat);
|
||||
// ajoute le composant ".y"
|
||||
m_pClassPointIntr->AddItem("y", CBotTypFloat);
|
||||
// ajoute le composant ".z"
|
||||
m_pClassPointIntr->AddItem("z", CBotTypFloat);
|
||||
|
||||
// ajoute le constructeur pour cette classe
|
||||
m_pClassPointIntr->AddFunction("point", rCPoint, cCPoint);
|
||||
|
||||
// défini la classe "object"
|
||||
CBotClass* pClassObject = new CBotClass( "object", NULL ) ;
|
||||
pClassObject->AddItem( "xx", CBotTypFloat );
|
||||
pClassObject->AddItem( "position", CBotTypResult( CBotTypIntrinsic, "point" ) );
|
||||
pClassObject->AddItem( "transport", CBotTypResult( CBotTypPointer, "object" ) );
|
||||
pClassObject->AddUpdateFunc( rMajObject );
|
||||
|
||||
InitClassFILE();
|
||||
|
||||
AfxEnableControlContainer();
|
||||
|
||||
// Standard initialization
|
||||
|
||||
#ifdef _AFXDLL
|
||||
Enable3dControls(); // Call this when using MFC in a shared DLL
|
||||
#else
|
||||
Enable3dControlsStatic(); // Call this when linking to MFC statically
|
||||
#endif
|
||||
|
||||
// Change the registry key under which our settings are stored.
|
||||
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
|
||||
|
||||
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
|
||||
|
||||
// Register document templates
|
||||
|
||||
CMultiDocTemplate* pDocTemplate;
|
||||
pDocTemplate = new CMultiDocTemplate(
|
||||
IDR_TESTCBTYPE,
|
||||
RUNTIME_CLASS(CTestCBotDoc),
|
||||
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
|
||||
RUNTIME_CLASS(CTestCBotView));
|
||||
AddDocTemplate(pDocTemplate);
|
||||
|
||||
// create main MDI Frame window
|
||||
CMainFrame* pMainFrame = new CMainFrame;
|
||||
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
|
||||
return FALSE;
|
||||
m_pMainWnd = pMainFrame;
|
||||
|
||||
// Parse command line for standard shell commands, DDE, file open
|
||||
CCommandLineInfo cmdInfo;
|
||||
ParseCommandLine(cmdInfo);
|
||||
|
||||
if (m_lpCmdLine[0] == 0)
|
||||
{
|
||||
CString Filename = GetProfileString(szSection, szFilename);
|
||||
if (Filename.IsEmpty()) Filename = "TstCbot.txt";
|
||||
else OpenDocumentFile(Filename);
|
||||
}
|
||||
else
|
||||
// Dispatch commands specified on the command line
|
||||
if (!ProcessShellCommand(cmdInfo))
|
||||
return FALSE;
|
||||
pMainFrame->ShowWindow(m_nCmdShow);
|
||||
pMainFrame->UpdateWindow();
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CAboutDlg dialog used for App About
|
||||
|
||||
class CAboutDlg : public CDialog
|
||||
{
|
||||
public:
|
||||
CAboutDlg();
|
||||
|
||||
// Dialog Data
|
||||
//{{AFX_DATA(CAboutDlg)
|
||||
enum { IDD = IDD_ABOUTBOX };
|
||||
//}}AFX_DATA
|
||||
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CAboutDlg)
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
protected:
|
||||
//{{AFX_MSG(CAboutDlg)
|
||||
// No message handlers
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
|
||||
{
|
||||
//{{AFX_DATA_INIT(CAboutDlg)
|
||||
//}}AFX_DATA_INIT
|
||||
}
|
||||
|
||||
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CAboutDlg)
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(CAboutDlg)
|
||||
// No message handlers
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
// App command to run the dialog
|
||||
void CTestCBotApp::OnAppAbout()
|
||||
{
|
||||
CAboutDlg aboutDlg;
|
||||
aboutDlg.DoModal();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotApp commands
|
||||
|
||||
int CTestCBotApp::ExitInstance()
|
||||
{
|
||||
delete m_pFuncFile;
|
||||
|
||||
CBotProgram::Free();
|
||||
return CWinApp::ExitInstance();
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
# Microsoft Developer Studio Project File - Name="TestCBot" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
|
||||
CFG=TestCBot - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "TestCBot.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "TestCBot.mak" CFG="TestCBot - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "TestCBot - Win32 Release" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "TestCBot - Win32 Debug" (based on "Win32 (x86) Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "TestCBot - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 5
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 5
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR /Yu"stdafx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD BASE RSC /l 0x100c /d "NDEBUG"
|
||||
# ADD RSC /l 0x100c /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
|
||||
# ADD LINK32 /nologo /subsystem:windows /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "TestCBot - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 5
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 5
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /Yu"stdafx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD BASE RSC /l 0x100c /d "_DEBUG"
|
||||
# ADD RSC /l 0x100c /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 /nologo /stack:0x7010 /subsystem:windows /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "TestCBot - Win32 Release"
|
||||
# Name "TestCBot - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotConsoleDlg.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ChildFrm.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MainFrm.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\PerformDlg.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"stdafx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBot.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBot.rc
|
||||
|
||||
!IF "$(CFG)" == "TestCBot - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "TestCBot - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBotDoc.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBotView.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CBotConsoleDlg.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ChildFrm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MainFrm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\PerformDlg.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBot.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBotDoc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCBotView.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\res\TestCBot.ico
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\res\TestCBot.rc2
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\res\TestCBotDoc.ico
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\res\Toolbar.bmp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Debug\CBot.lib
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
|
@ -0,0 +1,64 @@
|
|||
// TestCBot.h : main header file for the TESTCBOT application
|
||||
//
|
||||
|
||||
#if !defined(AFX_TESTCBOT_H__4D1BB903_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_TESTCBOT_H__4D1BB903_8E74_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
#ifndef __AFXWIN_H__
|
||||
#error include 'stdafx.h' before including this file for PCH
|
||||
#endif
|
||||
|
||||
#include "resource.h" // main symbols
|
||||
//#include "../CbotDll.h" // librairie CBot
|
||||
#include "../Cbot.h" // complet pour Browse
|
||||
|
||||
class CTestCBotView;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotApp:
|
||||
// See TestCBot.cpp for the implementation of this class
|
||||
//
|
||||
|
||||
class CTestCBotApp : public CWinApp
|
||||
{
|
||||
public:
|
||||
CTestCBotApp();
|
||||
|
||||
CEdit* m_pConsole;
|
||||
CTestCBotView* m_LastActive;
|
||||
CBotClass* m_pClassPoint;
|
||||
CBotClass* m_pClassPointIntr;
|
||||
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CTestCBotApp)
|
||||
public:
|
||||
virtual BOOL InitInstance();
|
||||
virtual int ExitInstance();
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
|
||||
//{{AFX_MSG(CTestCBotApp)
|
||||
afx_msg void OnAppAbout();
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_TESTCBOT_H__4D1BB903_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
|
||||
|
||||
#define WM_STARTPROG WM_APP + 0
|
||||
#define WM_ENDPROG WM_APP + 1
|
||||
#define WM_ACTWINDOW WM_APP + 2
|
|
@ -0,0 +1,564 @@
|
|||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// French (France) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDR_MAINFRAME ICON DISCARDABLE "res\\TestCBot.ico"
|
||||
IDR_TESTCBTYPE ICON DISCARDABLE "res\\TestCBotDoc.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Bitmap
|
||||
//
|
||||
|
||||
IDR_MAINFRAME BITMAP MOVEABLE PURE "res\\Toolbar.bmp"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Toolbar
|
||||
//
|
||||
|
||||
IDR_MAINFRAME TOOLBAR DISCARDABLE 16, 15
|
||||
BEGIN
|
||||
BUTTON ID_FILE_NEW
|
||||
BUTTON ID_FILE_OPEN
|
||||
BUTTON ID_FILE_SAVE
|
||||
SEPARATOR
|
||||
BUTTON ID_EDIT_CUT
|
||||
BUTTON ID_EDIT_COPY
|
||||
BUTTON ID_EDIT_PASTE
|
||||
SEPARATOR
|
||||
BUTTON ID_FILE_PRINT
|
||||
BUTTON ID_RUN
|
||||
SEPARATOR
|
||||
BUTTON ID_APP_ABOUT
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
IDR_MAINFRAME MENU PRELOAD DISCARDABLE
|
||||
BEGIN
|
||||
POPUP "&Fichier"
|
||||
BEGIN
|
||||
MENUITEM "&Nouveau\tCtrl+N", ID_FILE_NEW
|
||||
MENUITEM "&Ouvrir...\tCtrl+O", ID_FILE_OPEN
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Fichier récent", ID_FILE_MRU_FILE1, GRAYED
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "&Quitter", ID_APP_EXIT
|
||||
END
|
||||
POPUP "&Affichage"
|
||||
BEGIN
|
||||
MENUITEM "&Barre d'outils", ID_VIEW_TOOLBAR
|
||||
MENUITEM "Barre d'é&tat", ID_VIEW_STATUS_BAR
|
||||
END
|
||||
POPUP "&?"
|
||||
BEGIN
|
||||
MENUITEM "&A propos de TestCBot...", ID_APP_ABOUT
|
||||
END
|
||||
END
|
||||
|
||||
IDR_TESTCBTYPE MENU PRELOAD DISCARDABLE
|
||||
BEGIN
|
||||
POPUP "&Fichier"
|
||||
BEGIN
|
||||
MENUITEM "&Nouveau\tCtrl+N", ID_FILE_NEW
|
||||
MENUITEM "&Ouvrir...\tCtrl+O", ID_FILE_OPEN
|
||||
MENUITEM "&Fermer", ID_FILE_CLOSE
|
||||
MENUITEM "&Enregistrer\tCtrl+S", ID_FILE_SAVE
|
||||
MENUITEM "En®istrer sous...", ID_FILE_SAVE_AS
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Fichier récent", ID_FILE_MRU_FILE1, GRAYED
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "&Quitter", ID_APP_EXIT
|
||||
END
|
||||
POPUP "&Edition"
|
||||
BEGIN
|
||||
MENUITEM "&Annuler\tCtrl+Z", ID_EDIT_UNDO
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "&Couper\tCtrl+X", ID_EDIT_CUT
|
||||
MENUITEM "&Copier\tCtrl+C", ID_EDIT_COPY
|
||||
MENUITEM "C&oller\tCtrl+V", ID_EDIT_PASTE
|
||||
END
|
||||
POPUP "&Affichage"
|
||||
BEGIN
|
||||
MENUITEM "&Barre d'outils", ID_VIEW_TOOLBAR
|
||||
MENUITEM "Barre d'é&tat", ID_VIEW_STATUS_BAR
|
||||
END
|
||||
POPUP "Fe&nêtre"
|
||||
BEGIN
|
||||
MENUITEM "&Nouvelle fenêtre", ID_WINDOW_NEW
|
||||
MENUITEM "&Cascade", ID_WINDOW_CASCADE
|
||||
MENUITEM "&Mosaïque", ID_WINDOW_TILE_HORZ
|
||||
MENUITEM "&Réorganiser les icônes", ID_WINDOW_ARRANGE
|
||||
END
|
||||
POPUP "&?"
|
||||
BEGIN
|
||||
MENUITEM "&A propos de TestCBot...", ID_APP_ABOUT
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Accelerator
|
||||
//
|
||||
|
||||
IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE PURE
|
||||
BEGIN
|
||||
"C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
|
||||
"N", ID_FILE_NEW, VIRTKEY, CONTROL, NOINVERT
|
||||
"O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
|
||||
"S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
|
||||
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT
|
||||
VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT, NOINVERT
|
||||
VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT
|
||||
VK_F5, ID_RUN, VIRTKEY, NOINVERT
|
||||
VK_F6, ID_NEXT_PANE, VIRTKEY, NOINVERT
|
||||
VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT, NOINVERT
|
||||
VK_F7, ID_RUN, VIRTKEY, NOINVERT
|
||||
VK_F9, ID_TEST, VIRTKEY, NOINVERT
|
||||
VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
|
||||
VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT, NOINVERT
|
||||
"X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT
|
||||
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 265, 206
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "A propos de TestCBot"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
ICON IDR_MAINFRAME,IDC_STATIC,11,17,21,20
|
||||
LTEXT "TestCBot version 1.0",IDC_STATIC,40,10,119,8,
|
||||
SS_NOPREFIX
|
||||
LTEXT "Copyright D. Dumoulin (C) 2000",IDC_STATIC,40,25,119,8
|
||||
DEFPUSHBUTTON "OK",IDOK,226,7,32,14,WS_GROUP
|
||||
LTEXT "Programme de test pour la librairie CBot\n\nLes fonctions doivent être déclarées comme ""extern"" pour apparaître dans la liste lors de l'exécution.\n\n",
|
||||
IDC_STATIC,39,43,191,41
|
||||
LTEXT "Mais en fait, on peut accèder à toutes les fonctions marquées ""public"" quelles soient dans la fenêtre active ou non.",
|
||||
IDC_STATIC,39,89,187,36
|
||||
LTEXT "Les fonctions print( ... ) et println( ...) permettent d'afficher des résultats dans la console.\n\nLa fonction show( ... ) affiche les paramètres dans un dialogue, et suspend donc l'exécution.",
|
||||
IDC_STATIC,39,130,187,54
|
||||
END
|
||||
|
||||
IDD_DIALOG2 DIALOG DISCARDABLE 0, 0, 186, 95
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Dialog"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,129,7,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14
|
||||
END
|
||||
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040C04B0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "\0"
|
||||
VALUE "FileDescription", "Application MFC TestCBot\0"
|
||||
VALUE "FileVersion", "1, 0, 0, 1\0"
|
||||
VALUE "InternalName", "TestCBot\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1900\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "TestCBot.EXE\0"
|
||||
VALUE "ProductName", "Application TestCBot\0"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Traduction", 0x40c, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
IDD_ABOUTBOX, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 258
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 199
|
||||
END
|
||||
|
||||
IDD_DIALOG2, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 179
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 88
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE PRELOAD DISCARDABLE
|
||||
BEGIN
|
||||
IDR_MAINFRAME "TestCBot"
|
||||
IDR_TESTCBTYPE "\nTestCBot\nTestCBot\nCBot (*.txt)\n.txt\nTestCBot.Document\nTestCB Document"
|
||||
END
|
||||
|
||||
STRINGTABLE PRELOAD DISCARDABLE
|
||||
BEGIN
|
||||
AFX_IDS_APP_TITLE "TestCBot"
|
||||
AFX_IDS_IDLEMESSAGE "Prêt"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_INDICATOR_EXT "EXT"
|
||||
ID_INDICATOR_CAPS "MAJ"
|
||||
ID_INDICATOR_NUM "NUM"
|
||||
ID_INDICATOR_SCRL "DEF"
|
||||
ID_INDICATOR_OVR "ECR"
|
||||
ID_INDICATOR_REC "ENR"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_FILE_NEW "Crée un nouveau document\nNouveau"
|
||||
ID_FILE_OPEN "Ouvre un document existant\nOuvrir"
|
||||
ID_FILE_CLOSE "Ferme le document actif\nFermer"
|
||||
ID_FILE_SAVE "Enregistre le document actif\nEnregistrer"
|
||||
ID_FILE_SAVE_AS "Enregistre le document actif sous un nouveau nom\nEnregistrer sous"
|
||||
ID_FILE_PRINT "Imprime le document\nImprime"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_APP_ABOUT "Affiche des informations sur le programme\nA propos de"
|
||||
ID_APP_EXIT "Ferme l'application ; propose d'enregistrer les documents\nQuitter"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_FILE_MRU_FILE1 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE2 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE3 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE4 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE5 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE6 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE7 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE8 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE9 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE10 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE11 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE12 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE13 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE14 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE15 "Ouvre ce document"
|
||||
ID_FILE_MRU_FILE16 "Ouvre ce document"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_NEXT_PANE "Passe au volet de fenêtre suivant\nVolet suivant"
|
||||
ID_PREV_PANE "Revient au volet précédent\nVolet précédent"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_WINDOW_NEW "Ouvre une nouvelle fenêtre pour le document actif\nNouvelle fenêtre"
|
||||
ID_WINDOW_ARRANGE "Réorganise les icônes en bas de la fenêtre\nRéorganise les icônes"
|
||||
ID_WINDOW_CASCADE "Réorganise les fenêtres en cascade\nCascade"
|
||||
ID_WINDOW_TILE_HORZ "Réorganise les fenêtres en une mosaïque\nMosaïque"
|
||||
ID_WINDOW_TILE_VERT "Réorganise les fenêtres en une mosaïque\nMosaïque"
|
||||
ID_WINDOW_SPLIT "Fractionne la fenêtre active en deux volets\nFractionner"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_EDIT_CLEAR "Efface la sélection\nEffacer"
|
||||
ID_EDIT_CLEAR_ALL "Efface tout\nEffacer tout"
|
||||
ID_EDIT_COPY "Copie la sélection et la place dans le Presse-papiers\nCopier"
|
||||
ID_EDIT_CUT "Supprime la sélection et la place dans le Presse-papiers\nCopier"
|
||||
ID_EDIT_FIND "Recherche le texte spécifié\nRechercher"
|
||||
ID_EDIT_PASTE "Insère le contenu du Presse-papiers\nColler"
|
||||
ID_EDIT_REPEAT "Répète la dernière action\nRépéter"
|
||||
ID_EDIT_REPLACE "Remplace le texte spécifique par un texte différent\nRemplacer"
|
||||
ID_EDIT_SELECT_ALL "Sélectionne le document entier\nSélectionner tout"
|
||||
ID_EDIT_UNDO "Annule la dernière action\nAnnuler"
|
||||
ID_EDIT_REDO "Rétablit l'action précédemment annulée\nRétablir"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_VIEW_TOOLBAR "Affiche ou masque la barre d'outils\nBarre d'outils"
|
||||
ID_VIEW_STATUS_BAR "Affiche ou masque la barre d'état\nBarre d'état"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
AFX_IDS_SCSIZE "Change la taille de la fenêtre"
|
||||
AFX_IDS_SCMOVE "Change la position de la fenêtre"
|
||||
AFX_IDS_SCMINIMIZE "Réduit la fenêtre en icône"
|
||||
AFX_IDS_SCMAXIMIZE "Agrandit la fenêtre au format de l'écran"
|
||||
AFX_IDS_SCNEXTWINDOW "Passe à la fenêtre de document suivante"
|
||||
AFX_IDS_SCPREVWINDOW "Passe à la fenêtre de document précédente"
|
||||
AFX_IDS_SCCLOSE "Ferme la fenêtre active et propose l'enregistrement des documents"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
AFX_IDS_SCRESTORE "Restaure la fenêtre à sa taille d'origine"
|
||||
AFX_IDS_SCTASKLIST "Active la liste des tâches"
|
||||
AFX_IDS_MDICHILD "Active cette fenêtre"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
ID_RUN "Execute le programme CBot\nExecute (F5)"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
TX_TYPENAMES "les différents types"
|
||||
1001 "Byte"
|
||||
1002 "Short"
|
||||
1003 "Char"
|
||||
1004 "Int"
|
||||
1005 "Long"
|
||||
1006 "Real"
|
||||
1007 "Double"
|
||||
END
|
||||
|
||||
STRINGTABLE DISCARDABLE
|
||||
BEGIN
|
||||
1008 "Boolean"
|
||||
1009 "String"
|
||||
1010 "Array"
|
||||
1011 "Arraybody"
|
||||
1012 "Pointer"
|
||||
1013 "Nullpointer"
|
||||
1014 "nop"
|
||||
1015 "Class"
|
||||
1016 "Intrinsic"
|
||||
END
|
||||
|
||||
#endif // French (France) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// French (Switzerland) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH_SWISS
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_CONSOLE DIALOG DISCARDABLE 0, 0, 401, 210
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "CBot Console"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
LTEXT "Commande :",IDC_STATIC,7,177,40,8
|
||||
EDITTEXT IDC_EDIT2,7,189,329,14,ES_AUTOHSCROLL
|
||||
DEFPUSHBUTTON "Exécute",IDOK,344,189,50,14
|
||||
EDITTEXT IDC_EDIT1,7,7,387,167,ES_MULTILINE | ES_READONLY |
|
||||
ES_WANTRETURN | WS_VSCROLL
|
||||
END
|
||||
|
||||
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 177, 100
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Test performances"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
LTEXT "Boucles par seconde",IDC_STATIC,7,9,68,8
|
||||
EDITTEXT IDC_EDIT1,111,7,51,14,ES_AUTOHSCROLL | ES_READONLY
|
||||
LTEXT "Nombre de scripts",IDC_STATIC,7,55,58,8
|
||||
EDITTEXT IDC_EDIT2,111,52,40,14,ES_AUTOHSCROLL
|
||||
CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,152,52,
|
||||
10,14
|
||||
COMBOBOX IDC_COMBO1,111,74,52,111,CBS_DROPDOWNLIST | WS_VSCROLL |
|
||||
WS_TABSTOP
|
||||
LTEXT "Timer",IDC_STATIC,7,77,18,8
|
||||
LTEXT "Performance %",IDC_STATIC,7,28,48,8
|
||||
EDITTEXT IDC_EDIT3,111,25,51,14,ES_AUTOHSCROLL | ES_READONLY
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
IDD_CONSOLE, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 394
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 203
|
||||
END
|
||||
|
||||
IDD_DIALOG1, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 170
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 93
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
|
||||
"#define _AFX_NO_OLE_RESOURCES\r\n"
|
||||
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
|
||||
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
|
||||
"\r\n"
|
||||
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)\r\n"
|
||||
"#ifdef _WIN32\r\n"
|
||||
"LANGUAGE 12, 1\r\n"
|
||||
"#pragma code_page(1252)\r\n"
|
||||
"#endif\r\n"
|
||||
"#include ""res\\TestCBot.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
|
||||
"#include ""l.fra\\afxres.rc"" // Standard components\r\n"
|
||||
"#endif\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog Info
|
||||
//
|
||||
|
||||
IDD_DIALOG1 DLGINIT
|
||||
BEGIN
|
||||
IDC_COMBO1, 0x403, 2, 0
|
||||
0x0031,
|
||||
IDC_COMBO1, 0x403, 3, 0
|
||||
0x3031, "\000"
|
||||
IDC_COMBO1, 0x403, 4, 0
|
||||
0x3031, 0x0030,
|
||||
IDC_COMBO1, 0x403, 5, 0
|
||||
0x3031, 0x3030, "\000"
|
||||
0
|
||||
END
|
||||
|
||||
#endif // French (Switzerland) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
#define _AFX_NO_SPLITTER_RESOURCES
|
||||
#define _AFX_NO_OLE_RESOURCES
|
||||
#define _AFX_NO_TRACKER_RESOURCES
|
||||
#define _AFX_NO_PROPERTY_RESOURCES
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE 12, 1
|
||||
#pragma code_page(1252)
|
||||
#endif
|
||||
#include "res\TestCBot.rc2" // non-Microsoft Visual C++ edited resources
|
||||
#include "l.fra\afxres.rc" // Standard components
|
||||
#endif
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
class CPoint2
|
||||
{
|
||||
float x, y;
|
||||
void CPoint2(float x, float y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
public extern void T ( )
|
||||
{
|
||||
CPoint2 X( 12, 33 ), Y ( -4, 4/3 );
|
||||
print ( X, Y ) ;
|
||||
}
|
||||
|
||||
public extern void Hello ( )
|
||||
|
||||
{
|
||||
println ( "Hello" );
|
||||
}
|
||||
|
||||
public extern void test ( int n )
|
||||
{
|
||||
for ( int i = n; i>0 ; i--) print (i);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
public extern void Test ()
|
||||
{
|
||||
for ( int x = 100000; x>0 ; x-- ) { }
|
||||
}
|
||||
|
||||
float MaRoutine( CPoint A, CPoint B )
|
||||
{
|
||||
A.x -= B.x ; // distance en x
|
||||
A.y -= B.y ; // distance en y
|
||||
A.x *= A.x; // carré de la distance
|
||||
A.y += A.y; // carré de la distance
|
||||
println ( A, B ) ;
|
||||
return ( A.x + A.y ) ;
|
||||
}
|
||||
|
||||
public extern void TestAB ( )
|
||||
{
|
||||
CPoint A(3, 5) ;
|
||||
CPoint B(4, -2);
|
||||
println ( A, B ) ;
|
||||
MaRoutine( A, B ) ;
|
||||
println ( A, B ) ;
|
||||
}
|
||||
|
|
@ -0,0 +1,683 @@
|
|||
// TestCBotDoc.cpp : implementation of the CTestCBotDoc class
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestCBot.h"
|
||||
|
||||
#include "TestCBotDoc.h"
|
||||
#include "TestCBotView.h"
|
||||
#include "CBotConsoleDlg.h"
|
||||
#include "PerformDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotDoc
|
||||
|
||||
IMPLEMENT_DYNCREATE(CTestCBotDoc, CDocument)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CTestCBotDoc, CDocument)
|
||||
//{{AFX_MSG_MAP(CTestCBotDoc)
|
||||
ON_COMMAND(ID_RUN, OnRun)
|
||||
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
|
||||
ON_COMMAND(ID_TEST, OnTest)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotDoc construction/destruction
|
||||
|
||||
static BOOL test = FALSE;
|
||||
|
||||
|
||||
CTestCBotDoc::CTestCBotDoc()
|
||||
{
|
||||
m_pEdit = NULL;
|
||||
m_pProg = NULL;
|
||||
m_bModified = FALSE;
|
||||
}
|
||||
|
||||
CTestCBotDoc::~CTestCBotDoc()
|
||||
{
|
||||
delete m_pEdit;
|
||||
delete m_pProg;
|
||||
}
|
||||
|
||||
BOOL CTestCBotDoc::OnNewDocument()
|
||||
{
|
||||
if (!CDocument::OnNewDocument())
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotDoc serialization
|
||||
|
||||
void CTestCBotDoc::Serialize(CArchive& ar)
|
||||
{
|
||||
if (ar.IsStoring())
|
||||
{
|
||||
m_pEdit->GetWindowText(m_DocText);
|
||||
int w = m_DocText.GetLength();
|
||||
ar.Write((LPCTSTR)m_DocText, w);
|
||||
}
|
||||
else
|
||||
{
|
||||
int r;
|
||||
char buf[10001];
|
||||
|
||||
r = ar.Read(buf, 10000);
|
||||
buf[r] = 0;
|
||||
m_DocText = buf;
|
||||
|
||||
if ( m_pProg == NULL ) m_pProg = new CBotProgram();
|
||||
|
||||
if (!m_pProg->Compile(m_DocText, m_Liste, NULL))
|
||||
{
|
||||
delete m_pProg;
|
||||
m_pProg = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotDoc diagnostics
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CTestCBotDoc::AssertValid() const
|
||||
{
|
||||
CDocument::AssertValid();
|
||||
}
|
||||
|
||||
void CTestCBotDoc::Dump(CDumpContext& dc) const
|
||||
{
|
||||
CDocument::Dump(dc);
|
||||
}
|
||||
#endif //_DEBUG
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotDoc commands
|
||||
|
||||
void CTestCBotDoc::OnRun()
|
||||
{
|
||||
OnFileSave();
|
||||
|
||||
m_pEdit->GetWindowText(m_DocText);
|
||||
|
||||
CString TextError;
|
||||
int code, start, end;
|
||||
|
||||
if ( m_pProg == NULL ) m_pProg = new CBotProgram();
|
||||
|
||||
CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp();
|
||||
|
||||
if (!m_pProg->Compile(m_DocText, m_Liste, NULL))
|
||||
{
|
||||
m_pProg->GetError(code, start, end);
|
||||
delete m_pProg;
|
||||
m_pProg = NULL;
|
||||
|
||||
m_pEdit->SetSel( start, end );
|
||||
m_pEdit->SetFocus(); // met en évidence la partie avec problème
|
||||
|
||||
TextError = CBotProgram::GivErrorText( code );
|
||||
AfxMessageBox( TextError );
|
||||
|
||||
m_pEdit->SetFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if( m_Liste.GivSize() == 0 )
|
||||
{
|
||||
AfxMessageBox("Aucune fonction marquée \"extern\" !");
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < m_Liste.GivSize(); i++ )
|
||||
{
|
||||
int start, stop;
|
||||
m_pProg->GetPosition(m_Liste[i], start, stop, GetPosNom, GetPosParam);
|
||||
m_Liste[i] = m_DocText.Mid( start, stop-start );
|
||||
}
|
||||
|
||||
CBotConsoleDlg dlg;
|
||||
dlg.m_pListe = &m_Liste;
|
||||
dlg.m_pEditx = m_pEdit;
|
||||
|
||||
dlg.DoModal(); // dialogue pour faire la console
|
||||
|
||||
if ( dlg.m_code>0 )
|
||||
{
|
||||
CString TextError;
|
||||
|
||||
TextError = m_pProg->GivErrorText( dlg.m_code );
|
||||
|
||||
m_pEdit->SetSel( dlg.m_start, dlg.m_end );
|
||||
m_pEdit->SetFocus(); // met en évidence la partie avec problème
|
||||
|
||||
AfxMessageBox(TextError);
|
||||
}
|
||||
|
||||
m_pEdit->SetFocus();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void CTestCBotDoc::OnChangeEdit1()
|
||||
{
|
||||
SetModifiedFlag();
|
||||
m_bModified = TRUE;
|
||||
}
|
||||
|
||||
BOOL CTestCBotDoc::Compile()
|
||||
{
|
||||
m_pEdit->GetWindowText(m_DocText);
|
||||
|
||||
CString TextError;
|
||||
int code, start, end;
|
||||
|
||||
if ( m_pProg == NULL ) m_pProg = new CBotProgram();
|
||||
|
||||
char buffer[100];
|
||||
strcpy(buffer, "le pointeur à passer pour voir");
|
||||
|
||||
if (m_bModified && !m_pProg->Compile(m_DocText, m_Liste, (void*)buffer))
|
||||
{
|
||||
m_pProg->GetError(code, start, end);
|
||||
delete m_pProg;
|
||||
m_pProg = NULL;
|
||||
|
||||
m_pEdit->SetSel( start, end );
|
||||
m_pEdit->SetFocus(); // met en évidence la partie avec problème
|
||||
|
||||
TextError = CBotProgram::GivErrorText( code );
|
||||
AfxMessageBox( TextError );
|
||||
|
||||
m_pEdit->SetFocus();
|
||||
m_bModified = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( m_pProg->GetPosition( "TheTest", start, end) )
|
||||
{
|
||||
m_pEdit->SetSel( start, end );
|
||||
m_pEdit->SetFocus(); // met en évidence la partie avec problème
|
||||
}
|
||||
|
||||
m_bModified = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int compt = 0;
|
||||
// routine retournant le "pointeur" à un autre object
|
||||
BOOL rRetObject( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
pResult->SetPointer( NULL );
|
||||
compt+=45671;
|
||||
if (compt&0x11) return TRUE;
|
||||
|
||||
CBotVar* pAutre = CBotVar::Create("autre", CBotTypResult( CBotTypClass, "object" ));
|
||||
pAutre->SetUserPtr( (void*)2 );
|
||||
pResult->SetPointer( pAutre );
|
||||
|
||||
if (!pResult->IsElemOfClass("object"))
|
||||
return TRUE;
|
||||
|
||||
delete pAutre;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult cRetObject( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
return CBotTypResult( CBotTypPointer, "object");
|
||||
}
|
||||
|
||||
BOOL roRadar( CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception )
|
||||
{
|
||||
pResult->SetPointer( NULL );
|
||||
compt+=45671;
|
||||
if (compt&0x11) return TRUE;
|
||||
|
||||
CBotVar* pAutre = CBotVar::Create("autre", CBotTypResult( CBotTypClass, "object" ));
|
||||
pAutre->SetUserPtr( (void*)2 );
|
||||
pResult->SetPointer( pAutre );
|
||||
|
||||
if (!pResult->IsElemOfClass("object"))
|
||||
return TRUE;
|
||||
|
||||
delete pAutre;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult coRadar( CBotVar* pThis, CBotVar* &pVar )
|
||||
{
|
||||
void* pUser = pThis->GivUserPtr();
|
||||
return CBotTypResult( CBotTypPointer, "object");
|
||||
}
|
||||
|
||||
BOOL rMove( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
if ( test < 12 )
|
||||
{
|
||||
test++;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult cMove( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
BOOL rTurn( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult cTurn( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
BOOL rRadar( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
pResult->SetPointer( NULL );
|
||||
|
||||
if ( pVar ) pVar->debug();
|
||||
|
||||
compt+=45671;
|
||||
if (compt&0x11)
|
||||
{
|
||||
return FALSE; // TRUE;
|
||||
}
|
||||
|
||||
CBotVar* pAutre = CBotVar::Create("autre", CBotTypResult( CBotTypClass, "object" ));
|
||||
pAutre->SetUserPtr( (void*)2 );
|
||||
pResult->SetPointer( pAutre );
|
||||
|
||||
if (!pResult->IsElemOfClass("object"))
|
||||
return TRUE;
|
||||
|
||||
delete pAutre;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult cRadar( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
return CBotTypResult( CBotTypPointer, "object");
|
||||
}
|
||||
|
||||
// routine retournant le "pointeur" à un autre object
|
||||
BOOL rTEST( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
test = 1 ;
|
||||
if ( pVar == NULL ) return TRUE;
|
||||
|
||||
test = pVar->GivValInt();
|
||||
if ( test == 5 )
|
||||
{
|
||||
pVar = pVar->GivNext();
|
||||
pVar->SetUserPtr( OBJECTDELETED );
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult cTEST( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
// routine retournant le "pointeur" à un autre object
|
||||
BOOL rF( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||
{
|
||||
if ( pResult == NULL ) return TRUE;
|
||||
pResult->SetValInt(3);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBotTypResult cF( CBotVar* &pVar, void* pUser )
|
||||
{
|
||||
return CBotTypResult( CBotTypFloat );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
// Compilation d'une procédure avec un "point".
|
||||
|
||||
CBotTypResult cPoint(CBotVar* &var, void* user)
|
||||
{
|
||||
if ( var == 0 ) return CBotTypResult( CBotErrLowParam );
|
||||
|
||||
if ( var->GivType() <= CBotTypDouble )
|
||||
{
|
||||
var = var->GivNext();
|
||||
if ( var == 0 ) return CBotTypResult( CBotErrLowParam );
|
||||
if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum );
|
||||
var = var->GivNext();
|
||||
if ( var == 0 ) return CBotTypResult( CBotErrLowParam );
|
||||
if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum );
|
||||
var = var->GivNext();
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
if ( var->GivType() == CBotTypClass )
|
||||
{
|
||||
if ( !var->IsElemOfClass("point") ) return CBotTypResult( CBotErrBadParam );
|
||||
var = var->GivNext();
|
||||
return CBotTypResult( 0 );
|
||||
}
|
||||
|
||||
return CBotTypResult( CBotErrBadParam );
|
||||
}
|
||||
|
||||
// Donne un paramètre de type "point".
|
||||
#define UNIT 1
|
||||
|
||||
|
||||
CBotTypResult cSpace(CBotVar* &var, void* user)
|
||||
{
|
||||
CBotTypResult ret;
|
||||
|
||||
if ( var == 0 ) return CBotTypResult( CBotTypIntrinsic, "point" );
|
||||
ret = cPoint(var, user);
|
||||
if ( !ret.Eq(0) ) return ret;
|
||||
|
||||
if ( var == 0 ) return CBotTypIntrinsic;
|
||||
if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum );
|
||||
var = var->GivNext();
|
||||
|
||||
if ( var == 0 ) return CBotTypIntrinsic;
|
||||
if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum );
|
||||
var = var->GivNext();
|
||||
|
||||
if ( var == 0 ) return CBotTypIntrinsic;
|
||||
if ( var->GivType() > CBotTypDouble ) return CBotTypResult( CBotErrBadNum );
|
||||
var = var->GivNext();
|
||||
|
||||
if ( var != 0 ) return CBotErrOverParam;
|
||||
return CBotTypResult( CBotTypIntrinsic, "point" );
|
||||
}
|
||||
|
||||
// Instruction "space(center, rMin, rMax, dist)".
|
||||
|
||||
BOOL rSpace(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
CBotVar* pSub;
|
||||
float rMin, rMax, dist;
|
||||
|
||||
rMin = 5.0f*UNIT;
|
||||
rMax = 50.0f*UNIT;
|
||||
dist = 4.0f*UNIT;
|
||||
|
||||
if ( var == 0 )
|
||||
{
|
||||
// center = pThis->RetPosition(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( var != 0 )
|
||||
{
|
||||
rMin = var->GivValFloat()*UNIT;
|
||||
var = var->GivNext();
|
||||
|
||||
if ( var != 0 )
|
||||
{
|
||||
rMax = var->GivValFloat()*UNIT;
|
||||
var = var->GivNext();
|
||||
|
||||
if ( var != 0 )
|
||||
{
|
||||
dist = var->GivValFloat()*UNIT;
|
||||
var = var->GivNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( result != 0 )
|
||||
{
|
||||
pSub = result->GivItemList();
|
||||
if ( pSub != 0 )
|
||||
{
|
||||
pSub->SetValFloat(1);
|
||||
pSub = pSub->GivNext(); // "y"
|
||||
pSub->SetValFloat(2);
|
||||
pSub = pSub->GivNext(); // "z"
|
||||
// pSub->SetValFloat(3);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void CTestCBotDoc::OnTest()
|
||||
{
|
||||
CBotProgram::DefineNum("WingedGrabber", 1);
|
||||
CBotProgram::DefineNum("TrackedGrabber", 2);
|
||||
CBotProgram::DefineNum("WheeledGrabber", 3);
|
||||
CBotProgram::DefineNum("LeggedGrabber", 4);
|
||||
CBotProgram::DefineNum("WingedShooter", 5);
|
||||
CBotProgram::DefineNum("TrackedShooter", 6);
|
||||
CBotProgram::DefineNum("WheeledShooter", 7);
|
||||
CBotProgram::DefineNum("LeggedShooter", 8);
|
||||
CBotProgram::DefineNum("WingedOrgaShooter", 9);
|
||||
CBotProgram::DefineNum("TrackedOrgaShooter", 10);
|
||||
CBotProgram::DefineNum("WheeledOrgaShooter", 11);
|
||||
CBotProgram::DefineNum("LeggedOrgaShooter", 12);
|
||||
CBotProgram::DefineNum("WingedSniffer", 13);
|
||||
CBotProgram::DefineNum("TrackedSniffer", 14);
|
||||
CBotProgram::DefineNum("WheeledSniffer", 14);
|
||||
CBotProgram::DefineNum("LeggedSniffer", 15);
|
||||
CBotProgram::DefineNum("Thumper", 16);
|
||||
CBotProgram::DefineNum("PhazerShooter", 17);
|
||||
CBotProgram::DefineNum("Recycler", 18);
|
||||
CBotProgram::DefineNum("Shielder", 19);
|
||||
CBotProgram::DefineNum("Subber", 20);
|
||||
CBotProgram::DefineNum("Me", 21);
|
||||
|
||||
CBotProgram::DefineNum("TypeMarkPath", 111);
|
||||
|
||||
OnFileSave();
|
||||
|
||||
// CPerformDlg dlg;
|
||||
// dlg.m_Script = m_DocText;
|
||||
// dlg.DoModal();
|
||||
|
||||
// défini la routine RetObject
|
||||
CBotProgram::AddFunction( "Radar", rRetObject, cRetObject );
|
||||
|
||||
// ajoute une routine pour cette classe
|
||||
CBotProgram::AddFunction("Space", rSpace, cSpace);
|
||||
|
||||
// défini la routine Test
|
||||
CBotProgram::AddFunction( "TEST", rTEST, cTEST );
|
||||
CBotProgram::AddFunction( "F", rF, cF );
|
||||
|
||||
CBotProgram::AddFunction( "goto", rMove, cMove );
|
||||
CBotProgram::AddFunction( "fire", rTurn, cTurn );
|
||||
CBotProgram::AddFunction( "radar", rRadar, cRadar );
|
||||
|
||||
// crée une instance de la classe "Bot" pour ce robot
|
||||
CBotVar* pThisRobot = CBotVar::Create( "", CBotTypResult(CBotTypClass, "object") );
|
||||
pThisRobot->SetUserPtr( (void*)1 );
|
||||
pThisRobot->SetIdent( 1234 );
|
||||
|
||||
delete m_pProg;
|
||||
// crée un objet programme associé à cette instance
|
||||
m_pProg = new CBotProgram(pThisRobot);
|
||||
|
||||
// compile le programme
|
||||
CString TextError;
|
||||
int code, start, end;
|
||||
|
||||
m_pEdit->GetWindowText(m_DocText);
|
||||
if (!m_pProg->Compile(m_DocText, m_Liste, (void*) 44))
|
||||
{
|
||||
m_pProg->GetError(code, start, end);
|
||||
delete m_pProg;
|
||||
m_pProg = NULL;
|
||||
|
||||
delete pThisRobot;
|
||||
|
||||
m_pEdit->SetSel( start, end );
|
||||
m_pEdit->SetFocus(); // met en évidence la partie avec problème
|
||||
|
||||
TextError = CBotProgram::GivErrorText( code );
|
||||
AfxMessageBox( TextError );
|
||||
|
||||
m_pEdit->SetFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
// exécute pour voir
|
||||
m_pProg->Start(m_Liste[0]);
|
||||
|
||||
int mode = -1;
|
||||
|
||||
if ( mode >= 0 ) {
|
||||
|
||||
// sauve et restore à chaque pas possible
|
||||
while (!m_pProg->Run(NULL, 1))
|
||||
{
|
||||
const char* FunctionName;
|
||||
int start1, end1;
|
||||
m_pProg->GetRunPos(FunctionName, start1, end1);
|
||||
if ( end1 <= 0 )
|
||||
m_pProg->GetRunPos(FunctionName, start1, end1);
|
||||
m_pEdit->SetSel(start1, end1);
|
||||
|
||||
if ( mode == 0 ) continue;
|
||||
|
||||
FILE* pf;
|
||||
pf = fOpen( "TEST.CBO", "wb" );
|
||||
CBotClass::SaveStaticState(pf);
|
||||
m_pProg->SaveState(pf);
|
||||
fClose(pf);
|
||||
|
||||
if ( mode == 2 ) if (!m_pProg->Compile(m_DocText, m_Liste, (void*) 44))
|
||||
{
|
||||
m_pProg->GetError(code, start, end);
|
||||
delete m_pProg;
|
||||
m_pProg = NULL;
|
||||
|
||||
delete pThisRobot;
|
||||
|
||||
m_pEdit->SetSel( start, end );
|
||||
m_pEdit->SetFocus(); // met en évidence la partie avec problème
|
||||
|
||||
TextError = CBotProgram::GivErrorText( code );
|
||||
AfxMessageBox( TextError );
|
||||
|
||||
m_pEdit->SetFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
pf = fOpen( "TEST.CBO", "rb" );
|
||||
CBotClass::RestoreStaticState(pf);
|
||||
m_pProg->RestoreState(pf);
|
||||
fClose(pf);
|
||||
|
||||
int start2, end2;
|
||||
m_pProg->GetRunPos(FunctionName, start2, end2);
|
||||
if ( end2 <= 0 )
|
||||
m_pProg->GetRunPos(FunctionName, start2, end2);
|
||||
|
||||
if ( start1 != start2 || end1 != end2 )
|
||||
m_pProg->GetRunPos(FunctionName, start2, end2);
|
||||
m_pEdit->SetSel(start2, end2);
|
||||
}
|
||||
|
||||
if (m_pProg->GetError(code, start, end))
|
||||
{
|
||||
m_pEdit->SetSel(start, end);
|
||||
TextError = CBotProgram::GivErrorText(code);
|
||||
AfxMessageBox(TextError);
|
||||
}
|
||||
return;}
|
||||
|
||||
while (!m_pProg->Run(NULL, 0))
|
||||
{
|
||||
const char* FunctionName;
|
||||
int start, end;
|
||||
m_pProg->GetRunPos(FunctionName, start, end);
|
||||
m_pEdit->SetSel(start, end);
|
||||
|
||||
if ( FunctionName == NULL ) continue;
|
||||
CString info (FunctionName);
|
||||
CString sep (":\n");
|
||||
|
||||
int level = 0;
|
||||
const char* Name;
|
||||
while ( TRUE )
|
||||
{
|
||||
CBotVar* pVar = m_pProg->GivStackVars(Name, level--);
|
||||
if ( Name != FunctionName ) break;
|
||||
if ( pVar == NULL ) continue;
|
||||
// pVar->Maj(NULL, FALSE);
|
||||
while ( pVar != NULL )
|
||||
{
|
||||
info += sep;
|
||||
info += pVar->GivName() + " = " + pVar->GivValString();
|
||||
sep = ", ";
|
||||
pVar = pVar->GivNext();
|
||||
}
|
||||
sep = "\n";
|
||||
}
|
||||
if ( IDOK != AfxMessageBox(info, MB_OKCANCEL) ) break;
|
||||
|
||||
if ( test == 1 )
|
||||
{
|
||||
test = 0;
|
||||
FILE* pf;
|
||||
pf = fOpen( "TEST.CBO", "wb" );
|
||||
m_pProg->SaveState(pf);
|
||||
fClose(pf);
|
||||
}
|
||||
|
||||
if ( test == 2 )
|
||||
{
|
||||
test = 0;
|
||||
FILE* pf;
|
||||
pf = fOpen( "TEST.CBO", "rb" );
|
||||
m_pProg->RestoreState(pf);
|
||||
fClose(pf);
|
||||
}
|
||||
|
||||
if ( test == 12 )
|
||||
{
|
||||
test = 0;
|
||||
FILE* pf;
|
||||
pf = fOpen( "TEST.CBO", "wb" );
|
||||
m_pProg->SaveState(pf);
|
||||
fClose(pf);
|
||||
|
||||
pf = fOpen( "TEST.CBO", "rb" );
|
||||
m_pProg->RestoreState(pf);
|
||||
fClose(pf);
|
||||
|
||||
test = 13;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pProg->GetError(code, start, end))
|
||||
{
|
||||
m_pEdit->SetSel(start, end);
|
||||
TextError = CBotProgram::GivErrorText(code);
|
||||
AfxMessageBox(TextError);
|
||||
}
|
||||
|
||||
delete pThisRobot;
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// TestCBotDoc.h : interface of the CTestCBotDoc class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_TESTCBOTDOC_H__4D1BB90B_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_TESTCBOTDOC_H__4D1BB90B_8E74_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
|
||||
class CTestCBotDoc : public CDocument
|
||||
{
|
||||
protected: // create from serialization only
|
||||
CTestCBotDoc();
|
||||
DECLARE_DYNCREATE(CTestCBotDoc)
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
CEdit* m_pEdit; // pour mémoriser le texte, et l'afficher
|
||||
CBotProgram* m_pProg; // le programme compilé
|
||||
CString m_DocText;
|
||||
CBotStringArray m_Liste;
|
||||
BOOL m_bModified;
|
||||
|
||||
// Operations
|
||||
public:
|
||||
BOOL Compile();
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CTestCBotDoc)
|
||||
public:
|
||||
virtual BOOL OnNewDocument();
|
||||
virtual void Serialize(CArchive& ar);
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CTestCBotDoc();
|
||||
#ifdef _DEBUG
|
||||
virtual void AssertValid() const;
|
||||
virtual void Dump(CDumpContext& dc) const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CTestCBotDoc)
|
||||
afx_msg void OnRun();
|
||||
afx_msg void OnChangeEdit1();
|
||||
afx_msg void OnTest();
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_TESTCBOTDOC_H__4D1BB90B_8E74_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,126 @@
|
|||
// TestCBotView.cpp : implementation of the CTestCBotView class
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TestCBot.h"
|
||||
|
||||
#include "TestCBotDoc.h"
|
||||
#include "TestCBotView.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotView
|
||||
|
||||
IMPLEMENT_DYNCREATE(CTestCBotView, CView)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CTestCBotView, CView)
|
||||
//{{AFX_MSG_MAP(CTestCBotView)
|
||||
ON_WM_SIZE()
|
||||
ON_MESSAGE(WM_ACTWINDOW, ActWindow)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotView construction/destruction
|
||||
|
||||
CTestCBotView::CTestCBotView()
|
||||
{
|
||||
}
|
||||
|
||||
CTestCBotView::~CTestCBotView()
|
||||
{
|
||||
}
|
||||
|
||||
BOOL CTestCBotView::PreCreateWindow(CREATESTRUCT& cs)
|
||||
{
|
||||
return CView::PreCreateWindow(cs);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotView drawing
|
||||
|
||||
void CTestCBotView::OnDraw(CDC* pDC)
|
||||
{
|
||||
CTestCBotDoc* pDoc = GetDocument();
|
||||
ASSERT_VALID(pDoc);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotView diagnostics
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CTestCBotView::AssertValid() const
|
||||
{
|
||||
CView::AssertValid();
|
||||
}
|
||||
|
||||
void CTestCBotView::Dump(CDumpContext& dc) const
|
||||
{
|
||||
CView::Dump(dc);
|
||||
}
|
||||
|
||||
CTestCBotDoc* CTestCBotView::GetDocument() // non-debug version is inline
|
||||
{
|
||||
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestCBotDoc)));
|
||||
return (CTestCBotDoc*)m_pDocument;
|
||||
}
|
||||
#endif //_DEBUG
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTestCBotView message handlers
|
||||
|
||||
void CTestCBotView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
|
||||
{
|
||||
CTestCBotDoc* pDoc = GetDocument();
|
||||
// CTestCBotApp* pApp = (CTestCBotApp*)AfxGetApp();
|
||||
|
||||
if ( pDoc->m_pEdit == NULL)
|
||||
{
|
||||
pDoc->m_pEdit = new CEdit();
|
||||
CRect rect;
|
||||
GetClientRect( rect );
|
||||
|
||||
pDoc->m_pEdit->Create( WS_VISIBLE|WS_BORDER|WS_TABSTOP|ES_MULTILINE|ES_WANTRETURN|ES_NOHIDESEL|ES_AUTOVSCROLL,
|
||||
rect, this, IDC_EDIT1 );
|
||||
pDoc->m_pEdit->SetTabStops(12);
|
||||
pDoc->m_pEdit->SetWindowText(pDoc->m_DocText);
|
||||
}
|
||||
|
||||
if ( !bActivate && !pDoc->Compile() )
|
||||
{
|
||||
// comment faire pour réactiver l'ancien document
|
||||
}
|
||||
|
||||
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
|
||||
|
||||
if ( bActivate ) pDoc->m_pEdit->SetFocus();
|
||||
}
|
||||
|
||||
|
||||
void CTestCBotView::OnSize(UINT nType, int cx, int cy)
|
||||
{
|
||||
CView::OnSize(nType, cx, cy);
|
||||
|
||||
CTestCBotDoc* pDoc = GetDocument();
|
||||
if ( pDoc->m_pEdit != NULL )
|
||||
{
|
||||
CRect rect;
|
||||
GetClientRect( rect );
|
||||
pDoc->m_pEdit->MoveWindow( rect );
|
||||
pDoc->m_pEdit->SetFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
LONG CTestCBotView::ActWindow(UINT wparam, LONG lparam)
|
||||
{
|
||||
// GetParentFrame()->SetActiveView( this, TRUE );
|
||||
// CMDIChildWnd::OnMDIActivate(1, this, this)
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
// TestCBotView.h : interface of the CTestCBotView class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_TESTCBOTVIEW_H__4D1BB90D_8E74_11D4_A439_00D059085115__INCLUDED_)
|
||||
#define AFX_TESTCBOTVIEW_H__4D1BB90D_8E74_11D4_A439_00D059085115__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
class CTestCBotView : public CView
|
||||
{
|
||||
protected: // create from serialization only
|
||||
CTestCBotView();
|
||||
DECLARE_DYNCREATE(CTestCBotView)
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
CTestCBotDoc* GetDocument();
|
||||
|
||||
// Operations
|
||||
public:
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CTestCBotView)
|
||||
public:
|
||||
virtual void OnDraw(CDC* pDC); // overridden to draw this view
|
||||
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
|
||||
protected:
|
||||
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CTestCBotView();
|
||||
#ifdef _DEBUG
|
||||
virtual void AssertValid() const;
|
||||
virtual void Dump(CDumpContext& dc) const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CTestCBotView)
|
||||
afx_msg void OnSize(UINT nType, int cx, int cy);
|
||||
afx_msg LONG ActWindow(UINT wparam, LONG lparam) ;
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
#ifndef _DEBUG // debug version in TestCBotView.cpp
|
||||
inline CTestCBotDoc* CTestCBotView::GetDocument()
|
||||
{ return (CTestCBotDoc*)m_pDocument; }
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_TESTCBOTVIEW_H__4D1BB90D_8E74_11D4_A439_00D059085115__INCLUDED_)
|
|
@ -0,0 +1,15 @@
|
|||
extern public void TestNull ()
|
||||
{
|
||||
CPoint pointeur = null;
|
||||
|
||||
try {
|
||||
pointeur.x = 4; }
|
||||
catch ( 6007 ) {}
|
||||
|
||||
pointeur = new CPoint(1,2);
|
||||
|
||||
print ( pointeur.x, pointeur.y,
|
||||
pointeur );
|
||||
|
||||
pointeur.x = 5;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
// routine de Daniel qui plante après RestoreState
|
||||
|
||||
extern void object::Attack( )
|
||||
{
|
||||
int list[], i;
|
||||
object p;
|
||||
float dist, prox;
|
||||
point nav1, nav2, dest;
|
||||
boolean advance = true;
|
||||
|
||||
i = 0;
|
||||
list[i++] = WingedGrabber;
|
||||
list[i++] = TrackedGrabber;
|
||||
list[i++] = WheeledGrabber;
|
||||
list[i++] = LeggedGrabber;
|
||||
list[i++] = WingedShooter;
|
||||
list[i++] = TrackedShooter;
|
||||
list[i++] = WheeledShooter;
|
||||
list[i++] = LeggedShooter;
|
||||
list[i++] = WingedOrgaShooter;
|
||||
list[i++] = TrackedOrgaShooter;
|
||||
list[i++] = WheeledOrgaShooter;
|
||||
list[i++] = LeggedOrgaShooter;
|
||||
list[i++] = WingedSniffer;
|
||||
list[i++] = TrackedSniffer;
|
||||
list[i++] = WheeledSniffer;
|
||||
list[i++] = LeggedSniffer;
|
||||
list[i++] = Thumper;
|
||||
list[i++] = PhazerShooter;
|
||||
list[i++] = Recycler;
|
||||
list[i++] = Shielder;
|
||||
list[i++] = Subber;
|
||||
list[i++] = Me;
|
||||
|
||||
nav1.x = 1;//cmdline(0);
|
||||
nav1.y = 1;//cmdline(1);
|
||||
nav2.x = 2;//cmdline(2);
|
||||
nav2.y = 2;//cmdline(3);
|
||||
|
||||
while ( true )
|
||||
{
|
||||
while ( true )
|
||||
{
|
||||
// ennemi à proximité ?
|
||||
p = radar(list, 0, 360, 0, 40);
|
||||
if ( p == null ) break;
|
||||
// lui tire dessus
|
||||
fire(p.position);
|
||||
}
|
||||
|
||||
// se promène vers le point A
|
||||
goto(nav1);
|
||||
|
||||
while ( true )
|
||||
{
|
||||
// ennemi à proximité ?
|
||||
p = radar(list, 0, 360, 0, 40);
|
||||
if ( p == null ) break;
|
||||
// lui tire dessus
|
||||
fire(p.position);
|
||||
}
|
||||
|
||||
// se promène vers le point B
|
||||
goto(nav2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
class ESSAI
|
||||
{
|
||||
int x = 0;
|
||||
static int nb = 3;
|
||||
static int [ ] array ;
|
||||
|
||||
void Put( int val)
|
||||
{
|
||||
show(nb);
|
||||
array[ nb ] = val;
|
||||
// this.nb++;
|
||||
this.nb = this.nb + 1;
|
||||
show(nb, array);
|
||||
}
|
||||
int Get( )
|
||||
{
|
||||
nb--;
|
||||
show("out", nb, array);
|
||||
return array[ nb ] ;
|
||||
}
|
||||
}
|
||||
|
||||
extern public void T()
|
||||
{
|
||||
ESSAI t1 ( ) ;
|
||||
ESSAI t2 ( ) ;
|
||||
t1.nb++;
|
||||
t1.Put( 11 ); t1.Put( 12 ); t2.Put( 13 );
|
||||
|
||||
show ( t1.Get(), t2.Get(), t2.Get() ) ;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
extern public void TSTR()
|
||||
{
|
||||
string s = "C'est un essai";
|
||||
|
||||
print ( s, strlen(s), strleft(s, 3), strright(s,3), strmid(s, 2), strmid(s,2,3), strfind(s, "un"), strfind(s, "sdgfld") );
|
||||
|
||||
show ( strupper(s), strlower(s) );
|
||||
|
||||
s = "123.45" ;
|
||||
print ( strval(s) );
|
||||
|
||||
|
||||
string sub = strright("abcdef", 2); // sub vaut "ef###", # étant un caractère bizarre quelconque
|
||||
show (sub);
|
||||
int pos = strfind("abcdef", "xy"); // pos vaut -1. Pourquoi pas nan ?
|
||||
show(pos);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
public extern void tp()
|
||||
{
|
||||
int a [4], b[];
|
||||
a [ 0 ] = 8 ;
|
||||
|
||||
b = T ( a ) ;
|
||||
show ( a, b );
|
||||
}
|
||||
|
||||
int[] T ( int[] Z )
|
||||
{
|
||||
for ( int i = 0; i < 4 ; i++ ) Z[ i ] = i * i ;
|
||||
return Z;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
public extern void TestTableau ()
|
||||
{
|
||||
int tableau [ 12 ] ;
|
||||
|
||||
point array[ 12 ] [ 14 ] ;
|
||||
|
||||
point zéro ( 1, 2 ) ;
|
||||
point a = zéro ;
|
||||
|
||||
for ( int i = 0 ; i < 10 ; i++ ) array[ i ] [ i ]= zéro ;
|
||||
|
||||
array[ 5 ] [3 ] . x =1.5 ;
|
||||
|
||||
array[ 2 ] [ 2 ] . y = array[ 5 ] [ 5 ] . x ;
|
||||
|
||||
array[ 4 ] = array [ 2 ] ;
|
||||
|
||||
for ( int i = 0 ; i < 10 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) println ( i, j, array [ i ] [ j ] ) ;
|
||||
|
||||
show( zéro, a, array );
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
object radarGuepe(point orig, float dist)
|
||||
{
|
||||
int i;
|
||||
object pr, r;
|
||||
float mindist;
|
||||
|
||||
i = 0;
|
||||
mindist = 1000;
|
||||
while (i<30)
|
||||
{
|
||||
pr = radar(i);
|
||||
if (pr != null)
|
||||
{
|
||||
|
||||
if (F(orig, pr.position) < mindist and pr.category == AlienWasp and pr.altitude > 3)
|
||||
{
|
||||
mindist = distance(orig, pr.position);
|
||||
r = pr;
|
||||
}
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
if (mindist < dist) return(r); else return(null);
|
||||
}
|
||||
|
||||
|
||||
class Guepe
|
||||
{
|
||||
|
||||
point pos;
|
||||
|
||||
|
||||
void cherche(point orig, float dist)
|
||||
{
|
||||
object p;
|
||||
point o;
|
||||
|
||||
p = radarGuepe(orig, dist);
|
||||
while (p == null)
|
||||
{
|
||||
wait(0.1);
|
||||
p = radarGuepe(orig, dist);
|
||||
}
|
||||
|
||||
pos.x = p.position.x;
|
||||
pos.y = p.position.y;
|
||||
pos.z = p.position.z;
|
||||
|
||||
//o = p.position;
|
||||
//wait(0.1);
|
||||
|
||||
//vitessex = (p.position.x - o.x)/0.1;
|
||||
//vitessey = (p.position.y - o.y)/0.1;
|
||||
//vitessez = (p.position.z - o.z)/0.1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void tire(point orig, float orient)
|
||||
{
|
||||
//float t = 3; //temps d'anticipation
|
||||
float angle;
|
||||
point cible;
|
||||
|
||||
cible.x = pos.x;// + t*vitessex;
|
||||
cible.y = pos.y;// + t*vitessey;
|
||||
cible.z = pos.z;// + t*vitessez;
|
||||
|
||||
if (cible.x == 0) angle = 90; else
|
||||
angle = atan(cible.y / cible.x);
|
||||
if (cible.x < 0) angle = angle + 180;
|
||||
angle = angle - orient;
|
||||
if (angle > 180) angle = angle - 360;
|
||||
if (angle < -180) angle = angle + 360;
|
||||
turn(angle);
|
||||
|
||||
angle = atan((cible.z-orig.z) / distance2d(orig, cible));
|
||||
aim(angle);
|
||||
|
||||
fire(0.1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extern void object::Fourmi6()
|
||||
{
|
||||
//fps(1000);
|
||||
Guepe guepe = new Guepe();
|
||||
|
||||
while (true)
|
||||
{
|
||||
guepe.cherche(position, 50);
|
||||
|
||||
guepe.tire(position, orientation);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
public extern void object::Bug()
|
||||
{
|
||||
point a;
|
||||
a = position;
|
||||
TEST();
|
||||
float d=dist(a, position);
|
||||
}
|
||||
|
||||
float dist(point a, point b)
|
||||
{
|
||||
return a.x-b.x;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
extern public void main()
|
||||
{
|
||||
show(fact(30)) ;
|
||||
}
|
||||
|
||||
public int fact(int n)
|
||||
{
|
||||
return (fact(n-1)*n) ;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public extern void ccc()
|
||||
{
|
||||
int a;
|
||||
a = 0 ;
|
||||
|
||||
if ( a == 0 );
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
enum JourDeLaSemaine {
|
||||
lundi = 1,
|
||||
mardi,
|
||||
mercredi,
|
||||
jeudi,
|
||||
vendredi,
|
||||
samedi,
|
||||
dimanche = 0 }
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
extern public int Fibo( int n, boolean b )
|
||||
{
|
||||
if ( n < 2 ) return n;
|
||||
int a = Fibo(n-1, b) + Fibo(n-2, false);
|
||||
if ( b ) print (n + "=" + a);
|
||||
return a;
|
||||
}
|
||||
|
||||
extern public void t()
|
||||
{
|
||||
Fibo( 23, true);
|
||||
}
|
||||
|
||||
extern public void tt()
|
||||
{
|
||||
t();
|
||||
}
|
||||
|
||||
// cette routine n'est évidemment pas du tout obtimisée
|
||||
// c'est même un très mauvais exemple de programmation récursive
|
||||
|
||||
// pour un test de durée, Fibo(23, true) prend
|
||||
// en mode Debug 67 secondes
|
||||
// en mode Release 8 secondes
|
|
@ -0,0 +1,70 @@
|
|||
class CLASS22
|
||||
{
|
||||
static int nb = 2;
|
||||
void T22 ( ) { nb = nb / 0 ; }
|
||||
}
|
||||
|
||||
public extern void object :: TEST()
|
||||
{
|
||||
switch ( 1 )
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
file h();
|
||||
h.open("Mon Fichier.txt", "r");
|
||||
show ( h.filename, h.handle );
|
||||
h.filename = "xx";
|
||||
h.handle = 1 ;
|
||||
h.readln();
|
||||
h.close();
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
file h("Mon Fichier.txt");
|
||||
h.open("r");
|
||||
h.readln();
|
||||
h.close();
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
file h("Mon Fichier.txt", "r");
|
||||
h.readln();
|
||||
h.close();
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
file h();
|
||||
h.filename = "Mon Fichier.txt";
|
||||
h.open("r");
|
||||
h.readln();
|
||||
h.close();
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
file h = fileopen( "Mon 2Fichier.txt", "r" );
|
||||
h.readln();
|
||||
h.close();
|
||||
}
|
||||
}
|
||||
{
|
||||
file h( ) ;
|
||||
h.filename = "Test.h";
|
||||
h.open ( "r" );
|
||||
|
||||
|
||||
file pf ( "Mon Fichier.txt" ) ;
|
||||
pf . open ( "w" ) ;
|
||||
pf . writeln ( "Voici encore du texte" ) ;
|
||||
pf . writeln ( "et une seconde ligne" ) ;
|
||||
pf . close( );
|
||||
|
||||
pf . open ( "r" ) ;
|
||||
|
||||
while ( not pf . eof( ) )
|
||||
{
|
||||
string s = pf . readln ( );
|
||||
show ( s );
|
||||
}
|
||||
pf.close( );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
void tf()
|
||||
{
|
||||
file h;
|
||||
h.handle += 1 ;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
class Z
|
||||
{
|
||||
static int x = 0;
|
||||
private int y;
|
||||
|
||||
void T( )
|
||||
{
|
||||
// autorisé ici
|
||||
y = x ;
|
||||
this.y = this.x ;
|
||||
x = y ;
|
||||
this.x = this.y ;
|
||||
}
|
||||
}
|
||||
|
||||
extern public void test()
|
||||
{
|
||||
Z a();
|
||||
3 * a.x; // autorisé
|
||||
//vu 3 * a.y; // interdit
|
||||
//vu a.y = 3; // interdit ici
|
||||
a.x = 1; // autorisé
|
||||
|
||||
show ( a );
|
||||
a.T();
|
||||
show ( a );
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
public extern void TestIntrinsic()
|
||||
{
|
||||
point a ( 1, 2 );
|
||||
print (a);
|
||||
|
||||
a.x = 3;
|
||||
a.y = 4;
|
||||
|
||||
point b = a;
|
||||
|
||||
println ( b.x, b.y, b ) ;
|
||||
if ( b == a ) b.y = 0;
|
||||
println (a,b);
|
||||
if ( b != a ) b.y = a.y;
|
||||
println(a,b);
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
class t {
|
||||
point p;
|
||||
}
|
||||
|
||||
void object :: toto()
|
||||
{
|
||||
show ( Position ) ;
|
||||
}
|
||||
|
||||
extern public void object :: XX()
|
||||
{
|
||||
int test [];
|
||||
test [ 9999 ] = 3;
|
||||
|
||||
toto () ;
|
||||
/*
|
||||
Radar();
|
||||
|
||||
object test ;
|
||||
test = this. Radar();
|
||||
|
||||
do {
|
||||
test = this.Radar();
|
||||
} while ( test == null );
|
||||
|
||||
/*
|
||||
t test [ 4 ];
|
||||
for ( int i = 0 ; i < 4 ; i++ ) test [ i ] = new t();
|
||||
test [ 3 ] .p.x = 2;
|
||||
show ( test );
|
||||
/*
|
||||
int a = nan;
|
||||
show ( a ) ;
|
||||
|
||||
a = TypeMarkPath;
|
||||
show ( a, a++, --a ) ;
|
||||
|
||||
if ( a != nan ) a += 1 ;
|
||||
|
||||
a = TypeMarkPath;
|
||||
float q = a ;
|
||||
show ( a, q ) ;
|
||||
|
||||
return;
|
||||
|
||||
a += ++a;
|
||||
show ( a ) ;
|
||||
|
||||
boolean i = false;
|
||||
|
||||
if ( i == true ) {}
|
||||
|
||||
object p;
|
||||
if ( p == null) { p = p ; }
|
||||
*/
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
extern void Toto()
|
||||
{
|
||||
TEST(12);
|
||||
|
||||
for ( int i = 0 ; i<1000; i++)
|
||||
{
|
||||
int j = 1;
|
||||
if (i==55) TEST(12);
|
||||
}
|
||||
|
||||
TEST(2);
|
||||
|
||||
|
||||
// Nouveau();
|
||||
int toto[4];
|
||||
point Z[3];
|
||||
|
||||
Z[1].x = 11; Z[1].y = 12;
|
||||
|
||||
toto[2] = 12;
|
||||
toto[1] = nan;
|
||||
|
||||
// point test, autre(2,3) ;
|
||||
// object titi = Radar();
|
||||
|
||||
TEST ( 1 ) ;
|
||||
|
||||
toto[0] = 11;
|
||||
|
||||
TEST ( 2 ) ;
|
||||
|
||||
toto[6] = 0;
|
||||
}
|
||||
|
||||
extern void object::Nouveau()
|
||||
{
|
||||
point a;
|
||||
a = np(Position);
|
||||
}
|
||||
|
||||
point np(point b)
|
||||
{
|
||||
point c;
|
||||
c.x = b.y;
|
||||
c.y = b.x;
|
||||
return c ;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
class Guepet
|
||||
{
|
||||
|
||||
float a;
|
||||
float b;
|
||||
|
||||
void init()
|
||||
{
|
||||
a = 12.34;
|
||||
b = 56.78;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extern void object::Fourmi6()
|
||||
{
|
||||
Guepet guepe =new Guepet();
|
||||
|
||||
guepe.init();
|
||||
|
||||
|
||||
show("test "+guepe.a+" "+guepe.b);
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
class Guepet
|
||||
{
|
||||
|
||||
float a;
|
||||
float b;
|
||||
|
||||
void init()
|
||||
{
|
||||
a = 12.34;
|
||||
b = 56.78;
|
||||
|
||||
object x = radar(123);
|
||||
show("radar "+x.position.x);
|
||||
show("C'est fait");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extern void object::Fourmi6()
|
||||
{
|
||||
Guepet guepe=new Guepet();
|
||||
|
||||
guepe.init();
|
||||
|
||||
show("test "+guepe.a+" "+guepe.b);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
extern public void main()
|
||||
{
|
||||
// goto( 3, 4 );
|
||||
|
||||
while( true )
|
||||
{
|
||||
try { goto (12) ; }
|
||||
catch( FF( ) )
|
||||
{ show( "ko"); }
|
||||
}
|
||||
}
|
||||
|
||||
boolean FF()
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
extern public void xxx ()
|
||||
{
|
||||
CPoint test = null ;
|
||||
if ( test == null ) show ( "NULL" );
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
extern public void xx ()
|
||||
{
|
||||
CPoint pointeur, test = null ;
|
||||
pointeur = new CPoint ( 3, 4 );
|
||||
|
||||
if ( test == null ) show ( "NULL" );
|
||||
|
||||
CPoint pp = pointeur;
|
||||
|
||||
show( pointeur , pp );
|
||||
|
||||
pp.x = 33.3;
|
||||
if ( pointeur.x != pp.x ) 0/0;
|
||||
|
||||
pp = new CPoint();
|
||||
// pointeur = pp;
|
||||
|
||||
show( pointeur , pp );
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
class Guepet
|
||||
{
|
||||
|
||||
point pos;
|
||||
float t = 0.1;
|
||||
|
||||
void init()
|
||||
{
|
||||
pos.x = 12.123;
|
||||
pos.y = 34.345;
|
||||
|
||||
F(t);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extern void object::Fourmi6()
|
||||
{
|
||||
Guepet guepe=new Guepet();
|
||||
|
||||
guepe.init();
|
||||
|
||||
show ( guepe );
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
extern public void x ()
|
||||
{
|
||||
show ( 3 ** 4 );
|
||||
float z = 1e-3;
|
||||
show ( z );
|
||||
|
||||
CPoint b ( 4,5 );
|
||||
show ( b );
|
||||
|
||||
CPoint a ( ) ;
|
||||
a.x = 21; a.y = 12;
|
||||
show ( a ) ;
|
||||
|
||||
CPoint test = new CPoint ( 1,1 );
|
||||
test = new CPoint ( 2, 2 );
|
||||
show ( test );
|
||||
}
|
||||
|
||||
// crée un objet et retourne son pointeur
|
||||
CPoint newcpoint()
|
||||
{
|
||||
CPoint p = new CPoint ( 3, 3 );
|
||||
return p;
|
||||
}
|
||||
|
||||
extern public void y ()
|
||||
{
|
||||
CPoint test = newcpoint();
|
||||
println ( test );
|
||||
dontmodif( test );
|
||||
println ( test );
|
||||
}
|
||||
|
||||
// ne doit pas modifier l'objet en paramčtre
|
||||
void dontmodif ( CPoint pp )
|
||||
{
|
||||
pp.x = 5;
|
||||
pp.y = 2;
|
||||
println ( pp, pp.x, pp.y );
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
extern public void X()
|
||||
{
|
||||
point A [ ] ;
|
||||
A[5] = new point (2,3);
|
||||
int val = A[5].x++ + --A[5].y;
|
||||
show ( A, val );
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
extern void object::Bug( )
|
||||
{
|
||||
try{ int a = 44 ; a = 12 / 0 ; }
|
||||
catch(6000) { int b = 4 ; }
|
||||
finally { int z = 1 ; }
|
||||
|
||||
// tp ( A, B );
|
||||
|
||||
/* int a = 4, b = 2, c = nan;
|
||||
float x, y = 3/2, z = nan;
|
||||
boolean i, j = false, k = true;
|
||||
|
||||
string s, ss = "xyz";
|
||||
|
||||
while ( false )
|
||||
{
|
||||
object left, right;
|
||||
|
||||
left = Radar(TypeMarkPath, -45, 120, 100);
|
||||
right = Radar(TypeMarkPath, 45, 120, 100);
|
||||
|
||||
if ( left == null && right == null )
|
||||
{
|
||||
}
|
||||
}
|
||||
int t = fact ( 4 ) ;*/
|
||||
}
|
||||
|
||||
void tp( point a , point b )
|
||||
{
|
||||
a.x += b.x;
|
||||
}
|
||||
|
||||
|
||||
int fact( int n )
|
||||
{
|
||||
if ( n < 2 ) return n;
|
||||
return n * fact ( n - 1 ) ;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,13 @@
|
|||
//
|
||||
// TESTCBOT.RC2 - resources Microsoft Visual C++ does not edit directly
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#error this file is not editable by Microsoft Visual C++
|
||||
#endif //APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Add manually edited resources here...
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -0,0 +1,30 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by TestCBot.rc
|
||||
//
|
||||
#define IDD_ABOUTBOX 100
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDR_TESTCBTYPE 129
|
||||
#define IDD_DIALOG1 130
|
||||
#define IDD_CONSOLE 131
|
||||
#define IDD_DIALOG2 133
|
||||
#define IDC_EDIT1 1000
|
||||
#define TX_TYPENAMES 1000
|
||||
#define IDC_SPIN1 1001
|
||||
#define IDC_EDIT2 1002
|
||||
#define IDC_COMBO1 1003
|
||||
#define IDC_EDIT3 1004
|
||||
#define ID_RUN 32771
|
||||
#define ID_TEST 32772
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_3D_CONTROLS 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 135
|
||||
#define _APS_NEXT_COMMAND_VALUE 32773
|
||||
#define _APS_NEXT_CONTROL_VALUE 1004
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,13 @@
|
|||
extern void object::Solution( )
|
||||
{
|
||||
show ( "Solution " + Position );
|
||||
Carré(15);
|
||||
Carré(25);
|
||||
}
|
||||
|
||||
void object::Carré(float côté)
|
||||
{
|
||||
show ( "Carré " + Position );
|
||||
Move(côté);
|
||||
Turn(-90);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
extern public void x()
|
||||
{
|
||||
float a= 1, b = 2;
|
||||
a = b * ( 2 + 2 );
|
||||
// print (a);
|
||||
a += 4;
|
||||
// print (a);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
extern public void object::TEST23()
|
||||
{
|
||||
CLASS22 T;
|
||||
T.T22( ) ;
|
||||
|
||||
show( position );
|
||||
show( this.position );
|
||||
|
||||
// T22();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
extern public int testmw( int a)
|
||||
{
|
||||
boolean b = true ;
|
||||
|
||||
if (b)
|
||||
return 1 ;
|
||||
else
|
||||
return a ; 0 * testmw(a-1) ;
|
||||
}
|
||||
|
||||
public int Fibo2 ( int n )
|
||||
{
|
||||
print ( " bof " );
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
extern void object :: TEST22 ( )
|
||||
{
|
||||
show( position );
|
||||
show( this.position );
|
||||
|
||||
T();
|
||||
}
|
||||
|
||||
public void object :: T22()
|
||||
{
|
||||
show( position );
|
||||
show( this.position );
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
extern public void T() { T1(); }
|
||||
|
||||
public void T1()
|
||||
{
|
||||
show( "T1" );
|
||||
T2();
|
||||
}
|
||||
|
||||
public void T2()
|
||||
{
|
||||
show( "T2" );
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue