Skip to content

Commit

Permalink
Make all unit tests pass again.
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Oct 27, 2018
1 parent 5bded60 commit da973e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Translate/ModuleTranslator.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public class Point {
}
}
public static object pt = new Point(3.5, -0.4);
public static Point pt = new Point(3.5, -0.4);
}
}
";
Expand Down
24 changes: 15 additions & 9 deletions src/Translate/TypeReferenceTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ public DataType TypeOf(Node node)
switch (dt)
{
case DictType dict:
stackq.Push(dt);
stackq.Push(dt);
var (dtKey, nmKey) = Translate(dict.KeyType);
var (dtValue, nmValue) = Translate(dict.ValueType);
var nms = Join(nmKey, nmValue);
stackq.Pop();
return (
new CodeTypeReference("Dictionary", dtKey, dtValue),
Join(nms, GenericCollectionNamespace));
case InstanceType inst:
return (new CodeTypeReference(typeof(object)), null);
return TranslateInstance(inst);
case ListType list:
stackq.Push(dt);
var (dtElem, nmElem) = Translate(list.eltType);
Expand Down Expand Up @@ -117,7 +118,10 @@ public DataType TypeOf(Node node)
case TupleType tuple:
return TranslateTuple(tuple);
case FunType fun:
return TranslateFunc(fun);
stackq.Push(dt);
var ft = TranslateFunc(fun);
stackq.Pop();
return ft;
case ClassType classType:
return (
new CodeTypeReference(classType.name),
Expand All @@ -130,15 +134,21 @@ public DataType TypeOf(Node node)
throw new NotImplementedException($"Data type {dt} ({dt.GetType().Name}).");
}

private (CodeTypeReference, ISet<string>) TranslateInstance(InstanceType inst)
{
if (inst == DataType.Unknown)
return (new CodeTypeReference(typeof(object)
), null);
return this.Translate(inst.classType);
}

private (CodeTypeReference, ISet<string>) TranslateFunc(FunType fun)
{
if (fun.arrows.Count != 0)
{
// Pick an arrow at random.
var arrow = fun.arrows.First();
stackq.Push(fun);
var (args, nms) = Translate(arrow.Key);
stackq.Pop();
var s = arrow.Value.GetType().Name;
if (arrow.Value is InstanceType i && i.classType is ClassType c && c.name == "None")
{
Expand All @@ -148,9 +158,7 @@ public DataType TypeOf(Node node)
}
else
{
stackq.Push(fun);
var (ret, nmsRet) = Translate(arrow.Value);
stackq.Pop();
return (
new CodeTypeReference("Func", args),
Join(nms, Join(nmsRet, SystemNamespace)));
Expand Down Expand Up @@ -182,9 +190,7 @@ public DataType TypeOf(Node node)
var elementTypes = new List<CodeTypeReference>();
foreach (var type in types)
{
stackq.Push(type);
var (et, nm) = Translate(type);
stackq.Pop();
elementTypes.Add(et);
namespaces = Join(namespaces, nm);
}
Expand Down

0 comments on commit da973e1

Please sign in to comment.