Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
108 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
|
|
||
| """ | ||
| pyWasm | ||
| """ | ||
| from .src.utils import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from shapely.geometry import MultiPoint | ||
|
|
||
| def py_simple_add(a, b): | ||
| return a + b | ||
|
|
||
| def py_fibonacci(n): | ||
| """https://stackoverflow.com/a/52133289/2536357""" | ||
| i = 0 | ||
| nextterm = 1 | ||
| present = 1 | ||
| previous = 0 | ||
|
|
||
| while i < n: | ||
| nextterm = present + previous | ||
| present = previous | ||
| previous = nextterm | ||
| i = i + 1 | ||
|
|
||
| return nextterm | ||
|
|
||
| def py_shapely_convex_hull(shp=None): | ||
| if shp is None: | ||
| shp = tuple([ | ||
| (0.0, 0.0), | ||
| (4.0, 0.0), | ||
| (4.0, 1.0), | ||
| (1.0, 1.0), | ||
| (1.0, 4.0), | ||
| (0.0, 4.0), | ||
| (0.0, 0.0), | ||
| ]) | ||
|
|
||
| MultiPoint(shp).convex_hull | ||
|
|
||
| def py_reverse_string(string): | ||
| return string[::1] | ||
|
|
||
| try: | ||
| from pywasm.src.utils import allocate_bytes, write_to_memory, address_to_utf8 | ||
| except: | ||
| import sys | ||
| from os.path import abspath, dirname | ||
| sys.path.insert(0, abspath(dirname(dirname(dirname(__file__))))) | ||
| from pywasm.src.utils import allocate_bytes, write_to_memory, address_to_utf8 | ||
|
|
||
| def test_reverse(instance, func, bytestr): | ||
| """A simple string reversing test using Wasm memory""" | ||
| mem_view = allocate_bytes(instance) | ||
|
|
||
| mem_view = write_to_memory(bytestr, mem_view, offset=0) | ||
|
|
||
| result = func(0, len(bytestr)) | ||
|
|
||
| return address_to_utf8(mem_view, result, len(bytestr)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from distutils.core import setup | ||
|
|
||
| setup( | ||
| name='pywasm', | ||
| version='0.1dev', | ||
| packages=['pywasm',], | ||
| license='Apache 2.0', | ||
| long_description=open('README.md').read(), | ||
| ) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """ | ||
| Memeory Allocation Utilities | ||
| """ | ||
| def allocate_bytes(instance, size=8): | ||
| """Create a view for an instance""" | ||
| mem = instance.memory | ||
| return mem.uint8_view() | ||
|
|
||
| def write_to_memory(bytestr, mem_view, offset=0): | ||
| """Fill memory with values""" | ||
| for i, c in enumerate(bytestr): | ||
| mem_view[i] = c | ||
| return mem_view | ||
|
|
||
| def address_to_utf8(mem_view, address, length): | ||
| """Read from address into UTF-8""" | ||
| codes = mem_view[address:address+length] | ||
|
|
||
| string_ = '' | ||
| for i, c in enumerate(codes): | ||
| string_ += chr(c) | ||
|
|
||
| return string_.encode() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters