public override void CompileToDoubleOrNan() { Variable doubleVar; if (NumberVariables.TryGetValue(cellAddr, out doubleVar)) { doubleVar.EmitLoad(ilg); } else { if (var.Type == Typ.Value) { var.EmitLoad(ilg); UnwrapToDoubleOrNan(); } else if (var.Type == Typ.Number) { var.EmitLoad(ilg); } else // A variable of a type not convertible to a float64, so ArgTypeError { LoadErrorNan(ErrorValue.argTypeError); } } }
/// <summary> /// Insert code to unwrap the computed value of a cell, if the cell /// has type Value but is referred to as a Number more than once. /// Also register the unwrapped version of the variable /// in the NumberVariables dictionary. /// CodeGenerate.Initialize(ilg) must be called first. /// </summary> public void CreateUnwrappedNumberCells() { HashBag <FullCellAddr> numberUses = CountNumberUses(); foreach (KeyValuePair <FullCellAddr, int> numberUseCount in numberUses.ItemMultiplicities()) { FullCellAddr fca = numberUseCount.Key; if (numberUseCount.Value >= 2 && addressToVariable[fca].Type == Typ.Value) { Variable numberVar = new LocalVariable(fca + "_number", Typ.Number); ComputeCell ccell; if (fcaToComputeCell.TryGetValue(fca, out ccell)) // fca is ordinary computed cell { ccell.NumberVar = numberVar; } else // fca is an input cell { unwrapInputCells.Add(new UnwrapInputCell(addressToVariable[fca], numberVar)); } NumberVariables.Add(fca, numberVar); } } }