Skip to content

Commit 91f6185

Browse files
committed
feat (language): 支持 Objective-C++ 语言
1 parent fce5e38 commit 91f6185

7 files changed

Lines changed: 186 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发
4040
<img src="public/icons/lua.svg" width="60" alt="Lua">
4141
<img src="public/icons/nodejs.svg" width="60" alt="Node.js">
4242
<img src="public/icons/objective-c.svg" width="60" alt="Objective-C">
43+
<img src="public/icons/objective-cpp.svg" width="60" alt="Objective-C++">
4344
<img src="public/icons/php.svg" width="60" alt="PHP">
4445
<img src="public/icons/python.svg" width="60" alt="Python 2">
4546
<img src="public/icons/python.svg" width="60" alt="Python 3">

public/icons/objective-cpp.svg

Lines changed: 9 additions & 0 deletions
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#import <Foundation/Foundation.h>
2+
#include <iostream>
3+
#include <vector>
4+
#include <string>
5+
6+
int main(int argc, const char * argv[]) {
7+
@autoreleasepool {
8+
printf("🎉 欢迎使用 CodeForge!\n");
9+
printf("Welcome to CodeForge!\n");
10+
printf("\n");
11+
12+
printf("=========================================\n");
13+
printf(" CodeForge Objective-C++ \n");
14+
printf("=========================================\n");
15+
printf("\n");
16+
17+
printf("✅ Objective-C++运行成功! (Objective-C++ is working!)\n");
18+
printf("⚡ 这是Objective-C++程序 (This is Objective-C++ program)\n");
19+
printf("\n");
20+
21+
int number1 = 10;
22+
int number2 = 20;
23+
int result = number1 + number2;
24+
25+
printf("🔢 简单计算 (Simple calculation):\n");
26+
printf("%d + %d = %d\n", number1, number2, result);
27+
printf("\n");
28+
29+
printf("📝 字符串操作 (String operations):\n");
30+
std::string cppName = "CodeForge";
31+
std::string cppVersion = "Objective-C++";
32+
printf("平台名称 (Platform): %s\n", cppName.c_str());
33+
printf("语言版本 (Language): %s\n", cppVersion.c_str());
34+
printf("完整信息 (Full info): %s - %s\n", cppName.c_str(), cppVersion.c_str());
35+
printf("\n");
36+
37+
printf("🍎 数组示例 (Array example - Objective-C):\n");
38+
NSArray *fruits = @[@"苹果", @"香蕉", @"橙子", @"葡萄"];
39+
for (int i = 0; i < fruits.count; i++) {
40+
printf("%d. %s\n", i + 1, [fruits[i] UTF8String]);
41+
}
42+
printf("\n");
43+
44+
printf("🍇 Vector示例 (Vector example - C++):\n");
45+
std::vector<std::string> colors = {"红色", "蓝色", "绿色", "黄色"};
46+
for (size_t i = 0; i < colors.size(); i++) {
47+
printf("%zu. %s\n", i + 1, colors[i].c_str());
48+
}
49+
printf("\n");
50+
51+
int score = 85;
52+
printf("📊 成绩评估 (Score evaluation):\n");
53+
if (score >= 90) {
54+
printf("优秀! (Excellent!)\n");
55+
} else if (score >= 80) {
56+
printf("良好! (Good!)\n");
57+
} else if (score >= 60) {
58+
printf("及格 (Pass)\n");
59+
} else {
60+
printf("需要努力 (Need improvement)\n");
61+
}
62+
printf("\n");
63+
64+
printf("🔄 循环输出 (Loop output):\n");
65+
for (int i = 1; i <= 5; i++) {
66+
printf("第 %d 次输出 (Output #%d): Hello from CodeForge!\n", i, i);
67+
}
68+
printf("\n");
69+
70+
printf("🔁 While循环示例 (While loop example):\n");
71+
int counter = 1;
72+
while (counter <= 3) {
73+
printf("While循环: 第 %d 次\n", counter);
74+
counter++;
75+
}
76+
printf("\n");
77+
78+
printf("🎯 CodeForge Objective-C++代码执行完成!\n");
79+
printf("🎯 CodeForge Objective-C++ execution completed!\n");
80+
printf("\n");
81+
printf("感谢使用 CodeForge 代码执行环境! 🚀\n");
82+
printf("Thank you for using CodeForge! 🚀\n");
83+
}
84+
return 0;
85+
}

