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

The def code function doesn't compile correctly. #98

Open
ChrisCalderon opened this issue Apr 5, 2016 · 1 comment
Open

The def code function doesn't compile correctly. #98

ChrisCalderon opened this issue Apr 5, 2016 · 1 comment

Comments

@ChrisCalderon
Copy link

Here is my little python test:

import warnings; warnings.simplefilter('ignore')
from ethereum import tester as t
import serpent

s = t.state()
code = '''\
def code():
    FOO = 1

def shared():
    BAR = 1

def f(x):
    return([x+1, FOO, BAR]:arr)
'''

print serpent.compile_to_lll(code)
c = s.abi_contract(code)
print c.f(2)

When run, this outputs:

(seq 
  (set 'BAR 1)
  (return 0 
    (lll 
      (with '__funid 
        (div (calldataload 0) 
          26959946667150639794667015087019630673637144422540572481103610249216
        )
        (seq 
          (set 'BAR 1)
          (unless (iszero (eq (get '__funid) 616639478)) (set (get 'FOO) 1))
          (unless (iszero (eq (get '__funid) 469798393)) 
            (seq 
              (set 'x (calldataload 4))
              (with '_temp_900 
                (with '_temp93_arr (alloc 128) 
                  (seq 
                    (mstore (get '_temp93_arr) 3)
                    (mstore (add (get '_temp93_arr) 32) (add (get 'x) 1))
                    (mstore (add (get '_temp93_arr) 64) (get 'FOO))
                    (mstore (add (get '_temp93_arr) 96) (get 'BAR))
                    (add (get '_temp93_arr) 32)
                  )
                )
                (seq 
                  (mstore (sub (get '_temp_900) 64) 32)
                  (return (sub (get '_temp_900) 64) (add 64 (mul (mload (sub (get '_temp_900) 32)) 32)))
                )
              )
            )
          )
        )
      )
      0
    )
  )
)
[3, 0, 1]

As can be seen in the LLL, the code function gets turned into a normal function call; the line (unless (iszero (eq (get '__funid) 616639478)) (set (get 'FOO) 1)) should be (set 'FOO 1).

@ChrisCalderon
Copy link
Author

Maybe the serpent docs should just change def code(): to def any():?

https://github.com/ethereum/serpent/blob/develop/preprocess.cpp#L337

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant