Permalink
Browse files

Added STORE_GLOBAL and a test in test_basic. (#22)

* Added byte_STORE_GLOBAL

* Added a test, I think.

I used this small script to test STORE_GLOBAL and it worked.
  • Loading branch information...
1 parent de85193 commit 31e6c4a8212c35b5157919abff43a7daa0f377c6 @z0rberg z0rberg committed with llllllllll Nov 3, 2016
Showing with 20 additions and 0 deletions.
  1. +4 −0 byterun/pyvm2.py
  2. +16 −0 tests/test_basic.py
View
@@ -424,6 +424,10 @@ def byte_LOAD_GLOBAL(self, name):
raise NameError("global name '%s' is not defined" % name)
self.push(val)
+ def byte_STORE_GLOBAL(self, name):
+ f = self.frame
+ f.f_globals[name] = self.pop()
+
def byte_LOAD_DEREF(self, name):
self.push(self.frame.cells[name].get())
View
@@ -12,6 +12,22 @@ class TestIt(vmtest.VmTestCase):
def test_constant(self):
self.assert_ok("17")
+ def test_globals(self):
+ self.assert_ok("""\
+ global xyz
+ xyz=2106
+
+ def abc():
+ global xyz
+ xyz+=1
+ print("Midst:",xyz)
+
+
+ print "Pre:",xyz
+ abc()
+ print "Post:",xyz
+ """)
+
def test_for_loop(self):
self.assert_ok("""\
out = ""

0 comments on commit 31e6c4a

Please sign in to comment.