-
Notifications
You must be signed in to change notification settings - Fork 6
/
spec_structure.py
117 lines (94 loc) · 2.67 KB
/
spec_structure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""
PyWebAssembly - Implmentation of WebAssembly, and some tools.
Copyright (C) 2018-2019 Paul Dworzanski
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
verbose = 0
###############
###############
# 2 STRUCTURE #
###############
###############
#Chapter 2 defines the abstract syntax, which is used throughout the implementation. Not much is needed from this section, since most abstrct syntax is nested lists and dictionaries
# 2.2.3 FLOATING-POINT
# functions in this sectio are not currently used since we decided to use native Python floats, and struct.pack()/unpack() to encode/decode, but we may use these later to pass the rest of the NaN tests
def spec_fN(N,f):
fNmag = spec_fNmag(N,f)
if f>=0:
return fNmag
else:
return -1*fNmag
def spec_fNmag(N,f):
M=spec_signif(N)
E=spec_expon(N)
e=bitstring[1:E+1]
m=bitstring[E+1:]
if -1*(2**(E-1)) + 2 <= e <= 2**(E-1)-1:
pass
def spec_signif(N):
if verbose>=1: print("spec_signif(",N,")")
if N==32:
return 23
elif N==64:
return 52
else:
return None
def spec_signif_inv(signif):
if verbose>=1: print("spec_signif_inv(",signif,")")
if signif == 23:
return 32
elif signif == 52:
return 64
else:
return None
def spec_expon(N):
if verbose>=1: print("spec_expon(",N,")")
if N==32:
return 8
elif N==64:
return 11
else:
return None
def spec_expon_inv(expon):
if verbose>=1: print("spec_expon_inv(",expon,")")
if expon == 8:
return 32
elif expon == 11:
return 64
else:
return None
# 2.3.8 EXTERNAL TYPES
#similar things are defined in 2.5.10 and 4.2.11, we will reuse these for those
def spec_funcs(star):
funcs = []
for e in star:
if e[0] == 'func':
funcs += [e[1]]
return funcs
def spec_tables(star):
tables = []
for e in star:
if e[0] == 'table':
tables += [e[1]]
return tables
def spec_mems(star):
mems = []
for e in star:
if e[0] == 'mem':
mems += [e[1]]
return mems
def spec_globals(star):
globals_ = []
for e in star:
if e[0] == 'global':
globals_ += [e[1]]
return globals_