Skip to content

Commit

Permalink
Add ToStringExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
snaulX committed Sep 22, 2019
1 parent 07a1423 commit 23fc93e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/test.bld
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ main {
plus : <12:double>, <10:double>, <678:double>;
@sum.#set : ( plus : <12:double>, <13:double> ) ;
System.print : <Hello World!:string> ;
#print : ( ParseDouble : @sum ) ;
#print : ( toString : @sum ) ;
}
end
2 changes: 1 addition & 1 deletion wolvm/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Value GetField(string name)
}
}

public bool CheckType(string name) => VirtualMachine.GetWolClass(name) == type ? true : false; //thanks C# for one-string functions))
public bool CheckType(string name) => name == type.strtype ? true : false; //thanks C# for one-string functions))

public static Value GetSmallValue(string val, Value parent = null)
{
Expand Down
3 changes: 2 additions & 1 deletion wolvm/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static class VirtualMachine
{ "ParseInt", new ParseIntExpression() },
{ "set", new SetExpression() },
{ "ParseDouble", new ParseDoubleExpression() },
{ "System.input", new InputExpression() }
{ "System.input", new InputExpression() },
{ "toString", new ToStringExpression() }
};
private static bool test = false;

Expand Down
17 changes: 17 additions & 0 deletions wolvm/expressions/ToStringExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace wolvm
{
public class ToStringExpression : VMExpression
{
public Value ParseExpression(params Value[] args)
{
Value val = args[0];
if (val.CheckType("double")) return new Value(new wolString(((wolDouble)val.type).value.ToString()));
else if (val.CheckType("int")) return new Value(new wolString(((wolInt)val.type).value.ToString()));
else return new Value(new wolString(System.Text.RegularExpressions.Regex.Escape(val.type.strtype)));
}
}
}

0 comments on commit 23fc93e

Please sign in to comment.