int32 _Interpret_Do_CombinatorLeftParen ( ) { Context * cntx = _Context_ ; Compiler * compiler = cntx->Compiler0 ; int32 svcm = GetState ( compiler, COMPILE_MODE ), svclps = GetState ( compiler, C_COMBINATOR_LPAREN ) ; int32 blocksParsed = 0 ; byte * token ; SetState ( compiler, C_COMBINATOR_LPAREN, true ) ; SetState ( compiler, PREFIX_PARSING, true ) ; while ( 1 ) { token = _Lexer_ReadToken ( cntx->Lexer0, 0 ) ; if ( String_Equal ( ( char* ) token, ";" ) ) { CfrTil_EndBlock ( ) ; CfrTil_BeginBlock ( ) ; blocksParsed ++ ; continue ; } if ( String_Equal ( ( char* ) token, ")" ) ) { byte * token1 = Lexer_PeekNextNonDebugTokenWord ( cntx->Lexer0 ) ; if ( String_Equal ( token1, "{" ) ) { //_Lexer_NextNonDebugTokenWord ( cntx->Lexer0 ) ; // actually get token1 = "{" CfrTil_EndBlock ( ) ; //CfrTil_BeginBlock ( ) ; // callee handles this blocksParsed ++ ; break ; } else { token = _Lexer_ReadToken ( cntx->Lexer0, 0 ) ; // drop the ")" ?!? must be a better way than this ?!? continue ; } } Interpreter_InterpretAToken ( cntx->Interpreter0, token, - 1 ) ; if ( ( blocksParsed == 0 ) && ( cntx->CurrentlyRunningWord->CProperty & LITERAL ) && ( ! Is_LValue ( cntx->Interpreter0->w_Word ) ) ) //GetState ( cntx, C_LHS ) ) { // setup for optimization if this literal constant is the loop conditional BlockInfo * bi = ( BlockInfo* ) _Stack_Top ( compiler->BlockStack ) ; bi->LiteralWord = cntx->CurrentlyRunningWord ; } } SetState ( compiler, COMPILE_MODE, svcm ) ; SetState ( compiler, C_COMBINATOR_LPAREN, svclps ) ; //SetState ( compiler, PREFIX_ARG_PARSING, false ) ; SetState ( compiler, PREFIX_PARSING, false ) ; return blocksParsed ; }
int main (int argc, char * argv[]) { char * filename = argv[1]; Program_Module m = Program_ModuleNew(); Program_ParseArguments (m, argc, argv); printf ("Compiling %s\n", String_Data (m->options.file)); if (Parse_File (m, m->options.file) != 0) { printf ("Lex errors: %lu\n", Vector_Size (&m->errors.lexer)); VECTOR_FOREACH (struct Error_t, error, &m->errors.lexer) { Error_Print (stdout, error); } printf ("Parse errors: %lu\n", Vector_Size (&m->errors.parser)); VECTOR_FOREACH (struct Error_t, error, &m->errors.parser) { Error_Print (stdout, error); } VECTOR_FOREACH (struct Program_Option_t, o, &m->options.debug) { if (String_Equal (&o->key, "parse-only")) { printf ("Exiting, because of '%s'.\n", o->key.data); exit (0); } } printf ("Exiting, fix the errors and try again."); exit (0); }
void Parse_SkipUntil_EitherToken ( byte * end1, byte* end2 ) { while ( 1 ) { byte * token ; int inChar = ReadLine_PeekNextChar ( _Context_->ReadLiner0 ) ; if ( ( inChar == - 1 ) || ( inChar == eof ) ) break ; if ( ( token = ( char* ) Lexer_ReadToken ( _Context_->Lexer0 ) ) ) { if ( String_Equal ( token, end1 ) ) break ; if ( String_Equal ( token, end2 ) ) break ; } } }
Word * Finder_Word_FindUsing ( Finder * finder, byte * name ) { Word * word = 0 ; if ( name ) { if ( finder->QualifyingNamespace ) { if ( String_Equal ( ".", ( char* ) name ) ) word = Word_FindUsing ( name ) ; // keep QualifyingNamespace intact // ?? assumes function of CfrTil_Dot is always and only named "." ?? else #if OLD { word = Word_FindInOneNamespace ( finder->QualifyingNamespace, name ) ; if ( ! GetState ( _Context_, CONTEXT_PARSING_QUALIFIED_ID ) ) Finder_SetQualifyingNamespace ( finder, 0 ) ; // nb. QualifyingNamespace is only good for one find } #else { word = Word_FindInOneNamespace ( finder->QualifyingNamespace, name ) ; if ( ReadLine_IsReverseTokenQualifiedID ( _Context_->ReadLiner0 ) ) { SetState ( _Context_, CONTEXT_PARSING_QUALIFIED_ID, false ) ; Finder_SetQualifyingNamespace ( finder, 0 ) ; // nb. QualifyingNamespace is only good for approximately one find } } #endif } if ( ! word ) word = Word_FindUsing ( name ) ; } return word ; }
BOOL ECP_GetBoolean(LPBOOL lpBool, LPTSTR pszSrc) { if (String_Equal(pszSrc, _T("TRUE"), FALSE)) { *lpBool = TRUE; } else if (String_Equal(pszSrc, _T("FALSE"), FALSE)) { *lpBool = FALSE; } else { MessageBox(g_hwndMain, _T("Error while parsing boolean value. Must be TRUE or FALSE."), _T("Clipbook Error"), MB_OK); return (FALSE); } return (TRUE); }
BOOL CALLBACK FindOpenFileEnumProc(HWND hwnd, LPARAM lParam) { TCHAR szClass[80]; GetClassName(hwnd, szClass, 79); if (String_Equal(szClass, WC_PCP_TEXTEDIT, FALSE)) { LPFILEINFO lpfi = (LPFILEINFO)GetWindowLong(GetParent(hwnd), GWL_USERDATA); if (String_Equal((LPTSTR)lParam, lpfi->szFileName, FALSE)) { s_bOpen = TRUE; MDI_Activate(g_hwndMDIClient, hwnd); return (FALSE); } } return (TRUE); }
void ReadTable_LParen ( ReadLiner * rl ) { #if MARU || MARU_2_4 || MARU_NILE if ( ( rl->InputFile != stdin ) && _Q_->OVT_CfrTil->InNamespace ) { if ( String_Equal ( ( CString ) _Q_->OVT_CfrTil->InNamespace->s_Symbol.S_Name, "Maru" ) ) { ungetc ( rl->InputKeyedCharacter, rl->InputFile ) ; Maru_RawReadFlag = 1 ; imaru_nile ( ) ; Maru_RawReadFlag = 0 ; return ; } } #endif ReadTable_Default ( rl ) ; }
void Interpret_DoParenthesizedRValue ( ) { Context * cntx = _Context_ ; Compiler * compiler = cntx->Compiler0 ; int32 svcm = GetState ( compiler, COMPILE_MODE ) ; byte * token ; while ( 1 ) { token = _Lexer_ReadToken ( cntx->Lexer0, 0 ) ; if ( String_Equal ( ( char* ) token, ")" ) ) { break ; } Interpreter_InterpretAToken ( cntx->Interpreter0, token, - 1 ) ; } SetState ( compiler, COMPILE_MODE, svcm ) ; }
dllist * _CfrTil_Interpret_ReadToList ( ) { byte * token ; Interpreter * interp = _Context_->Interpreter0 ; interp->InterpList = List_New ( ) ; while ( token = Lexer_ReadToken ( _Lexer_ ) ) { if ( String_Equal ( token, ";l" ) ) break ; Word * word = _Interpreter_TokenToWord ( interp, token ) ; if ( word ) { _Word_Interpret ( word ) ; //List_Push_A_1Value_Node ( interp->InterpList, word ) ; List_Push ( interp->InterpList, word ) ; } } return interp->InterpList ; }
void HLSLGenerator::OutputExpression(HLSLExpression* expression) { if (expression->nodeType == HLSLNodeType_IdentifierExpression) { HLSLIdentifierExpression* identifierExpression = static_cast<HLSLIdentifierExpression*>(expression); const char* name = identifierExpression->name; if (!m_legacy && GetIsSamplerType(identifierExpression->expressionType) && identifierExpression->global) { if (identifierExpression->expressionType.baseType == HLSLBaseType_Sampler2D) { m_writer.Write("%s(%s_texture, %s_sampler)", m_textureSampler2DCtor, name, name); } else if (identifierExpression->expressionType.baseType == HLSLBaseType_SamplerCube) { m_writer.Write("%s(%s_texture, %s_sampler)", m_textureSamplerCubeCtor, name, name); } } else { m_writer.Write("%s", name); } } else if (expression->nodeType == HLSLNodeType_CastingExpression) { HLSLCastingExpression* castingExpression = static_cast<HLSLCastingExpression*>(expression); m_writer.Write("("); OutputDeclaration(castingExpression->type, ""); m_writer.Write(")("); OutputExpression(castingExpression->expression); m_writer.Write(")"); } else if (expression->nodeType == HLSLNodeType_ConstructorExpression) { HLSLConstructorExpression* constructorExpression = static_cast<HLSLConstructorExpression*>(expression); m_writer.Write("%s(", GetTypeName(constructorExpression->type)); OutputExpressionList(constructorExpression->argument); m_writer.Write(")"); } else if (expression->nodeType == HLSLNodeType_LiteralExpression) { HLSLLiteralExpression* literalExpression = static_cast<HLSLLiteralExpression*>(expression); switch (literalExpression->type) { case HLSLBaseType_Half: case HLSLBaseType_Float: { // Don't use printf directly so that we don't use the system locale. char buffer[64]; String_FormatFloat(buffer, sizeof(buffer), literalExpression->fValue); m_writer.Write("%s", buffer); } break; case HLSLBaseType_Int: m_writer.Write("%d", literalExpression->iValue); break; case HLSLBaseType_Bool: m_writer.Write("%s", literalExpression->bValue ? "true" : "false"); break; default: ASSERT(0); } } else if (expression->nodeType == HLSLNodeType_UnaryExpression) { HLSLUnaryExpression* unaryExpression = static_cast<HLSLUnaryExpression*>(expression); const char* op = "?"; bool pre = true; switch (unaryExpression->unaryOp) { case HLSLUnaryOp_Negative: op = "-"; break; case HLSLUnaryOp_Positive: op = "+"; break; case HLSLUnaryOp_Not: op = "!"; break; case HLSLUnaryOp_PreIncrement: op = "++"; break; case HLSLUnaryOp_PreDecrement: op = "++"; break; case HLSLUnaryOp_PostIncrement: op = "++"; pre = false; break; case HLSLUnaryOp_PostDecrement: op = "--"; pre = false; break; } m_writer.Write("("); if (pre) { m_writer.Write("%s", op); OutputExpression(unaryExpression->expression); } else { OutputExpression(unaryExpression->expression); m_writer.Write("%s", op); } m_writer.Write(")"); } else if (expression->nodeType == HLSLNodeType_BinaryExpression) { HLSLBinaryExpression* binaryExpression = static_cast<HLSLBinaryExpression*>(expression); m_writer.Write("("); OutputExpression(binaryExpression->expression1); const char* op = "?"; switch (binaryExpression->binaryOp) { case HLSLBinaryOp_Add: op = " + "; break; case HLSLBinaryOp_Sub: op = " - "; break; case HLSLBinaryOp_Mul: op = " * "; break; case HLSLBinaryOp_Div: op = " / "; break; case HLSLBinaryOp_Less: op = " < "; break; case HLSLBinaryOp_Greater: op = " > "; break; case HLSLBinaryOp_LessEqual: op = " <= "; break; case HLSLBinaryOp_GreaterEqual: op = " >= "; break; case HLSLBinaryOp_Equal: op = " == "; break; case HLSLBinaryOp_NotEqual: op = " != "; break; case HLSLBinaryOp_Assign: op = " = "; break; case HLSLBinaryOp_AddAssign: op = " += "; break; case HLSLBinaryOp_SubAssign: op = " -= "; break; case HLSLBinaryOp_MulAssign: op = " *= "; break; case HLSLBinaryOp_DivAssign: op = " /= "; break; case HLSLBinaryOp_And: op = " && "; break; case HLSLBinaryOp_Or: op = " || "; break; default: ASSERT(0); } m_writer.Write("%s", op); OutputExpression(binaryExpression->expression2); m_writer.Write(")"); } else if (expression->nodeType == HLSLNodeType_ConditionalExpression) { HLSLConditionalExpression* conditionalExpression = static_cast<HLSLConditionalExpression*>(expression); m_writer.Write("(("); OutputExpression(conditionalExpression->condition); m_writer.Write(")?("); OutputExpression(conditionalExpression->trueExpression); m_writer.Write("):("); OutputExpression(conditionalExpression->falseExpression); m_writer.Write("))"); } else if (expression->nodeType == HLSLNodeType_MemberAccess) { HLSLMemberAccess* memberAccess = static_cast<HLSLMemberAccess*>(expression); m_writer.Write("("); OutputExpression(memberAccess->object); m_writer.Write(").%s", memberAccess->field); } else if (expression->nodeType == HLSLNodeType_ArrayAccess) { HLSLArrayAccess* arrayAccess = static_cast<HLSLArrayAccess*>(expression); OutputExpression(arrayAccess->array); m_writer.Write("["); OutputExpression(arrayAccess->index); m_writer.Write("]"); } else if (expression->nodeType == HLSLNodeType_FunctionCall) { HLSLFunctionCall* functionCall = static_cast<HLSLFunctionCall*>(expression); const char* name = functionCall->function->name; if (!m_legacy) { if (String_Equal(name, "tex2D")) { name = m_tex2DFunction; } else if (String_Equal(name, "tex2Dproj")) { name = m_tex2DProjFunction; } else if (String_Equal(name, "tex2Dlod")) { name = m_tex2DLodFunction; } else if (String_Equal(name, "texCUBE")) { name = m_texCubeFunction; } else if (String_Equal(name, "texCUBEbias")) { name = m_texCubeBiasFunction; } } m_writer.Write("%s(", name); OutputExpressionList(functionCall->argument); m_writer.Write(")"); } else { m_writer.Write("<unknown expression>"); } }
void File_Open(LPTSTR pszFile, int nLineFeedType) { MDICREATESTRUCT mcs; HWND hwndChild, hwndEdit, hwndPrev; HCURSOR hOldCursor; // LPEDITVIEW lpew; FILEINFO fi; int i; // FIXME: TEMP INITSTRUCT(fi, FALSE); SetCapture(g_hwndMain); hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); EnumChildWindows(g_hwndMDIClient, FindOpenFileEnumProc, (LPARAM)pszFile); if (s_bOpen) { HWND hwnd; TCHAR szMsg[MAX_PATH + 30]; s_bOpen = FALSE; hwnd = Main_GetFileInfoByFileName(pszFile, &fi); ASSERT(!(fi.dwFileType & FI_TYPE_MASK_EDIT)); MDI_Activate(g_hwndMDIClient, hwnd); // FIXME: Should only be done if modified _stprintf(szMsg, String_LoadString(IDS_FORMAT_FILE_ALREADYOPEN), pszFile); if (MessageBox(g_hwndMain, szMsg, g_szAppName, MB_YESNO | MB_ICONQUESTION) == IDYES) { File_ReloadFile(pszFile); } goto err_return; } hwndPrev = MDI_MyGetActive(FALSE); mcs.szTitle = pszFile; mcs.szClass = g_szEditChild; // g_szHexChild mcs.hOwner = g_hInstance; mcs.x = mcs.cx = CW_USEDEFAULT; mcs.y = mcs.cy = CW_USEDEFAULT; mcs.style = MDIS_ALLCHILDSTYLES | WS_CLIPCHILDREN; // a messy way of setting the file to open for the edit control if (String_Equal(pszFile, _T("Edit"), TRUE)) { s_nNumEdits++; fi.dwFileType |= FI_TYPE_MASK_EDIT; _stprintf(fi.szFileName, _T("Edit%d"), s_nNumEdits); } else { ASSERT(Path_FileExists(pszFile)); fi.dwFileType = FI_TYPE_TEXT; _tcscpy(fi.szFileName, pszFile); } mcs.lParam = (LPARAM)&fi; if ((!IsWindow(hwndPrev) && g_WindowSettings.nMDIWinState == MDISTATE_MAXIMIZED) || (IsWindow(hwndPrev) && IsMaximized(hwndPrev))) { mcs.style |= WS_MAXIMIZE; g_WindowSettings.nMDIWinState = MDISTATE_MAXIMIZED; } hwndChild = MDI_Create(g_hwndMDIClient, &mcs); ASSERT(hwndChild != NULL); hwndEdit = GetDlgItem(hwndChild, IDC_EDIT_MDICHILD); if ((_tcscmp(pszFile, _T("Edit"))) == 0) { File_Addify(hwndChild, hwndEdit, fi.szFileName); goto normal_return; } else { TCHAR szText[MAX_PATH]; TC_ITEM tci; FILEINFO fi; tci.mask = TCIF_TEXT | TCIF_PARAM; tci.pszText = szText; tci.cchTextMax = MAX_PATH; if (TabCtrl_GetItem(g_hwndTabWindowBar, 0, &tci)) { ASSERT(IsWindow((HWND)tci.lParam)); Main_GetFileInfo((HWND)tci.lParam, &fi); if ((fi.dwFileType & FI_TYPE_MASK_FIRST) && !EditView_GetModify(GetDlgItem((HWND)tci.lParam, IDC_EDIT_MDICHILD))) { Window_Close((HWND)tci.lParam); } } } File_Addify(hwndChild, hwndEdit, pszFile); FileNotify_AddFile(&s_fns, pszFile, FN_NOTIFY_DEFAULT); FileNotify_StartMonitoring(&s_fns); MRU_Write(_T("File MRU"), pszFile, g_MRUSettings.nFileMax); for (i = IDM_RECENTFILES; DeleteMenu(g_hMenuRecentFiles, i, MF_BYCOMMAND); i++) ; /* empty body */ MRU_SetMenu(g_hMenuRecentFiles, _T("File MRU"), g_MRUSettings.nFileMax, IDM_RECENTFILES); normal_return: // lpew = MDI_GetEditView(NULL); /// TextBuffer_SetCRLFMode(lpew->lpes, (nLineFeedType == CRLF_STYLE_AUTOMATIC) ? TextBuffer_GetCRLFMode(lpew->lpes) : nLineFeedType); // EditChild_SetLineFeed(lpew->hwnd, TextBuffer_GetCRLFMode(lpew->lpes)); err_return: SetCursor(hOldCursor); ReleaseCapture(); }
void _Compiler_RemoveLocalFrame ( Compiler * compiler ) { int32 parameterVarsSubAmount, returnValueFlag ; Compiler_SetLocalsFrameSize_AtItsCellOffset ( compiler ) ; parameterVarsSubAmount = ( compiler->NumberOfParameterVariables * CELL ) ; if ( GetState ( _Context_, C_SYNTAX ) && ( ! String_Equal ( compiler->CurrentWord->S_ContainingNamespace->Name, "void" ) ) ) { SetState ( compiler, RETURN_TOS, true ) ; } //returnValueFlag = rvf = ( _Context_->CurrentRunWord->CProperty & C_RETURN ) || ( GetState ( compiler, RETURN_TOS | RETURN_EAX ) ) || IsWordRecursive || compiler->ReturnVariableWord ; returnValueFlag = ( _Context_->CurrentlyRunningWord->CProperty & C_RETURN ) || ( GetState ( compiler, RETURN_TOS | RETURN_EAX ) ) || IsWordRecursive || compiler->ReturnVariableWord ; Word * word = compiler->ReturnVariableWord ; #if 0 if ( GetState ( _Context_->Compiler0, SAVE_ESP ) ) { _Compile_ESP_Restore ( ) ; } #endif if ( word ) { _Compile_GetVarLitObj_RValue_To_Reg ( word, EAX, 0 ) ; // nb. these variables have no lasting lvalue - they exist on the stack - therefore we can only return there rvalue } //else if ( compiler->NumberOfParameterVariables && returnValueFlag && ( ! compiler->NumberOfRegisterVariables ) && ( ! GetState ( compiler, RETURN_EAX ) ) ) else if ( compiler->NumberOfParameterVariables && returnValueFlag && ( ! GetState ( compiler, RETURN_EAX ) ) ) { #if 0 // for some unknown reason this code will overwrite the function call address also byte add_esi_eax [ ] = { 0x01, 0x06 } ; //0106 add [esi], eax byte * here = _Q_CodeByteArray->EndIndex ; if ( memcmp ( add_esi_eax, here - 2, 2 ) ) { //_ByteArray_UnAppendSpace ( _Q_CodeByteArray, 2 ) ; SetHere ( Here - 2 ) ; _Compile_X_Group1 ( ADD, REG, MEM, EAX, DSP, 0, 0, CELL ) ; // result is on TOS } //{returnValueFlag ++ ; rvf = 0 ;} //else #else Compile_Move_TOS_To_EAX ( DSP ) ; // save TOS to EAX so we can set return it as TOS below #endif //else { parameterVarsSubAmount += CELL ; rvf = 0 ; } } else if ( GetState ( compiler, RETURN_TOS ) ) { Compile_Move_TOS_To_EAX ( DSP ) ; } _Compile_LEA ( DSP, FP, 0, - LocalVarIndex_Disp ( 1 ) ) ; // restore sp - release locals stack frame _Compile_Move_StackN_To_Reg ( FP, DSP, 1 ) ; // restore the saved pre fp - cf AddLocalsFrame // remove the incoming parameters -- like in C parameterVarsSubAmount -= returnValueFlag * CELL ; // reduce the subtract amount to make room for the return value if ( parameterVarsSubAmount > 0 ) { Compile_SUBI ( REG, DSP, 0, parameterVarsSubAmount, CELL ) ; // remove stack variables } else if ( parameterVarsSubAmount < 0 ) { Compile_ADDI ( REG, DSP, 0, - parameterVarsSubAmount, CELL ) ; // add a place on the stack for return value } //if ( rvf && returnValueFlag && ( ! GetState ( compiler, RETURN_EAX ) ) ) if ( returnValueFlag && ( ! GetState ( compiler, RETURN_EAX ) ) ) { // nb : stack was already adjusted accordingly for this above by reducing the SUBI subAmount or adding if there weren't any parameter variables Compile_Move_EAX_To_TOS ( DSP ) ; } }