TinyFS.Core
0.0.2
dotnet add package TinyFS.Core --version 0.0.2
NuGet\Install-Package TinyFS.Core -Version 0.0.2
<PackageReference Include="TinyFS.Core" Version="0.0.2" />
<PackageVersion Include="TinyFS.Core" Version="0.0.2" />
<PackageReference Include="TinyFS.Core" />
paket add TinyFS.Core --version 0.0.2
#r "nuget: TinyFS.Core, 0.0.2"
#:package TinyFS.Core@0.0.2
#addin nuget:?package=TinyFS.Core&version=0.0.2
#tool nuget:?package=TinyFS.Core&version=0.0.2
TinyFS
Taking inspiration from the tinygo project.
F# for WebAssembly.
TinyFS is a F# to Wasm Compiler.
Leveraging the FSharp.Compiler.Service nuget package to generate an Abstract Syntax Tree (AST). Then walking the AST to generate Wasm bytes.
Current feature status:
- Support for
int32,int64,float32,float64andboolprimitives - The basic mathematical operators (
+,-,*,/,%) are supported%- modulo not supported by floating point primitives
- The basic boolean operators (
=,<>,>,>=,<,<=) are supported - Local parameters are supported, as well as mutable parameters.
if/elseexpression is supported- No
elifyet
- No
while...do
Installing as Nuget Tool
The fastest way to get started is to install via nuget tool.
- Install a flavor of .NET 9 from microsoft
- Run the following command:
dotnet tool install --global TinyFS.Cli- To update if already installed:
dotnet tool update -g TinyFS.Cli
- To update if already installed:
- You now have access to the
tinyfscli tool
Usage
How to compile and use.
- Write a valid .fs program containing the supported fs syntax listed above/below
- See examples to get started
- Currently every *.fs file requires main function with a single unit parameter to exist
- All code must be in a single .fs file, TinyFS does not currently support importing across files.
- Run
tinyfs compile <.fs file>to generate a wasm file - Run
tinyfs run <.wasm file>to run the generated wasm- Can also run in any other wasm compliant runtime.
- This leverages the wasmtime nuget package.
- You can also use
tinyfs compile -r <.fs file>to compile and run in one command.
Alpha Notice
⚠️⚠️⚠️⚠️⚠️⚠️
This is still alpha software, bugs are to be expected. The more complex the code, the more likely it will break.
By day I mainly program in C#, so I won't claim this library is optimized or error free. I mainly undertook this as a learning opportunity. There are currently no longer term plans for what this project will look like moving forward.
Feel free to raise an issue if you see something could be improved.
Supported Syntax
The easier a language construct is able to be mapped into WebAssembly the more likely it is to be implemented. I don't currently have any long term plans on what I'm planning on doing with this project.
Below lists the following language features that are supported.
Please see the examples folder for examples of compileable F# syntax that is ready to be used.
Basic Types
https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/basic-types
-
bool- by converting to WebAssembly'si32 -
byte -
sbyte- by up converting to WebAssembly'si32 -
int16- by up converting to WebAssembly'si32 -
uint16 -
int/int32 -
uint/uint32 -
long/int64 -
ulong/uint64 -
nativeint- probably never -
unativeint- probably never -
decimal -
float32/single(32 bit) -
float/double(64 bit) -
char -
string -
unit
- WebAssembly provides builtin support for
int32,int64,float32andfloat64. Everything else comes extra.
Language Constructs
-
letbindings -
if...then...else -
while...do loops -
for...to loops -
match expression - arrays
- exception handling
- generics
- collections
- types
- tuples, options, results
- records and untions
- structs
- object oriented programming (class, interfaces, etc)
- reflection - probably never
- computation expressions
- async/task expressions
Operators
https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/
Arithmetic Operators
-
+ -
- -
* -
/ -
% -
**
For currently supported primitive types
Comparison Operators
-
= -
<> -
< -
<= -
> -
>=
For currently supported primitive types
Boolean Operators
-
&& -
||
For currently supported primitive types
Bitwise Operators
-
&&& -
||| -
<<< -
>>> -
^^^ -
~~~
Function Symbols and Operators
-
-> -
|> -
||> -
|||> -
>> -
<< -
<| -
<|| -
<|||
Other Features
- Importing code across files
- Building an entire *.fsproj file
- Using standard library
How Is This Working
I'm using the FSharp.Compiler.Service nuget package to generate a usable Abstract Syntax Tree (AST) given F# code.
Then using what I learned in WebAssembly from the Ground Up for converting the F# AST to Wasm.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- FSharp.Compiler.Service (>= 43.9.201)
- FSharp.Core (>= 9.0.201)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.