Skip to content

Commit 7863ca3

Browse files
Added More Packages and stuff
1 parent 4221e49 commit 7863ca3

7 files changed

Lines changed: 81 additions & 39 deletions

File tree

EZCode/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<configuration>
33
<runtime>
44
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5-
<probing privatePath="Debug/Libraries;Release/Libraries" />
5+
<probing privatePath="Debug/net.8.0/Libraries/" />
66
</assemblyBinding>
77
</runtime>
88
</configuration>

EZCode/EZHelp.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ public static object GetParameter(object obj, string type)
185185

186186
return e.ObjectParse(obj, type);
187187
}
188+
public static Exception SetError(Exception exception)
189+
{
190+
Error = exception.Message;
191+
throw exception;
192+
}
188193
public bool Evaluate(string expression)
189194
{
190195
try
@@ -617,7 +622,6 @@ public float MathFunc(object obj, object op)
617622
}
618623
}
619624
string operation = string.Join("", op.ToString().ToLower().ToCharArray().Select((x, y) => { if (y == 0) return char.Parse(x.ToString().ToUpper()); else return x; }));
620-
621625
object[] parameters = [val1];
622626
if (!obj2_is_null) parameters = [..parameters, val2];
623627

@@ -636,5 +640,30 @@ public float Average(object obj)
636640
float all = numbers.Sum();
637641
return all / numbers.Length;
638642
}
643+
public float Pi() => MathF.PI;
644+
public float E() => MathF.E;
645+
public float Clamp(object _val, object _min, object _max)
646+
{
647+
float val = FloatParse(_val);
648+
float min = FloatParse(_min);
649+
float max = FloatParse(_max);
650+
651+
if (val < min) return min;
652+
else if (val > max) return max;
653+
else return val;
654+
}
655+
public float Power(object _val, object _pow)
656+
{
657+
float val = FloatParse(_val);
658+
float pow = FloatParse(_pow);
659+
return MathF.Pow(val, pow);
660+
}
661+
public string Trim(object text) => StringParse(text).Trim();
662+
public string ToLower(object text) => StringParse(text).ToLower();
663+
public string ToUpper(object text) => StringParse(text).ToUpper();
664+
public string Replace(object text, object older, object newwer) => StringParse(text).Replace(StringParse(older), StringParse(newwer));
665+
public string Substring(object text, object index, object length) => StringParse(text).Substring(IntParse(index), IntParse(length));
666+
public bool StartsWith(object text, object val) => StringParse(text).StartsWith(StringParse(val));
667+
public bool EndsWith(object text, object val) => StringParse(text).EndsWith(StringParse(val));
639668
}
640669
}

