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
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/dotnet/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,7 @@ export const makeDotnetCompiler: CompilerFactory<Streams, Program> = async (ctx,
const runtimeFactory = new DotnetRuntimeFactory(compiler);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
const runtime = runtimeFactory.create(ctx, files[0].content);
const runtime = runtimeFactory.create(ctx, files);
return new DotnetProgram(runtime);
}
};
Expand Down
8 changes: 4 additions & 4 deletions apps/ppp/src/lib/runtime/dotnet/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ export class DotnetTestCompilerFactory {
const runtimeFactory = new DotnetRuntimeFactory(compiler);
return {
async compile(ctx, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
const runtime = runtimeFactory.create(ctx, files[0].content, executionCode);
const runtime = runtimeFactory.create(ctx, [
...files,
{ filename: 'execution', content: executionCode }
]);
return new DotnetTestProgram<I, O>(typeFullName, methodName, runtime);
}
};
Expand Down
3 changes: 1 addition & 2 deletions apps/ppp/src/lib/runtime/gleam/test-compiler-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Context } from 'libs/context';
import type { Streams } from 'libs/io';
import { createLogger, redirect, type Logger } from 'libs/logger';
import { compileJsModule } from 'libs/js';
import type { TestCompiler } from 'libs/testing';
import { JsTestProgram } from 'javascript-runtime';
import { GleamModuleCompiler } from 'gleam-runtime';
Expand Down Expand Up @@ -48,7 +47,7 @@ export class GleamTestCompilerFactory {
throw new Error('Compilation of multiple files is not implemented');
}
const jsCode = compiler.compile(files[0].content);
return new TestProgram(await compileJsModule(jsCode), this.patchedConsole);
return new TestProgram([{ filename: 'main', content: jsCode }], this.patchedConsole);
}
};
}
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/go/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export const makeGoCompiler: CompilerFactory<Streams, Program> = async (ctx, str
logger.info(`Loaded ${wasmUrl}`);
return {
async compile(ctx, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new GoProgram(await goExecutorFactory(ctx, streams, files[0].content));
return new GoProgram(await goExecutorFactory(ctx, streams, files));
}
};
};
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/go/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export class GoTestCompilerFactory {
this.logger.info(`Loaded ${wasmUrl}`);
return {
compile: async (ctx, files) => {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new TestProgram(await goEvaluatorFactory(ctx, this.streams, files[0].content));
return new TestProgram(await goEvaluatorFactory(ctx, this.streams, files));
}
};
}
Expand Down
7 changes: 2 additions & 5 deletions apps/ppp/src/lib/runtime/java/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ export const makeJavaCompiler: CompilerFactory<Streams, Program> = async (ctx, s
}).then((response) => response.arrayBuffer());
logger.info(`Loaded ${libZipUrl}`);
const fs = await initFs(libZipData);
const compiler = new JavaCompiler(jvmFactory, `/home/${CLASSNAME}.java`, fs);
const compiler = new JavaCompiler(jvmFactory, fs);
return {
async compile(ctx, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
await compiler.compile(ctx, files[0].content);
await compiler.compile(ctx, files);
return new JavaProgram(CLASSNAME, jvmFactory);
}
};
Expand Down
18 changes: 8 additions & 10 deletions apps/ppp/src/lib/runtime/java/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class JavaTestCompilerFactory {
}).then((response) => response.arrayBuffer());
this.logger.info(`Loaded ${libZipUrl}`);
const fs = await initFs(libZipData);
const compiler = new JavaCompiler(jvmFactory, `/home/${className}.java`, fs);
const compiler = new JavaCompiler(jvmFactory, fs);
class TestProgram extends JavaTestProgram<I, O> implements Disposable {
private output?: O;
private saveOutput(output: O) {
Expand All @@ -59,22 +59,20 @@ export class JavaTestCompilerFactory {
}
return {
async compile(ctx, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
// TODO: Fix handling compilation errors or at least remove previous
// compilation output
await compiler.compile(
ctx,
`${files[0].content}

public class ${className} {
await compiler.compile(ctx, [
...files,
{
filename: className,
content: `public class ${className} {
${classDefinitions}
public static void main(String[] args) {
${mainMethodBody}
}
}`
);
}
]);
const program = new TestProgram(className, jvmFactory);
ctx.onCancel(() => {
program[Symbol.dispose]();
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/js/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export const makeJsCompiler: CompilerFactory<Streams, Program> = async (_, strea
const patchedConsole = redirect(globalThis.console, createLogger(streams.out));
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new JsProgram(files[0].content, patchedConsole);
return new JsProgram(files, patchedConsole);
}
};
};
6 changes: 1 addition & 5 deletions apps/ppp/src/lib/runtime/js/test-compiler-factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Streams } from 'libs/io';
import { createLogger, redirect } from 'libs/logger';
import { compileJsModule } from 'libs/js';
import type { TestCompiler } from 'libs/testing';
import { JsTestProgram } from 'javascript-runtime';

Expand All @@ -21,10 +20,7 @@ export class JsTestCompilerFactory {
}
return {
compile: async (_, files) => {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new TestProgram(await compileJsModule(files[0].content), this.patchedConsole);
return new TestProgram(files, this.patchedConsole);
}
};
}
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/php/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export const makePhpCompiler: CompilerFactory<Streams, Program> = async (ctx, st
logger.info(`Loaded ${phpWasmUrl}`);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new PHPProgram(files[0].content, php, streams);
return new PHPProgram(files, php, streams);
}
};
};
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/php/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export class PhpTestCompilerFactory {
this.logger.info(`Loaded ${phpWasmUrl}`);
return {
compile: async (ctx, files) => {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
const program = new TestProgram(this.streams, php, files[0].content);
const program = new TestProgram(this.streams, php, files);
ctx.onCancel(() => {
program[Symbol.dispose]();
});
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/python/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export const makePythonCompiler: CompilerFactory<Streams, Program> = async (ctx,
logger.info(`Loaded ${indexUrl}`);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new PyProgram(files[0].content, pyRuntime);
return new PyProgram(files, pyRuntime);
}
};
};
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/python/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export class PythonTestCompilerFactory {
this.logger.info(`Loaded ${indexUrl}`);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new TestProgram(pyRuntime, files[0].content);
return new TestProgram(pyRuntime, files);
}
};
}
Expand Down
9 changes: 3 additions & 6 deletions apps/ppp/src/lib/runtime/ruby/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ export const makeRubyCompiler: CompilerFactory<Streams, Program> = async (ctx, s
);
logger.info(`Loaded ${rubyWasmUrl}`);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
const vm = await createRubyVM(ctx, streams, rubyWasmModule);
return new RubyProgram(files[0].content, vm);
async compile(ctx, files) {
const vm = await createRubyVM(ctx, streams, rubyWasmModule, files);
return new RubyProgram(files, vm);
}
};
};
12 changes: 6 additions & 6 deletions apps/ppp/src/lib/runtime/ruby/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Streams } from 'libs/io';
import { inContext, type Context } from 'libs/context';
import type { TestCompiler } from 'libs/testing';
import { createLogger, type Logger } from 'libs/logger';
import { RubyTestProgram, createRubyVM } from 'ruby-runtime';
import { RubyTestProgram, createRubyVM, rubyEntryFile, rubyFilePath } from 'ruby-runtime';

import rubyWasmUrl from 'ruby-runtime/ruby.wasm?url';

Expand Down Expand Up @@ -33,11 +33,11 @@ export class RubyTestCompilerFactory {
this.logger.info(`Loaded ${rubyWasmUrl}`);
return {
compile: async (ctx, files) => {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
const vm = await createRubyVM(ctx, this.streams, rubyWasmModule);
await inContext(ctx, vm.evalAsync(files[0].content));
const vm = await createRubyVM(ctx, this.streams, rubyWasmModule, files);
const entry = rubyFilePath(rubyEntryFile(files));
// Load the entry from the VM filesystem instead of evaluating it
// inline, so require_relative works across the program files.
await inContext(ctx, vm.evalAsync(`load '${entry}'`));
return new TestProgram(vm);
}
};
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/rust/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export const makeRustCompiler: CompilerFactory<Streams, Program> = async (ctx, s
const wasi = createWASI(streams, libs);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new RustProgram(files[0].content, wasi, miri);
return new RustProgram(files, wasi, miri);
}
};
};
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/rust/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ export class RustTestCompilerFactory {
const wasi = createWASI(this.streams, libs);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new TestProgram(files[0].content, wasi, miri, 'case_output');
return new TestProgram(files, wasi, miri, 'case_output');
}
};
}
Expand Down
9 changes: 5 additions & 4 deletions apps/ppp/src/lib/runtime/ts/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export const makeTsCompiler: CompilerFactory<Streams, Program> = async (_, strea
const patchedConsole = redirect(globalThis.console, createLogger(streams.out));
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new JsProgram(compileTsModule(files[0].content), patchedConsole);
const modules = files.map((file) => ({
filename: file.filename,
content: compileTsModule(file.content)
}));
return new JsProgram(modules, patchedConsole);
}
};
};
18 changes: 10 additions & 8 deletions apps/ppp/src/lib/runtime/ts/test-compiler-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { File } from 'libs/compiler';
import type { Streams } from 'libs/io';
import { compileJsModule } from 'libs/js';
import { compileJsFiles } from 'libs/js';
import { createLogger, redirect } from 'libs/logger';
import type { TestCompiler } from 'libs/testing';
import { JsTestProgram } from 'javascript-runtime';
Expand All @@ -16,19 +17,20 @@ export class TsTestCompilerFactory {

create<M, I, O>(invokeTestMethod: InvokeTestMethod<M, I, O>): TestCompiler<I, O> {
class TestProgram extends JsTestProgram<M, I, O> {
protected override async compile(files: File[]): Promise<M> {
const modules = files.map((file) => ({
filename: file.filename,
content: compileTsModule(file.content)
}));
return await compileJsFiles<M>(modules);
}
override async executeTest(m: M, input: I): Promise<O> {
return invokeTestMethod(m, input);
}
}
return {
compile: async (_, files) => {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new TestProgram(
await compileJsModule(compileTsModule(files[0].content)),
this.patchedConsole
);
return new TestProgram(files, this.patchedConsole);
}
};
}
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/zig/compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export const makeZigCompiler: CompilerFactory<Streams, Program> = async (ctx, st
const compiler = new ZigCompiler(compilerWasi, zigWasmModule);
return {
async compile(ctx, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
const program = await compiler.compile(ctx, files[0].content);
const program = await compiler.compile(ctx, files);
return new ZigProgram(
programWasi,
program.buffer instanceof ArrayBuffer
Expand Down
5 changes: 1 addition & 4 deletions apps/ppp/src/lib/runtime/zig/test-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ export class ZigTestCompilerFactory {
]);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error('Compilation of multiple files is not implemented');
}
return new TestProgram(files[0].content, wasi, zigWasmModule, 'case_output');
return new TestProgram(files, wasi, zigWasmModule, 'case_output');
}
};
}
Expand Down
9 changes: 7 additions & 2 deletions packages/dotnet-runtime/compiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,22 @@ internal static async Task<int> Init(string[] urls)

[JSExport]
[RequiresUnreferencedCode("Calls System.AppDomain.Load(Byte[])")]
internal static int Compile(string[] code)
internal static int Compile(string[] filenames, string[] code)
{
if (references == null)
{
Logger.Error("Compiler is not initialized");
return -1;
}
if (filenames.Length != code.Length)
{
Logger.Error("Filenames and sources counts do not match");
return -1;
}
SyntaxTree[] trees = new SyntaxTree[code.Length];
for (int i = 0; i < code.Length; i++)
{
SyntaxTree tree = CSharpSyntaxTree.ParseText(code[i]);
SyntaxTree tree = CSharpSyntaxTree.ParseText(code[i], path: filenames[i]);
var hasDiagnosticError = false;
foreach (var diagnostic in tree.GetDiagnostics())
{
Expand Down
2 changes: 1 addition & 1 deletion packages/dotnet-runtime/compiler/dotnet-compiler.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkgs.stdenv.mkDerivation {

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "sha256-UFR5yFD5oYmayQJKQXxoE7/p2M/j1td+QaxIibBLtT8=";
outputHash = "sha256-BQcQWLpLw9DiCaFvAoHYyX2vadAO81WqhF0omFjQ3UU=";

dontConfigure = true;
dontStrip = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/dotnet-runtime/src/dotnet-compiler-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface CompilerModuleImports {
export interface CompilerModuleExports {
Compiler: {
Init: (dllUrls: string[]) => Promise<number>;
Compile: (code: string[]) => number;
Compile: (filenames: string[], code: string[]) => number;
Run: (typeFullName: string, methodName: string, args: string[]) => number;
GetResultAsString: () => string | null;
DisposeAssembly: () => void;
Expand Down
Loading
Loading