-
Notifications
You must be signed in to change notification settings - Fork 28
Wasm csharp biding generator #117
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
base: main
Are you sure you want to change the base?
Changes from all commits
45c3674
2b8ae27
da18768
0f58d42
606ac85
8b9ff86
4b302ed
d7f6529
144c5e5
2d6035c
cff1e1c
f4b75ae
92583f0
4358d72
de6d8e5
86654f6
d7c7494
7aaa8c3
84116eb
f8ecba6
a29dd05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ out/ | |
| splashkit/ | ||
| generated/ | ||
| __pycache__/ | ||
| _framework/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { dotnet } from "./wwwroot/_framework/dotnet.js"; | ||
|
|
||
| const loadDotNet = async () => { | ||
| const { setModuleImports, getAssemblyExports, getConfig } = await dotnet | ||
| .withDiagnosticTracing(false) | ||
| .withApplicationArgumentsFromQuery() | ||
| .create(); | ||
|
|
||
| setModuleImports("main.js", { | ||
| window: { | ||
| location: { | ||
| href: () => globalThis.window.location.href, | ||
| }, | ||
| }, | ||
| SplashKitBackendWASM: { | ||
| // TODO: Pass the rest of the SplashKit functions | ||
| write_line, | ||
| refresh_screen, | ||
| open_window, | ||
| fill_ellipse: () => { | ||
| // Research how to pass a JS object in WASM | ||
| fill_ellipse(color_black(), 260, 260, 200, 200); | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const config = getConfig(); | ||
| const exports = await getAssemblyExports(config.mainAssemblyName); | ||
| return exports; | ||
| }; | ||
|
|
||
| const CompileAndRun = async (code, reportError) => { | ||
| try { | ||
| const exports = await loadDotNet(); | ||
| const result = await exports.CSharpCodeRunner.CompileAndRun(code); | ||
| if (result.includes("Compilation failed")) { | ||
| const errors = result.split(":"); | ||
| const errorLine = errors[1].split("Line"); | ||
|
|
||
| const indexCorrector = 1; | ||
| const filePath = "__USERCODE__/code/main.cs"; | ||
| reportError( | ||
| filePath, | ||
| result, | ||
| Number(errorLine[1]) + indexCorrector, | ||
| null, | ||
| true, | ||
| ); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error during code execution:", error); | ||
| } | ||
| }; | ||
|
|
||
| // This event will be trigger by the csharp compiler | ||
| document.addEventListener("compileAndRun", (ev) => { | ||
| CompileAndRun(ev.detail.program[0].source, ev.detail.reportError); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| "use strict"; | ||
|
|
||
| class CSharpCompiler extends Compiler { | ||
| constructor() { | ||
| super(); | ||
| this.signalReady(); | ||
| } | ||
|
|
||
| async compileAll(compileList, sourceList, print) { | ||
| let compiled = { | ||
| output: null, | ||
| }; | ||
|
|
||
| let hasErrors = false; | ||
|
|
||
| // If all good, then output the 'compiled' result | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Daniel, |
||
| if (!hasErrors) { | ||
| compiled.output = []; | ||
| for (let i = 0; i < sourceList.length; i++) { | ||
| compiled.output.push({ | ||
| name: sourceList[i].name, | ||
| source: sourceList[i].source, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return compiled; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering if there is any documentation present on what data the compiled variable holds? If so please could you add it. I understand the priority right now is getting the program working, so please add a comment if you don't have time to document |
||
| } | ||
|
|
||
| } | ||
|
|
||
| // The name has to match the one in languageDefinitions.js | ||
| registerCompiler("csharpCompiler", new CSharpCompiler()); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,7 +285,7 @@ class ExecutionEnvironment extends EventTarget{ | |
|
|
||
| iframe.id="iframetest"; // this code is primordial... | ||
| if (language.needsSandbox) | ||
| iframe.sandbox = 'allow-scripts allow-modals'; | ||
| iframe.sandbox = 'allow-scripts allow-modals allow-same-origin'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Daniel, |
||
|
|
||
| container.appendChild(iframe); | ||
| iframe.src="executionEnvironment.html"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,41 @@ | |
| // should inherit from Compiler, and need to register themselves to be used | ||
|
|
||
| let SplashKitOnlineLanguageDefinitions = [ | ||
| { | ||
| name: "CSharp", | ||
| userVisibleName: "C#", | ||
| aliases: ['C#', 'CSharp'], | ||
| sourceExtensions: ['cs'], | ||
| compilableExtensions: ['cs'], | ||
| defaultSourceExtension: "cs", | ||
| setups: [{ | ||
| name: "C#", | ||
| runtimeFiles: [ | ||
| { src: "moduleEventTarget.js", type: "text/javascript" }, | ||
| { src: "loadsplashkit.js", type: "text/javascript" }, | ||
| { src: "fsevents.js", type: "text/javascript" }, | ||
| { src: "CSharpWasm/main.js", type: "module" }, | ||
| { src: "runtimes/ExecutionEnvironmentInternal.js", type: "text/javascript" }, | ||
| { src: "runtimes/csharp/csharpRuntime.js", type: "text/javascript" }, | ||
| ], | ||
| runtimeDependencies: [ | ||
| "runtimes/javascript/bin/SplashKitBackendWASM.js", | ||
| "runtimes/javascript/bin/SplashKitBackendWASM.wasm", | ||
| ], | ||
| compilerFiles: [ | ||
| "compilers/csharp/csharpCompiler.js", | ||
| ], | ||
| runtimeSizeAprox: 20, | ||
| compilerSizeAprox: 150, | ||
| compilerName: "csharpCompiler", | ||
| supportHotReloading: false, | ||
| getDefaultProject: ()=>{return makeNewProject_CSharp;}, | ||
| persistentFilesystem: false, | ||
| compiled: true, | ||
| needsSandbox: false, | ||
| needsServiceWorker: false, | ||
| }] | ||
| }, | ||
|
Comment on lines
+14
to
+48
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curios, is this process documented somewhere? |
||
| { | ||
| name: "JavaScript", | ||
| userVisibleName: "JavaScript", | ||
|
|
@@ -21,12 +56,12 @@ let SplashKitOnlineLanguageDefinitions = [ | |
| setups: [{ | ||
| name: "JavaScript Native", | ||
| runtimeFiles: [ | ||
| "babel/babel.js", //intention is to make this a compilerFile instead | ||
| "moduleEventTarget.js", | ||
| "loadsplashkit.js", | ||
| "fsevents.js", | ||
| "executionEnvironment_CodeProcessor.js", //intention is to make this a compilerFile instead | ||
| "executionEnvironment_Internal.js", // and this should be based on ExecutionEnvironmentInternal.js | ||
| { src: "babel/babel.js", type: "text/javascript" }, //intention is to make this a compilerFile instead | ||
| { src: "moduleEventTarget.js", type: "text/javascript" }, | ||
| { src: "loadsplashkit.js", type: "text/javascript" }, | ||
| { src: "fsevents.js", type: "text/javascript" }, | ||
| { src: "executionEnvironment_CodeProcessor.js", type: "text/javascript" }, //intention is to make this a compilerFile instead | ||
| { src: "executionEnvironment_Internal.js", type: "text/javascript" }, // and this should be based on ExecutionEnvironmentInternal.js | ||
| ], | ||
| runtimeDependencies: [ | ||
| "runtimes/javascript/bin/SplashKitBackendWASM.js", | ||
|
|
@@ -56,9 +91,9 @@ let SplashKitOnlineLanguageDefinitions = [ | |
| setups: [{ | ||
| name: "C++ (Clang)", | ||
| runtimeFiles: [ | ||
| "runtimes/ExecutionEnvironmentInternal.js", | ||
| "runtimes/cxx/cxxRuntime.js", | ||
| "runtimes/cxx/bin/SplashKitBackendWASMCPP.js", | ||
| { src: "runtimes/ExecutionEnvironmentInternal.js", type: "text/javascript" }, | ||
| { src: "runtimes/cxx/cxxRuntime.js", type: "text/javascript" }, | ||
| { src: "runtimes/cxx/bin/SplashKitBackendWASMCPP.js", type: "text/javascript" }, | ||
| ], | ||
| runtimeDependencies: [ | ||
| "runtimes/cxx/bin/SplashKitBackendWASMCPP.js", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Daniel,
Don't fix it for this commit as I get that this is a work in progress but in your next pull request please can you add some documentation or comments to this code. That is if no documentation exists