• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dart-lang / wasm / 4775430471

23 Apr 2023 12:22AM UTC coverage: 90.827%. Remained the same
4775430471

push

github

GitHub
Fix formatting (#142)

604 of 665 relevant lines covered (90.83%)

13.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/wasm/lib/src/wasmer_api.dart
1
// Copyright (c) 2020, the Dart project authors.  Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4

5
// This file has been automatically generated. Please do not edit it manually.
6
// To regenerate the file, use the following command
7
// "generate_ffi_boilerplate.py".
8

9
import 'dart:convert';
10
import 'dart:ffi';
11
import 'dart:typed_data';
12

13
part 'wasmer_api.g.dart';
14

15
// wasm_valkind_enum
16
const int wasmerValKindI32 = 0;
17
const int wasmerValKindI64 = 1;
18
const int wasmerValKindF32 = 2;
19
const int wasmerValKindF64 = 3;
20
// The void tag is not part of the C API. It's used to represent the return type
21
// of a void function.
22
const int wasmerValKindVoid = -1;
23

24
// wasm_externkind_enum
25
const int wasmerExternKindFunction = 0;
26
const int wasmerExternKindGlobal = 1;
27
const int wasmerExternKindTable = 2;
28
const int wasmerExternKindMemory = 3;
29

30
// wasm_mutability_enum
31
const int wasmerMutabilityConst = 0;
32
const int wasmerMutabilityVar = 1;
33

34
String wasmerExternKindName(int kind) {
13✔
35
  switch (kind) {
36
    case wasmerExternKindFunction:
13✔
37
      return 'function';
38
    case wasmerExternKindGlobal:
13✔
39
      return 'global';
40
    case wasmerExternKindTable:
13✔
41
      return 'table';
42
    case wasmerExternKindMemory:
13✔
43
      return 'memory';
44
    default:
45
      return 'unknown';
46
  }
47
}
48

49
String wasmerValKindName(int kind) {
13✔
50
  switch (kind) {
51
    case wasmerValKindI32:
13✔
52
      return 'int32';
53
    case wasmerValKindI64:
12✔
54
      return 'int64';
55
    case wasmerValKindF32:
9✔
56
      return 'float32';
57
    case wasmerValKindF64:
9✔
58
      return 'float64';
59
    case wasmerValKindVoid:
8✔
60
      return 'void';
61
    default:
62
      return 'unknown';
63
  }
64
}
65

66
String wasmerMutabilityName(int kind) {
1✔
67
  switch (kind) {
68
    case wasmerMutabilityConst:
1✔
69
      return 'const';
70
    case wasmerMutabilityVar:
1✔
71
      return 'var';
72
    default:
73
      return 'unknown';
74
  }
75
}
76

77
// wasm_val_t
78
class WasmerVal extends Struct {
79
  // wasm_valkind_t
80
  @Uint8()
81
  external int kind;
82

83
  // This is a union of int32_t, int64_t, float, and double. The kind determines
84
  // which type it is. It's declared as an int64_t because that's large enough
85
  // to hold all the types. We use ByteData to get the other types.
86
  @Int64()
87
  external int value;
88

89
  int get _off32 => Endian.host == Endian.little ? 0 : 4;
6✔
90

91
  int get i64 => value;
10✔
92

93
  ByteData get _getterBytes => ByteData(8)..setInt64(0, value, Endian.host);
12✔
94

95
  int get i32 => _getterBytes.getInt32(_off32, Endian.host);
12✔
96

97
  double get f32 => _getterBytes.getFloat32(_off32, Endian.host);
4✔
98

99
  double get f64 => _getterBytes.getFloat64(0, Endian.host);
3✔
100

101
  set i64(int val) => value = val;
8✔
102

103
  set _val(ByteData bytes) => value = bytes.getInt64(0, Endian.host);
9✔
104

105
  set i32(int val) => _val = ByteData(8)..setInt32(_off32, val, Endian.host);
15✔
106

107
  set f32(num val) =>
1✔
108
      _val = ByteData(8)..setFloat32(_off32, val as double, Endian.host);
4✔
109

110
  set f64(num val) =>
1✔
111
      _val = ByteData(8)..setFloat64(0, val as double, Endian.host);
3✔
112

113
  bool get isI32 => kind == wasmerValKindI32;
×
114

115
  bool get isI64 => kind == wasmerValKindI64;
×
116

117
  bool get isF32 => kind == wasmerValKindF32;
×
118

119
  bool get isF64 => kind == wasmerValKindF64;
×
120

121
  dynamic get toDynamic {
7✔
122
    switch (kind) {
7✔
123
      case wasmerValKindI32:
7✔
124
        return i32;
3✔
125
      case wasmerValKindI64:
5✔
126
        return i64;
5✔
127
      case wasmerValKindF32:
1✔
128
        return f32;
1✔
129
      case wasmerValKindF64:
1✔
130
        return f64;
1✔
131
    }
132
  }
133

134
  bool fill(int kind_, dynamic val) {
7✔
135
    kind = kind_;
7✔
136
    switch (kind) {
7✔
137
      case wasmerValKindI32:
7✔
138
        if (val is! int) return false;
3✔
139
        i32 = val;
3✔
140
        return true;
141
      case wasmerValKindI64:
5✔
142
        if (val is! int) return false;
5✔
143
        i64 = val;
4✔
144
        return true;
145
      case wasmerValKindF32:
1✔
146
        if (val is! num) return false;
1✔
147
        f32 = val;
1✔
148
        return true;
149
      case wasmerValKindF64:
1✔
150
        if (val is! num) return false;
1✔
151
        f64 = val;
1✔
152
        return true;
153
    }
154
    return false;
155
  }
156
}
157

158
// wasmer_limits_t
159
class WasmerLimits extends Struct {
160
  @Uint32()
161
  external int min;
162

163
  @Uint32()
164
  external int max;
165
}
166

167
// Default maximum, which indicates no upper limit.
168
const int wasmLimitsMaxDefault = 0xffffffff;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc