Skip to content

Commit

Permalink
Formatting again
Browse files Browse the repository at this point in the history
  • Loading branch information
zdimension committed Sep 19, 2015
1 parent 7bababa commit d0316fe
Show file tree
Hide file tree
Showing 101 changed files with 1,407 additions and 1,398 deletions.
7 changes: 4 additions & 3 deletions src/Hassium/Debug/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public static void PrintTokens(List<Token> tokens)
var position = 0;
foreach (Token token in tokens)
{
Console.WriteLine(position + new string(' ', tokens.Count.ToString().Length + 2 - position.ToString().Length) + "Type: " + token.TokenClass +
Console.WriteLine(position +
new string(' ', tokens.Count.ToString().Length + 2 - position.ToString().Length) +
"Type: " + token.TokenClass +
new string(' ',
tokens.Max(x => x.TokenClass.ToString().Length) + 3 -
token.TokenClass.ToString().Length) + "Value: " + token.Value);
Expand All @@ -26,5 +28,4 @@ public static void PrintTokens(List<Token> tokens)
Console.WriteLine();
}
}
}

}
12 changes: 9 additions & 3 deletions src/Hassium/Functions/ConsoleFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static HassiumObject Print(HassiumObject[] args)
Console.Write(String.Join("", args.Select(x => x.ToString())));
return null;
}

/// <summary>
/// Prints the specified string to the console (see <c>Print</c>) followed by a newline.
/// </summary>
Expand All @@ -29,6 +30,7 @@ public static HassiumObject PrintLn(HassiumObject[] args)
Console.WriteLine(String.Join("", args.Select(x => x.ToString())));
return null;
}

/// <summary>
/// Prints the specified array to the console followed by a newline.
/// </summary>
Expand All @@ -40,17 +42,20 @@ public static HassiumObject PrintArr(HassiumObject[] args)
Console.WriteLine(HassiumConvert.toString(new[] {args[0]}).ToString());
return null;
}

/// <summary>
/// Prompt the user to type something and return the input.
/// </summary>
/// <param name="args">No parameters.</param>
/// <returns>Nothing.</returns>
[IntFunc("input", new []{0,1,2})]
[IntFunc("input", new[] {0, 1, 2})]
public static HassiumObject Input(HassiumObject[] args)
{
if (args.Length > 0 && args[0].HBool().Value) return Console.ReadKey(args.Length == 2 && args[1].HBool().Value).KeyChar;
if (args.Length > 0 && args[0].HBool().Value)
return Console.ReadKey(args.Length == 2 && args[1].HBool().Value).KeyChar;
return Console.ReadLine();
}

/// <summary>
/// Clears the console.
/// </summary>
Expand All @@ -62,6 +67,7 @@ public static HassiumObject Cls(HassiumObject[] args)
Console.Clear();
return null;
}

/// <summary>
/// Waits for the user to press any key.
/// </summary>
Expand All @@ -74,4 +80,4 @@ public static HassiumObject Pause(HassiumObject[] args)
return null;
}
}
}
}
10 changes: 5 additions & 5 deletions src/Hassium/Functions/Constructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public static HassiumObject Array(HassiumObject[] args)
return new HassiumArray(new HassiumObject[args[0].HInt().Value]);
}

[IntFunc("Random", true, new []{0, 1})]
[IntFunc("Random", true, new[] {0, 1})]
public static HassiumObject Random(HassiumObject[] args)
{
return args.Length > 0 ? new HassiumRandom(new Random(args[0].HInt().Value)) : new HassiumRandom(new Random());
return args.Length > 0
? new HassiumRandom(new Random(args[0].HInt().Value))
: new HassiumRandom(new Random());
}



