Skip to content
Open
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
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .NET/Mono Bext Codegen

> [!WARNING]
> The Codegen is currently a work-in-progress and does not have anything useful implemented in it.
> The Codegen is currently a work-in-progress.

This is a codegen for [the B extended compiler](https://github.com/bext-lang/b). It introduces targets that produce [.NET](https://dotnet.microsoft.com/en-us/)/[Mono](https://www.mono-project.com/) compatible binaries.

Expand All @@ -18,10 +18,25 @@ $ ./build/b -tlist

## Targets and Dependencies

Right now the codegen introduces only one target `ilasm-mono`. It expects `ilasm` and `mono` executables to be available in the `$PATH` environment variables. Lots of Linux distros provide them via the mono packages in their official repos:
Right now the codegen introduces two targets `ilasm-mono` and `ilasm-core`.

`ilasm-mono` target expects `ilasm` and `mono` executables to be available in the `$PATH` environment variables. Lots of Linux distros provide them via the mono packages in their official repos:

```consols
$ sudo xbps-install mono # Void Linux
$ sudo apt install mono-devel # Ubuntu
...
```

On Windows the `mono` executable isn't used so it doesn't need to be in `$PATH`, instead the `ilasm-mono` target executes the resulting binary using .NET Framework. Both .NET Framework's `ilasm` and [.NET Core's `ilasm`](https://www.nuget.org/packages/runtime.win-x64.Microsoft.NETCore.ILAsm) can be used by the target to compile the binary on Windows.

.NET Core's `ilasm` can be also used on [Linux](https://www.nuget.org/packages/runtime.linux-x64.Microsoft.NETCore.ILAsm) and [macOS](https://www.nuget.org/packages/runtime.osx-arm64.Microsoft.NETCore.ILAsm) instead of Mono's `ilasm` if desired.

`ilasm-core` target expects .NET 9 SDK/Runtime (or later) to be installed and the `dotnet` executable to be available in the `$PATH` environment variables. Lots of Linux distros provide them via `dotnet-sdk-[version]` (and `dotnet-runtime-[version]`) packages in their official repos:

```consols
$ sudo apt install dotnet-sdk-9.0 # Ubuntu
...
```

It also expects the `ilasm` executable to be in the `$PATH` environment variables, which can be obtained from either Mono or the .NET Core ILAsm NuGet packages linked above (recommended), the .NET Framework one can be also used on Windows.
29 changes: 29 additions & 0 deletions libb/ilasm-core.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// because Windows
usleep(us) {
__asm__(
"ldarg.0",
"conv.i4",
"ldc.i4 1000",
"div",
"call void [mscorlib]System.Threading.Thread::Sleep(int32)",
"ldc.i8 0",
"ret"
);
}

char(s,n) {
__asm__(
"ldarg 0",
"ldarg 1",
"add",
"ldind.i1",
"conv.i8",
"ret"
);
}

extrn printf;
__variadic__(printf, 1);
extrn putchar;
extrn getchar;
extrn exit;
28 changes: 25 additions & 3 deletions libb/ilasm-mono.b
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
putchar(x) {
// because Windows
usleep(us) {
__asm__(
"ldarg.0",
"conv.u2",
"call void class [mscorlib]System.Console::Write(char)"
"conv.i4",
"ldc.i4 1000",
"div",
"call void [mscorlib]System.Threading.Thread::Sleep(int32)",
"ldc.i8 0",
"ret"
);
}

char(s,n) {
__asm__(
"ldarg 0",
"ldarg 1",
"add",
"ldind.i1",
"conv.i8",
"ret"
);
}

extrn printf;
__variadic__(printf, 1);
extrn putchar;
extrn getchar;
extrn exit;
Loading