EZCode/Interpreter.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ internal set
3030
private string? Input = null;
3131
public enum EZInputType { Console, InputMethod }
3232
public EZInputType InputType { get; set; } = EZInputType.Console;
33-
public void SetInput(string input, EZInputType inputType = EZInputType.InputMethod)
33+
public void SetInput(string input, EZInputType inputType = EZInputType.InputMethod)
3434
{
3535
InputType = inputType;
36-
Input = input;
36+
Input = input;
3737
}
3838
public string ConsoleInput()
3939
{
@@ -104,6 +104,8 @@ public Interpreter(Parser parser, Debug.Breakpoint[]? breakpoints = null)
104104
private DataType? Returning = null;
105105
private int StackNumber = 0;
106106
public Stack<string> StackTrace { get; private set; }
107+
internal record Library(string name, string[] files);
108+
internal List<Library> DllLibraries { get; set; } = [];
107109
public Exception[] Errors { get; private set; } = [];
108110
public Var[] Vars { get; set; } = [];
109111
public Method[] Methods { get; set; } = [];
@@ -114,7 +116,6 @@ public Interpreter(Parser parser, Debug.Breakpoint[]? breakpoints = null)
114116
public void Interperate() => Interperate(parser.LinesWithTokens);
115117
public void Interperate(LineWithTokens[] LineTokens)
116118
{
117-
int endcode = 0;
118119
var temp_stack = new Stack<string>(StackTrace);
119120

120121
Package.RemoveAllPackagesFromExecutionDirectory(AppDomain.CurrentDomain.BaseDirectory);
@@ -192,13 +193,19 @@ public void Interperate(LineWithTokens[] LineTokens)
192193

193194
if (projects.Any(x => !string.IsNullOrEmpty(x.LibraryDirectory)))
194195
{
195-
string destination = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Libraries");
196+
string destination = AppDomain.CurrentDomain.BaseDirectory;
196197
foreach (var project in projects)
197198
{
198199
if (FirstToken.StringValue == "include")
199-
Package.AddPackageToExecutionDirectory(project, destination);
200-
else
201-
Package.RemovePackageFromExecutionDirectory(project, destination);
200+
{
201+
Package.AddPackageToExecutionDirectory(project, destination, out var files);
202+
DllLibraries.Add(new Library(project.Name, files));
203+
}
204+
else
205+
{
206+
var library = DllLibraries.FirstOrDefault(x => x.name == project.Name);
207+
Package.RemovePackageFromExecutionDirectory(library.files);
208+
}
202209
}
203210
}
204211

@@ -1294,7 +1301,7 @@ public object Reflect(CSharpMethod method)
12941301
}
12951302
public static object? InvokeMethod(string methodPath, object[] parameters, EZHelp e)
12961303
{
1297-
// Split the method path into type and method name
1304+
// Split the method files into type and method name
12981305
string[] pathParts = methodPath.Split('.');
12991306
if (pathParts.Length < 2)
13001307
{
@@ -1303,10 +1310,10 @@ public object Reflect(CSharpMethod method)
13031310

13041311
if (pathParts.Length >= 2 && pathParts[1].Equals("dll"))
13051312
{
1306-
// If the method path contains an assembly name, load the assembly
1313+
// If the method files contains an assembly name, load the assembly
13071314
string assemblyPath = pathParts[0] + "." + pathParts[1];
1308-
string subdirectory = pathParts[0]; // Name of the subdirectory is first part of namespace
1309-
string fullAssemblyPath = Path.Combine(subdirectory, assemblyPath); // Combine subdirectory path with assembly name
1315+
string subdirectory = Package.LibraryDirName; // Name of the subdirectory is first part of namespace
1316+
string fullAssemblyPath = Path.Combine(subdirectory, assemblyPath); // Combine subdirectory files with assembly name
13101317
Assembly assembly = Assembly.LoadFrom(fullAssemblyPath);
13111318

13121319
// Get the type name
@@ -1361,7 +1368,7 @@ public object Reflect(CSharpMethod method)
13611368
throw new ArgumentException($"Type \"{typeName}\" not found");
13621369
}
13631370

1364-
// Get the method name from the path
1371+
// Get the method name from the files
13651372
string methodName = pathParts.Last();
13661373

13671374
// Find the method in the type

EZCode/Package.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ namespace EZCodeLanguage
55
public static class Package
66
{
77
public static string PackagesDirectory = "D:\\EZCodeLanguage\\Packages\\";
8-
public static void AddPackageToExecutionDirectory(Project project, string executionDirectory)
8+
public static string LibraryDirName = "Libraries";
9+
public static void AddPackageToExecutionDirectory(Project project, string executionDirectory, out string[] files)
910
{
11+
files = [];
1012
string projectPath = GetPackageDirectory(project.Name);
1113
string libraryDirectory = Path.Combine(projectPath, project.LibraryDirectory ?? throw new Exception("Project.LibraryDirectory is null"));
12-
string executionSubDirectoryName = project.LibraryDirectory.Split(['/', '\\']).First();
14+
string executionSubDirectoryName = LibraryDirName;
1315
string executionSubDirectory = Path.Combine(executionDirectory, executionSubDirectoryName);
1416

1517
Directory.CreateDirectory(executionSubDirectory);
@@ -20,29 +22,38 @@ public static void AddPackageToExecutionDirectory(Project project, string execut
2022
string libraryFileName = Path.GetFileName(libraryFile);
2123
string executionSubDirectoryFile = Path.Combine(executionSubDirectory, libraryFileName);
2224
File.Copy(libraryFile, executionSubDirectoryFile);
25+
files = [.. files, executionSubDirectoryFile];
2326
}
2427
}
25-
public static void RemovePackageFromExecutionDirectory(Project project, string executionDirectory)
28+
public static void RemovePackageFromExecutionDirectory(string[] projectFileNames)
2629
{
27-
string libraryDirectory = project.LibraryDirectory ?? throw new Exception("Project.LibraryDirectory is null");
28-
string executionSubDirectory = Path.Combine(executionDirectory, libraryDirectory);
29-
30-
Directory.Delete(executionSubDirectory, true);
30+
foreach(string file in projectFileNames)
31+
{
32+
File.Delete(file);
33+
}
3134
}
3235
public static void RemoveAllPackagesFromExecutionDirectory(string executionDirectory)
3336
{
34-
string[] directories = Directory.GetDirectories(executionDirectory);
35-
foreach (string directory in directories)
37+
try
3638
{
37-
try
38-
{
39-
Directory.Delete(directory, true);
40-
}
41-
catch
39+
string executionSubDirectory = Path.Combine(executionDirectory, LibraryDirName);
40+
string[] files = Directory.GetFiles(executionSubDirectory);
41+
foreach (string file in files)
4242
{
43+
try
44+
{
45+
File.Delete(file);
46+
}
47+
catch
48+
{
4349

50+
}
4451
}
4552
}
53+
catch
54+
{
55+
56+
}
4657
}
4758
public static string GetPackageDirectory(string package_name)
4859
{

EZCode/Parser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public Parser(string code, string file)
436436
public LineWithTokens[] Parse() => LinesWithTokens = TokenArray(Code, FilePath).Where(x => x.Line.Value.ToString() != "").ToArray();
437437
private LineWithTokens[] TokenArray(string code, string file, bool insideClass = false)
438438
{
439-
// Set the file path property
439+
// Set the file files property
440440
FilePath = file;
441441
// Set the Code property to the parameter if it isn't null
442442
Code ??= code;
@@ -1093,7 +1093,7 @@ just trying to get string version of parts */
10931093
string part = parts[i].ToString();
10941094
// get where '(' starts
10951095
int ch = Array.IndexOf(part.ToCharArray(), '(');
1096-
// gets the path from the part
1096+
// gets the files from the part
10971097
string path = part[..ch];
10981098
// gets the type from inside the ""
10991099
string type = part.Substring(ch + 1, part.Length - ch - 2).Replace("\"", "");
@@ -1102,7 +1102,7 @@ just trying to get string version of parts */
11021102
}
11031103
else if (parts[i].ToString() == "runexec")
11041104
{
1105-
// path of the CSharp Method
1105+
// files of the CSharp Method
11061106
string path = parts[i + 1].ToString();
11071107
// parameters of the method
11081108
string[]? vars = null;

TestEnv/Code.ezcode

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
include winforms
1+
include main
22

3-
window main new : title:Hello World
4-
5-
defaultsettings
6-
runapp : main
7-
8-
main open
3+
print 'str startswith : Hello World, He'

TestEnv/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using EZCodeLanguage;
22
using System.Diagnostics;
33

4-
// set up path variables
4+
// set up files variables
55
string path = "Code.ezcode";
66
string full_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
77
string code = File.ReadAllText(path);

0 commit comments

Comments
 (0)