Skip to content

Commit fce5e38

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

8 files changed

Lines changed: 172 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ pnpm-lock.yaml
2929
go.mod
3030
.RData
3131
.Rhistory
32+
program

README.md

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

public/icons/objective-c.svg

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

src-tauri/src/plugins/manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::plugins::javascript_nodejs::JavaScriptNodeJsPlugin;
1616
use crate::plugins::kotlin::KotlinPlugin;
1717
use crate::plugins::lua::LuaPlugin;
1818
use crate::plugins::nodejs::NodeJSPlugin;
19+
use crate::plugins::objective_c::ObjectiveCPlugin;
1920
use crate::plugins::php::PHPPlugin;
2021
use crate::plugins::python2::Python2Plugin;
2122
use crate::plugins::python3::Python3Plugin;
@@ -64,6 +65,7 @@ impl PluginManager {
6465
plugins.insert("cangjie".to_string(), Box::new(CangjiePlugin));
6566
plugins.insert("haskell".to_string(), Box::new(HaskellPlugin));
6667
plugins.insert("lua".to_string(), Box::new(LuaPlugin));
68+
plugins.insert("objective-c".to_string(), Box::new(ObjectiveCPlugin));
6769
plugins.insert(
6870
"javascript-nodejs".to_string(),
6971
Box::new(JavaScriptNodeJsPlugin),

src-tauri/src/plugins/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ pub mod kotlin;
387387
pub mod lua;
388388
pub mod manager;
389389
pub mod nodejs;
390+
pub mod objective_c;
390391
pub mod php;
391392
pub mod python2;
392393
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 ObjectiveCPlugin;
5+
6+
impl LanguagePlugin for ObjectiveCPlugin {
7+
fn get_order(&self) -> i32 {
8+
27
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-c"
17+
}
18+
19+
fn get_file_extension(&self) -> String {
20+
self.get_config()
21+
.map(|config| config.extension.clone())
22+
.unwrap_or_else(|| "m".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-c"),
65+
before_compile: Some(String::from(
66+
"clang -framework Foundation $filename -o program",
67+
)),
68+
extension: String::from("m"),
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 & 1 deletion
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} from '@codemirror/legacy-modes/mode/clike'
14+
import {kotlin, scala, objectiveC} 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'
@@ -219,6 +219,8 @@ export function useCodeMirrorEditor(props: Props)
219219
return StreamLanguage.define(haskell)
220220
case 'lua':
221221
return StreamLanguage.define(lua)
222+
case 'objective-c':
223+
return StreamLanguage.define(objectiveC)
222224
default:
223225
return null
224226
}

0 commit comments

Comments
 (0)