Skip to content

Commit

Permalink
ezrSquared prerelease-1.0.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Dec 29, 2022
1 parent 275207d commit e586717
Show file tree
Hide file tree
Showing 7 changed files with 1,278 additions and 488 deletions.
812 changes: 424 additions & 388 deletions Classes/Values.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public static class constants
{
public const string VERSION = "beta-1.3.0.0.1";
public const string VERSION_DATE = "28.12.2022";
public const string VERSION = "prerelease-1.0.0.0.0";
public const string VERSION_DATE = "29.12.2022";

public const string LETTERS_UNDERSCORE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
public const string ALPHANUM_UNDERSCORE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
Expand Down
792 changes: 792 additions & 0 deletions Libraries/IO.cs

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions Libraries/Test.cs

This file was deleted.

20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ And the differences:
### Released
**Check the [GitHub Commits](https://github.com/Uralstech/ezrSquared/commits) for all changes in source code**

* **prerelease-1.0.0.0.0** - [29-12-22]
* Removed CSAEL support - because I believe CSAELs are unnecessary (check the release notes to know more)
* Added (UNTESTED) builtin IO libraries (`file`, `folder` and `path`)
* Added `try_as_integer` and `try_as_float` functions to `strings` and `character_lists`
* A TON of 'polishing' - take that as you will, check the commits
* Removed `test` CSAEL

* **beta-1.3.0.0.1** - [28-12-22]
* Made CSAELs (`CSharp Assisted Ezr² Libraries`) much better - check the `test` CSAEL included in ezr²
* Some other improvements which I'm too lazy to point out - check the commits
Expand Down Expand Up @@ -72,6 +79,15 @@ And the differences:

### Planned

* **1.0.0.0.0**
* Builtin libraries - for `IO`, `Math`, `Time`, etc
* **prerelease-1.1.0.0.0**
* Builtin `Math` library

* **prerelease-1.2.0.0.0**
* Builtin `Time` library, with integration to the IO libraries
* Builtin `Random` library

* **prerelease-1.3.0.0.0**
* Maybe some other libraries?

* **release-1.0.0.0.0**
* Finished documentation
106 changes: 42 additions & 64 deletions ezr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using ezrSquared.Helpers;
using static ezrSquared.Constants.constants;
using System.Reflection;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;

using ezrSquared.Libraries.IO;

namespace ezrSquared.Main
{
Expand Down Expand Up @@ -2344,8 +2344,8 @@ public runtimeResult visit(node node, context context)
private runtimeResult visit_numberNode(numberNode node, context context)
{
if (node.valueToken.type == TOKENTYPE.INT)
return new runtimeResult().success(new integerNumber((int)node.valueToken.value).setPosition(node.startPos, node.endPos).setContext(context));
return new runtimeResult().success(new floatNumber((float)node.valueToken.value).setPosition(node.startPos, node.endPos).setContext(context));
return new runtimeResult().success(new integer_number((int)node.valueToken.value).setPosition(node.startPos, node.endPos).setContext(context));
return new runtimeResult().success(new float_number((float)node.valueToken.value).setPosition(node.startPos, node.endPos).setContext(context));
}

private runtimeResult visit_stringNode(stringNode node, context context)
Expand All @@ -2355,7 +2355,7 @@ private runtimeResult visit_stringNode(stringNode node, context context)

private runtimeResult visit_charListNode(charListNode node, context context)
{
return new runtimeResult().success(new characterList(node.valueToken.value.ToString()).setPosition(node.startPos, node.endPos).setContext(context));
return new runtimeResult().success(new character_list(node.valueToken.value.ToString()).setPosition(node.startPos, node.endPos).setContext(context));
}

private runtimeResult visit_arrayNode(arrayNode node, context context)
Expand Down Expand Up @@ -2510,7 +2510,7 @@ private runtimeResult visit_unaryOperationNode(unaryOperationNode node, context
error? err = null;
item? res = null;
if (node.operatorToken.type == TOKENTYPE.MINUS)
res = variable.multedBy(new integerNumber(-1), out err);
res = variable.multedBy(new integer_number(-1), out err);
else if (node.operatorToken.matchString(TOKENTYPE.KEY, "invert") || node.operatorToken.matchString(TOKENTYPE.KEY, "v"))
res = variable.invert(out err);

Expand Down Expand Up @@ -2561,38 +2561,38 @@ private runtimeResult visit_countNode(countNode node, context context)
item start = result.register(visit(node.startValueNode, context));
if (result.shouldReturn()) return result;

if (start is not integerNumber && start is not floatNumber)
return result.failure(new runtimeError(start.startPos, start.endPos, RT_TYPE, "Count loop start must be an integerNumber or floatNumber", context));
if (start is not integer_number && start is not float_number)
return result.failure(new runtimeError(start.startPos, start.endPos, RT_TYPE, "Count loop start must be an integer_number or float_number", context));

if (start is integerNumber)
i = ((integerNumber)start).storedValue;
if (start is integer_number)
i = ((integer_number)start).storedValue;
else
i = (int)((floatNumber)start).storedValue;
i = (int)((float_number)start).storedValue;
}

item end = result.register(visit(node.endValueNode, context));
if (result.shouldReturn()) return result;

if (end is not integerNumber && end is not floatNumber)
return result.failure(new runtimeError(end.startPos, end.endPos, RT_TYPE, "Count loop end must be an integerNumber or floatNumber", context));
if (end is not integer_number && end is not float_number)
return result.failure(new runtimeError(end.startPos, end.endPos, RT_TYPE, "Count loop end must be an integer_number or float_number", context));

if (end is integerNumber)
length = ((integerNumber)end).storedValue;
if (end is integer_number)
length = ((integer_number)end).storedValue;
else
length = (int)((floatNumber)end).storedValue;
length = (int)((float_number)end).storedValue;

if (node.stepValueNode != null)
{
item step = result.register(visit(node.stepValueNode, context));
if (result.shouldReturn()) return result;

if (step is not integerNumber && step is not floatNumber)
return result.failure(new runtimeError(step.startPos, step.endPos, RT_TYPE, "Count loop step must be an integerNumber or floatNumber", context));
if (step is not integer_number && step is not float_number)
return result.failure(new runtimeError(step.startPos, step.endPos, RT_TYPE, "Count loop step must be an integer_number or float_number", context));

if (step is integerNumber)
step_ = ((integerNumber)step).storedValue;
if (step is integer_number)
step_ = ((integer_number)step).storedValue;
else
step_ = (int)((floatNumber)step).storedValue;
step_ = (int)((float_number)step).storedValue;
}

string? varName = null;
Expand All @@ -2602,7 +2602,7 @@ private runtimeResult visit_countNode(countNode node, context context)
for (int j = i; j < length; j += step_)
{
if (varName != null)
context.symbolTable.set(varName, new integerNumber(j));
context.symbolTable.set(varName, new integer_number(j));

item body = result.register(visit(node.bodyNode, context));
if (result.shouldReturn() && !result.loopShouldSkip && !result.loopShouldStop) return result;
Expand Down Expand Up @@ -2778,7 +2778,7 @@ private runtimeResult visit_includeNode(includeNode node, context context)

string file = node.nameToken.value.ToString();

List<string> plausibleFilepaths = new List<string>() { Path.Join(LIBPATH, file), Path.Join(Directory.GetCurrentDirectory(), file), file };
List<string> plausibleFilepaths = new List<string>() { Path.Join(Directory.GetCurrentDirectory(), file), file };
for (int i = 0; i < LOCALLIBPATHS.Count; i++)
plausibleFilepaths.Add(Path.Join(LOCALLIBPATHS[i], file));

Expand Down Expand Up @@ -2835,41 +2835,16 @@ private runtimeResult visit_includeNode(includeNode node, context context)
formattedFileName += name[i];
}

item value;
string? extension = Path.GetExtension(realFilepath);
if (extension == null) extension = "";

if (extension == ".cs")
{
Script<item> csScript = CSharpScript.Create<item>(script, ScriptOptions.Default.WithReferences(typeof(ezr).Assembly).WithImports("ezrSquared.Main", "ezrSquared.Nodes", "ezrSquared.Errors", "ezrSquared.Helpers", "ezrSquared.General", "ezrSquared.Values", "ezrSquared.Constants.constants"));
csScript.Compile();

try
{
Task<ScriptState<item>> exeTask = csScript.RunAsync();
if (exeTask.Result.ReturnValue == null)
return result.failure(new runtimeError(node.startPos, node.endPos, RT_RUN, $"Failed to finish executing script \"{file}\"\n\nReturn value is null", context));

value = exeTask.Result.ReturnValue.setPosition(node.startPos, node.endPos).setContext(context);
}
catch (Exception error)
{
return result.failure(new runtimeError(node.startPos, node.endPos, RT_RUN, $"Failed to finish executing script \"{file}\"\n\n{error.Message}", context));
}
}
else
{
token[] tokens = new lexer(file, script).compileTokens(out error? error);
if (error != null)
return result.failure(new runtimeError(node.startPos, node.endPos, RT_RUN, $"Failed to finish executing script \"{file}\"\n\n{error.asString()}", context));
token[] tokens = new lexer(file, script).compileTokens(out error? error);
if (error != null)
return result.failure(new runtimeError(node.startPos, node.endPos, RT_RUN, $"Failed to finish executing script \"{file}\"\n\n{error.asString()}", context));

parseResult parseResult = new parser(tokens).parse();
if (parseResult.error != null)
return result.failure(new runtimeError(node.startPos, node.endPos, RT_RUN, $"Failed to finish executing script \"{file}\"\n\n{parseResult.error.asString()}", context));
parseResult parseResult = new parser(tokens).parse();
if (parseResult.error != null)
return result.failure(new runtimeError(node.startPos, node.endPos, RT_RUN, $"Failed to finish executing script \"{file}\"\n\n{parseResult.error.asString()}", context));

value = result.register(new @class(formattedFileName, parseResult.node, new string[0]).setPosition(node.startPos, node.endPos).setContext(context).execute(new item[0]));
if (result.shouldReturn()) return result;
}
item value = result.register(new @class(formattedFileName, parseResult.node, new string[0]).setPosition(node.startPos, node.endPos).setContext(context).execute(new item[0]));
if (result.shouldReturn()) return result;

context.symbolTable.set(formattedFileName, value);
return result.success(value);
Expand Down Expand Up @@ -2897,15 +2872,14 @@ private runtimeResult visit_includeNode(includeNode node, context context)
private @string RTRUN = new(RT_RUN);
private @string RTIO = new(RT_IO);

private builtinFunction funcShow = new("show", new string[1] { "message" });
private builtinFunction funcShowError = new("show_error", new string[2] { "tag", "message" });
private builtinFunction funcGet = new("get", new string[1] { "message" });
private builtinFunction funcClear = new("clear", new string[0]);
private builtinFunction funcHash = new("hash", new string[1] { "value" });
private builtinFunction funcTypeOf = new("type_of", new string[1] { "value" });
private builtinFunction funcRun = new("run", new string[1] { "file" });
private builtin_function funcShow = new("show", new string[1] { "message" });
private builtin_function funcShowError = new("show_error", new string[2] { "tag", "message" });
private builtin_function funcGet = new("get", new string[1] { "message" });
private builtin_function funcClear = new("clear", new string[0]);
private builtin_function funcHash = new("hash", new string[1] { "value" });
private builtin_function funcTypeOf = new("type_of", new string[1] { "value" });
private builtin_function funcRun = new("run", new string[1] { "file" });

public static string LIBPATH = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"\Libraries\");
public static List<string> LOCALLIBPATHS = new List<string>();

public ezr()
Expand Down Expand Up @@ -2935,6 +2909,10 @@ public ezr()
globalPredefinedSymbolTable.set("type_of", funcTypeOf);
globalPredefinedSymbolTable.set("run", funcRun);

globalPredefinedSymbolTable.set("file", new @file());
globalPredefinedSymbolTable.set("folder", new folder());
globalPredefinedSymbolTable.set("path", new path());

globalPredefinedContext.symbolTable = globalPredefinedSymbolTable;
}

Expand Down
12 changes: 0 additions & 12 deletions ezrSquared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@
<ApplicationIcon>Graphics\Icon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Libraries\Test.cs" />
</ItemGroup>

<ItemGroup>
<Content Include="Graphics\Icon.ico" />
<Content Include="Libraries\Test.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="Builds\Installer\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.4.0" />
</ItemGroup>

</Project>

0 comments on commit e586717

Please sign in to comment.