|
6 | 6 | from .__expression import Block, Expression |
7 | 7 | from .__feature import Feature |
8 | 8 | from .__functionref import FunctionRef |
| 9 | +from .__global import Global |
9 | 10 | from ._binaryen import ffi, lib |
10 | | -from .internals import ( |
11 | | - BinaryenGlobalRef, |
12 | | - BinaryenHeapType, |
13 | | - BinaryenLiteral, |
14 | | - BinaryenOp, |
15 | | - BinaryenType, |
16 | | -) |
| 11 | +from .internals import BinaryenHeapType, BinaryenLiteral, BinaryenOp, BinaryenType |
17 | 12 | from .type import TypeNone |
18 | 13 |
|
19 | 14 | type BinaryenExportRef = Any |
@@ -60,10 +55,10 @@ def i32(self, value: int): |
60 | 55 | def i64(self, value: int): |
61 | 56 | return self.const(literal.int64(value)) |
62 | 57 |
|
63 | | - def f32(self, value: int): |
| 58 | + def f32(self, value: float): |
64 | 59 | return self.const(literal.float32(value)) |
65 | 60 |
|
66 | | - def f64(self, value: int): |
| 61 | + def f64(self, value: float): |
67 | 62 | return self.const(literal.float64(value)) |
68 | 63 |
|
69 | 64 | def block( |
@@ -385,11 +380,25 @@ def add_function_export( |
385 | 380 |
|
386 | 381 | def add_global( |
387 | 382 | self, name: bytes, global_type: BinaryenType, mutable: bool, init: Expression |
388 | | - ) -> BinaryenGlobalRef: |
| 383 | + ): |
389 | 384 | ref = lib.BinaryenAddGlobal(self.ref, name, global_type, mutable, init.ref) |
390 | | - return ref |
| 385 | + return Global(ref) |
| 386 | + |
| 387 | + def get_global(self, name: bytes): |
| 388 | + ref = lib.BinaryenGetGlobal(self.ref, name) |
| 389 | + if ref == ffi.NULL: |
| 390 | + return None |
| 391 | + return Global(ref) |
| 392 | + |
| 393 | + def remove_global(self, name: bytes): |
| 394 | + lib.BinaryenRemoveGlobal(self.ref, name) |
| 395 | + |
| 396 | + def get_num_globals(self): |
| 397 | + return int(lib.BinaryenGetNumGlobals(self.ref)) |
391 | 398 |
|
392 | | - # TODO: GetGlobal, RemoveGlobal, GetNumGlobals, GetGlobalByIndex |
| 399 | + def get_global_by_index(self, index: int): |
| 400 | + ref = lib.BinaryenGetGlobalByIndex(self.ref, index) |
| 401 | + return Global(ref) |
393 | 402 |
|
394 | 403 | # TODO: AddTag, GetTag, RemoveTag |
395 | 404 |
|
|
0 commit comments