Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

externの実装 #40

Closed
4 tasks done
kumavale opened this issue Nov 27, 2022 · 4 comments · Fixed by #58 or #65
Closed
4 tasks done

externの実装 #40

kumavale opened this issue Nov 27, 2022 · 4 comments · Fixed by #58 or #65
Labels
enhancement New feature or request

Comments

@kumavale
Copy link
Owner

kumavale commented Nov 27, 2022

#[link(name = "System.Console.dll")]
extern {
    mod System {
        struct Console {}
        impl Console {
            fn WriteLine(_: string) {}
        }
    }
}
#[link(name = "System.Windows.Forms.dll")]
extern {
    mod System {
        mod Windows {
            mod Forms {
                struct DialogResult {}
                struct MessageBox {}
                impl MessageBox {
                    fn Show(text: string) -> DialogResult {}
                }
            }
        }
    }
}
fn main() {
    System::Windows::Forms::MessageBox::Show("hello!");
    System::Console::WriteLine("ok");
}

言語としては物凄く面倒くさい仕様になってしまうが、最終的に外部crateとしてこの部分(System名前空間)を提供すれば使いやすくなるのではないか。

Tasks

  • modをネストできるように
  • 名前空間のマージ
  • to_ilstrでアセンブリ参照と完全パス名を生成できるように
  • アセンブリ参照を自動で読み込む(.assembly extern System.Console {}
    -> extern宣言でpublickeytokenも定義させて、それを元に生成...?
@kumavale kumavale added the enhancement New feature or request label Nov 27, 2022
@kumavale kumavale mentioned this issue Nov 27, 2022
4 tasks
@kumavale
Copy link
Owner Author

kumavale commented Dec 7, 2022

メモ

  • c#に限らないのでexternだけで良い。"C#"は要らない。
  • fnの処理内容は書く必要はないため、;で終わりにしたいが、パースの関係上{}でとりあえずokとする。

@kumavale
Copy link
Owner Author

kumavale commented Dec 8, 2022

.Net側の名前空間も宣言する必要があるなぁ

#[link(name = "System.Console.dll")]
extern {
    mod System {
        struct Console {}
        impl Console {
            fn WriteLine(_: string) {}
        }
    }
}
fn main() {
    System::Console::WriteLine("ok");
}

@kumavale
Copy link
Owner Author

kumavale commented Dec 8, 2022

こうするとSystem.Console.dllのSystem名前空間とSystem.Windows.Forms.dllのSystem名前空間が別々のNameSpaceとして保存されるからSystem::Windows::Forms::MessageBoxでNameSpaceのfindが上手くいかない。

NameSpaceをマージする機能が欲しい。

#[link(name = "System.Console.dll")]
extern {
    mod System {
        struct Console {}
        impl Console {
            fn WriteLine(_: string) {}
        }
    }
}
#[link(name = "System.Windows.Forms.dll")]
extern {
    mod System {
        mod Windows {
            mod Forms {
                struct DialogResult {}
                struct MessageBox {}
                impl MessageBox {
                    fn Show(text: string) -> DialogResult {}
                }
            }
        }
    }
}
fn main() {
    System::Windows::Forms::MessageBox::Show("hello!");
    System::Console::WriteLine("ok");
    println!("ok");
}

@kumavale kumavale linked a pull request Dec 8, 2022 that will close this issue
kumavale added a commit that referenced this issue Dec 8, 2022
* とりあえずSystem.Console.dllは動作できるものができた

* Refactoring about Delimiter

* OuterAttributeのパース処理を追加

* attributeからdllファイル名を取得する処理を追加(wip)

* Refactoring

* System名前空間に対応した
@kumavale kumavale reopened this Dec 8, 2022
@kumavale kumavale changed the title extern "c#"の実装 externの実装 Dec 9, 2022
@kumavale
Copy link
Owner Author

kumavale commented Dec 9, 2022

.ctorはコンストラクタを示す特別なキーワードとしたい。

#[link(name = "System.Drawing.Primitives.dll")]
extern {
    mod System {
        mod Drawing {
            struct Size {
                Width: i32,
                Height: i32,
            }
            impl Size {
                fn .ctor(width: i32, height: i32) -> Size {}
            }
        }
    }
}
fn main() {
    let s: System::Drawing::Size = System::Drawing::Size::.ctor(2, 3);
    assert_eq!(s.Width == 2 && s.Height == 3);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant