Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Commit

Permalink
Removed lint from types.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Feb 21, 2017
1 parent 7a799dd commit ac32d12
Show file tree
Hide file tree
Showing 22 changed files with 505 additions and 208 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Expand Up @@ -19,6 +19,9 @@
quotes: ["error", "single", {
avoidEscape: true,
allowTemplateLiterals: false
}]
}],

// Disallow ternary operators
no-ternary: "error"
}
}
2 changes: 1 addition & 1 deletion batavia/builtins/filter.js
Expand Up @@ -8,7 +8,7 @@ function filter(args, kwargs) {
if (kwargs && Object.keys(kwargs).length > 0) {
throw new exceptions.TypeError.$pyclass("filter() doesn't accept keyword arguments")
}
return new types.filter(args, kwargs)
return new types.Filter(args, kwargs)
}
filter.__doc__ = 'filter(function or None, iterable) --> filter object\n\nReturn an iterator yielding those items of iterable for which function(item)\nis true. If function is None, return the items that are true.'

Expand Down
2 changes: 1 addition & 1 deletion batavia/builtins/map.js
Expand Up @@ -14,7 +14,7 @@ function map(args, kwargs) {
throw new exceptions.TypeError.$pyclass('map() must have at least two arguments.')
}

return new types.map(args, kwargs)
return new types.Map(args, kwargs)
}
map.__doc__ = 'map(func, *iterables) --> map object\n\nMake an iterator that computes the function using arguments from\neach of the iterables. Stops when the shortest iterable is exhausted.'

Expand Down
10 changes: 5 additions & 5 deletions batavia/types.js
Expand Up @@ -34,8 +34,8 @@ types['Complex'] = require('./types/Complex')
types['DictView'] = require('./types/DictView')
types['Ellipsis'] = require('./types/Ellipsis')

types['filter'] = require('./types/Filter')
types['map'] = require('./types/Map')
types['Filter'] = require('./types/Filter')
types['Map'] = require('./types/Map')

