MCPcopy Create free account
hub / github.com/WheretIB/nullc / Compile

Method Compile

NULLC/Compiler.cpp:1109–1359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1107#endif
1108
1109bool Compiler::Compile(const char* str, bool noClear)
1110{
1111 CodeInfo::nodeList.clear();
1112 NodeZeroOP::DeleteNodes();
1113
1114 if(!noClear)
1115 {
1116 lexer.Clear(baseModuleSize);
1117 moduleSource.clear();
1118 dupStringsModule.Clear();
1119 funcMap.clear();
1120 importStack.clear();
1121 moduleStack.clear();
1122 codeSourceRange.clear();
1123 }
1124 unsigned int lexStreamStart = lexer.GetStreamSize();
1125 lexer.Lexify(str);
1126 unsigned int lexStreamEnd = lexer.GetStreamSize();
1127
1128 unsigned moduleBase = moduleStack.size();
1129
1130 if(BinaryCache::GetBytecode("$base$.nc"))
1131 moduleStack.push_back(ModuleInfo("$base$.nc", BinaryCache::GetBytecode("$base$.nc"), 0, CodeRange(lexer.GetStreamStart()[0].pos, lexer.GetStreamStart()[baseModuleSize - 1].pos)));
1132
1133 const char *importPath = BinaryCache::GetImportPath();
1134
1135 Lexeme *start = &lexer.GetStreamStart()[lexStreamStart];
1136 while(start->type == lex_import)
1137 {
1138 start++;
1139 char path[256], *cPath = path, *pathNoImport = path;
1140 Lexeme *name = start;
1141 if(start->type != lex_string)
1142 {
1143 CodeInfo::lastError.Init("ERROR: string expected after import", start->pos);
1144 return false;
1145 }
1146 cPath += SafeSprintf(cPath, 256, "%s%.*s", importPath ? importPath : "", start->length, start->pos);
1147 if(importPath)
1148 pathNoImport = path + strlen(importPath);
1149
1150 start++;
1151 while(start->type == lex_point)
1152 {
1153 start++;
1154 if(start->type != lex_string)
1155 {
1156 CodeInfo::lastError.Init("ERROR: string expected after '.'", start->pos);
1157 return false;
1158 }
1159 cPath += SafeSprintf(cPath, 256 - int(cPath - path), "/%.*s", start->length, start->pos);
1160 start++;
1161 }
1162 if(start->type != lex_semicolon)
1163 {
1164 CodeInfo::lastError.Init("ERROR: ';' not found after import expression", name->pos);
1165 return false;
1166 }

Callers 1

nullcCompileFunction · 0.45

Calls 15

ModuleInfoClass · 0.85
CodeRangeClass · 0.85
BuildModuleFunction · 0.85
SetGlobalSizeFunction · 0.85
ParseCodeFunction · 0.85
AllocateStringFunction · 0.85
strchrFunction · 0.85
SelectTypeByPointerFunction · 0.85
FunctionAddFunction · 0.85
FunctionStartFunction · 0.85
AddReturnNodeFunction · 0.85
FunctionEndFunction · 0.85

Tested by

no test coverage detected