[IntFunc("Event", true, -1)]
public static HassiumObject Event(HassiumObject[] args)
Expand All @@ -62,5 +63,4 @@ public static HassiumObject Event(HassiumObject[] args)
return ret;
}
}
}

}
3 changes: 1 addition & 2 deletions src/Hassium/Functions/ILibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ public interface ILibrary
{
//Dictionary<string, InternalFunction> GetFunctions();
}
}

}
11 changes: 6 additions & 5 deletions src/Hassium/Functions/InternalFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Hassium.Functions
{
public delegate HassiumObject HassiumFunctionDelegate (params HassiumObject[] arguments);
public delegate HassiumObject HassiumFunctionDelegate(params HassiumObject[] arguments);

public class InternalFunction : HassiumObject
{
Expand Down Expand Up @@ -36,13 +36,15 @@ public InternalFunction(HassiumFunctionDelegate target, int[] args, bool prop =

public override string ToString()
{
return string.Format("[InternalFunction: {0}`{1}]", target.Method.Name, target.Method.GetParameters().Count());
return string.Format("[InternalFunction: {0}`{1}]", target.Method.Name,
target.Method.GetParameters().Count());
}

public override HassiumObject Invoke(params HassiumObject[] args)
{
if (!Arguments.Contains(args.Length) && Arguments[0] != -1)
throw new Exception("Function " + target.Method.Name + " has " + Arguments.Max() + " arguments, but is invoked with " + args.Length);
throw new Exception("Function " + target.Method.Name + " has " + Arguments.Max() +
" arguments, but is invoked with " + args.Length);
return target(args);
}
}
Expand Down Expand Up @@ -95,5 +97,4 @@ public IntFunc(string name, bool constr, int[] args)
Arguments = args;
}
}
}

}
127 changes: 65 additions & 62 deletions src/Hassium/Functions/MiscFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,35 @@

namespace Hassium.Functions
{
public class MiscFunctions : ILibrary
{
[IntFunc("type", 1)]
public static HassiumObject Type(HassiumObject[] args)
{
return args[0].GetType().ToString().Substring(args[0].GetType().ToString().LastIndexOf(".", StringComparison.Ordinal) + 1);
}
public class MiscFunctions : ILibrary
{
[IntFunc("type", 1)]
public static HassiumObject Type(HassiumObject[] args)
{
return
args[0].GetType()
.ToString()
.Substring(args[0].GetType().ToString().LastIndexOf(".", StringComparison.Ordinal) + 1);
}

[IntFunc("throw", -1)]
public static HassiumObject Throw(HassiumObject[] args)
{
throw new Exception(String.Join("", args.Cast<object>()));
}
[IntFunc("throw", -1)]
public static HassiumObject Throw(HassiumObject[] args)
{
throw new Exception(String.Join("", args.Cast<object>()));
}

[IntFunc("fill", 2)]
public static HassiumObject Fill(HassiumObject[] args)
{
HassiumObject[] array = new HassiumObject[args[1].HInt().Value];

var fillvalue = new[] { args[0] };
var fillvalue = new[] {args[0]};
Array.Copy(fillvalue, array, 1);
int arraylgt = array.Length / 2;
for(int i = 1; i < array.Length; i *= 2)
for (int i = 1; i < array.Length; i *= 2)
{
int cplength = i;
if(i > arraylgt)
if (i > arraylgt)
{
cplength = array.Length - i;
}
Expand Down Expand Up @@ -61,7 +64,7 @@ public static HassiumObject FillZero(HassiumObject[] args)
return Enumerable.Repeat(zero, args[0].HInt().Value).ToArray();
}

[IntFunc("range", new []{2,3})]
[IntFunc("range", new[] {2, 3})]
public static HassiumObject Range(HassiumObject[] args)
{
var from = args[0].HDouble().Value;
Expand All @@ -80,53 +83,53 @@ public static HassiumObject Range(HassiumObject[] args)
return list.ToArray().Select(x => new HassiumDouble(x)).ToArray();
}
return from == to
? new[] { from }.Select(x => new HassiumDouble(x)).ToArray()
? new[] {from}.Select(x => new HassiumDouble(x)).ToArray()
: (to < from
? Enumerable.Range((int)to, (int)from).Reverse().Cast<HassiumDouble>().ToArray()
: Enumerable.Range((int)from, (int)to).Select(x => new HassiumDouble(x)).ToArray());
? Enumerable.Range((int) to, (int) from).Reverse().Cast<HassiumDouble>().ToArray()
: Enumerable.Range((int) from, (int) to).Select(x => new HassiumDouble(x)).ToArray());
}

[IntFunc("runtimecall", -1)]
public static HassiumObject RuntimeCall(HassiumObject[] args)
{
string fullpath = args[0].ToString();
string typename = fullpath.Substring(0, fullpath.LastIndexOf('.'));
string membername = fullpath.Split('.').Last();
object[] margs = args.Skip(1).ToArray();
Type t = System.Type.GetType(typename);
if(t == null) throw new ArgumentException("The type '" + typename + "' doesn't exist.");
object instance = null;
try
{
instance = Activator.CreateInstance(t);
}
catch (Exception)
{
}
var test = t.GetMember(membername).First();
switch (test.MemberType)
{
case MemberTypes.Field:
var fv = t.GetField(membername).GetValue(null);
if(fv is double) return new HassiumDouble((double)fv);
if(fv is int) return new HassiumInt((int)fv);
if(fv is string) return new HassiumString((string)fv);
if(fv is Array) return new HassiumArray((Array)fv);
if(fv is IDictionary) return new HassiumDictionary((IDictionary)fv);
if (fv is bool) return new HassiumBool((bool) fv);
else return (HassiumObject)(object) fv;
case MemberTypes.Method:
case MemberTypes.Constructor:
var result = t.InvokeMember(
membername,
BindingFlags.InvokeMethod,
null,
instance,
margs
);
return (HassiumObject)result;
}
return null;
}
}
}
public static HassiumObject RuntimeCall(HassiumObject[] args)
{
string fullpath = args[0].ToString();
string typename = fullpath.Substring(0, fullpath.LastIndexOf('.'));
string membername = fullpath.Split('.').Last();
object[] margs = args.Skip(1).ToArray();
Type t = System.Type.GetType(typename);
if (t == null) throw new ArgumentException("The type '" + typename + "' doesn't exist.");
object instance = null;
try
{
instance = Activator.CreateInstance(t);
}
catch (Exception)
{
}
var test = t.GetMember(membername).First();
switch (test.MemberType)
{
case MemberTypes.Field:
var fv = t.GetField(membername).GetValue(null);
if (fv is double) return new HassiumDouble((double) fv);
if (fv is int) return new HassiumInt((int) fv);
if (fv is string) return new HassiumString((string) fv);
if (fv is Array) return new HassiumArray((Array) fv);
if (fv is IDictionary) return new HassiumDictionary((IDictionary) fv);
if (fv is bool) return new HassiumBool((bool) fv);
else return (HassiumObject) (object) fv;
case MemberTypes.Method:
case MemberTypes.Constructor:
var result = t.InvokeMember(
membername,
BindingFlags.InvokeMethod,
null,
instance,
margs
);
return (HassiumObject) result;
}
return null;
}
}
}
22 changes: 12 additions & 10 deletions src/Hassium/Functions/SystemFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Hassium.Functions
{
public class SystemFunctions : ILibrary
{

[IntFunc("system", -1)]
public static HassiumObject System(HassiumObject[] args)
{
Expand All @@ -27,14 +26,14 @@ public static HassiumObject System(HassiumObject[] args)
}
};
process.Start();

var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

return output;
}

