Skip to content

Commit b296fcc

Browse files
committed
Indent with 4 spaces
1 parent eda1648 commit b296fcc

File tree

1 file changed

+160
-160
lines changed

1 file changed

+160
-160
lines changed

Python/emscripten_trampoline.c

Lines changed: 160 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef int (*CountArgsFunc)(PyCFunctionWithKeywords func);
2121
EMSCRIPTEN_KEEPALIVE const int _PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET = offsetof(_PyRuntimeState, emscripten_count_args_function);
2222

2323
EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), {
24-
return Module._PyEM_CountArgsPtr; // initialized below
24+
return Module._PyEM_CountArgsPtr; // initialized below
2525
}
2626
// Binary module for the checks. It has to be done in web assembly because
2727
// clang/llvm have no support yet for the reference types yet. In fact, the wasm
@@ -33,162 +33,162 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), {
3333
// gets us the output we need.
3434
//
3535
// (module
36-
// (type $type0 (func (param) (result i32)))
37-
// (type $type1 (func (param i32) (result i32)))
38-
// (type $type2 (func (param i32 i32) (result i32)))
39-
// (type $type3 (func (param i32 i32 i32) (result i32)))
40-
// (type $type4 (func (param i32 i32 i32 i32) (result i32)))
41-
// (type $blocktype (func (param i32) (result)))
42-
// (table $funcs (import "e" "t") 0 funcref)
43-
// (export "f" (func $f))
44-
// (func $f (param $fptr i32) (result i32)
45-
// (local $fref funcref)
46-
// local.get $fptr
47-
// table.get $funcs
48-
// local.tee $fref
49-
// ref.test $type4
50-
// (block $b (type $blocktype)
51-
// i32.eqz
52-
// br_if $b
53-
// i32.const 4
54-
// return
36+
// (type $type0 (func (param) (result i32)))
37+
// (type $type1 (func (param i32) (result i32)))
38+
// (type $type2 (func (param i32 i32) (result i32)))
39+
// (type $type3 (func (param i32 i32 i32) (result i32)))
40+
// (type $type4 (func (param i32 i32 i32 i32) (result i32)))
41+
// (type $blocktype (func (param i32) (result)))
42+
// (table $funcs (import "e" "t") 0 funcref)
43+
// (export "f" (func $f))
44+
// (func $f (param $fptr i32) (result i32)
45+
// (local $fref funcref)
46+
// local.get $fptr
47+
// table.get $funcs
48+
// local.tee $fref
49+
// ref.test $type4
50+
// (block $b (type $blocktype)
51+
// i32.eqz
52+
// br_if $b
53+
// i32.const 4
54+
// return
55+
// )
56+
// local.get $fref
57+
// ref.test $type3
58+
// (block $b (type $blocktype)
59+
// i32.eqz
60+
// br_if $b
61+
// i32.const 3
62+
// return
63+
// )
64+
// local.get $fref
65+
// ref.test $type2
66+
// (block $b (type $blocktype)
67+
// i32.eqz
68+
// br_if $b
69+
// i32.const 2
70+
// return
71+
// )
72+
// local.get $fref
73+
// ref.test $type1
74+
// (block $b (type $blocktype)
75+
// i32.eqz
76+
// br_if $b
77+
// i32.const 1
78+
// return
79+
// )
80+
// local.get $fref
81+
// ref.test $type0
82+
// (block $b (type $blocktype)
83+
// i32.eqz
84+
// br_if $b
85+
// i32.const 0
86+
// return
87+
// )
88+
// i32.const -1
5589
// )
56-
// local.get $fref
57-
// ref.test $type3
58-
// (block $b (type $blocktype)
59-
// i32.eqz
60-
// br_if $b
61-
// i32.const 3
62-
// return
63-
// )
64-
// local.get $fref
65-
// ref.test $type2
66-
// (block $b (type $blocktype)
67-
// i32.eqz
68-
// br_if $b
69-
// i32.const 2
70-
// return
71-
// )
72-
// local.get $fref
73-
// ref.test $type1
74-
// (block $b (type $blocktype)
75-
// i32.eqz
76-
// br_if $b
77-
// i32.const 1
78-
// return
79-
// )
80-
// local.get $fref
81-
// ref.test $type0
82-
// (block $b (type $blocktype)
83-
// i32.eqz
84-
// br_if $b
85-
// i32.const 0
86-
// return
87-
// )
88-
// i32.const -1
89-
// )
9090
// )
9191
addOnPreRun(() => {
92-
// Try to initialize countArgsFunc
93-
const code = new Uint8Array([
94-
0x00, 0x61, 0x73, 0x6d, // \0asm magic number
95-
0x01, 0x00, 0x00, 0x00, // version 1
96-
0x01, 0x23, // Type section, body is 0x23 bytes
97-
0x06, // 6 entries
98-
0x60, 0x00, 0x01, 0x7f, // (type $type0 (func (param) (result i32)))
99-
0x60, 0x01, 0x7f, 0x01, 0x7f, // (type $type1 (func (param i32) (result i32)))
100-
0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, // (type $type2 (func (param i32 i32) (result i32)))
101-
0x60, 0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, // (type $type3 (func (param i32 i32 i32) (result i32)))
102-
0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, // (type $type4 (func (param i32 i32 i32 i32) (result i32)))
103-
0x60, 0x01, 0x7f, 0x00, // (type $blocktype (func (param i32) (result)))
104-
0x02, 0x09, // Import section, 0x9 byte body
105-
0x01, // 1 import (table $funcs (import "e" "t") 0 funcref)
106-
0x01, 0x65, // "e"
107-
0x01, 0x74, // "t"
108-
0x01, // importing a table
109-
0x70, // of entry type funcref
110-
0x00, 0x00, // table limits: no max, min of 0
111-
0x03, 0x02, // Function section
112-
0x01, 0x01, // We're going to define one function of type 1 (func (param i32) (result i32))
113-
0x07, 0x05, // export section
114-
0x01, // 1 export
115-
0x01, 0x66, // called "f"
116-
0x00, // a function
117-
0x00, // at index 0
92+
// Try to initialize countArgsFunc
93+
const code = new Uint8Array([
94+
0x00, 0x61, 0x73, 0x6d, // \0asm magic number
95+
0x01, 0x00, 0x00, 0x00, // version 1
96+
0x01, 0x23, // Type section, body is 0x23 bytes
97+
0x06, // 6 entries
98+
0x60, 0x00, 0x01, 0x7f, // (type $type0 (func (param) (result i32)))
99+
0x60, 0x01, 0x7f, 0x01, 0x7f, // (type $type1 (func (param i32) (result i32)))
100+
0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, // (type $type2 (func (param i32 i32) (result i32)))
101+
0x60, 0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, // (type $type3 (func (param i32 i32 i32) (result i32)))
102+
0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, // (type $type4 (func (param i32 i32 i32 i32) (result i32)))
103+
0x60, 0x01, 0x7f, 0x00, // (type $blocktype (func (param i32) (result)))
104+
0x02, 0x09, // Import section, 0x9 byte body
105+
0x01, // 1 import (table $funcs (import "e" "t") 0 funcref)
106+
0x01, 0x65, // "e"
107+
0x01, 0x74, // "t"
108+
0x01, // importing a table
109+
0x70, // of entry type funcref
110+
0x00, 0x00, // table limits: no max, min of 0
111+
0x03, 0x02, // Function section
112+
0x01, 0x01, // We're going to define one function of type 1 (func (param i32) (result i32))
113+
0x07, 0x05, // export section
114+
0x01, // 1 export
115+
0x01, 0x66, // called "f"
116+
0x00, // a function
117+
0x00, // at index 0
118118

119-
0x0a, 0x52, // Code section,
120-
0x01, 0x50, // one entry of length 50
121-
0x01, 0x01, 0x70, // one local of type funcref
122-
// Body of the function
123-
0x20, 0x00, // local.get $fptr
124-
0x25, 0x00, // table.get $funcs
125-
0x22, 0x01, // local.tee $fref
126-
0xfb, 0x14, 0x04, // ref.test $type4
127-
0x02, 0x05, // block $b (type $blocktype)
128-
0x45, // i32.eqz
129-
0x0d, 0x00, // br_if $b
130-
0x41, 0x04, // i32.const 4
131-
0x0f, // return
132-
0x0b, // end block
119+
0x0a, 0x52, // Code section,
120+
0x01, 0x50, // one entry of length 50
121+
0x01, 0x01, 0x70, // one local of type funcref
122+
// Body of the function
123+
0x20, 0x00, // local.get $fptr
124+
0x25, 0x00, // table.get $funcs
125+
0x22, 0x01, // local.tee $fref
126+
0xfb, 0x14, 0x04, // ref.test $type4
127+
0x02, 0x05, // block $b (type $blocktype)
128+
0x45, // i32.eqz
129+
0x0d, 0x00, // br_if $b
130+
0x41, 0x04, // i32.const 4
131+
0x0f, // return
132+
0x0b, // end block
133133

134-
0x20, 0x01, // local.get $fref
135-
0xfb, 0x14, 0x03, // ref.test $type3
136-
0x02, 0x05, // block $b (type $blocktype)
137-
0x45, // i32.eqz
138-
0x0d, 0x00, // br_if $b
139-
0x41, 0x03, // i32.const 3
140-
0x0f, // return
141-
0x0b, // end block
134+
0x20, 0x01, // local.get $fref
135+
0xfb, 0x14, 0x03, // ref.test $type3
136+
0x02, 0x05, // block $b (type $blocktype)
137+
0x45, // i32.eqz
138+
0x0d, 0x00, // br_if $b
139+
0x41, 0x03, // i32.const 3
140+
0x0f, // return
141+
0x0b, // end block
142142

143-
0x20, 0x01, // local.get $fref
144-
0xfb, 0x14, 0x02, // ref.test $type2
145-
0x02, 0x05, // block $b (type $blocktype)
146-
0x45, // i32.eqz
147-
0x0d, 0x00, // br_if $b
148-
0x41, 0x02, // i32.const 2
149-
0x0f, // return
150-
0x0b, // end block
143+
0x20, 0x01, // local.get $fref
144+
0xfb, 0x14, 0x02, // ref.test $type2
145+
0x02, 0x05, // block $b (type $blocktype)
146+
0x45, // i32.eqz
147+
0x0d, 0x00, // br_if $b
148+
0x41, 0x02, // i32.const 2
149+
0x0f, // return
150+
0x0b, // end block
151151

152-
0x20, 0x01, // local.get $fref
153-
0xfb, 0x14, 0x01, // ref.test $type1
154-
0x02, 0x05, // block $b (type $blocktype)
155-
0x45, // i32.eqz
156-
0x0d, 0x00, // br_if $b
157-
0x41, 0x01, // i32.const 1
158-
0x0f, // return
159-
0x0b, // end block
152+
0x20, 0x01, // local.get $fref
153+
0xfb, 0x14, 0x01, // ref.test $type1
154+
0x02, 0x05, // block $b (type $blocktype)
155+
0x45, // i32.eqz
156+
0x0d, 0x00, // br_if $b
157+
0x41, 0x01, // i32.const 1
158+
0x0f, // return
159+
0x0b, // end block
160160

161-
0x20, 0x01, // local.get $fref
162-
0xfb, 0x14, 0x00, // ref.test $type0
163-
0x02, 0x05, // block $b (type $blocktype)
164-
0x45, // i32.eqz
165-
0x0d, 0x00, // br_if $b
166-
0x41, 0x00, // i32.const 0
167-
0x0f, // return
168-
0x0b, // end block
161+
0x20, 0x01, // local.get $fref
162+
0xfb, 0x14, 0x00, // ref.test $type0
163+
0x02, 0x05, // block $b (type $blocktype)
164+
0x45, // i32.eqz
165+
0x0d, 0x00, // br_if $b
166+
0x41, 0x00, // i32.const 0
167+
0x0f, // return
168+
0x0b, // end block
169169

170-
0x41, 0x7f, // i32.const -1
171-
0x0b // end function
172-
]);
173-
let ptr = 0;
174-
try {
175-
const mod = new WebAssembly.Module(code);
176-
const inst = new WebAssembly.Instance(mod, {e: {t: wasmTable}});
177-
ptr = addFunction(inst.exports.f);
178-
} catch(e) {
179-
// If something goes wrong, we'll null out _PyEM_CountFuncParams and fall
180-
// back to the JS trampoline.
181-
}
182-
Module._PyEM_CountArgsPtr = ptr;
183-
const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET/4];
184-
HEAP32[__PyRuntime/4 + offset] = ptr;
170+
0x41, 0x7f, // i32.const -1
171+
0x0b // end function
172+
]);
173+
let ptr = 0;
174+
try {
175+
const mod = new WebAssembly.Module(code);
176+
const inst = new WebAssembly.Instance(mod, {e: {t: wasmTable}});
177+
ptr = addFunction(inst.exports.f);
178+
} catch(e) {
179+
// If something goes wrong, we'll null out _PyEM_CountFuncParams and fall
180+
// back to the JS trampoline.
181+
}
182+
Module._PyEM_CountArgsPtr = ptr;
183+
const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET/4];
184+
HEAP32[__PyRuntime/4 + offset] = ptr;
185185
});
186186
);
187187

