Code coverage report for sc/lang/klass/constructors.js

Statements: 100% (129 / 129)      Branches: 100% (14 / 14)      Functions: 100% (21 / 21)      Lines: 100% (129 / 129)      Ignored: none     

All files » sc/lang/klass/ » constructors.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 2291     1 1 1   1 1   1       1       1       1 1   1   1       1 1   1       1       1 1 1   1   3361 3361       1   1   1       1 1 1 1   1   4       1   1       1 1 1       1     1 1 1 1   1 1 1 1   1 1 1 1   1 1 1 1   1 2015     1 3376     1 270     1 256     1 15837   15837 15     15822   15822 233 233 233     15822     1 2782   2782   2782 596 596 596     2782     1 1051 1051 1051 228 228 228   1051     1 2270   2270   2270 128 128 128     2270     1 2597 2597 2597 2597     1 168 168 168 168     1 1 1 1 1 1   1     1 1731 1731 1731     1 1474 1474       1 1 1 1     1 1 1 1 1    
(function(sc) {
  "use strict";
 
  require("./klass");
  require("./define");
  require("../bytecode");
 
  var $ = sc.lang.$;
  var define = sc.lang.klass.define;
 
  var SCNil = define("Nil", {
    __tag: sc.TAG_NIL
  });
 
  var SCSymbol = define("Symbol", {
    __tag: sc.TAG_SYM
  });
 
  define("Boolean", {
    __tag: sc.TAG_BOOL
  });
 
  var SCTrue  = define("True  : Boolean");
  var SCFalse = define("False : Boolean");
 
  define("Magnitude");
 
  var SCChar = define("Char : Magnitude", {
    __tag: sc.TAG_CHAR
  });
 
  define("Number : Magnitude");
  define("SimpleNumber : Number");
 
  var SCInteger = define("Integer : SimpleNumber", {
    __tag: sc.TAG_INT
  });
 
  var SCFloat = define("Float : SimpleNumber", {
    __tag: sc.TAG_FLOAT
  });
 
  define("Association : Magnitude");
  define("Collection");
  define("SequenceableCollection : Collection");
 
  define("ArrayedCollection : SequenceableCollection", {
    constructor: function SCArrayedCollection() {
      this.__super__("SequenceableCollection");
      this._ = [];
    }
  });
 
  define("RawArray : ArrayedCollection");
 
  var SCArray = define("Array : ArrayedCollection");
 
  var SCString = define("String : RawArray", {
    __tag: sc.TAG_STR
  });
 
  define("Set : Collection");
  define("Dictionary : Set");
  define("IdentityDictionary : Dictionary");
  define("Environment : IdentityDictionary");
 
  define("Event : Environment", {
    constructor: function SCEvent() {
      this.__super__("Environment");
    }
  });
 
  define("AbstractFunction");
 
  var SCFunction = define("Function : AbstractFunction", {
    __tag: sc.TAG_FUNC
  });
 
  define("Stream : AbstractFunction");
  define("Thread : Stream");
  define("Routine : Thread", {
    __tag: sc.TAG_ROUTINE
  });
 
  var SCRef = define("Ref : AbstractFunction");
 
  // $
  var $nil = (function() {
    var instance = new SCNil();
    instance._ = null;
    return instance;
  })();
  var $true = (function() {
    var instance = new SCTrue();
    instance._ = true;
    return instance;
  })();
  var $false = (function() {
    var instance = new SCFalse();
    instance._ = false;
    return instance;
  })();
  var $integers = {};
  var $floats   = {};
  var $symbols  = {};
  var $chars    = {};
 
  $.addProperty("Nil", function() {
    return $nil;
  });
 
  $.addProperty("Boolean", function(value) {
    return value ? $true : $false;
  });
 
  $.addProperty("True", function() {
    return $true;
  });
 
  $.addProperty("False", function() {
    return $false;
  });
 
  $.addProperty("Integer", function(value) {
    var instance;
 
    if (!global.isFinite(value)) {
      return $.Float(+value);
    }
 
    value = value|0;
 
    if (!$integers.hasOwnProperty(value)) {
      instance = new SCInteger();
      instance._ = value;
      $integers[value] = instance;
    }
 
    return $integers[value];
  });
 
  $.addProperty("Float", function(value) {
    var instance;
 
    value = +value;
 
    if (!$floats.hasOwnProperty(value)) {
      instance = new SCFloat();
      instance._ = value;
      $floats[value] = instance;
    }
 
    return $floats[value];
  });
 
  $.addProperty("Symbol", function(value) {
    var instance;
    value = String(value);
    if (!$symbols.hasOwnProperty(value)) {
      instance = new SCSymbol();
      instance._ = value;
      $symbols[value] = instance;
    }
    return $symbols[value];
  });
 
  $.addProperty("Char", function(value) {
    var instance;
 
    value = String(value).charAt(0);
 
    if (!$chars.hasOwnProperty(value)) {
      instance = new SCChar();
      instance._ = value;
      $chars[value] = instance;
    }
 
    return $chars[value];
  });
 
  $.addProperty("Array", function(value, immutable) {
    var instance = new SCArray();
    instance._ = value || [];
    instance.__immutable = !!immutable;
    return instance;
  });
 
  $.addProperty("String", function(value, mutable) {
    var instance = new SCString();
    instance._ = String(value).split("").map($.Char);
    instance.__immutable = !mutable;
    return instance;
  });
 
  $.addProperty("Event", function(value) {
    var instance, i, imax, j;
    i = imax = j = value;
    instance = $("Event").new();
    for (i = j = 0, imax = value.length >> 1; i < imax; ++i) {
      instance.put(value[j++], value[j++]);
    }
    return instance;
  });
 
  $.addProperty("Function", function(value, def) {
    var instance = new SCFunction();
    instance._bytecode = sc.lang.bytecode.create(value, def).setOwner(instance);
    return instance;
  });
 
  $.addProperty("Func", function(func) {
    return $.Function(function() {
      return [ func ];
    });
  });
 
  $.addProperty("Ref", function(value) {
    var instance = new SCRef();
    instance._$value = value;
    return instance;
  });
 
  $.addProperty("nil", $nil);
  $.addProperty("true", $true);
  $.addProperty("false", $false);
  $.addProperty("int0", $.Integer(0));
  $.addProperty("int1", $.Integer(1));
})(sc);