Skip to content

Commit

Permalink
hopefully fixes readme
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Apr 6, 2011
1 parent 9350ddd commit bf88eb5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ Credits
License
-------
pyasm
:copyright: 2008 by Florian Boesch <pyalot@gmail.com>.
:license: GNU AGPL v3 or later, see LICENSE for more details.
:copyright: 2008 by Florian Boesch <pyalot@gmail.com>.
:license: GNU AGPL v3 or later, see LICENSE for more details.
pynarcissus
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The Initial Developer of the Original Code is
Brendan Eich <brendan@mozilla.org>.
Portions created by the Initial Developer are Copyright (C) 2004
the Initial Developer. All Rights Reserved.
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The Initial Developer of the Original Code is
Brendan Eich <brendan@mozilla.org>.
Portions created by the Initial Developer are Copyright (C) 2004
the Initial Developer. All Rights Reserved.

7 changes: 5 additions & 2 deletions compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ def add_property(obj, key, value):
obj.addProperty(str, value)

for node in nodes:
self.compile_node(node[0])
string = new_string(str(node[0].value))
self.frame.push_string(addressof(string))
self.compile_node(node[1])

obj = self.frame.peek(-3)
Expand Down Expand Up @@ -934,7 +935,9 @@ def typeof(v):
return addressof(self.rt.typeof(v))

self.call(typeof, t)
self.frame.push('string', eax)
reg = self.frame.alloc_reg()
self.assembler.mov(reg, eax)
self.frame.push('string', reg)

def op_nop(self, node):
pass
Expand Down
9 changes: 8 additions & 1 deletion object.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ def int(value):
def object(pointer):
return Value((addressof(pointer) << 1) | 1)

@staticmethod
def boolean(value):
self.raw = Value.true if value else Value.false

def isInt(self):
return not bool(self.raw & 1)

Expand Down Expand Up @@ -296,13 +300,16 @@ def dump(self):
shape = obj.getShape()
while True:
if shape.name:
print ' ' + shape.name
print ' %s: %d' % (shape.name, obj.getProperties()[shape.slot])

if shape.next:
shape = shape.next[0]
else:
break

for i in range(0, shape.length):
print ' %d: %d' % (i, obj.getElements()[i])

class Error:
pass

Expand Down
32 changes: 15 additions & 17 deletions runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def typeof(self, v):
def type(self, v):
if v.isInteger():
return ecma_type['number']
if v.isBool():
if v.isBoolean():
return ecma_type['boolean']
if v.isNull():
return ecma_type['null']
Expand Down Expand Up @@ -102,43 +102,41 @@ def toNumber(self, v):

def toBoolean(self, v):
if v.isUndefined():
return boxed_bool(False)
return Value(Value.false)
if v.isNull():
return boxed_bool(False)
return Value(Value.false)
if v.isBool():
return v
if v.isInteger():
return boxed_bool(v.toInteger())
return Value.boolean(v.toInteger())

obj = v.toObject()
if obj.isObject():
return boxed_bool(True)
return Value(Value.true)
if obj.isString():
if len(obj.to(PrimitiveString).str):
return boxed_bool(True)
return boxed_bool(False)
return Value.boolean(obj.toPrimitive())

assert obj.isDouble()
double_value = obj.to(PrimitiveDouble).value
if math.isnan(double_value):
return boxed_bool(False)
return boxed_bool(double_value)
double = obj.toPrimitive()
if math.isnan(double):
return Value(Value.false)
return Value.boolean(double)

def toString(self, v):
if v.isUndefined():
return boxed_object(self.strings['undefined'])
return Value.object(self.strings['undefined'])
if v.isNull():
return boxed_object(self.strings['null'])
return Value.object(self.strings['null'])
if v.isBool():
return boxed_object(self.strings['true'] if v.toBoolean() else self.strings['false'])
return Value.object(self.strings['true'] if v.toBoolean() else self.strings['false'])
if v.isInteger():
return boxed_object(new_string(str(v.toInteger())))
return Value.object(new_string(str(v.toInteger())))

assert v.isObject()
obj = v.toObject()
if obj.isPrimitive():
if obj.isDouble():
return boxed_number(obj.toPrimitive())
return Value.object(new_string(str(obj.toPrimitive())))
else:
return v

Expand Down

0 comments on commit bf88eb5

Please sign in to comment.