[swfinterp] Implement String basics
parent
e983cf5277
commit
3cbcff8a2d
|
@ -0,0 +1,11 @@
|
||||||
|
// input: []
|
||||||
|
// output: 3
|
||||||
|
|
||||||
|
package {
|
||||||
|
public class StringBasics {
|
||||||
|
public static function main():int{
|
||||||
|
var s:String = "abc";
|
||||||
|
return s.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
// input: []
|
||||||
|
// output: 2
|
||||||
|
|
||||||
|
package {
|
||||||
|
public class StringConversion {
|
||||||
|
public static function main():int{
|
||||||
|
var s:String = String(99);
|
||||||
|
return s.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -148,6 +148,9 @@ def _read_byte(reader):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
StringClass = _AVMClass('(no name idx)', 'String')
|
||||||
|
|
||||||
|
|
||||||
class SWFInterpreter(object):
|
class SWFInterpreter(object):
|
||||||
def __init__(self, file_contents):
|
def __init__(self, file_contents):
|
||||||
self._patched_functions = {}
|
self._patched_functions = {}
|
||||||
|
@ -483,6 +486,17 @@ class SWFInterpreter(object):
|
||||||
res = args[0].join(obj)
|
res = args[0].join(obj)
|
||||||
stack.append(res)
|
stack.append(res)
|
||||||
continue
|
continue
|
||||||
|
elif obj == StringClass:
|
||||||
|
if mname == 'String':
|
||||||
|
assert len(args) == 1
|
||||||
|
assert isinstance(args[0], (int, compat_str))
|
||||||
|
res = compat_str(args[0])
|
||||||
|
stack.append(res)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(
|
||||||
|
'Function String.%s is not yet implemented'
|
||||||
|
% mname)
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'Unsupported property %r on %r'
|
'Unsupported property %r on %r'
|
||||||
% (mname, obj))
|
% (mname, obj))
|
||||||
|
@ -532,7 +546,10 @@ class SWFInterpreter(object):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
res = scopes[0]
|
res = scopes[0]
|
||||||
stack.append(res[mname])
|
if mname not in res and mname == 'String':
|
||||||
|
stack.append(StringClass)
|
||||||
|
else:
|
||||||
|
stack.append(res[mname])
|
||||||
elif opcode == 94: # findproperty
|
elif opcode == 94: # findproperty
|
||||||
index = u30()
|
index = u30()
|
||||||
mname = self.multinames[index]
|
mname = self.multinames[index]
|
||||||
|
@ -576,7 +593,7 @@ class SWFInterpreter(object):
|
||||||
pname = self.multinames[index]
|
pname = self.multinames[index]
|
||||||
if pname == 'length':
|
if pname == 'length':
|
||||||
obj = stack.pop()
|
obj = stack.pop()
|
||||||
assert isinstance(obj, list)
|
assert isinstance(obj, (compat_str, list))
|
||||||
stack.append(len(obj))
|
stack.append(len(obj))
|
||||||
elif isinstance(pname, compat_str): # Member access
|
elif isinstance(pname, compat_str): # Member access
|
||||||
obj = stack.pop()
|
obj = stack.pop()
|
||||||
|
|
Loading…
Reference in New Issue