Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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);
});
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
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;
}

}

// 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';

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,
}]
},
{
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
Loading