Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
240 commits
Select commit Hold shift + click to select a range
081d318
Remove code specific to guessing game
binyamin555 Jan 1, 2025
373cd2b
Remove older overloading support
binyamin555 Jan 2, 2025
eeadaff
Add base compiler exception
binyamin555 Jan 2, 2025
9e70c76
Add compiler cast exception
binyamin555 Jan 2, 2025
7c3ac89
Simplify Compiler.TypeSystem.Int32 construction
binyamin555 Jan 2, 2025
c52b6af
Add dynamically computed types support for CO
binyamin555 Jan 2, 2025
5695b5d
Add on-demand IR compilation for Local
binyamin555 Jan 2, 2025
483275c
Remove support for `null` in function name
binyamin555 Jan 2, 2025
b90635e
Add PartiallyCompiledObjectException
binyamin555 Jan 2, 2025
6c6af86
Add ZSharp.Compiler.Objects project
binyamin555 Jan 2, 2025
ad1de16
Add ArgumentMismatchException
binyamin555 Jan 2, 2025
60b6d74
Add error messages class
binyamin555 Jan 2, 2025
b1d3381
Add simple overloading group object & support
binyamin555 Jan 2, 2025
2966998
Add object build state helper class
binyamin555 Jan 2, 2025
ba8d4d7
Move RTFunction from ZSharp.Compiler to ZSharp.Compiler.Objects
binyamin555 Jan 2, 2025
738338b
Add support for loading overloads from IR to CO
binyamin555 Jan 2, 2025
72675d3
Add automatic operator overload groups creation
binyamin555 Jan 2, 2025
526c692
Add + operator overload for i32 and i32
binyamin555 Jan 2, 2025
d175d42
Remove the increment function
binyamin555 Jan 2, 2025
d23039f
Move Parameter and Signature to sig/
binyamin555 Jan 9, 2025
30fac0c
Add tokens to module node
binyamin555 Jan 9, 2025
71114b6
Add tokens to constructor node
binyamin555 Jan 9, 2025
35a78b8
Add tokens to oop definition node
binyamin555 Jan 9, 2025
77a5698
Add tokens to class parser
binyamin555 Jan 9, 2025
2a95eca
Move if statement node to flow/
binyamin555 Jan 9, 2025
9168d6d
Add tokens to parameter node
binyamin555 Jan 9, 2025
a187408
Remove unused class
binyamin555 Jan 9, 2025
2a7e767
Remove unused class
binyamin555 Jan 11, 2025
8308b3d
Remove unused usings
binyamin555 Jan 11, 2025
c027591
Make while node generic
binyamin555 Jan 11, 2025
d7e7887
Make while node parser generic
binyamin555 Jan 11, 2025
62bd5a8
Cast local initializer to local type
binyamin555 Jan 11, 2025
63f2b9b
Remove casts from WhileLoop object
binyamin555 Jan 11, 2025
c691c32
Move while compiler to core compilers
binyamin555 Jan 11, 2025
cab07e5
Add while expression test file
binyamin555 Jan 11, 2025
52ea099
Fix main to use generic while parser
binyamin555 Jan 11, 2025
901e8a7
Update main test project file
binyamin555 Jan 11, 2025
83c8be6
Add support for compiling if statements
binyamin555 Jan 11, 2025
c95f7f7
Add if statement to parser
binyamin555 Jan 11, 2025
37fd91b
Add if-statement test file
binyamin555 Jan 11, 2025
1137510
Update guessing-game to use if statements
binyamin555 Jan 11, 2025
f9eb86f
Update launchSettings.json
binyamin555 Jan 11, 2025
bcf8269
Add basic support for generic classes in IR
binyamin555 Feb 1, 2025
6b29c53
Remove unused classes in IR
binyamin555 Feb 1, 2025
ae5b522
Fix type support in IR <-> IL due to changes in IR type system
binyamin555 Feb 1, 2025
fcd1dc1
Make the class CO more generic
binyamin555 Feb 1, 2025
bf3d0dc
Remove problematic code
binyamin555 Feb 1, 2025
86c0c40
Update core compiler types to use newer IR type system
binyamin555 Feb 1, 2025
5b74258
Allow constructors to be called for base initialization as well
binyamin555 Feb 1, 2025
b305f73
Merge pull request #12 from zsharp-lang/dev/fix-ir-type-system
binyamin555 Feb 1, 2025
c96ceb2
Add todo project test file
binyamin555 Feb 2, 2025
86d4f5c
Organize test projects
binyamin555 Feb 2, 2025
da6502e
Add array literal and organize literal AST nodes files
binyamin555 Feb 2, 2025
a25240a
Add index expression AST node
binyamin555 Feb 2, 2025
5781e1a
Add `for` statement AST node
binyamin555 Feb 2, 2025
2eedbdb
Add array literal parser function
binyamin555 Feb 2, 2025
3e513e3
Add index expression parser function
binyamin555 Feb 2, 2025
98ccfea
Add `for` statement parser (and `in` keyword)
binyamin555 Feb 2, 2025
c467cd7
Add index and array literal parsers to test parser
binyamin555 Feb 2, 2025
60d775f
Add `for` statement parser to test parser
binyamin555 Feb 2, 2025
be831f7
Add `case` statement parser to test parser
binyamin555 Feb 2, 2025
7fc28a6
Remove empty folder
binyamin555 Feb 27, 2025
739f528
Update constructor node to be an expression
binyamin555 Feb 27, 2025
f248480
Add IR module initializer
binyamin555 Feb 27, 2025
8d95eb0
Make IR constructor an IR object
binyamin555 Feb 27, 2025
51ffa71
Fix constructor parser to wrap it in statement
binyamin555 Feb 27, 2025
d113b4b
Remove unused classes
binyamin555 Feb 27, 2025
85c6ad1
Use evaluate when compiling callee in call expression
binyamin555 Feb 27, 2025
ce8df5a
Add `case` CO
binyamin555 Feb 27, 2025
e163aea
Add support for compiling case statements
binyamin555 Feb 27, 2025
d7e3fc1
Add lots of objects
binyamin555 Feb 27, 2025
f8b3e08
Add object type
binyamin555 Feb 27, 2025
a810021
Fix IR loader to support the newer IR type system
binyamin555 Feb 27, 2025
4e118c3
Add generic CompileIRType method
binyamin555 Feb 27, 2025
45493b9
Add generic CompileIRType protocol
binyamin555 Feb 27, 2025
24e2bad
Add == operator for `string` and `bool`
binyamin555 Feb 27, 2025
ae76801
Add support for `var` fields in class
binyamin555 Feb 27, 2025
09c407b
Fix things in the runtime
binyamin555 Feb 27, 2025
3721459
Add more things to the source compilers
binyamin555 Feb 27, 2025
c8bbd0e
Add support for parsing array literals
binyamin555 Feb 27, 2025
a98911d
Add default metaclass
binyamin555 Feb 27, 2025
dfec2fe
Update guessing-game.zs to use new feaures
binyamin555 Feb 27, 2025
0403ae0
Add more test projects
binyamin555 Feb 27, 2025
372a4bf
Add/fix support for object initalization delegation
binyamin555 Mar 2, 2025
0a1aff6
Update class test file
binyamin555 Mar 2, 2025
faf0e42
Add support for binding overload group to instance on member access
binyamin555 Mar 16, 2025
29e9ad0
Update test-class-fields.zs to use support for binding
binyamin555 Mar 16, 2025
0e27d61
Update simple-user-system.zs to mark added features
binyamin555 Mar 16, 2025
23eadad
Fix generic class instance to support rt member access
binyamin555 Mar 22, 2025
5abcdf5
Add equality operator
binyamin555 Mar 22, 2025
c2fe0f2
Add string inequality operator
binyamin555 Mar 22, 2025
b8d63ef
Add UnexpectedTokenError exception class
binyamin555 Mar 22, 2025
2b7f1fc
Fix IR -> IL module loader to load types first
binyamin555 Mar 22, 2025
b1603ef
Fix method parser to use new parser scoping system
binyamin555 Mar 22, 2025
c543655
Add support for method overload binding in constructor
binyamin555 Mar 22, 2025
714a562
Fix simple-user-system.zs test file
binyamin555 Mar 22, 2025
7908873
Update README.md
binyamin555 Mar 22, 2025
bd97c8d
Update simple-user-system.zs
binyamin555 Mar 22, 2025
e8b42e6
Move IR function body to functional/
binyamin555 Apr 6, 2025
9dc37ca
Add base type reference interface
binyamin555 Apr 6, 2025
71c55f5
Add base member reference interface
binyamin555 Apr 6, 2025
be5c2c4
Add method reference class
binyamin555 Apr 6, 2025
d56fc5f
Add generic method instance class
binyamin555 Apr 6, 2025
4aea0f7
Add field reference class
binyamin555 Apr 6, 2025
d842fcf
Fix IR type definitions to use the new type reference interface
binyamin555 Apr 6, 2025
e1269bd
Fix call virtual to use method reference
binyamin555 Apr 6, 2025
feff541
Fix create instance to use constructor reference
binyamin555 Apr 6, 2025
d4db1b2
Fix field accessors to use field reference
binyamin555 Apr 6, 2025
c438661
Save progress
binyamin555 Apr 21, 2025
650dbf4
Add support for generic functions
binyamin555 Apr 22, 2025
1c0e606
Remove unused assignment
binyamin555 Apr 22, 2025
3e3c6e4
Fix overload group map
binyamin555 Apr 22, 2025
7742581
Modify index protocol to return null instead of error
binyamin555 Apr 22, 2025
d5aaae3
Remove IR.MemberReference
binyamin555 Apr 22, 2025
f3d62a4
Fix IL global function loader
binyamin555 Apr 22, 2025
544bd67
Add support for generic methods
binyamin555 Apr 22, 2025
d8f855d
Add parenthesized expression support
binyamin555 Apr 22, 2025
58b3a22
Add generic Id function
binyamin555 Apr 22, 2025
4bb02b3
Update main test file
binyamin555 Apr 22, 2025
a1dd2c4
Patch fix for accessing member while type not built
binyamin555 Apr 22, 2025
8b97400
Update simple-user-system.zs
binyamin555 Apr 22, 2025
3e37974
Add support for array literal initialization
binyamin555 Apr 22, 2025
2c4f68d
Add methods to exposed IL list
binyamin555 Apr 22, 2025
0a636db
Fix member access from generic class instance
binyamin555 Apr 22, 2025
d0da104
Fix global to cast initializer to type
binyamin555 Apr 22, 2025
f7b77b7
Fix todo.zs to work with lists
binyamin555 Apr 22, 2025
7419b7c
Move list type to an "external" dll
binyamin555 Apr 22, 2025
e16f81e
Rename Member to Constructor in ConstructorReference
binyamin555 Apr 23, 2025
34cb7cb
Fix code resolving IR references to IL
binyamin555 Apr 23, 2025
69baac8
Edit comment
binyamin555 Apr 23, 2025
0a097a4
Add todo comment
binyamin555 Apr 23, 2025
bd04e45
Split generic class loading from regular class loading
binyamin555 Apr 23, 2025
d0edb0b
Fix function loading
binyamin555 Apr 23, 2025
6296003
Organize some COs
binyamin555 Apr 23, 2025
f5ad8a2
Add compiler Result type
binyamin555 Apr 23, 2025
c3c3daa
Add type aliases
binyamin555 Apr 23, 2025
077fe5a
Add implicit cast protocol for assignments
binyamin555 Apr 23, 2025
888037a
Implement interface reference IR
binyamin555 Apr 23, 2025
edf2517
Add support for IR <-> IL interfaces
binyamin555 Apr 23, 2025
adcc6aa
Add support for loading interfaces into CO
binyamin555 Apr 23, 2025
e482562
Use implicit cast instead of cast
binyamin555 Apr 23, 2025
a7078d6
Fix class compiler to create class instead of generic class
binyamin555 Apr 23, 2025
196e90f
Update test case (simple.zs)
binyamin555 Apr 23, 2025
6aad731
Fix referencing system
binyamin555 Apr 25, 2025
e4b892b
Add constructor from Dictionary to Mapping
binyamin555 Apr 25, 2025
4fcea68
Fix IR -> CO loader
binyamin555 Apr 25, 2025
9f9c47f
Add IType compiler protocol
binyamin555 Apr 25, 2025
5f58f97
Add type disassembler
binyamin555 Apr 25, 2025
e8772db
Update simple.zs test file
binyamin555 Apr 25, 2025
3f95422
Add support for custom implementors
binyamin555 Apr 25, 2025
b2f54a4
Fix many things
binyamin555 May 10, 2025
2f98441
Update README.md
binyamin555 May 10, 2025
2cc48a7
Add for loops
binyamin555 May 13, 2025
2605e3b
Fix method inside generic type resolution
binyamin555 May 13, 2025
27d2796
Add simply file system module
binyamin555 May 13, 2025
b71381d
Add support for \t in string and char literals
binyamin555 May 17, 2025
90590c8
Patch document compiler to not handle statements
binyamin555 May 17, 2025
4fafb0c
Add support for loading operator from any IR module
binyamin555 May 26, 2025
4a2117e
Add / operator for path / directory
binyamin555 May 26, 2025
ab167d1
Update method IR to wrap function
binyamin555 May 28, 2025
f235def
Use alias
binyamin555 May 28, 2025
7092a97
Add support for `is of` operator
binyamin555 May 29, 2025
7c32fd5
Add support for overriding values in Cache
binyamin555 May 29, 2025
4aa6cd8
Add very basic type inference support
binyamin555 May 29, 2025
863c4d0
Fix IsOfExpression node
binyamin555 May 29, 2025
da7b167
Remove old inference system
binyamin555 May 29, 2025
2731b22
Add prototype-grade `as` operator support
binyamin555 May 29, 2025
712a905
Remove OnCast handler from TypeCast
binyamin555 Jun 2, 2025
2c40ca4
Make ImportedName a node
binyamin555 Jun 8, 2025
4d61822
Fix IR loader to defer loading base type
binyamin555 Jun 8, 2025
92472f8
Fix source compiler
binyamin555 Jun 8, 2025
7c83c43
Resultify the core compiler code base
binyamin555 Jun 8, 2025
ee6d431
Add missing file to source compiler
binyamin555 Jun 8, 2025
ecbf68d
Organize the IR -> IL loader
binyamin555 Jun 8, 2025
886ccdf
Add more things
binyamin555 Jun 8, 2025
8de1107
Fix compiler crashing when document-level code returns void
binyamin555 Jun 8, 2025
4235bb7
Organize code base
binyamin555 Jun 11, 2025
512e0c8
Add new runtime
binyamin555 Jul 18, 2025
a8b52cb
Update IR
binyamin555 Jul 18, 2025
73260d7
Add stuff
binyamin555 Jul 18, 2025
07cd0ad
Add more stuff
binyamin555 Jul 18, 2025
08d0bc7
Add more loaders to runtime
binyamin555 Jul 18, 2025
f34f2e2
Remove .T template files
binyamin555 Jul 18, 2025
9f03255
Add type loader helpers
binyamin555 Jul 18, 2025
5af1e19
Add IR compiler project
binyamin555 Jul 20, 2025
209417c
Make IR compiler non-static
binyamin555 Jul 21, 2025
2d925aa
Add Compile prefix to methods
binyamin555 Jul 21, 2025
f9cce50
Add CompileCode method
binyamin555 Jul 21, 2025
29dca0a
Add CompileType methods
binyamin555 Jul 21, 2025
965a93d
Fix things
binyamin555 Jul 26, 2025
aa661ba
Add ILLoader custom attributes
binyamin555 Jul 30, 2025
38839eb
Add ILLoader stuff
binyamin555 Jul 30, 2025
19902c2
Fix the standard filesystem library
binyamin555 Jul 30, 2025
74c0f9c
Fix interpreter and runtime
binyamin555 Jul 30, 2025
a533b34
Fix dotnet importer
binyamin555 Jul 30, 2025
37b9cb5
Add project compiler
binyamin555 Jul 30, 2025
b894d7b
Add question mark
binyamin555 Jul 30, 2025
4bffa73
I'm tired
binyamin555 Jul 30, 2025
9b355a4
Remove IR submodules
binyamin555 Jul 31, 2025
6b847d3
Implement project discovery
binyamin555 Jul 31, 2025
6a19193
Add ZSC.Project
binyamin555 Jul 31, 2025
cf70f01
Make SubModuleDiscovery class static
binyamin555 Aug 11, 2025
24cf088
Rename IRObject to IRDefinition
binyamin555 Aug 11, 2025
bf1b0e9
Make `Module` inherit `IRDefinition`
binyamin555 Aug 12, 2025
9c88aa0
Rename variable
binyamin555 Aug 12, 2025
0bdaaea
Change many many many things
binyamin555 Sep 11, 2025
4a1ebee
Merge branch 'dev/v1' into dev/add-more-nodes
binyamin555 Sep 11, 2025
ff25647
Merge pull request #14 from zsharp-lang/dev/add-more-nodes
binyamin555 Sep 11, 2025
efee1e4
Revise README with updated Discord link
binyamin555 Sep 11, 2025
dcb9379
Delete .vscode/settings.json
binyamin555 Sep 11, 2025
5e4c5d7
Remove old runtime adapter code
binyamin555 Sep 11, 2025
9d52bdd
Create test.zs using my phone
binyamin555 Sep 12, 2025
65de05f
See https://tenor.com/view/order-star-wars-mas-amedda-galactic-republ…
binyamin555 Sep 14, 2025
5307cdd
Add test.zs in ZSharp.CLI
binyamin555 Sep 14, 2025
8ca456a
Merge branch 'dev/v1' of https://github.com/zsharp-lang/zsv1 into dev/v1
binyamin555 Sep 14, 2025
3d00b13
Add IR system and organize some stuff
binyamin555 Sep 14, 2025
c5cf918
Upgrade to .NET 9
binyamin555 Sep 14, 2025
ffebfc4
This should do it
binyamin555 Sep 14, 2025
cf8ca4f
Rename IR classes to better reflect their purposes
binyamin555 Oct 8, 2025
383d529
Remove support for debugging
binyamin555 Oct 9, 2025
e7d5a55
Add stuff
binyamin555 Oct 9, 2025
7ad4de8
Add features "playground"
binyamin555 Oct 9, 2025
7e46d6e
Fix delegate exposer
binyamin555 Oct 11, 2025
425e182
Update the discord invite link because I accidentally deleted the exi…
binyamin555 Oct 15, 2025
7dfaa00
Fix naming/typos
binyamin555 Oct 15, 2025
bb7157c
Add evaluation system to compiler
binyamin555 Oct 15, 2025
bf62dd3
Add support for forwarded types in IL modules exposed to Z#
binyamin555 Oct 15, 2025
3199996
Add core module
binyamin555 Oct 15, 2025
75b05bb
Make error messages more clear when object does not support member ac…
binyamin555 Oct 15, 2025
0868e37
Update test file
binyamin555 Oct 15, 2025
ab64fc8
Fix not returning error result
binyamin555 Oct 15, 2025
99b6125
Remove BALSHOY comment
binyamin555 Oct 15, 2025
d0aad8b
Merge pull request #16 from zsharp-lang/dev/stuff
binyamin555 Oct 15, 2025
002b2a7
Add basic support for type checking and implicit casting
binyamin555 Oct 17, 2025
2531ccc
Fix proxy to always expect return type of Result
binyamin555 Oct 17, 2025
baa3f24
Fix annoying warning
binyamin555 Oct 17, 2025
2f8dbba
Make ILLoader even better
binyamin555 Oct 18, 2025
4f5e324
Update test file
binyamin555 Oct 18, 2025
ffe60c5
Make string and object wrappers use the proper semantic type
binyamin555 Oct 18, 2025
5355c0d
Add support for construcings instances from IL types
binyamin555 Oct 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,4 @@ FodyWeavers.xsd
*.sln.iml

