Skip to content

Commit

Permalink
Release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zs-3 authored Aug 3, 2024
1 parent d455bb2 commit 2b16315
Show file tree
Hide file tree
Showing 22 changed files with 5,580 additions and 182 deletions.
68 changes: 35 additions & 33 deletions ZS/Argument.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
using Microsoft.SmallBasic.Library;
using System;

/// <summary>
/// The Arguments object provides operations to access the command-line arguments that were passed at the start of this program.
/// This class has been taken from Small Basic version 0.2.
/// </summary>
[SmallBasicType]
public static class ZSArguments
namespace ZS
{
private static string[] args = Environment.GetCommandLineArgs();

/// <summary>
/// Gets the number of command-line arguments passed to this program.
/// </summary>
public static Primitive Count
{
get { return (args.Length != 0) ? (args.Length - 1) : 0; }
}
/// <summary>
/// The Arguments object provides operations to access the command-line arguments that were passed at the start of this program.
/// This class has been taken from Small Basic version 0.2.
/// </summary>
[SmallBasicType]
public static class ZSArguments
{
private static string[] args = Environment.GetCommandLineArgs();

/// <summary>
/// Returns the specified argument.
/// </summary>
/// <param name="index">
/// Index of the argument.
/// </param>
/// <returns>
/// The command-line argument at the specified index.
/// </returns>
public static Primitive GetArgument(Primitive index)
{
int num = index;
if (num >= 1 && num < args.Length)
{
return new Primitive(args[num]);
}
return new Primitive("");
}
}
/// <summary>
/// Gets the number of command-line arguments passed to this program.
/// </summary>
public static Primitive Count {
get { return (args.Length != 0) ? (args.Length - 1) : 0; }
}

/// <summary>
/// Returns the specified argument.
/// </summary>
/// <param name="index">
/// Index of the argument.
/// </param>
/// <returns>
/// The command-line argument at the specified index.
/// </returns>
public static Primitive GetArgument(Primitive index)
{
int num = index;
if (num >= 1 && num < args.Length) {
return new Primitive(args[num]);
}
return new Primitive("");
}
}
}
20 changes: 11 additions & 9 deletions ZS/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ZS
/// Provides System.Environment Functions For Small Basic.
/// </summary>
[SmallBasicType]
public class ZSEnvironment
public static class ZSEnvironment
{
/// <summary>
/// Gets the command line for the application.
Expand Down Expand Up @@ -162,9 +162,9 @@ public static Primitive Version {
/// Gets the amount of physical memory allocated for the process.
/// </summary>
/// <value>The amount of physical memory allocated for the process, in bytes.</value>
public static long WorkingSet {
public static Primitive WorkingSet {
get {
return Environment.WorkingSet;
return Environment.WorkingSet.ToString();
}
}

Expand All @@ -178,12 +178,14 @@ public static void Exit(Primitive exitCode)
}

/// <summary>
/// Returns the command-line arguments for the process.
/// Returns the command-line arguments for the process as a single string with arguments separated by a delimiter.
/// </summary>
/// <returns>An array of strings representing the command-line arguments.</returns>
public static string[] GetCommandLineArgs()
/// <returns>A string representing the command-line arguments, separated by commas.</returns>
public static Primitive GetCommandLineArgs()
{
return Environment.GetCommandLineArgs();
string[] args = Environment.GetCommandLineArgs();
string result = string.Join(",", args);
return result;
}

/// <summary>
Expand Down Expand Up @@ -213,9 +215,9 @@ public static Primitive GetEnvironmentVariable(Primitive variable, EnvironmentVa
/// Returns the names of the logical drives on the current machine.
/// </summary>
/// <returns>An array of strings representing the names of the logical drives.</returns>
public static string[] GetLogicalDrives()
public static Primitive GetLogicalDrives()
{
return Environment.GetLogicalDrives();
return Environment.GetLogicalDrives().ToString();
}

/// <summary>
Expand Down
175 changes: 88 additions & 87 deletions ZS/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,114 +3,115 @@
using System.Collections.Generic;
using System.Reflection;

/// <summary>
/// The Platform object provides a way to generically invoke other .NET libraries.
/// This class has been taken from Small Basic version 0.2.
/// </summary>
[SmallBasicType]
public static class ZSPlatform
namespace ZS
{
private static Dictionary<string, int> _nameGenerationMap = new Dictionary<string, int>();

private static Dictionary<string, object> _objectMap = new Dictionary<string, object>();

/// <summary>
/// Creates an instance of a specified .NET type.
/// For Example : System.DateTime
/// The Platform object provides a way to generically invoke other .NET libraries.
/// This class has been taken from Small Basic version 0.2.
/// </summary>
/// <param name="typeName">The fully qualified name of the type.</param>
/// <returns>A unique identifier for the created instance or "ERROR" if creation fails.</returns>
public static Primitive CreateInstance(Primitive typeName)
[SmallBasicType]
public static class ZSPlatform
{
try
private static Dictionary<string, int> _nameGenerationMap = new Dictionary<string, int>();
private static Dictionary<string, object> _objectMap = new Dictionary<string, object>();

/// <summary>
/// Creates an instance of a specified .NET type.
/// </summary>
/// <param name="typeName">The fully qualified name of the type.</param>
/// <returns>A unique identifier for the created instance or "ERROR" if creation fails.</returns>
public static Primitive CreateInstance(Primitive typeName)
{
Type type = Type.GetType(typeName);
object value = Activator.CreateInstance(type);
string text = GenerateNewName("Instance");
_objectMap[text] = value;
return text;
}
catch (Exception ex)
{
return "ERROR : " + ex.Message;
try
{
Type type = Type.GetType(typeName);
object value = Activator.CreateInstance(type);
string text = GenerateNewName("Instance");
_objectMap[text] = value;
return text;
}
catch (Exception ex)
{
return "ERROR" + ex.Message;
}
}
}

/// <summary>
/// Invokes a method on an instance of a .NET type.
/// </summary>
/// <param name="instanceId">The unique identifier of the instance.</param>
/// <param name="methodName">The name of the method to invoke.</param>
/// <param name="argumentsStackName">The name of the stack containing the method arguments.</param>
/// <returns>The result of the method invocation or "ERROR" if invocation fails.</returns>
public static Primitive InvokeInstanceMethod(Primitive instanceId, Primitive methodName, Primitive argumentsStackName)
{
try
/// <summary>
/// Invokes a method on an instance of a .NET type.
/// </summary>
/// <param name="instanceId">The unique identifier of the instance.</param>
/// <param name="methodName">The name of the method to invoke.</param>
/// <param name="argumentsStackName">The name of the stack containing the method arguments.</param>
/// <returns>The result of the method invocation or "ERROR" if invocation fails.</returns>
public static Primitive InvokeInstanceMethod(Primitive instanceId, Primitive methodName, Primitive argumentsStackName)
{
object obj = _objectMap[instanceId];
MethodInfo method = obj.GetType().GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
int num = Stack.GetCount(argumentsStackName);
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == num)
try
{
List<object> list = new List<object>();
for (int num2 = num - 1; num2 >= 0; num2--)
object obj = _objectMap[instanceId.ToString()];
MethodInfo method = obj.GetType().GetMethod(methodName.ToString(), BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
int num = Stack.GetCount(argumentsStackName);
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == num)
{
list[num2] = Stack.PopValue(argumentsStackName);
object[] list = new object[num];
for (int num2 = num - 1; num2 >= 0; num2--)
{
list[num2] = Stack.PopValue(argumentsStackName);
}
return new Primitive(method.Invoke(obj, list));
}
return new Primitive(method.Invoke(obj, list.ToArray()));
return "ERROR";
}
catch (Exception ex)
{
return "ERROR" + ex.Message;
}
return "ERROR";
}
catch (Exception ex)
{
return "ERROR : " + ex.Message;
}
}

/// <summary>
/// Invokes a static method on a .NET type.
/// </summary>
/// <param name="typeName">The fully qualified name of the type.</param>
/// <param name="methodName">The name of the method to invoke.</param>
/// <param name="argumentsStackName">The name of the stack containing the method arguments.</param>
/// <returns>The result of the method invocation or "ERROR" if invocation fails.</returns>
public static Primitive InvokeStaticMethod(Primitive typeName, Primitive methodName, Primitive argumentsStackName)
{
try
/// <summary>
/// Invokes a static method on a .NET type.
/// </summary>
/// <param name="typeName">The fully qualified name of the type.</param>
/// <param name="methodName">The name of the method to invoke.</param>
/// <param name="argumentsStackName">The name of the stack containing the method arguments.</param>
/// <returns>The result of the method invocation or "ERROR" if invocation fails.</returns>
public static Primitive InvokeStaticMethod(Primitive typeName, Primitive methodName, Primitive argumentsStackName)
{
Type type = Type.GetType(typeName);
MethodInfo method = type.GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public);
int num = Stack.GetCount(argumentsStackName);
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == num)
try
{
List<object> list = new List<object>();
for (int num2 = num - 1; num2 >= 0; num2--)
Type type = Type.GetType(typeName.ToString());
MethodInfo method = type.GetMethod(methodName.ToString(), BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public);
int num = Stack.GetCount(argumentsStackName);
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == num)
{
list[num2] = Stack.PopValue(argumentsStackName);
object[] list = new object[num];
for (int num2 = num - 1; num2 >= 0; num2--)
{
list[num2] = Stack.PopValue(argumentsStackName);
}
return new Primitive(method.Invoke(null, list));
}
return new Primitive(method.Invoke(null, list.ToArray()));
return "ERROR";
}
catch (Exception ex)
{
return "ERROR" + ex.Message;
}
return "ERROR";
}
catch (Exception ex)

/// <summary>
/// Generates a new unique name with a specified prefix.
/// </summary>
/// <param name="prefix">The prefix for the generated name.</param>
/// <returns>A new unique name.</returns>
internal static string GenerateNewName(string prefix)
{
return "ERROR : " + ex.Message;
int num = 0;
_nameGenerationMap.TryGetValue(prefix, out num);
num++;
_nameGenerationMap[prefix] = num;
return prefix + num.ToString();
}
}

/// <summary>
/// Generates a new unique name with a specified prefix.
/// </summary>
/// <param name="prefix">The prefix for the generated name.</param>
/// <returns>A new unique name.</returns>
internal static string GenerateNewName(string prefix)
{
int num = 0;
_nameGenerationMap.TryGetValue(prefix, out num);
num++;
_nameGenerationMap[prefix] = num;
return prefix + num.ToString();
}
}
Loading

0 comments on commit 2b16315

Please sign in to comment.