Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/modules-init-1000' into …
Browse files Browse the repository at this point in the history
…feature/modules-init-1000

# Conflicts:
#	src/ScriptEngine/Libraries/LibraryManager.cs
#	src/ScriptEngine/RuntimeEnvironment.cs
  • Loading branch information
EvilBeaver committed Jan 27, 2025
2 parents 369fb42 + cabdcde commit a52bead
Show file tree
Hide file tree
Showing 43 changed files with 692 additions and 217 deletions.
6 changes: 4 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pipeline {

environment {
VersionPrefix = '2.0.0'
VersionSuffix = 'rc4'+"-${(long)(currentBuild.startTimeInMillis/60000)}"
VersionSuffix = 'rc5'+"-${(long)(currentBuild.startTimeInMillis/60000)}"
outputEnc = '65001'
}

Expand Down Expand Up @@ -62,7 +62,8 @@ pipeline {
bat "chcp $outputEnc > nul\r\n dotnet publish src/OneScriptDocumenter/OneScriptDocumenter.csproj -c Release -o doctool"
bat "chcp $outputEnc > nul\r\n\"${tool 'MSBuild'}\" Build.csproj /t:CleanAll;PrepareDistributionFiles;CreateNuget"

stash includes: 'tests, built/**', name: 'buildResults'
stash includes: 'built/**', name: 'buildResults'
stash includes: 'tests/native-api/bin*/*.dll', name: 'nativeApiTestsDll'
}
}
}
Expand Down Expand Up @@ -132,6 +133,7 @@ pipeline {
deleteDir()
}
unstash 'buildResults'
unstash 'nativeApiTestsDll'
bat "chcp $outputEnc > nul\r\n\"${tool 'MSBuild'}\" Build.csproj /t:Test"

junit 'tests/*.xml'
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ OneScript позволяет создавать и выполнять текст

