From 67eb3acad9aac396d88d4db8e6c7e52230170f69 Mon Sep 17 00:00:00 2001 From: Saalvage Date: Wed, 25 Mar 2020 21:28:30 +0100 Subject: [PATCH 1/7] - slight optimization for clamp function --- bbruntime/bbmath.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bbruntime/bbmath.cpp b/bbruntime/bbmath.cpp index 48b96eeb..1fbc8691 100644 --- a/bbruntime/bbmath.cpp +++ b/bbruntime/bbmath.cpp @@ -31,7 +31,13 @@ float bbClamp( float v, float lo, float hi){ if (lo > hi){ std::swap(lo,hi); } - return (float)max(lo, min(v, hi)); + if (v < lo){ + return lo; + } else if (v > hi){ + return hi; + } else{ + return v; + } } //return rand float from 0...1 From 8c294f5c4dcb37e2365ec1c0e8ad693b0f4ff06f Mon Sep 17 00:00:00 2001 From: Saalvage Date: Thu, 26 Mar 2020 01:52:46 +0100 Subject: [PATCH 2/7] - slightly optimized Absolute function --- bbruntime/basic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bbruntime/basic.cpp b/bbruntime/basic.cpp index 6fe240d7..c0883eee 100644 --- a/bbruntime/basic.cpp +++ b/bbruntime/basic.cpp @@ -476,7 +476,7 @@ BBStr *_bbReadStr(){ } int _bbAbs( int n ){ - return n>=0 ? n : -n; + return n & 0x7FFFFFFF; } int _bbSgn( int n ){ From 0d05d5097ceaca045f9b0fd57284edcf9618910a Mon Sep 17 00:00:00 2001 From: Saalvage Date: Fri, 27 Mar 2020 14:37:08 +0100 Subject: [PATCH 3/7] - removed DEMO and EDU --- bbruntime_dll/bbruntime_dll.cpp | 14 ------------- blitz/main.cpp | 9 -------- blitzide/about.cpp | 37 ++++----------------------------- blitzide/about.h | 2 +- blitzide/blitzide.cpp | 4 ---- blitzide/blitzide.rc | 6 +++--- blitzide/editor.cpp | 4 ---- blitzide/mainframe.cpp | 6 +----- compiler/parser.cpp | 9 -------- config/config.h | 14 +------------ linker/image_util.cpp | 5 ----- linker/linker.cpp | 10 +-------- 12 files changed, 11 insertions(+), 109 deletions(-) diff --git a/bbruntime_dll/bbruntime_dll.cpp b/bbruntime_dll/bbruntime_dll.cpp index f1a696f9..02e09ba6 100644 --- a/bbruntime_dll/bbruntime_dll.cpp +++ b/bbruntime_dll/bbruntime_dll.cpp @@ -4,10 +4,6 @@ #include "bbruntime_dll.h" #include "../debugger/debugger.h" -#ifdef PRODEMO -#include "../shareprot/shareprot.h" -#endif - using namespace std; #include @@ -39,12 +35,6 @@ static void rtSym( const char *sym,void *pc ){ syms[sym]=pc; } -#ifdef PRODEMO -static void killer(){ - ExitProcess( -1 ); -} -#endif - static void _cdecl seTranslator( unsigned int u,EXCEPTION_POINTERS* pExp ){ switch( u ){ case EXCEPTION_INT_DIVIDE_BY_ZERO: @@ -118,10 +108,6 @@ void Runtime::execute( void (*pc)(),const char *args,Debugger *dbg ){ while( params.size() && params[params.size()-1]==' ' ) params=params.substr( 0,params.size()-1 ); if( gx_runtime=gxRuntime::openRuntime( hinst,params,dbg ) ){ - -#ifdef PRODEMO - shareProtCheck( killer ); -#endif bbruntime_run( gx_runtime,pc,debug ); gxRuntime *t=gx_runtime; diff --git a/blitz/main.cpp b/blitz/main.cpp index 29962ee5..7eadcc60 100644 --- a/blitz/main.cpp +++ b/blitz/main.cpp @@ -130,11 +130,6 @@ static void versInfo(){ cout<<"Linker version:"<EnableWindow(0); @@ -94,22 +94,7 @@ void aboutBlitz( bool delay ){ t+="Blitz2D"; #endif -#ifdef EDU - t+=" - Educational Version"; -#else -#ifdef DEMO - t+=" - Demo Version\n\n"; - /* - int n=shareProtCheck(); - if( n>1 ) t+=itoa(n)+" runs left"; - else if( n ) t+=itoa(n)+" run left"; - else t+="expired"; - t+=")\n\n"; - */ -#else - t+=" - Release Version\n\n"; -#endif -#endif +t+=" - Release Version\n\n"; about.GetDlgItem( IDC_PRODUCT )->SetWindowText( t.c_str() ); @@ -117,20 +102,6 @@ void aboutBlitz( bool delay ){ t="Runtime V"+itoa((VERSION&0xffff)/1000)+"."+itoa((VERSION&0xffff)%1000); about.GetDlgItem( IDC_VERSION )->SetWindowText( t.c_str() ); -#ifdef DEMO - - if( delay ){ - about.GetDlgItem( IDOK )->ShowWindow( SW_HIDE ); - about.GetDlgItem( IDC_PROGRESS1 )->ShowWindow( SW_SHOW ); - for( int k=0;k<100;++k ){ - ((CProgressCtrl*)about.GetDlgItem( IDC_PROGRESS1 ))->SetPos( k+1 ); - about.wait( 50 ); - } - about.GetDlgItem( IDOK )->ShowWindow( SW_SHOW ); - } - -#endif - about.GetDlgItem( IDC_PROGRESS1 )->ShowWindow( SW_HIDE ); about.wait(); about.EndDialog(0); diff --git a/blitzide/about.h b/blitzide/about.h index 41751087..c652d68e 100644 --- a/blitzide/about.h +++ b/blitzide/about.h @@ -2,6 +2,6 @@ #ifndef ABOUT_H #define ABOUT_H -void aboutBlitz( bool delay ); +void aboutBlitz(); #endif \ No newline at end of file diff --git a/blitzide/blitzide.cpp b/blitzide/blitzide.cpp index 7f6ead66..a9413ed9 100644 --- a/blitzide/blitzide.cpp +++ b/blitzide/blitzide.cpp @@ -24,10 +24,6 @@ BOOL BlitzIDE::InitInstance(){ mainFrame=new MainFrame(); m_pMainWnd = mainFrame; -#ifdef DEMO - aboutBlitz( true ); -#endif - mainFrame->LoadFrame( IDR_MAINFRAME ); mainFrame->MoveWindow( CRect( prefs.win_rect ) ); mainFrame->ShowWindow( m_nCmdShow ); diff --git a/blitzide/blitzide.rc b/blitzide/blitzide.rc index d2326906..57e603b5 100644 --- a/blitzide/blitzide.rc +++ b/blitzide/blitzide.rc @@ -295,11 +295,11 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION CAPTION "About Blitz" FONT 10, "MS Sans Serif" BEGIN - DEFPUSHBUTTON "Okee Dokee!",IDOK,79,150,50,14 + DEFPUSHBUTTON "Okay then..",IDOK,79,150,50,14 CONTROL 132,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZEIMAGE,11, 5,64,32 - CTEXT "BlitzPlus - Demo Version",IDC_PRODUCT,78,7,139,8 - CTEXT "IDE V1.1 Runtime V1.1 Linker V1.1",IDC_VERSION,78,27, + CTEXT "",IDC_PRODUCT,78,7,139,8 + CTEXT "",IDC_VERSION,78,27, 139,8 CTEXT "Copyright Blitz Research Ltd",IDC_STATIC,78,17,139,8 CONTROL "Progress1",IDC_PROGRESS1,"msctls_progress32",PBS_SMOOTH | diff --git a/blitzide/editor.cpp b/blitzide/editor.cpp index faddcad4..9aaaf9fb 100644 --- a/blitzide/editor.cpp +++ b/blitzide/editor.cpp @@ -5,11 +5,7 @@ static bool locked; -#ifdef DEMO -static const int TEXTLIMIT=16384; -#else static const int TEXTLIMIT=1024*1024-1; -#endif static const UINT wm_Find=RegisterWindowMessage( FINDMSGSTRING ); diff --git a/blitzide/mainframe.cpp b/blitzide/mainframe.cpp index 61da64ff..38b57ee2 100644 --- a/blitzide/mainframe.cpp +++ b/blitzide/mainframe.cpp @@ -734,10 +734,6 @@ void MainFrame::programCompile(){ } void MainFrame::programPublish(){ -#ifdef DEMO - MessageBox( "Create Executable unavailable in demo version","Sorry!",MB_TOPMOST|MB_SETFOREGROUND|MB_ICONINFORMATION ); - return; -#endif Editor *e=getEditor();if( !e ) return; if( prefs.prg_debug ){ string t= @@ -796,7 +792,7 @@ void MainFrame::helpForward(){ } void MainFrame::helpAbout(){ - aboutBlitz( false ); + aboutBlitz(); } void MainFrame::ctrlTab(){ diff --git a/compiler/parser.cpp b/compiler/parser.cpp index ffc43b05..b9db05c2 100644 --- a/compiler/parser.cpp +++ b/compiler/parser.cpp @@ -3,11 +3,7 @@ #include #include "parser.h" -#ifdef DEMO -static const int TEXTLIMIT=16384; -#else static const int TEXTLIMIT=1024*1024-1; -#endif enum{ STMTS_PROG,STMTS_BLOCK,STMTS_LINE @@ -84,11 +80,6 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope, bool debug){ int pos=toker->pos(); -#ifdef DEMO - if( Toker::chars_toked>TEXTLIMIT ){ - ex( "Demo version source limit exceeded" ); - } -#endif switch( toker->curr() ){ case INCLUDE: { diff --git a/config/config.h b/config/config.h index 28f408c3..e9d52a02 100644 --- a/config/config.h +++ b/config/config.h @@ -10,18 +10,6 @@ #define PRO_F 0 #endif -#ifdef DEMO -#define DEMO_F 0x080000 -#else -#define DEMO_F 0 -#endif - -#ifdef EDU -#define EDU_F 0x200000 -#else -#define EDU_F 0 -#endif - -#define VERSION (BASE_VER|PRO_F|DEMO_F|EDU_F) +#define VERSION (BASE_VER|PRO_F) #endif diff --git a/linker/image_util.cpp b/linker/image_util.cpp index 99cf71aa..aa28072b 100644 --- a/linker/image_util.cpp +++ b/linker/image_util.cpp @@ -2,8 +2,6 @@ #include "std.h" #include "image_util.h" -#ifndef DEMO - #pragma pack( push,1 ) struct Head{ short machine,num_sects; @@ -360,6 +358,3 @@ void closeImage(){ delete[] stub; img_file=0; } - -#endif - diff --git a/linker/linker.cpp b/linker/linker.cpp index c4c8c2a3..985572e8 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -130,11 +130,7 @@ int Linker::version(){ } bool Linker::canCreateExe(){ -#ifdef DEMO - return false; -#else return true; -#endif } Module *Linker::createModule(){ @@ -151,10 +147,6 @@ Linker *_cdecl linkerGetLinker(){ bool BBModule::createExe( const char *exe_file,const char *dll_file ){ -#ifdef DEMO - return false; -#else - //find proc address of bbWinMain HMODULE hmod=LoadLibrary( dll_file );if( !hmod ) return false; int proc=(int)GetProcAddress( hmod,"_bbWinMain@0" ); @@ -210,5 +202,5 @@ bool BBModule::createExe( const char *exe_file,const char *dll_file ){ closeImage(); return true; -#endif + } From ffdce1ec6d42f77ffdfd1c0b591c20105c17fbc9 Mon Sep 17 00:00:00 2001 From: Saalvage Date: Fri, 27 Mar 2020 18:05:11 +0100 Subject: [PATCH 4/7] Removed NaN constant, improved Infinity constant and implemented efficient PowTwo calculation --- bbruntime/basic.cpp | 10 ++++++++++ bbruntime/basic.h | 3 +++ bbruntime/bbmath.cpp | 6 ++++++ compiler/exprnode.cpp | 4 ++++ compiler/parser.cpp | 13 +++---------- compiler/toker.cpp | 3 ++- compiler/toker.h | 2 +- 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/bbruntime/basic.cpp b/bbruntime/basic.cpp index c0883eee..52b35ebc 100644 --- a/bbruntime/basic.cpp +++ b/bbruntime/basic.cpp @@ -483,6 +483,10 @@ int _bbSgn( int n ){ return n>0 ? 1 : (n<0 ? -1 : 0); } +int _bbPowTwo( int n ){ + return n * n; +} + int _bbMod( int x,int y ){ return x%y; } @@ -495,6 +499,10 @@ float _bbFSgn( float n ){ return n>0 ? 1 : (n<0 ? -1 : 0); } +float _bbFPowTwo( float n ){ + return n * n; +} + float _bbFMod( float x,float y ){ return (float)fmod( x,y ); } @@ -589,11 +597,13 @@ void basic_link( void (*rtSym)( const char *sym,void *pc ) ){ rtSym( "_bbReadStr",_bbReadStr ); rtSym( "_bbAbs",_bbAbs ); rtSym( "_bbSgn",_bbSgn ); + rtSym( "_bbPowTwo",_bbPowTwo ); rtSym( "_bbMod",_bbMod ); rtSym( "_bbFAbs",_bbFAbs ); rtSym( "_bbFSgn",_bbFSgn ); rtSym( "_bbFMod",_bbFMod ); rtSym( "_bbFPow",_bbFPow ); + rtSym( "_bbFPowTwo",_bbFPowTwo ); rtSym( "_bbMakeBool", _bbMakeBool ); rtSym( "RuntimeStats",bbRuntimeStats ); } diff --git a/bbruntime/basic.h b/bbruntime/basic.h index f7cd342a..9fbcbb7d 100644 --- a/bbruntime/basic.h +++ b/bbruntime/basic.h @@ -138,11 +138,14 @@ BBStr * _bbReadStr(); int _bbAbs( int n ); int _bbSgn( int n ); +int _bbPowTwo( int n); int _bbMod( int x,int y ); float _bbFAbs( float n ); float _bbFSgn( float n ); +float _bbFPowTwo( float n ); float _bbFMod( float x,float y ); float _bbFPow( float x,float y ); +float _bbFPowTwo( float n ); int _bbMakeBool( int n ); void bbRuntimeStats(); diff --git a/bbruntime/bbmath.cpp b/bbruntime/bbmath.cpp index 1fbc8691..c0b85ea3 100644 --- a/bbruntime/bbmath.cpp +++ b/bbruntime/bbmath.cpp @@ -40,6 +40,11 @@ float bbClamp( float v, float lo, float hi){ } } +int bbIsNaN( float n ){ + unsigned int i = *((unsigned int*)(void*)&n); + return ((i&0x7F800000)==0x7F800000) && ((i&(~0xFF800000)) != 0); +} + //return rand float from 0...1 static inline float rnd(){ rnd_state=RND_A*(rnd_state%RND_Q)-RND_R*(rnd_state/RND_Q); @@ -94,6 +99,7 @@ void math_link( void (*rtSym)( const char *sym,void *pc ) ){ rtSym( "#Min#n#m",bbMin ); rtSym( "#Max#n#m",bbMax ); rtSym( "#Clamp#v#lo#hi",bbClamp ); + rtSym( "%IsNaN#n",bbIsNaN ); rtSym( "#Rnd#from#to=0",bbRnd ); rtSym( "%Rand%from%to=1",bbRand ); rtSym( "SeedRnd%seed",bbSeedRnd ); diff --git a/compiler/exprnode.cpp b/compiler/exprnode.cpp index 5313af75..7e749e6e 100644 --- a/compiler/exprnode.cpp +++ b/compiler/exprnode.cpp @@ -321,6 +321,7 @@ ExprNode *UniExprNode::semant( Environ *e ){ case '-':e=d_new IntConstNode( -c->intValue() );break; case ABS:e=d_new IntConstNode( c->intValue()>=0 ? c->intValue() : -c->intValue() );break; case SGN:e=d_new IntConstNode( c->intValue()>0 ? 1 : (c->intValue()<0 ? -1 : 0) );break; + case POWTWO:e=d_new IntConstNode( c->intValue()*c->intValue() );break; } }else{ switch( op ){ @@ -328,6 +329,7 @@ ExprNode *UniExprNode::semant( Environ *e ){ case '-':e=d_new FloatConstNode( -c->floatValue() );break; case ABS:e=d_new FloatConstNode( c->floatValue()>=0 ? c->floatValue() : -c->floatValue() );break; case SGN:e=d_new FloatConstNode( c->floatValue()>0 ? 1 : (c->floatValue()<0 ? -1 : 0) );break; + case POWTWO:e=d_new FloatConstNode( c->floatValue()*c->floatValue() );break; } } delete this; @@ -345,6 +347,7 @@ TNode *UniExprNode::translate( Codegen *g ){ case '-':n=IR_NEG;break; case ABS:return call( "__bbAbs",l ); case SGN:return call( "__bbSgn",l ); + case POWTWO:return call( "__bbPowTwo", l ); } }else{ switch( op ){ @@ -352,6 +355,7 @@ TNode *UniExprNode::translate( Codegen *g ){ case '-':n=IR_FNEG;break; case ABS:return fcall( "__bbFAbs",l ); case SGN:return fcall( "__bbFSgn",l ); + case POWTWO:return fcall( "__bbFPowTwo", l ); } } return d_new TNode( n,l,0 ); diff --git a/compiler/parser.cpp b/compiler/parser.cpp index b9db05c2..8f4160bf 100644 --- a/compiler/parser.cpp +++ b/compiler/parser.cpp @@ -2,6 +2,7 @@ #include "std.h" #include #include "parser.h" +#include static const int TEXTLIMIT=1024*1024-1; @@ -659,7 +660,7 @@ ExprNode *Parser::parseUniExpr( bool opt ){ result=parseUniExpr( false ); result=d_new AfterNode( result ); break; - case '+':case '-':case '~':case ABS:case SGN: + case '+':case '-':case '~':case ABS:case SGN:case POWTWO: toker->next(); result=parseUniExpr( false ); if( c=='~' ){ @@ -674,11 +675,6 @@ ExprNode *Parser::parseUniExpr( bool opt ){ return result; } -// Don't ask me what this does. Thanks Juan! -float stuff(unsigned int i){ - return *((float*)(void*)&i); -} - ExprNode *Parser::parsePrimary( bool opt ){ a_ptr expr; @@ -739,10 +735,7 @@ ExprNode *Parser::parsePrimary( bool opt ){ result=d_new FloatConstNode( 3.1415926535897932384626433832795f ); toker->next();break; case INFINITY: - result=d_new FloatConstNode( stuff(0x7F800000) ); - toker->next();break; - case NANCONST: - result=d_new FloatConstNode( stuff(0x7FFFFFFF) ); + result=d_new FloatConstNode(INFINITY); toker->next();break; case BBTRUE: result=d_new IntConstNode( 1 ); diff --git a/compiler/toker.cpp b/compiler/toker.cpp index 5d9b93b7..026e5dc2 100644 --- a/compiler/toker.cpp +++ b/compiler/toker.cpp @@ -81,7 +81,8 @@ static void makeKeywords(){ alphaTokes["Null"]=NULLCONST; alphaTokes["Infinity"]=INFINITY; - alphaTokes["NaN"]=NANCONST; + + alphaTokes["PowTwo"]=POWTWO; map::const_iterator it; for( it=alphaTokes.begin();it!=alphaTokes.end();++it ){ diff --git a/compiler/toker.h b/compiler/toker.h index f74205ff..577d9234 100644 --- a/compiler/toker.h +++ b/compiler/toker.h @@ -29,7 +29,7 @@ enum{ AND,OR,LOR,XOR,NOT,SHL,SHR,SAR, LE,GE,NE, - IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,NANCONST + IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,POWTWO }; class Toker{ From e71f355694b3c54e7d536ed96f1e9e25504613bc Mon Sep 17 00:00:00 2001 From: Saalvage Date: Fri, 27 Mar 2020 18:46:20 +0100 Subject: [PATCH 5/7] Revert "Removed NaN constant, improved Infinity constant and implemented efficient PowTwo calculation" This reverts commit ffdce1ec6d42f77ffdfd1c0b591c20105c17fbc9. --- bbruntime/basic.cpp | 10 ---------- bbruntime/basic.h | 3 --- bbruntime/bbmath.cpp | 6 ------ compiler/exprnode.cpp | 4 ---- compiler/parser.cpp | 13 ++++++++++--- compiler/toker.cpp | 3 +-- compiler/toker.h | 2 +- 7 files changed, 12 insertions(+), 29 deletions(-) diff --git a/bbruntime/basic.cpp b/bbruntime/basic.cpp index 52b35ebc..c0883eee 100644 --- a/bbruntime/basic.cpp +++ b/bbruntime/basic.cpp @@ -483,10 +483,6 @@ int _bbSgn( int n ){ return n>0 ? 1 : (n<0 ? -1 : 0); } -int _bbPowTwo( int n ){ - return n * n; -} - int _bbMod( int x,int y ){ return x%y; } @@ -499,10 +495,6 @@ float _bbFSgn( float n ){ return n>0 ? 1 : (n<0 ? -1 : 0); } -float _bbFPowTwo( float n ){ - return n * n; -} - float _bbFMod( float x,float y ){ return (float)fmod( x,y ); } @@ -597,13 +589,11 @@ void basic_link( void (*rtSym)( const char *sym,void *pc ) ){ rtSym( "_bbReadStr",_bbReadStr ); rtSym( "_bbAbs",_bbAbs ); rtSym( "_bbSgn",_bbSgn ); - rtSym( "_bbPowTwo",_bbPowTwo ); rtSym( "_bbMod",_bbMod ); rtSym( "_bbFAbs",_bbFAbs ); rtSym( "_bbFSgn",_bbFSgn ); rtSym( "_bbFMod",_bbFMod ); rtSym( "_bbFPow",_bbFPow ); - rtSym( "_bbFPowTwo",_bbFPowTwo ); rtSym( "_bbMakeBool", _bbMakeBool ); rtSym( "RuntimeStats",bbRuntimeStats ); } diff --git a/bbruntime/basic.h b/bbruntime/basic.h index 9fbcbb7d..f7cd342a 100644 --- a/bbruntime/basic.h +++ b/bbruntime/basic.h @@ -138,14 +138,11 @@ BBStr * _bbReadStr(); int _bbAbs( int n ); int _bbSgn( int n ); -int _bbPowTwo( int n); int _bbMod( int x,int y ); float _bbFAbs( float n ); float _bbFSgn( float n ); -float _bbFPowTwo( float n ); float _bbFMod( float x,float y ); float _bbFPow( float x,float y ); -float _bbFPowTwo( float n ); int _bbMakeBool( int n ); void bbRuntimeStats(); diff --git a/bbruntime/bbmath.cpp b/bbruntime/bbmath.cpp index c0b85ea3..1fbc8691 100644 --- a/bbruntime/bbmath.cpp +++ b/bbruntime/bbmath.cpp @@ -40,11 +40,6 @@ float bbClamp( float v, float lo, float hi){ } } -int bbIsNaN( float n ){ - unsigned int i = *((unsigned int*)(void*)&n); - return ((i&0x7F800000)==0x7F800000) && ((i&(~0xFF800000)) != 0); -} - //return rand float from 0...1 static inline float rnd(){ rnd_state=RND_A*(rnd_state%RND_Q)-RND_R*(rnd_state/RND_Q); @@ -99,7 +94,6 @@ void math_link( void (*rtSym)( const char *sym,void *pc ) ){ rtSym( "#Min#n#m",bbMin ); rtSym( "#Max#n#m",bbMax ); rtSym( "#Clamp#v#lo#hi",bbClamp ); - rtSym( "%IsNaN#n",bbIsNaN ); rtSym( "#Rnd#from#to=0",bbRnd ); rtSym( "%Rand%from%to=1",bbRand ); rtSym( "SeedRnd%seed",bbSeedRnd ); diff --git a/compiler/exprnode.cpp b/compiler/exprnode.cpp index 7e749e6e..5313af75 100644 --- a/compiler/exprnode.cpp +++ b/compiler/exprnode.cpp @@ -321,7 +321,6 @@ ExprNode *UniExprNode::semant( Environ *e ){ case '-':e=d_new IntConstNode( -c->intValue() );break; case ABS:e=d_new IntConstNode( c->intValue()>=0 ? c->intValue() : -c->intValue() );break; case SGN:e=d_new IntConstNode( c->intValue()>0 ? 1 : (c->intValue()<0 ? -1 : 0) );break; - case POWTWO:e=d_new IntConstNode( c->intValue()*c->intValue() );break; } }else{ switch( op ){ @@ -329,7 +328,6 @@ ExprNode *UniExprNode::semant( Environ *e ){ case '-':e=d_new FloatConstNode( -c->floatValue() );break; case ABS:e=d_new FloatConstNode( c->floatValue()>=0 ? c->floatValue() : -c->floatValue() );break; case SGN:e=d_new FloatConstNode( c->floatValue()>0 ? 1 : (c->floatValue()<0 ? -1 : 0) );break; - case POWTWO:e=d_new FloatConstNode( c->floatValue()*c->floatValue() );break; } } delete this; @@ -347,7 +345,6 @@ TNode *UniExprNode::translate( Codegen *g ){ case '-':n=IR_NEG;break; case ABS:return call( "__bbAbs",l ); case SGN:return call( "__bbSgn",l ); - case POWTWO:return call( "__bbPowTwo", l ); } }else{ switch( op ){ @@ -355,7 +352,6 @@ TNode *UniExprNode::translate( Codegen *g ){ case '-':n=IR_FNEG;break; case ABS:return fcall( "__bbFAbs",l ); case SGN:return fcall( "__bbFSgn",l ); - case POWTWO:return fcall( "__bbFPowTwo", l ); } } return d_new TNode( n,l,0 ); diff --git a/compiler/parser.cpp b/compiler/parser.cpp index 8f4160bf..b9db05c2 100644 --- a/compiler/parser.cpp +++ b/compiler/parser.cpp @@ -2,7 +2,6 @@ #include "std.h" #include #include "parser.h" -#include static const int TEXTLIMIT=1024*1024-1; @@ -660,7 +659,7 @@ ExprNode *Parser::parseUniExpr( bool opt ){ result=parseUniExpr( false ); result=d_new AfterNode( result ); break; - case '+':case '-':case '~':case ABS:case SGN:case POWTWO: + case '+':case '-':case '~':case ABS:case SGN: toker->next(); result=parseUniExpr( false ); if( c=='~' ){ @@ -675,6 +674,11 @@ ExprNode *Parser::parseUniExpr( bool opt ){ return result; } +// Don't ask me what this does. Thanks Juan! +float stuff(unsigned int i){ + return *((float*)(void*)&i); +} + ExprNode *Parser::parsePrimary( bool opt ){ a_ptr expr; @@ -735,7 +739,10 @@ ExprNode *Parser::parsePrimary( bool opt ){ result=d_new FloatConstNode( 3.1415926535897932384626433832795f ); toker->next();break; case INFINITY: - result=d_new FloatConstNode(INFINITY); + result=d_new FloatConstNode( stuff(0x7F800000) ); + toker->next();break; + case NANCONST: + result=d_new FloatConstNode( stuff(0x7FFFFFFF) ); toker->next();break; case BBTRUE: result=d_new IntConstNode( 1 ); diff --git a/compiler/toker.cpp b/compiler/toker.cpp index 026e5dc2..5d9b93b7 100644 --- a/compiler/toker.cpp +++ b/compiler/toker.cpp @@ -81,8 +81,7 @@ static void makeKeywords(){ alphaTokes["Null"]=NULLCONST; alphaTokes["Infinity"]=INFINITY; - - alphaTokes["PowTwo"]=POWTWO; + alphaTokes["NaN"]=NANCONST; map::const_iterator it; for( it=alphaTokes.begin();it!=alphaTokes.end();++it ){ diff --git a/compiler/toker.h b/compiler/toker.h index 577d9234..f74205ff 100644 --- a/compiler/toker.h +++ b/compiler/toker.h @@ -29,7 +29,7 @@ enum{ AND,OR,LOR,XOR,NOT,SHL,SHR,SAR, LE,GE,NE, - IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,POWTWO + IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,NANCONST }; class Toker{ From 4e252c17ab5cd2e6229a1783b4935eaace479428 Mon Sep 17 00:00:00 2001 From: Saalvage Date: Fri, 27 Mar 2020 18:58:36 +0100 Subject: [PATCH 6/7] - final patch for PowTwo by juan --- bbruntime/bbmath.cpp | 6 +++ compiler/codegen.h | 4 +- compiler/codegen_x86/codegen_x86.cpp | 6 ++- compiler/exprnode.cpp | 4 ++ compiler/parser.cpp | 13 ++--- compiler/toker.cpp | 3 +- compiler/toker.h | 2 +- diff.txt | 76 ++++++++++++++++++++++++++++ 8 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 diff.txt diff --git a/bbruntime/bbmath.cpp b/bbruntime/bbmath.cpp index 1fbc8691..c0b85ea3 100644 --- a/bbruntime/bbmath.cpp +++ b/bbruntime/bbmath.cpp @@ -40,6 +40,11 @@ float bbClamp( float v, float lo, float hi){ } } +int bbIsNaN( float n ){ + unsigned int i = *((unsigned int*)(void*)&n); + return ((i&0x7F800000)==0x7F800000) && ((i&(~0xFF800000)) != 0); +} + //return rand float from 0...1 static inline float rnd(){ rnd_state=RND_A*(rnd_state%RND_Q)-RND_R*(rnd_state/RND_Q); @@ -94,6 +99,7 @@ void math_link( void (*rtSym)( const char *sym,void *pc ) ){ rtSym( "#Min#n#m",bbMin ); rtSym( "#Max#n#m",bbMax ); rtSym( "#Clamp#v#lo#hi",bbClamp ); + rtSym( "%IsNaN#n",bbIsNaN ); rtSym( "#Rnd#from#to=0",bbRnd ); rtSym( "%Rand%from%to=1",bbRand ); rtSym( "SeedRnd%seed",bbSeedRnd ); diff --git a/compiler/codegen.h b/compiler/codegen.h index d29615d2..fe022f00 100644 --- a/compiler/codegen.h +++ b/compiler/codegen.h @@ -12,11 +12,11 @@ enum{ IR_JSR,IR_RET,IR_AND,IR_LOR,IR_OR,IR_XOR,IR_SHL,IR_SHR,IR_SAR, IR_CALL,IR_RETURN,IR_CAST, - IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV, + IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV,IR_POWTWO, IR_SETEQ,IR_SETNE,IR_SETLT,IR_SETGT,IR_SETLE,IR_SETGE, IR_FCALL,IR_FRETURN,IR_FCAST, - IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV, + IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV,IR_FPOWTWO, IR_FSETEQ,IR_FSETNE,IR_FSETLT,IR_FSETGT,IR_FSETLE,IR_FSETGE, }; diff --git a/compiler/codegen_x86/codegen_x86.cpp b/compiler/codegen_x86/codegen_x86.cpp index 8c443f58..c0f8aea6 100644 --- a/compiler/codegen_x86/codegen_x86.cpp +++ b/compiler/codegen_x86/codegen_x86.cpp @@ -117,6 +117,7 @@ Tile *Codegen_x86::munchUnary( TNode *t ){ string s; switch( t->op ){ case IR_NEG:s="\tneg\t%l\n";break; + case IR_POWTWO:s="\timul\t%l,%l\n";break; default:return 0; } return d_new Tile( s,munchReg( t->l ) ); @@ -228,6 +229,7 @@ Tile *Codegen_x86::munchFPUnary( TNode *t ){ string s; switch( t->op ){ case IR_FNEG:s="\tfchs\n";break; + case IR_FPOWTWO:s="\tfmulp\tst(0)\n";break; default:return 0; } return d_new Tile( s,munchFP( t->l ) ); @@ -420,7 +422,7 @@ Tile *Codegen_x86::munchReg( TNode *t ){ case IR_CONST: q=d_new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" ); break; - case IR_NEG: + case IR_NEG:case IR_POWTWO: q=munchUnary( t ); break; case IR_AND:case IR_LOR:case IR_OR:case IR_XOR: @@ -463,7 +465,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){ s="\tpush\t%l\n\tfild\t[esp]\n\tpop\t%l\n"; q=d_new Tile( s,munchReg( t->l ) ); break; - case IR_FNEG: + case IR_FNEG:case IR_FPOWTWO: q=munchFPUnary( t ); break; case IR_FADD:case IR_FSUB:case IR_FMUL:case IR_FDIV: diff --git a/compiler/exprnode.cpp b/compiler/exprnode.cpp index 5313af75..2e65f8fb 100644 --- a/compiler/exprnode.cpp +++ b/compiler/exprnode.cpp @@ -321,6 +321,7 @@ ExprNode *UniExprNode::semant( Environ *e ){ case '-':e=d_new IntConstNode( -c->intValue() );break; case ABS:e=d_new IntConstNode( c->intValue()>=0 ? c->intValue() : -c->intValue() );break; case SGN:e=d_new IntConstNode( c->intValue()>0 ? 1 : (c->intValue()<0 ? -1 : 0) );break; + case POWTWO:e=d_new IntConstNode( c->intValue()*c->intValue() );break; } }else{ switch( op ){ @@ -328,6 +329,7 @@ ExprNode *UniExprNode::semant( Environ *e ){ case '-':e=d_new FloatConstNode( -c->floatValue() );break; case ABS:e=d_new FloatConstNode( c->floatValue()>=0 ? c->floatValue() : -c->floatValue() );break; case SGN:e=d_new FloatConstNode( c->floatValue()>0 ? 1 : (c->floatValue()<0 ? -1 : 0) );break; + case POWTWO:e=d_new FloatConstNode( c->floatValue()*c->floatValue() );break; } } delete this; @@ -345,6 +347,7 @@ TNode *UniExprNode::translate( Codegen *g ){ case '-':n=IR_NEG;break; case ABS:return call( "__bbAbs",l ); case SGN:return call( "__bbSgn",l ); + case POWTWO:return d_new TNode(IR_POWTWO, l); } }else{ switch( op ){ @@ -352,6 +355,7 @@ TNode *UniExprNode::translate( Codegen *g ){ case '-':n=IR_FNEG;break; case ABS:return fcall( "__bbFAbs",l ); case SGN:return fcall( "__bbFSgn",l ); + case POWTWO:return d_new TNode(IR_FPOWTWO, l); } } return d_new TNode( n,l,0 ); diff --git a/compiler/parser.cpp b/compiler/parser.cpp index b9db05c2..8f4160bf 100644 --- a/compiler/parser.cpp +++ b/compiler/parser.cpp @@ -2,6 +2,7 @@ #include "std.h" #include #include "parser.h" +#include static const int TEXTLIMIT=1024*1024-1; @@ -659,7 +660,7 @@ ExprNode *Parser::parseUniExpr( bool opt ){ result=parseUniExpr( false ); result=d_new AfterNode( result ); break; - case '+':case '-':case '~':case ABS:case SGN: + case '+':case '-':case '~':case ABS:case SGN:case POWTWO: toker->next(); result=parseUniExpr( false ); if( c=='~' ){ @@ -674,11 +675,6 @@ ExprNode *Parser::parseUniExpr( bool opt ){ return result; } -// Don't ask me what this does. Thanks Juan! -float stuff(unsigned int i){ - return *((float*)(void*)&i); -} - ExprNode *Parser::parsePrimary( bool opt ){ a_ptr expr; @@ -739,10 +735,7 @@ ExprNode *Parser::parsePrimary( bool opt ){ result=d_new FloatConstNode( 3.1415926535897932384626433832795f ); toker->next();break; case INFINITY: - result=d_new FloatConstNode( stuff(0x7F800000) ); - toker->next();break; - case NANCONST: - result=d_new FloatConstNode( stuff(0x7FFFFFFF) ); + result=d_new FloatConstNode(INFINITY); toker->next();break; case BBTRUE: result=d_new IntConstNode( 1 ); diff --git a/compiler/toker.cpp b/compiler/toker.cpp index 5d9b93b7..026e5dc2 100644 --- a/compiler/toker.cpp +++ b/compiler/toker.cpp @@ -81,7 +81,8 @@ static void makeKeywords(){ alphaTokes["Null"]=NULLCONST; alphaTokes["Infinity"]=INFINITY; - alphaTokes["NaN"]=NANCONST; + + alphaTokes["PowTwo"]=POWTWO; map::const_iterator it; for( it=alphaTokes.begin();it!=alphaTokes.end();++it ){ diff --git a/compiler/toker.h b/compiler/toker.h index f74205ff..577d9234 100644 --- a/compiler/toker.h +++ b/compiler/toker.h @@ -29,7 +29,7 @@ enum{ AND,OR,LOR,XOR,NOT,SHL,SHR,SAR, LE,GE,NE, - IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,NANCONST + IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,POWTWO }; class Toker{ diff --git a/diff.txt b/diff.txt new file mode 100644 index 00000000..f62dbf66 --- /dev/null +++ b/diff.txt @@ -0,0 +1,76 @@ +diff --git a/compiler/codegen.h b/compiler/codegen.h +index d29615d..fe022f0 100644 +--- a/compiler/codegen.h ++++ b/compiler/codegen.h +@@ -12,11 +12,11 @@ enum{ + IR_JSR,IR_RET,IR_AND,IR_LOR,IR_OR,IR_XOR,IR_SHL,IR_SHR,IR_SAR, + + IR_CALL,IR_RETURN,IR_CAST, +- IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV, ++ IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV,IR_POWTWO, + IR_SETEQ,IR_SETNE,IR_SETLT,IR_SETGT,IR_SETLE,IR_SETGE, + + IR_FCALL,IR_FRETURN,IR_FCAST, +- IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV, ++ IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV,IR_FPOWTWO, + IR_FSETEQ,IR_FSETNE,IR_FSETLT,IR_FSETGT,IR_FSETLE,IR_FSETGE, + }; + +diff --git a/compiler/codegen_x86/codegen_x86.cpp b/compiler/codegen_x86/codegen_x86.cpp +index 7ba0d4e..f012cf1 100644 +--- a/compiler/codegen_x86/codegen_x86.cpp ++++ b/compiler/codegen_x86/codegen_x86.cpp +@@ -117,6 +117,7 @@ Tile *Codegen_x86::munchUnary( TNode *t ){ + string s; + switch( t->op ){ + case IR_NEG:s="\tneg\t%l\n";break; ++ case IR_POWTWO:s="\timul\t%l,%l\n";break; + default:return 0; + } + return d_new Tile( s,munchReg( t->l ) ); +@@ -220,6 +221,7 @@ Tile *Codegen_x86::munchFPUnary( TNode *t ){ + string s; + switch( t->op ){ + case IR_FNEG:s="\tfchs\n";break; ++ case IR_FPOWTWO:s="\tfmulp\tst(0)\n";break; + default:return 0; + } + return d_new Tile( s,munchFP( t->l ) ); +@@ -408,7 +410,7 @@ Tile *Codegen_x86::munchReg( TNode *t ){ + case IR_CONST: + q=d_new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" ); + break; +- case IR_NEG: ++ case IR_NEG:case IR_POWTWO: + q=munchUnary( t ); + break; + case IR_AND:case IR_LOR:case IR_OR:case IR_XOR: +@@ -451,7 +453,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){ + s="\tpush\t%l\n\tfild\t[esp]\n\tpop\t%l\n"; + q=d_new Tile( s,munchReg( t->l ) ); + break; +- case IR_FNEG: ++ case IR_FNEG:case IR_FPOWTWO: + q=munchFPUnary( t ); + break; + case IR_FADD:case IR_FSUB:case IR_FMUL:case IR_FDIV: +diff --git a/compiler/exprnode.cpp b/compiler/exprnode.cpp +index fcb9556..9affd5a 100644 +--- a/compiler/exprnode.cpp ++++ b/compiler/exprnode.cpp +@@ -345,6 +345,7 @@ TNode *UniExprNode::translate( Codegen *g ){ + case '-':n=IR_NEG;break; + case ABS:return call( "__bbAbs",l ); + case SGN:return call( "__bbSgn",l ); ++ case POWTWO:return d_new TNode(IR_POWTWO, l); + } + }else{ + switch( op ){ +@@ -352,6 +353,7 @@ TNode *UniExprNode::translate( Codegen *g ){ + case '-':n=IR_FNEG;break; + case ABS:return fcall( "__bbFAbs",l ); + case SGN:return fcall( "__bbFSgn",l ); ++ case POWTWO:return d_new TNode(IR_FPOWTWO, l); + } + } + return d_new TNode( n,l,0 ); From 53b2fca30d94b7d8e226c6d11f249594bb93e1be Mon Sep 17 00:00:00 2001 From: Saalvage Date: Fri, 27 Mar 2020 19:08:46 +0100 Subject: [PATCH 7/7] - tiny cleanup --- diff.txt | 76 -------------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 diff.txt diff --git a/diff.txt b/diff.txt deleted file mode 100644 index f62dbf66..00000000 --- a/diff.txt +++ /dev/null @@ -1,76 +0,0 @@ -diff --git a/compiler/codegen.h b/compiler/codegen.h -index d29615d..fe022f0 100644 ---- a/compiler/codegen.h -+++ b/compiler/codegen.h -@@ -12,11 +12,11 @@ enum{ - IR_JSR,IR_RET,IR_AND,IR_LOR,IR_OR,IR_XOR,IR_SHL,IR_SHR,IR_SAR, - - IR_CALL,IR_RETURN,IR_CAST, -- IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV, -+ IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV,IR_POWTWO, - IR_SETEQ,IR_SETNE,IR_SETLT,IR_SETGT,IR_SETLE,IR_SETGE, - - IR_FCALL,IR_FRETURN,IR_FCAST, -- IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV, -+ IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV,IR_FPOWTWO, - IR_FSETEQ,IR_FSETNE,IR_FSETLT,IR_FSETGT,IR_FSETLE,IR_FSETGE, - }; - -diff --git a/compiler/codegen_x86/codegen_x86.cpp b/compiler/codegen_x86/codegen_x86.cpp -index 7ba0d4e..f012cf1 100644 ---- a/compiler/codegen_x86/codegen_x86.cpp -+++ b/compiler/codegen_x86/codegen_x86.cpp -@@ -117,6 +117,7 @@ Tile *Codegen_x86::munchUnary( TNode *t ){ - string s; - switch( t->op ){ - case IR_NEG:s="\tneg\t%l\n";break; -+ case IR_POWTWO:s="\timul\t%l,%l\n";break; - default:return 0; - } - return d_new Tile( s,munchReg( t->l ) ); -@@ -220,6 +221,7 @@ Tile *Codegen_x86::munchFPUnary( TNode *t ){ - string s; - switch( t->op ){ - case IR_FNEG:s="\tfchs\n";break; -+ case IR_FPOWTWO:s="\tfmulp\tst(0)\n";break; - default:return 0; - } - return d_new Tile( s,munchFP( t->l ) ); -@@ -408,7 +410,7 @@ Tile *Codegen_x86::munchReg( TNode *t ){ - case IR_CONST: - q=d_new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" ); - break; -- case IR_NEG: -+ case IR_NEG:case IR_POWTWO: - q=munchUnary( t ); - break; - case IR_AND:case IR_LOR:case IR_OR:case IR_XOR: -@@ -451,7 +453,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){ - s="\tpush\t%l\n\tfild\t[esp]\n\tpop\t%l\n"; - q=d_new Tile( s,munchReg( t->l ) ); - break; -- case IR_FNEG: -+ case IR_FNEG:case IR_FPOWTWO: - q=munchFPUnary( t ); - break; - case IR_FADD:case IR_FSUB:case IR_FMUL:case IR_FDIV: -diff --git a/compiler/exprnode.cpp b/compiler/exprnode.cpp -index fcb9556..9affd5a 100644 ---- a/compiler/exprnode.cpp -+++ b/compiler/exprnode.cpp -@@ -345,6 +345,7 @@ TNode *UniExprNode::translate( Codegen *g ){ - case '-':n=IR_NEG;break; - case ABS:return call( "__bbAbs",l ); - case SGN:return call( "__bbSgn",l ); -+ case POWTWO:return d_new TNode(IR_POWTWO, l); - } - }else{ - switch( op ){ -@@ -352,6 +353,7 @@ TNode *UniExprNode::translate( Codegen *g ){ - case '-':n=IR_FNEG;break; - case ABS:return fcall( "__bbFAbs",l ); - case SGN:return fcall( "__bbFSgn",l ); -+ case POWTWO:return d_new TNode(IR_FPOWTWO, l); - } - } - return d_new TNode( n,l,0 );