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
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:

publish-nuget:
name: Publish as dotnet tool to NuGet
runs-on: ubuntu-latest
runs-on: windows-latest
needs: publish-release
steps:
- name: Checkout
Expand All @@ -120,10 +120,10 @@ jobs:
with:
dotnet-version: 10.0.x
- name: Build
run: dotnet build ./src/HydraScript/HydraScript.csproj -c Release -v n \
/p:Version=${{ needs.publish-release.outputs.determined_version }} \
run: dotnet build ./src/HydraScript/HydraScript.csproj -c Release -v n `
/p:Version=${{ needs.publish-release.outputs.determined_version }} `
/p:PublishAot=false /p:PublishSingleFile=false
- name: Publish
run: dotnet nuget push ./src/HydraScript/bin/Release/*.nupkg \
--api-key ${{ secrets.NUGET_API_KEY }} \
run: dotnet nuget push ./src/HydraScript/bin/Release/*.nupkg `
--api-key ${{ secrets.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.15.6" />
<PackageVersion Include="BenchmarkDotNet" Version="0.15.8" />
<PackageVersion Include="EnvironmentAbstractions" Version="5.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="10.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0" />
<PackageVersion Include="System.IO.Abstractions" Version="22.0.16" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="10.0.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.1" />
<PackageVersion Include="System.IO.Abstractions" Version="22.1.0" />
<PackageVersion Include="Visitor.NET" Version="4.2.0" />
<PackageVersion Include="Visitor.NET.AutoVisitableGen" Version="1.5.2" />
<PackageVersion Include="ZLinq" Version="1.5.4" />
Expand Down
18 changes: 16 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ type composite = {
}
```

#### Strings

Strings support following operations:
- index access, returns `string`:
```
let str = "str"
>>> str[1] // t
```
- length getter:
```
let str = "str"
>>> ~str // 3
```

### Variables

For declaring mutable variables use `let`:
Expand Down Expand Up @@ -165,8 +179,8 @@ array = array ++ [5, 7] // concatenation
| ! | unary | boolean | boolean |
| - | unary | number | number |
| ++ | binary | [] | [] |
| :: | binary | [] и number | void |
| ~ | unary | [] | number |
| :: | binary | [] and number | void |
| ~ | unary | [] or string | number |

### Conditionals

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace HydraScript.Application.StaticAnalysis;

public interface IHydraScriptTypesService
{
public Type Number { get; }

public Type Boolean { get; }

public Type String { get; }

public Type Undefined { get; }

public Type Void { get; }

public IEnumerable<Type> GetDefaultTypes();

public bool Contains(Type type);

public object? GetDefaultValueForType(Type type);

public bool IsExplicitCastAllowed(Type from, Type to);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface ITypeDeclarationsResolver
public void Store(TypeDeclaration declaration);

public void Resolve();

IHydraScriptTypesService TypesService { get; }
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using HydraScript.Domain.IR.Types;

namespace HydraScript.Application.StaticAnalysis.Impl;

internal class HydraScriptTypesService : IHydraScriptTypesService
{
private readonly HashSet<Type> _types;
private readonly Dictionary<Type, List<Type>> _allowedConversions;

public HydraScriptTypesService()
{
_types =
[
Number,
Boolean,
String,
Null,
Undefined,
Void
];
_allowedConversions = new()
{
[String] = [new Any()],
[Number] = [String, Boolean],
[Boolean] = [String, Number],
};
}

public Type Number => NumberType.Instance;

public Type Boolean => BooleanType.Instance;

public Type String => StringType.Instance;

private Type Null => NullType.Instance;

public Type Undefined => "undefined";

public Type Void => "void";

public IEnumerable<Type> GetDefaultTypes() => _types;

public bool Contains(Type type) => _types.Contains(type);

public object? GetDefaultValueForType(Type type)
{
if (type is NullableType)
return null;
if (type.Equals(Boolean))
return false;
if (type.Equals(Number))
return 0;
if (type.Equals(String))
return string.Empty;
if (type.Equals(Void))
return new object();
if (type.Equals(Null))
return null;
if (type is ArrayType)
return new List<object>();

return new object();
}

public bool IsExplicitCastAllowed(Type from, Type to)
{
var typeEqualityComparer = default(CommutativeTypeEqualityComparer);

if (typeEqualityComparer.Equals(from, to))
return true;

if (!_allowedConversions.TryGetValue(to, out var allowedFrom))
return false;

for (var i = 0; i < allowedFrom.Count; i++)
{
if (typeEqualityComparer.Equals(allowedFrom[i], from))
return true;
}

return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@

namespace HydraScript.Application.StaticAnalysis.Impl;

internal class StandardLibraryProvider : IStandardLibraryProvider
internal class StandardLibraryProvider(IHydraScriptTypesService typesService) : IStandardLibraryProvider
{
private readonly IJavaScriptTypesProvider _provider;

public StandardLibraryProvider(IJavaScriptTypesProvider provider) =>
_provider = provider;

public ISymbolTable GetStandardLibrary()
{
var library = new SymbolTable();

foreach (var type in _provider.GetDefaultTypes())
foreach (var type in typesService.GetDefaultTypes())
library.AddSymbol(new TypeSymbol(type));

var symbolTable = new SymbolTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace HydraScript.Application.StaticAnalysis.Impl;

internal class TypeDeclarationsResolver(
IJavaScriptTypesProvider provider,
IHydraScriptTypesService typesService,
ISymbolTableStorage symbolTables,
IVisitor<TypeValue, Type> typeBuilder) : ITypeDeclarationsResolver
{
Expand All @@ -16,7 +16,7 @@ public void Store(TypeDeclaration declaration) =>

public void Resolve()
{
var defaults = provider.GetDefaultTypes()
var defaults = TypesService.GetDefaultTypes()
.AsValueEnumerable()
.Select(x => new TypeSymbol(x))
.ToList();
Expand All @@ -43,4 +43,6 @@ public void Resolve()
}
}
}

public IHydraScriptTypesService TypesService { get; } = typesService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public static IServiceCollection AddStaticAnalysis(this IServiceCollection servi
services.AddSingleton<ITypeDeclarationsResolver, TypeDeclarationsResolver>();

services.AddSingleton<IStandardLibraryProvider, StandardLibraryProvider>();
services.AddSingleton<IJavaScriptTypesProvider, JavaScriptTypesProvider>();
services.AddSingleton<IDefaultValueForTypeCalculator, DefaultValueForTypeCalculator>();
services.AddSingleton<IExplicitCastValidator, ExplicitCastValidator>();
services.AddSingleton<IHydraScriptTypesService, HydraScriptTypesService>();

services.AddSingleton<IAmbiguousInvocationStorage, AmbiguousInvocationStorage>();

Expand Down
Loading