🎉 initial commit: Nyash Programming Language完成版
🚀 主要機能: • Everything is Box哲学による革新的アーキテクチャ • WebAssemblyブラウザー対応プレイグラウンド • アーティスト協同制作デモ - 複数Boxインスタンス実証 • 視覚的デバッグシステム - DebugBox完全統合 • static box Mainパターン - メモリ安全設計 ⚡ 言語機能: • NOT/AND/OR/除算演算子完全実装 • ジェネリクス/テンプレートシステム • 非同期処理(nowait/await) • try/catchエラーハンドリング • Canvas統合グラフィックス 🎨 ブラウザー体験: • 9種類のインタラクティブデモ • リアルタイムコード実行 • WebCanvas/WebConsole/WebDisplay • モバイル対応完了 🤖 Built with Claude Code collaboration Ready for public release!
This commit is contained in:
67
src/boxes/bool_box.rs
Normal file
67
src/boxes/bool_box.rs
Normal file
@ -0,0 +1,67 @@
|
||||
// BoolBox implementation - Boolean values in Nyash
|
||||
use crate::box_trait::NyashBox;
|
||||
use std::any::Any;
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Boolean values in Nyash - true/false
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct BoolBox {
|
||||
pub value: bool,
|
||||
id: u64,
|
||||
}
|
||||
|
||||
impl BoolBox {
|
||||
pub fn new(value: bool) -> Self {
|
||||
static mut COUNTER: u64 = 0;
|
||||
let id = unsafe {
|
||||
COUNTER += 1;
|
||||
COUNTER
|
||||
};
|
||||
|
||||
Self { value, id }
|
||||
}
|
||||
|
||||
pub fn true_box() -> Self {
|
||||
Self::new(true)
|
||||
}
|
||||
|
||||
pub fn false_box() -> Self {
|
||||
Self::new(false)
|
||||
}
|
||||
}
|
||||
|
||||
impl NyashBox for BoolBox {
|
||||
fn to_string_box(&self) -> crate::box_trait::StringBox {
|
||||
crate::box_trait::StringBox::new(if self.value { "true" } else { "false" })
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> crate::box_trait::BoolBox {
|
||||
if let Some(other_bool) = other.as_any().downcast_ref::<BoolBox>() {
|
||||
crate::box_trait::BoolBox::new(self.value == other_bool.value)
|
||||
} else {
|
||||
crate::box_trait::BoolBox::new(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn type_name(&self) -> &'static str {
|
||||
"BoolBox"
|
||||
}
|
||||
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn box_id(&self) -> u64 {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for BoolBox {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", if self.value { "true" } else { "false" })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user