.lh/
/ZSharpTest/test.zs
12 changes: 0 additions & 12 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion CommonZ/CommonZ.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
32 changes: 32 additions & 0 deletions CommonZ/IResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public interface IResult<out TResult, out TError>
where TResult : class?
where TError : class
{
public bool IsOk { get; }

public bool IsError { get; }

public TResult Unwrap();

public TError UnwrapError();

public IResult<TResult, TError> When(Action<TResult> action)
{
if (this.Ok(out var result))
action(result);

return this;
}

public IResult<R, TError> When<R>(Func<TResult, R> map) where R : class;

public IResult<TResult, TError> Else(Action<TError> action)
{
if (this.Error(out var error))
action(error);

return this;
}

public IResult<TResult, E> Else<E>(Func<TError, E> map) where E : class;
}
47 changes: 47 additions & 0 deletions CommonZ/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Diagnostics.CodeAnalysis;

namespace CommonZ
{
public sealed class Result<TResult, TError>
: IResult<TResult, TError>
where TResult : class?
where TError : class
{
private readonly TResult? result;
private readonly TError? error;

[MemberNotNullWhen(true, nameof(result))]
public bool IsOk => result is not null;

[MemberNotNullWhen(true, nameof(error))]
public bool IsError => error is not null;

private Result(TResult? result, TError? error)
{
this.result = result;
this.error = error;
}

public static Result<TResult, TError> Ok(TResult result)
=> new(result, null);

public static Result<TResult, TError> Error(TError error)
=> new(null, error);

TResult IResult<TResult, TError>.Unwrap()
=> result ?? throw new InvalidOperationException(error!.ToString());

TError IResult<TResult, TError>.UnwrapError()
=> error ?? throw new InvalidOperationException("Result is Ok");

IResult<R, TError> IResult<TResult, TError>.When<R>(Func<TResult, R> map)
=> IsOk
? Result<R, TError>.Ok(map(result))
: Result<R, TError>.Error(error!);

IResult<TResult, E> IResult<TResult, TError>.Else<E>(Func<TError, E> map)
=> IsOk
? Result<TResult, E>.Ok(result)
: Result<TResult, E>.Error(map(error!));
}
}
7 changes: 5 additions & 2 deletions CommonZ/collections/CacheBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ public abstract class CacheBase<Key, Value>

