summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/c-cpp.yml4
-rw-r--r--dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc33
-rw-r--r--samples/cxx/example.cc6
-rw-r--r--tools/cppdrv.json2
4 files changed, 32 insertions, 13 deletions
diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml
index 9e7f7a1..231f0e7 100644
--- a/.github/workflows/c-cpp.yml
+++ b/.github/workflows/c-cpp.yml
@@ -2,9 +2,9 @@ name: C/C++ CI (CompilerKit)
on:
push:
- branches: [ "master" ]
+ branches: [ "stable" ]
pull_request:
- branches: [ "master" ]
+ branches: [ "stable" ]
jobs:
build:
diff --git a/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc b/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc
index 19bbe91..2539f1f 100644
--- a/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc
+++ b/dev/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc
@@ -508,8 +508,22 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
"__NECTI_LOCAL_VAR_" + varName + "\n";
kOrigin += 1UL;
} else {
+ auto mangled = valueOfVar;
+
+ if (mangled.find("(") != std::string::npos) {
+ auto ret = mangled.erase(mangled.find("("));
+ mangled = "__NECTI_";
+ mangled += ret;
+
+ syntax_tree.fUserValue = "jmp " + mangled + "\n";
+ syntax_tree.fUserValue +=
+ instr + " rax, " + kRegisterList[kRegisterMap.size()] + "\n";
+
+ goto done;
+ }
+
syntax_tree.fUserValue =
- instr + kRegisterList[kRegisterMap.size()] + ", " + valueOfVar + "\n";
+ instr + kRegisterList[kRegisterMap.size()] + ", " + mangled + "\n";
kOrigin += 1UL;
}
@@ -635,16 +649,16 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
try {
auto pos = text.find("return") + strlen("return") + 1;
CompilerKit::STLString subText = text.substr(pos);
- subText = subText.erase(subText.find(";"));
- size_t indxReg = 0UL;
+ if (subText.find(";") == CompilerKit::STLString::npos) break;
+
+ subText = subText.erase(subText.find(";"));
+ size_t indxReg = 0UL;
if (!subText.empty() && subText[0] != '\"' && subText[0] != '\'') {
if (!isdigit(subText[0])) {
for (auto pair : kRegisterMap) {
++indxReg;
- if (pair != subText) continue;
-
syntax_tree.fUserValue = "mov rax, " + kRegisterList[indxReg - 1] + "\nret\n";
kOrigin += 1UL;
@@ -687,10 +701,15 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendCPlusPlusAMD64::Compile(
}
}
+ syntax_tree.fUserValue = "ret\n";
+ kOrigin += 1UL;
+
break;
} catch (...) {
syntax_tree.fUserValue = "ret\n";
kOrigin += 1UL;
+
+ break;
}
}
default: {
@@ -762,7 +781,7 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) {
kKeywords.emplace_back("using", CompilerKit::kKeywordKindTypedef);
kKeywords.emplace_back("{", CompilerKit::kKeywordKindBodyStart);
kKeywords.emplace_back("}", CompilerKit::kKeywordKindBodyEnd);
- kKeywords.emplace_back("auto", CompilerKit::kKeywordKindVariable);
+ kKeywords.emplace_back("auto", CompilerKit::kKeywordKindType);
kKeywords.emplace_back("int", CompilerKit::kKeywordKindType);
kKeywords.emplace_back("bool", CompilerKit::kKeywordKindType);
kKeywords.emplace_back("unsigned", CompilerKit::kKeywordKindType);
@@ -773,7 +792,7 @@ NECTI_MODULE(CompilerCPlusPlusAMD64) {
kKeywords.emplace_back("double", CompilerKit::kKeywordKindType);
kKeywords.emplace_back("void", CompilerKit::kKeywordKindType);
- kKeywords.emplace_back("auto*", CompilerKit::kKeywordKindVariablePtr);
+ kKeywords.emplace_back("auto*", CompilerKit::kKeywordKindTypePtr);
kKeywords.emplace_back("int*", CompilerKit::kKeywordKindTypePtr);
kKeywords.emplace_back("bool*", CompilerKit::kKeywordKindTypePtr);
kKeywords.emplace_back("unsigned*", CompilerKit::kKeywordKindTypePtr);
diff --git a/samples/cxx/example.cc b/samples/cxx/example.cc
index 9ee2a30..e74acbb 100644
--- a/samples/cxx/example.cc
+++ b/samples/cxx/example.cc
@@ -2,13 +2,13 @@
#warning test macro warning #1
int bar() {
- int yyy = 100;
+ auto yyy = 17800;
return yyy;
}
int foo() {
- int arg1 = 0;
- return bar();
+ int arg1 = bar();
+ return arg1;
}
int main() {
diff --git a/tools/cppdrv.json b/tools/cppdrv.json
index 2968f4c..a9245ff 100644
--- a/tools/cppdrv.json
+++ b/tools/cppdrv.json
@@ -6,7 +6,7 @@
"output_name": "cppdrv",
"compiler_flags": ["-L/usr/local/lib", "-lCompilerKit"],
"cpp_macros": [
- "__CXXDRV__=202504",
+ "__CPPDRV__=202504",
"kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)"
]
}