- установить [homebrew](https://brew.sh/index_ru)
- установить mono командой `brew install mono`
- скачать [ovm](https://github.com/oscript-library/ovm/releases)
- выполнить команду `mono ovm.exe install stable`
- выполнить команду `mono ovm.exe use stable`
- скачать [ovm](https://github.com/oscript-library/ovm/releases). Скачать файл `ovm.exe` (несмотря на расширение .exe он сработает на MacOS)
- выполнить команду `mono path/to/ovm.exe install stable`

*Совет: Чтобы корректно указать путь до `ovm.exe` перенесите мышкой файл `ovm.exe` в терминал. Пример полной команды: `mono Users/username/Downloads/ovm.exe install stable`*
- выполнить команду `mono path/to/ovm.exe use stable`
- перезапустить терминал

#### Донастройка Self-Contained варианта поставки (не требующего инсталляции dotnet)
Expand Down
17 changes: 17 additions & 0 deletions install/builders/base-image/Dockerfile.mono
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:18.04

# MAINTAINER EvilBeaver <[email protected]>

ENV LANG ru_RU.UTF-8

RUN apt update \
&& apt-get -y install locales tzdata \
&& locale-gen ru_RU && locale-gen ru_RU.UTF-8 \
&& update-locale LANG=ru_RU.UTF-8 \
&& apt install -y gnupg ca-certificates \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
&& sh -c 'echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" > /etc/apt/sources.list.d/mono-official-stable.list' \
&& apt-get update \
&& apt-get -y install mono-runtime binutils curl mono-devel ca-certificates-mono mono-vbnc referenceassemblies-pcl mono-fastcgi-server4 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/*
11 changes: 11 additions & 0 deletions install/builders/base-image/Dockerfile_v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM evilbeaver/mono-ru:6.12

# Файл базируется на моно с русской локалью
# Устанавливает через ovm версию движка

LABEL MAINTAINER="EvilBeaver <[email protected]>"

ARG VERSION=stable

RUN curl -L https://github.com/oscript-library/ovm/releases/latest/download/ovm.exe > ovm.exe \
&& mono ovm.exe use --install $VERSION
20 changes: 20 additions & 0 deletions install/builders/base-image/Dockerfile_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM evilbeaver/onescript:1.9.2

# Использует в качестве системы с ovm и mono образ onescript, создаваемый из файла Dockerfile_v1 (лежит рядом в репо)
# Потом копирует бинари из него в образ от Microsoft

LABEL MAINTAINER="EvilBeaver <[email protected]>"

ARG VERSION="dev"

# Установка FDD двойки через ovm, имеющийся в базовом образе
RUN mono ovm.exe install --fdd ${VERSION}

# Основной образ
FROM mcr.microsoft.com/dotnet/aspnet:6.0

ARG VERSION="dev"

RUN mkdir -p /var/oscript
COPY --from=0 /root/.local/share/ovm/${VERSION}/ /var/oscript/
ENV PATH="$PATH:/var/oscript/bin"
5 changes: 5 additions & 0 deletions src/OneScript.Core/Commons/IndexedNameValueCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public int IndexOf(string name)
return index;
}

public string NameOf(int index)
{
return _nameIndex.First(pair => pair.Value == index).Key;
}

public bool TryGetValue(string name, out T result)
{
int idx;
Expand Down
27 changes: 27 additions & 0 deletions src/OneScript.Core/Compilation/Binding/ISymbolTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/

using OneScript.Contexts;

namespace OneScript.Compilation.Binding
{
public interface ISymbolTable
{
SymbolScope GetScope(int index);
IAttachableContext GetBinding(int scopeIndex);
int ScopeCount { get; }
int PushScope(SymbolScope scope, IAttachableContext target);
void PopScope();
bool FindVariable(string name, out SymbolBinding binding);
bool TryFindMethodBinding(string name, out SymbolBinding binding);
bool TryFindMethod(string name, out IMethodSymbol method);
SymbolBinding DefineMethod(IMethodSymbol symbol);
SymbolBinding DefineVariable(IVariableSymbol symbol);
IVariableSymbol GetVariable(SymbolBinding binding);
IMethodSymbol GetMethod(SymbolBinding binding);
}
}
2 changes: 1 addition & 1 deletion src/OneScript.Core/Compilation/Binding/SymbolTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This Source Code Form is subject to the terms of the

namespace OneScript.Compilation.Binding
{
public class SymbolTable
public class SymbolTable : ISymbolTable
{
private class BindingRecord
{
Expand Down
21 changes: 7 additions & 14 deletions src/OneScript.Core/Compilation/CompilerFrontendBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected CompilerFrontendBase(

public SymbolScope FillSymbols(Type targetType)
{
var symbolsProvider = Services.Resolve<CompileTimeSymbolsProvider>();
var symbolsProvider = Services.Resolve<TypeSymbolsProviderFactory>();
var typeSymbols = symbolsProvider.Get(targetType);
ModuleSymbols = new SymbolScope();
typeSymbols.FillSymbols(ModuleSymbols);
Expand Down Expand Up @@ -85,23 +85,16 @@ public IExecutableModule CompileBatch(SourceCode source)
return CompileBatchInternal(symbols, parsedModule);
}

protected abstract IExecutableModule CompileInternal(SymbolTable symbols, ModuleNode parsedModule, Type classType);
protected abstract IExecutableModule CompileInternal(ISymbolTable symbols, ModuleNode parsedModule, Type classType);

protected abstract IExecutableModule CompileExpressionInternal(SymbolTable symbols, ModuleNode parsedModule);
protected abstract IExecutableModule CompileExpressionInternal(ISymbolTable symbols, ModuleNode parsedModule);

protected abstract IExecutableModule CompileBatchInternal(SymbolTable symbols, ModuleNode parsedModule);
protected abstract IExecutableModule CompileBatchInternal(ISymbolTable symbols, ModuleNode parsedModule);

private SymbolTable PrepareSymbols()
private ISymbolTable PrepareSymbols()
{
var actualTable = new SymbolTable();
if (SharedSymbols != default)
{
for (int i = 0; i < SharedSymbols.ScopeCount; i++)
{
actualTable.PushScope(SharedSymbols.GetScope(i), SharedSymbols.GetBinding(i));
}
}

var actualTable = new CompoundSymbolTable(SharedSymbols);

ModuleSymbols ??= new SymbolScope();
actualTable.PushScope(ModuleSymbols, null);

Expand Down
137 changes: 137 additions & 0 deletions src/OneScript.Core/Compilation/CompoundSymbolTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/

using System;
using System.Runtime.CompilerServices;
using OneScript.Compilation.Binding;
using OneScript.Contexts;

namespace OneScript.Compilation
{
public class CompoundSymbolTable : ISymbolTable
{
private readonly ISymbolTable _masterTable;
private readonly SymbolTable _innerTable;

public CompoundSymbolTable(ISymbolTable masterTable)
{
_masterTable = masterTable;
_innerTable = new SymbolTable();
}

private int MasterSize => _masterTable.ScopeCount;

public SymbolScope GetScope(int index)
{
return index < MasterSize ?
_masterTable.GetScope(index) :
_innerTable.GetScope(index - MasterSize);
}

public IAttachableContext GetBinding(int scopeIndex)
{
return scopeIndex < MasterSize ?
_masterTable.GetBinding(scopeIndex) :
_innerTable.GetBinding(scopeIndex - MasterSize);
}

public int ScopeCount => _masterTable.ScopeCount + _innerTable.ScopeCount;

public int PushScope(SymbolScope scope, IAttachableContext target)
{
return _innerTable.PushScope(scope, target) + MasterSize;
}

public void PopScope()
{
if (_innerTable.ScopeCount == 0)
throw new InvalidOperationException("Inner scopes are empty");

_innerTable.PopScope();
}

public bool FindVariable(string name, out SymbolBinding binding)
{
if (_innerTable.FindVariable(name, out binding))
{
ShiftToPublicIndex(ref binding);
return true;
}

return _masterTable.FindVariable(name, out binding);
}

public bool TryFindMethodBinding(string name, out SymbolBinding binding)
{
if (_innerTable.TryFindMethodBinding(name, out binding))
{
ShiftToPublicIndex(ref binding);
return true;
}

return _masterTable.TryFindMethodBinding(name, out binding);
}

public bool TryFindMethod(string name, out IMethodSymbol method)
{
return _innerTable.TryFindMethod(name, out method)
|| _masterTable.TryFindMethod(name, out method);
}

public SymbolBinding DefineMethod(IMethodSymbol symbol)
{
var binding = _innerTable.DefineMethod(symbol);
ShiftToPublicIndex(ref binding);
return binding;
}

public SymbolBinding DefineVariable(IVariableSymbol symbol)
{
var binding = _innerTable.DefineVariable(symbol);
ShiftToPublicIndex(ref binding);
return binding;
}

public IVariableSymbol GetVariable(SymbolBinding binding)
{
if (binding.ScopeNumber < MasterSize)
{
return _masterTable.GetVariable(binding);
}
else
{
UnshiftToInnerIndex(ref binding);
return _innerTable.GetVariable(binding);
}
}

public IMethodSymbol GetMethod(SymbolBinding binding)
{
if (binding.ScopeNumber < MasterSize)
{
return _masterTable.GetMethod(binding);
}
else
{
UnshiftToInnerIndex(ref binding);
return _innerTable.GetMethod(binding);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ShiftToPublicIndex(ref SymbolBinding binding)
{
binding.ScopeNumber += MasterSize;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void UnshiftToInnerIndex(ref SymbolBinding binding)
{
binding.ScopeNumber -= MasterSize;
}
}
}
2 changes: 1 addition & 1 deletion src/OneScript.Core/Compilation/ICompilerBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ICompilerBackend

bool GenerateCodeStat { get; set; }

public SymbolTable Symbols { get; set; }
public ISymbolTable Symbols { get; set; }

IExecutableModule Compile(ModuleNode parsedModule, Type classType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ This Source Code Form is subject to the terms of the

namespace OneScript.Compilation
{
public interface IModuleSymbolsProvider
/// <summary>
/// Провайдер дополнительных внешних символов для класса при компиляции.
/// </summary>
public interface ITypeSymbolsProvider
{
void FillSymbols(SymbolScope moduleScope);
}
Expand Down
Loading

0 comments on commit a52bead

Please sign in to comment.