types['Function'] = require('./types/Function')
types['Method'] = require('./types/Method')
Expand Down Expand Up @@ -97,11 +97,11 @@ types.issubclass = function(cls, type) {
} else {
switch (typeof cls) {
case 'boolean':
return type === Bool
return type === types.Bool
case 'number':
return type === Int
return type === types.Int
case 'string':
return type === Str
return type === types.Str
case 'object':
if (type === null || type === types.NoneType) {
return cls === null
Expand Down
166 changes: 145 additions & 21 deletions batavia/types/Bool.js
Expand Up @@ -33,8 +33,13 @@ Bool.prototype.__str__ = function(args, kwargs) {

Bool.prototype.__float__ = function() {
var types = require('../types')

return new types.Float(this.valueOf() ? 1.0 : 0.0)
var this_bool
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool)
}

/**************************************************
Expand Down Expand Up @@ -185,10 +190,18 @@ Bool.prototype.__floordiv__ = function(other) {
var message = ''

if (types.isinstance(other, types.Int)) {
thisValue = this.valueOf() ? 1 : 0
if (this.valueOf()) {
thisValue = 1
} else {
thisValue = 0
}
message = 'integer division or modulo by zero'
} else {
thisValue = this.valueOf() ? 1.0 : 0.0
if (this.valueOf()) {
thisValue = 1.0
} else {
thisValue = 0.0
}
message = 'float divmod()'
}

Expand All @@ -212,6 +225,7 @@ Bool.prototype.__truediv__ = function(other) {

Bool.prototype.__mul__ = function(other) {
var types = require('../types')
var this_bool

if (types.isinstance(other, Bool)) {
if (this.valueOf() && other.valueOf()) {
Expand All @@ -220,9 +234,14 @@ Bool.prototype.__mul__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Float)) {
return new types.Float((this.valueOf() ? 1.0 : 0.0) * other.valueOf())
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool * other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return new types.Int((this.valueOf() ? 1 : 0) * other.valueOf())
return new types.Int(this_bool * other.valueOf())
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for *: 'bool' and '" + type_name(other) + "'")
} }
Expand All @@ -233,6 +252,7 @@ Bool.prototype.__mod__ = function(other) {

Bool.prototype.__add__ = function(other) {
var types = require('../types')
var this_bool

if (types.isinstance(other, Bool)) {
if (this.valueOf() && other.valueOf()) {
Expand All @@ -243,16 +263,22 @@ Bool.prototype.__add__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Float)) {
return new types.Float((this.valueOf() ? 1.0 : 0.0) + other.valueOf())
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool + other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return new types.Int(other.val.add(this.valueOf() ? 1 : 0))
return new types.Int(other.val.addthis_bool)
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for +: 'bool' and '" + type_name(other) + "'")
}
}

Bool.prototype.__sub__ = function(other) {
var types = require('../types')
var this_bool

if (types.isinstance(other, Bool)) {
if (this.valueOf() && other.valueOf()) {
Expand All @@ -265,9 +291,14 @@ Bool.prototype.__sub__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Float)) {
return new types.Float((this.valueOf() ? 1.0 : 0.0) - other.valueOf())
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool - other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return new types.Int(other.val.sub(this.valueOf() ? 1 : 0).neg())
return new types.Int(other.val.subthis_bool.neg())
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for -: 'bool' and '" + type_name(other) + "'")
}
Expand All @@ -279,6 +310,7 @@ Bool.prototype.__getitem__ = function(other) {

Bool.prototype.__lshift__ = function(other) {
var types = require('../types')
var this_bool

if (types.isinstance(other, Bool)) {
if (this.valueOf() && other.valueOf()) {
Expand All @@ -291,13 +323,19 @@ Bool.prototype.__lshift__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Int)) {
return new types.Int((this.valueOf() ? 1 : 0) << other.valueOf())
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
return new types.Int(this_bool << other.valueOf())
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for <<: 'bool' and '" + type_name(other) + "'")
} }

Bool.prototype.__rshift__ = function(other) {
var types = require('../types')
var this_bool

if (types.isinstance(other, Bool)) {
if (this.valueOf() && !other.valueOf()) {
Expand All @@ -306,56 +344,110 @@ Bool.prototype.__rshift__ = function(other) {
return new types.Int(0)
}
} else if (types.isinstance(other, types.Int)) {
return new types.Int((this.valueOf() ? 1 : 0) >> other.valueOf())
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
return new types.Int(this_bool >> other.valueOf())
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for >>: 'bool' and '" + type_name(other) + "'")
} }

Bool.prototype.__and__ = function(other) {
var types = require('../types')
var this_bool, other_bool

if (types.isinstance(other, types.Int)) {
return this.__int__().__and__(other)
} else if (types.isinstance(other, Bool)) {
return new Boolean((this.valueOf() ? 1 : 0) & (other.valueOf() ? 1 : 0))
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
if (other.valueOf()) {
other_bool = 1
} else {
other_bool = 0
}
return new Bool(this_bool & other_bool)
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for &: 'bool' and '" + type_name(other) + "'")
}
}

Bool.prototype.__xor__ = function(other) {
var types = require('../types')
var this_bool, other_bool

if (types.isinstance(other, types.Int)) {
return this.__int__().__xor__(other)
} else if (types.isinstance(other, Bool)) {
return new Boolean((this.valueOf() ? 1 : 0) ^ (other.valueOf() ? 1 : 0))
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
if (other.valueOf()) {
other_bool = 1
} else {
other_bool = 0
}
return new Bool(this_bool ^ other_bool)
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for ^: 'bool' and '" + type_name(other) + "'")
}
}

Bool.prototype.__or__ = function(other) {
var types = require('../types')
var this_bool, other_bool

if (types.isinstance(other, types.Int)) {
return this.__int__().__or__(other)
} else if (types.isinstance(other, Bool)) {
return new Boolean((this.valueOf() ? 1 : 0) | (other.valueOf() ? 1 : 0))
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
if (other.valueOf()) {
other_bool = 1
} else {
other_bool = 0
}
return new Bool(this_bool | other_bool)
} else {
throw new exceptions.TypeError.$pyclass("unsupported operand type(s) for |: 'bool' and '" + type_name(other) + "'")
}
}

Bool.prototype.__ge__ = function(other) {
var types = require('../types')
var this_bool, other_bool

if (types.isinstance(other, types.Float)) {
return new types.Float((this.valueOf() ? 1.0 : 0.0) >= other.valueOf())
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool >= other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__ge__(other)
} else if (types.isinstance(other, Bool)) {
return new Boolean((this.valueOf() ? 1 : 0) >= (other.valueOf() ? 1 : 0))
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
if (other.valueOf()) {
other_bool = 1
} else {
other_bool = 0
}
return new Bool(this_bool >= other_bool)
} else if (types.isbataviainstance(other)) {
throw new exceptions.TypeError.$pyclass('unorderable types: bool() >= ' + type_name(other) + '()')
} else {
Expand All @@ -365,13 +457,29 @@ Bool.prototype.__ge__ = function(other) {

Bool.prototype.__le__ = function(other) {
var types = require('../types')
var this_bool, other_bool

if (types.isinstance(other, types.Float)) {
return new types.Float((this.valueOf() ? 1.0 : 0.0) <= other.valueOf())
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool <= other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__le__(other)
} else if (types.isinstance(other, Bool)) {
return new Boolean((this.valueOf() ? 1 : 0) <= (other.valueOf() ? 1 : 0))
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
if (other.valueOf()) {
other_bool = 1
} else {
other_bool = 0
}
return new Bool(this_bool <= other_bool)
} else if (types.isbataviainstance(other)) {
throw new exceptions.TypeError.$pyclass('unorderable types: bool() <= ' + type_name(other) + '()')
} else {
Expand All @@ -381,13 +489,29 @@ Bool.prototype.__le__ = function(other) {

Bool.prototype.__lt__ = function(other) {
var types = require('../types')
var this_bool, other_bool

if (types.isinstance(other, types.Float)) {
return new types.Float((this.valueOf() ? 1.0 : 0.0) < other.valueOf())
if (this.valueOf()) {
this_bool = 1.0
} else {
this_bool = 0.0
}
return new types.Float(this_bool < other.valueOf())
} else if (types.isinstance(other, types.Int)) {
return this.__int__().__lt__(other)
} else if (types.isinstance(other, Bool)) {
return new Boolean((this.valueOf() ? 1 : 0) < (other.valueOf() ? 1 : 0))
if (this.valueOf()) {
this_bool = 1
} else {
this_bool = 0
}
if (other.valueOf()) {
other_bool = 1
} else {
other_bool = 0
}
return new Bool(this_bool < other_bool)
} else if (types.isbataviainstance(other)) {
throw new exceptions.TypeError.$pyclass('unorderable types: bool() < ' + type_name(other) + '()')
} else {
Expand Down

0 comments on commit ac32d12

Please sign in to comment.