public Cache<Key, Value>? Parent { get; set; }

public T Cache<T>(Key key, T value)
public T Cache<T>(Key key, T value, bool set = false)
where T : Value
{
_cache.Add(key, value);
if (set)
_cache[key] = value;
else
_cache.Add(key, value);
return value;
}

Expand Down
6 changes: 6 additions & 0 deletions CommonZ/collections/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
public class Mapping<Key, Value> : Dictionary<Key, Value>
where Key : notnull
{
public Mapping() : base() { }

public Mapping(IDictionary<Key, Value> dictionary) : base(dictionary) { }

public Mapping(IEnumerable<KeyValuePair<Key, Value>> items) : base(items) { }

public virtual void OnAdd(Key key, Value value) { }

public virtual void OnRemove(Key key) { }
Expand Down
70 changes: 70 additions & 0 deletions CommonZ/extensions/IResultExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using CommonZ;
using System.Diagnostics.CodeAnalysis;
using static System.Runtime.InteropServices.JavaScript.JSType;

public static class IResultExtensions
{
public static bool Ok<TResult, TError>(
this IResult<TResult, TError> result,
[NotNullWhen(true)] out TResult? output
)
where TResult : class?
where TError : class
=> (output = result.IsOk ? result.Unwrap() : null) is not null;

public static bool Error<TResult, TError>(
this IResult<TResult, TError> result,
[NotNullWhen(true)] out TError? error
)
where TResult : class?
where TError : class
=> (error = result.IsError ? result.UnwrapError() : null) is not null;

public static IResult<TResult, TError> When<TResult, TError>(
this IResult<TResult, TError> result,
out TResult? output
)
where TResult : class?
where TError : class
{
output = result.IsOk ? result.Unwrap() : null;
return result;
}

public static IResult<TResult, TError> Else<TResult, TError>(
this IResult<TResult, TError> result,
out TError? error
)
where TResult : class?
where TError : class
{
error = result.IsError ? result.UnwrapError() : null;
return result;
}

public static IResult<R, TError> When<TResult, TError, R>(
this IResult<TResult, TError> result,
Func<TResult, IResult<R, TError>> map
)
where TResult : class?
where TError : class
where R : class
{
if (result.IsError) return result.When(_ => (null as R)!);

return map(result.Unwrap()).Else(e => e);
}

//public static IResult<TResult, TError> Else<TResult, TError>(
// this IResult<TResult, TError> result,
// Action<TError> action
//)
// where TResult : class?
// where TError : class
//{
// if (result.IsError)
// action(result.UnwrapError());

// return result;
//}
}
28 changes: 28 additions & 0 deletions Examples/test.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { print } from "std:io";
import { Void, Test } from "std:types";

print("[CT] Hello, World!");

import { Directory } from "std:fs";

import { CompilerObject } from "core:compiler";

module A {
print("[CT] Inside module A");

fun main(): Void {
print(Directory.cwd().toString());
print(Test(Directory.cwd().toString()));

print("[RT] Hello, World!");
return;
}
}

if (false) {
print("[CT] Condition is true");
} else {
print("[CT] Condition is false");
}

A.main();
75 changes: 7 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,15 @@
# Z# Language


Welcome to the Z# language repository! This repository holds the first released version of Z#.

Z# is a typesafe, interpreterd language. It is still very much a WIP so don't expect it to work smoothly.

The current state of the project is:
* [x] Tokenizer
* [x] Parser
* [x] Resolver
* [x] Compiler
* [x] IR Layer
* [x] ZSRuntime
* [ ] Platform Compiler

## Structure

The whole compiler is separated to multiple modules, each with a different purpose.
> This README file is out-of-date. I will update this once I have enough time and an acceptable working version.
> If you have any questions regarding this project, you can join the discord server ~~[discord server](https://discord.gg/Uc3GN2bfG9)~~ [discord channel on PLTD](https://discord.gg/jkCSRvpyYA).

To understand the architecture of the compiler, one needs to understand the architecture of the language.

The language is interpreted and it allows using statements in top-level scopes (e.g. document, module, etc..).
Also, it is typesafe. The compiler creates an IR of the code and the interpreter holds a runtime representation of the IR.

The IR defines a static structure, while the runtime objects can vary during execution.

## Running

Simply run the main project (ZSharpTest).

You can edit the [`test.zs`](ZSharpTest/test.zs) file.
Welcome to the Z# language repository! This repository holds the first released version of Z#.

## ToDo
Z# is a typesafe, interpreterd language. It is still very much a WIP so don't expect it to work smoothly.

* [ ] Add support for type-inference
- [x] Local inference
- [ ] Function return type
* [ ] Implement the overloading protocol (C#)
* [ ] Implement the `compile` protocol (both `IRObject` and `IR Type`) (C#, Z#)
* [ ] Implement better Z# RT VM API (C#)
- [x] Function calls
- [ ] Object construction, instantiation and initialization
- [x] IR loading
* [x] Organize IR loading in Z# RT VM (C#)
* [ ] Implement document-level definitions
- [ ] Functions
- [ ] Globals
* [ ] Implement OOP types
- [ ] Class
- [ ] Interface
- [ ] Typeclass
- [ ] Structure
* [ ] Add support for decorators
* [ ] Add support for custom attributes
* [ ] Implement the CG `Execute`/`Evaluate` command.
* [ ] Implement the `import(string)` CG function (C#)
- [ ] Add support for extensible `StringImporter`
* [ ] Add support for definition templates
- [ ] Functions
- [ ] Classes (which includes methods, properties, fields, etc..)
* [x] Fix module references lookup code (consider the fact that IR have 2 sources: `Read` and `EvaluateType`).
- > The way this works is by analyzing each function code right after the body is compiled.
* [ ] ZSharp.Compiler project
- [ ] IR Generator
- [ ] Generators
- [ ] Document
- [ ] Function Body
- [ ] Module
- [ ] OOP Types
- [ ] Method Body
This repository is undergoing massive rewrites and the architecture is still under development.
Due to that, contributions are currently not accepted.

## ToDo (High Level)
* [ ] C# Interop with Z# (C# Reflection -> IR)
* [ ] Add more language features
* [ ] Fully implement the IR -> CG loader
However, suggestions about everything (syntax, concepts, architecture, etc..) are always welcome.
45 changes: 45 additions & 0 deletions Testing/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using ZSharp.Importer.ILLoader;
using Objects = ZSharp.Importer.ILLoader.Objects;

var rtm = ZSharp.IR.RuntimeModule.Standard;
var coc = new ZSharp.Compiler.Compiler(rtm);
var rt = new ZSharp.Platform.Runtime.Runtime(new()
{
Array = rtm.TypeSystem.Array,
Boolean = rtm.TypeSystem.Boolean,
Char = null!,
Float16 = null!,
Float32 = rtm.TypeSystem.Float32,
Float64 = null!,
Float128 = null!,
Object = rtm.TypeSystem.Object,
Pointer = rtm.TypeSystem.Pointer,
Reference = rtm.TypeSystem.Reference,
SInt8 = null!,
SInt16 = null!,
SInt32 = rtm.TypeSystem.Int32,
SInt64 = null!,
SIntNative = null!,
String = rtm.TypeSystem.String,
UInt8 = null!,
UInt16 = null!,
UInt32 = null!,
UInt64 = null!,
UIntNative = null!,
Void = rtm.TypeSystem.Void
});

var ilLoader = new ILLoader(coc, rt);

coc.TS.SInt32 = ilLoader.TypeSystem.SInt32;

var code = rt.Expose("Hello, Exposed String!");
var exposed = rt.Evaluate(code, rtm.TypeSystem.Object);
System.Console.WriteLine(exposed);

var typedCode = ilLoader.ExposeAsIR(12);
var typedExposed = rt.Evaluate(typedCode, rtm.TypeSystem.Int32);
System.Console.WriteLine(typedExposed);


System.Console.WriteLine(string.Empty);
14 changes: 14 additions & 0 deletions Testing/Testing.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ZSharp.Importer.ILLoader\ZSharp.Importer.ILLoader.csproj" />
</ItemGroup>

</Project>
Loading