188188
void
189189
_Py_EmscriptenTrampoline_Init(_PyRuntimeState *runtime)
190190
{
191-
runtime->emscripten_count_args_function = _PyEM_GetCountArgsPtr();
191+
runtime->emscripten_count_args_function = _PyEM_GetCountArgsPtr();
192192
}
193193

194194
// We have to be careful to work correctly with memory snapshots. Even if we are
@@ -200,7 +200,7 @@ _Py_EmscriptenTrampoline_Init(_PyRuntimeState *runtime)
200200
* Backwards compatible trampoline works with all JS runtimes
201201
*/
202202
EM_JS(PyObject*, _PyEM_TrampolineCall_JS, (PyCFunctionWithKeywords func, PyObject *arg1, PyObject *arg2, PyObject *arg3), {
203-
return wasmTable.get(func)(arg1, arg2, arg3);
203+
return wasmTable.get(func)(arg1, arg2, arg3);
204204
});
205205

206206
typedef PyObject* (*zero_arg)(void);
@@ -214,23 +214,23 @@ _PyEM_TrampolineCall(PyCFunctionWithKeywords func,
214214
PyObject* args,
215215
PyObject* kw)
216216
{
217-
CountArgsFunc count_args = _PyRuntime.emscripten_count_args_function;
218-
if (count_args == 0) {
219-
return _PyEM_TrampolineCall_JS(func, self, args, kw);
220-
}
221-
switch (count_args(func)) {
222-
case 0:
223-
return ((zero_arg)func)();
224-
case 1:
225-
return ((one_arg)func)(self);
226-
case 2:
227-
return ((two_arg)func)(self, args);
228-
case 3:
229-
return ((three_arg)func)(self, args, kw);
230-
default:
231-
PyErr_SetString(PyExc_SystemError, "Handler takes too many arguments");
232-
return NULL;
233-
}
217+
CountArgsFunc count_args = _PyRuntime.emscripten_count_args_function;
218+
if (count_args == 0) {
219+
return _PyEM_TrampolineCall_JS(func, self, args, kw);
220+
}
221+
switch (count_args(func)) {
222+
case 0:
223+
return ((zero_arg)func)();
224+
case 1:
225+
return ((one_arg)func)(self);
226+
case 2:
227+
return ((two_arg)func)(self, args);
228+
case 3:
229+
return ((three_arg)func)(self, args, kw);
230+
default:
231+
PyErr_SetString(PyExc_SystemError, "Handler takes too many arguments");
232+
return NULL;
233+
}
234234
}
235235

236236
#endif

0 commit comments

Comments
 (0)