[IntFunc("date", new []{1, 3, 6, 0})]
[IntFunc("date", new[] {1, 3, 6, 0})]
public static HassiumObject Date(HassiumObject[] args)
{
switch (args.Length)
Expand All @@ -53,24 +52,27 @@ public static HassiumObject Date(HassiumObject[] args)
}
}

[IntFunc("dateParse", new []{1, 2})]
[IntFunc("dateParse", new[] {1, 2})]
public static HassiumObject DateParse(HassiumObject[] args)
{
return args.Length == 2 ? new HassiumDate(DateTime.ParseExact(args[0].ToString(), args[1].ToString(), CultureInfo.InvariantCulture)) : new HassiumDate(DateTime.Parse(args[0].ToString()));
return args.Length == 2
? new HassiumDate(DateTime.ParseExact(args[0].ToString(), args[1].ToString(),
CultureInfo.InvariantCulture))
: new HassiumDate(DateTime.Parse(args[0].ToString()));
}

[IntFunc("time", new []{0, 1, 3})]
[IntFunc("time", new[] {0, 1, 3})]
public static HassiumObject Time(HassiumObject[] args)
{
switch(args.Length)
switch (args.Length)
{
case 0:
return new HassiumDate(DateTime.Now);
case 1:
return new HassiumDate(DateTime.Now).toString(new HassiumObject[] { args[0].ToString() });
return new HassiumDate(DateTime.Now).toString(new HassiumObject[] {args[0].ToString()});
default:
return new HassiumDate(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
args[0].HDouble().ValueInt, args[1].HDouble().ValueInt, args[2].HDouble().ValueInt));
args[0].HDouble().ValueInt, args[1].HDouble().ValueInt, args[2].HDouble().ValueInt));
}
}

Expand Down Expand Up @@ -102,4 +104,4 @@ public static HassiumObject Eval(HassiumObject[] args)
return null;
}
}
}
}
5 changes: 2 additions & 3 deletions src/Hassium/HassiumObjects/Collections/HassiumStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Hassium.HassiumObjects.Collections
{
public class HassiumStack: HassiumObject
public class HassiumStack : HassiumObject
{
public Stack<HassiumObject> Value { get; private set; }

Expand Down Expand Up @@ -47,5 +47,4 @@ private HassiumObject push(HassiumObject[] args)
return null;
}
}
}

}
Loading

0 comments on commit d0316fe

Please sign in to comment.