Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
45c3674
Add initial C# WebAssembly project structure and setup
daosgava Dec 14, 2024
2b8ae27
Refine .gitignore to streamline ignored files and directories
daosgava Dec 14, 2024
da18768
Add C# support with compiler and runtime integration
daosgava Dec 21, 2024
0f58d42
Refactor C# runtime integration: update event handling and remove unu…
daosgava Dec 21, 2024
606ac85
Remove redundant console log for IDE initialization
daosgava Dec 21, 2024
8b9ff86
Merge branch 'main' into wasm-csharp-interop
daosgava Dec 21, 2024
4b302ed
Update comment for clarity in CSharpCompiler registration
daosgava Dec 21, 2024
d7f6529
Refactor C# WebAssembly integration: remove run button and related co…
daosgava Dec 21, 2024
144c5e5
Remove redundant console log in project initializer for C# project cr…
daosgava Dec 21, 2024
2d6035c
CSharpWasm.dll update
daosgava Dec 21, 2024
cff1e1c
Overload write_line function
daosgava Jan 7, 2025
f4b75ae
add error handling and namespace
daosgava Jan 7, 2025
92583f0
fix indentation, use sample from splash kit website
daosgava Jan 7, 2025
4358d72
Add comments with future work
daosgava Jan 7, 2025
de6d8e5
Improve comments and remove unnecessary methods
daosgava Jan 7, 2025
86654f6
Initial Setup
daosgava Mar 26, 2025
d7c7494
Minor change
daosgava Mar 26, 2025
7aaa8c3
add generated file to gitignore
daosgava Mar 26, 2025
84116eb
improve format, parameters and return type
daosgava Mar 30, 2025
f8ecba6
Folder restructuring
daosgava Apr 4, 2025
a29dd05
cleaning folder structure
daosgava Apr 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ out/
splashkit/
generated/
__pycache__/
_framework/
Binary file added Browser_IDE/CSharpWasm/bin/CSharpWasm.dll
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/System.Console.dll
Binary file not shown.
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/System.Runtime.dll
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/mscorlib.dll
Binary file not shown.
Binary file added Browser_IDE/CSharpWasm/bin/netstandard.dll
Binary file not shown.
58 changes: 58 additions & 0 deletions Browser_IDE/CSharpWasm/main.js
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);
});
Comment on lines +3 to +58
Copy link
Collaborator

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

33 changes: 33 additions & 0 deletions Browser_IDE/compilers/csharp/csharpCompiler.js
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Daniel,
While I can see what is going on here. (Using the compiled binaries to compile a program), adding a comment here clarifying that the program is being complied not the binaries would help with clarity

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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());
1 change: 0 additions & 1 deletion Browser_IDE/executionEnvironment.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@
<script src="downloadHandler.js"></script>
<script src="executionEnvironment_Page.js"></script>
<script src="runtimes/ExecutionEnvironmentInternalLoader.js"></script>

</html>
2 changes: 1 addition & 1 deletion Browser_IDE/executionEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Daniel,
While I can understand what is going on here with CORS, I think a comment clarifying what these three attributes do would be valuable, particularly for those working on this project in the future


container.appendChild(iframe);
iframe.src="executionEnvironment.html";
Expand Down
53 changes: 44 additions & 9 deletions Browser_IDE/languageDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curios, is this process documented somewhere?

{
name: "JavaScript",
userVisibleName: "JavaScript",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading