Skip to content

Commit

Permalink
Add StringBuilder compiler support
Browse files Browse the repository at this point in the history
  • Loading branch information
leppie committed Sep 15, 2019
1 parent 0850577 commit 8f7dcea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions IronScheme/IronScheme/Compiler/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.Scripting.Utils;
using BigInteger = Oyster.Math.IntX;
using System.Reflection.Emit;
using System.Text;

namespace IronScheme.Compiler
{
Expand Down Expand Up @@ -102,6 +103,11 @@ protected static Expression GetCons(object args, CodeBlock cb)
SchemeChar f = (SchemeChar)args;
return Ast.Constant(new SchemeCharConstant(f));
}
else if (args is StringBuilder)
{
StringBuilder f = (StringBuilder)args;
return Ast.Constant(new StringBuilderConstant(f));
}
else
{
if (args is long)
Expand Down
27 changes: 27 additions & 0 deletions IronScheme/IronScheme/Compiler/IronSchemeConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Scripting.Generation;
using BigInteger = Oyster.Math.IntX;
using System.Diagnostics;
using System.Text;

namespace IronScheme.Compiler
{
Expand Down Expand Up @@ -317,6 +318,32 @@ public override object Create()
}
}

sealed class StringBuilderConstant : CompilerConstant
{
readonly StringBuilder value;

public StringBuilderConstant(StringBuilder f)
{
value = f;
}

public override Type Type
{
get { return typeof(StringBuilder); }
}

public override void EmitCreation(CodeGen cg)
{
cg.EmitConstant(value.ToString());
cg.EmitNew(typeof(StringBuilder), new Type[] { typeof(string) });
}

public override object Create()
{
return value;
}
}

sealed class SchemeCharConstant : CompilerConstant
{
readonly SchemeChar value;
Expand Down
2 changes: 2 additions & 0 deletions IronScheme/IronScheme/Runtime/Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ static double SafeConvert(object obj)
}
}

// todo: this can probably be easily ported to Scheme
//based on lsqrt()
[Builtin("bignum-sqrt", AllowConstantFold = true)]
public static object SqrtBigInteger(object num)
Expand Down Expand Up @@ -633,6 +634,7 @@ public static object SqrtBigInteger(object num)
return x1;
}

// todo: this can probably be easily ported to Scheme
[Builtin("bignum-sqrt-exact", AllowConstantFold = true)]
public static object ExactSqrtBigInteger(object num)
{
Expand Down

0 comments on commit 8f7dcea

Please sign in to comment.