src-tauri/src/plugins/manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::plugins::kotlin::KotlinPlugin;
1717
use crate::plugins::lua::LuaPlugin;
1818
use crate::plugins::nodejs::NodeJSPlugin;
1919
use crate::plugins::objective_c::ObjectiveCPlugin;
20+
use crate::plugins::objective_cpp::ObjectiveCppPlugin;
2021
use crate::plugins::php::PHPPlugin;
2122
use crate::plugins::python2::Python2Plugin;
2223
use crate::plugins::python3::Python3Plugin;
@@ -66,6 +67,7 @@ impl PluginManager {
6667
plugins.insert("haskell".to_string(), Box::new(HaskellPlugin));
6768
plugins.insert("lua".to_string(), Box::new(LuaPlugin));
6869
plugins.insert("objective-c".to_string(), Box::new(ObjectiveCPlugin));
70+
plugins.insert("objective-cpp".to_string(), Box::new(ObjectiveCppPlugin));
6971
plugins.insert(
7072
"javascript-nodejs".to_string(),
7173
Box::new(JavaScriptNodeJsPlugin),

src-tauri/src/plugins/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ pub mod lua;
388388
pub mod manager;
389389
pub mod nodejs;
390390
pub mod objective_c;
391+
pub mod objective_cpp;
391392
pub mod php;
392393
pub mod python2;
393394
pub mod python3;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use super::{LanguagePlugin, PluginConfig};
2+
use std::vec;
3+
4+
pub struct ObjectiveCppPlugin;
5+
6+
impl LanguagePlugin for ObjectiveCppPlugin {
7+
fn get_order(&self) -> i32 {
8+
28
9+
}
10+
11+
fn get_language_name(&self) -> &'static str {
12+
"Objective-C++"
13+
}
14+
15+
fn get_language_key(&self) -> &'static str {
16+
"objective-cpp"
17+
}
18+
19+
fn get_file_extension(&self) -> String {
20+
self.get_config()
21+
.map(|config| config.extension.clone())
22+
.unwrap_or_else(|| "mm".to_string())
23+
}
24+
25+
fn get_version_args(&self) -> Vec<&'static str> {
26+
vec!["--version"]
27+
}
28+
29+
fn get_path_command(&self) -> String {
30+
"which clang++".to_string()
31+
}
32+
33+
fn get_command(
34+
&self,
35+
_file_path: Option<&str>,
36+
_is_version: bool,
37+
_file_name: Option<String>,
38+
) -> String {
39+
if _is_version {
40+
let clang_command = if self.get_execute_home().is_some() {
41+
"./clang++"
42+
} else {
43+
"clang++"
44+
};
45+
46+
return clang_command.to_string();
47+
}
48+
49+
if let Some(config) = self.get_config() {
50+
if let Some(run_cmd) = &config.run_command {
51+
return if let Some(file_name) = _file_name {
52+
run_cmd.replace("$filename", &file_name)
53+
} else {
54+
run_cmd.clone()
55+
};
56+
}
57+
}
58+
self.get_default_command()
59+
}
60+
61+
fn get_default_config(&self) -> PluginConfig {
62+
PluginConfig {
63+
enabled: true,
64+
language: String::from("objective-cpp"),
65+
before_compile: Some(String::from(
66+
"clang++ -framework Foundation $filename -o program",
67+
)),
68+
extension: String::from("mm"),
69+
execute_home: None,
70+
run_command: Some(String::from("./program")),
71+
after_compile: Some(String::from("rm -f program")),
72+
template: Some(String::from(
73+
"// Objective-C++ 示例代码 - CodeForge 代码执行环境\n\n",
74+
)),
75+
timeout: Some(30),
76+
console_type: Some(String::from("console")),
77+
}
78+
}
79+
80+
fn get_default_command(&self) -> String {
81+
self.get_config()
82+
.and_then(|config| config.run_command.clone())
83+
.unwrap_or_else(|| "./program".to_string())
84+
}
85+
}

src/composables/useCodeMirrorEditor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {xml} from '@codemirror/lang-xml'
1111
import {php} from '@codemirror/lang-php'
1212
import {shell} from '@codemirror/legacy-modes/mode/shell'
1313
import {swift} from '@codemirror/legacy-modes/mode/swift'
14-
import {kotlin, scala, objectiveC} from '@codemirror/legacy-modes/mode/clike'
14+
import {kotlin, objectiveC, objectiveCpp, scala} from '@codemirror/legacy-modes/mode/clike'
1515
import {clojure} from '@codemirror/legacy-modes/mode/clojure'
1616
import {ruby} from '@codemirror/legacy-modes/mode/ruby'
1717
import {groovy} from '@codemirror/legacy-modes/mode/groovy'
@@ -221,6 +221,8 @@ export function useCodeMirrorEditor(props: Props)
221221
return StreamLanguage.define(lua)
222222
case 'objective-c':
223223
return StreamLanguage.define(objectiveC)
224+
case 'objective-cpp':
225+
return StreamLanguage.define(objectiveCpp)
224226
default:
225227
return null
226228
}
@@ -289,7 +291,6 @@ export function useCodeMirrorEditor(props: Props)
289291
}
290292
}
291293

292-
// 其余代码完全保持不变...
293294
const loadEditorConfig = async () => {
294295
try {
295296
const globalConfig = await invoke<any>('get_app_config')

0 commit comments

Comments
 (0)