-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin_api_host.nim
More file actions
5597 lines (5580 loc) · 249 KB
/
plugin_api_host.nim
File metadata and controls
5597 lines (5580 loc) · 249 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{.push, hint[DuplicateModuleImport]: off.}
import
std / [options]
from std / unicode import Rune
import
results, wasmtime
{.pop.}
type
## Represents a cursor in a text editor. Line and column are both zero based.
## The column is in bytes.
Cursor* = object
line*: int32
column*: int32
## The column of 'last' is exclusive.
Selection* = object
first*: Cursor
last*: Cursor
Vec2f* = object
x*: float32
y*: float32
Rect* = object
pos*: Vec2f
size*: Vec2f
ActiveEditorFlag* = enum
IncludeCommandLine = "include-command-line",
IncludePopups = "include-popups"
ActiveEditorFlags* = set[ActiveEditorFlag]
Lamport* = object
replicaId*: uint16
value*: uint32
Bias* = enum
Left = "left", Right = "right"
OverlayRenderLocation* = enum
Inline = "inline", Below = "below", Above = "above"
Anchor* = object
timestamp*: Lamport
offset*: uint32
bias*: Bias
## Shared reference to a byte buffer. The data is stored in the editor, not in the plugin, so shared buffers
## can be used to efficiently share data with another plugin or another thread.
## Buffers are reference counted internally, and this resource also affects that reference count.
## Shared reference to a rope. The rope data is stored in the editor, not in the plugin, so ropes
## can be used to efficiently access any document content or share a string with another plugin.
## Ropes are reference counted internally, and this resource also affects that reference count.
## Non-owning handle to an editor.
Editor* = object
id*: uint64
## Non-owning handle to a text editor.
TextEditor* = object
id*: uint64
## Non-owning handle to a document.
Document* = object
id*: uint64
## Non-owning handle to a text document.
TextDocument* = object
id*: uint64
Task* = object
id*: uint64
ChannelListenResponse* = enum
Continue = "continue", Stop = "stop"
## Represents the read end of a channel. All APIs are non-blocking.
## Represents the write end of a channel. All APIs are non-blocking.
## Resource which represents a running process started by a plugin.
## Shared handle for a view.
View* = object
id*: int32
## Shared handle to a custom render view
TextureFormat* = enum
Rgba8 = "rgba8", Rgba32 = "rgba32"
Platform* = enum
Gui = "gui", Tui = "tui"
BackgroundExecutor* = enum
Thread = "thread", ThreadPool = "thread-pool"
CommandError* = enum
NotAllowed = "not-allowed", NotFound = "not-found"
VfsError* = enum
NotAllowed = "not-allowed", NotFound = "not-found"
ReadFlag* = enum
Binary = "binary"
ReadFlags* = set[ReadFlag]
ScrollBehaviour* = enum
CenterAlways = "center-always", CenterOffscreen = "center-offscreen",
CenterMargin = "center-margin", ScrollToMargin = "scroll-to-margin",
TopOfScreen = "top-of-screen"
ScrollSnapBehaviour* = enum
Never = "never", Always = "always",
MinDistanceOffscreen = "min-distance-offscreen",
MinDistanceCenter = "min-distance-center"
when not declared(SharedBufferResource):
{.error: "Missing resource type definition for " & "SharedBufferResource" &
". Define the type before the importWit statement.".}
when not declared(RopeResource):
{.error: "Missing resource type definition for " & "RopeResource" &
". Define the type before the importWit statement.".}
when not declared(ReadChannelResource):
{.error: "Missing resource type definition for " & "ReadChannelResource" &
". Define the type before the importWit statement.".}
when not declared(WriteChannelResource):
{.error: "Missing resource type definition for " & "WriteChannelResource" &
". Define the type before the importWit statement.".}
when not declared(ProcessResource):
{.error: "Missing resource type definition for " & "ProcessResource" &
". Define the type before the importWit statement.".}
when not declared(RenderViewResource):
{.error: "Missing resource type definition for " & "RenderViewResource" &
". Define the type before the importWit statement.".}
type
ExportedFuncs* = object
mContext*: ptr ContextT
mMemory*: Option[ExternT]
mRealloc*: Option[ExternT]
mDealloc*: Option[ExternT]
mStackAlloc*: Option[ExternT]
mStackSave*: Option[ExternT]
mStackRestore*: Option[ExternT]
initPlugin*: FuncT
handleCommand*: FuncT
handleModeChanged*: FuncT
handleViewRenderCallback*: FuncT
handleChannelUpdate*: FuncT
notifyTaskComplete*: FuncT
handleMove*: FuncT
savePluginState*: FuncT
loadPluginState*: FuncT
handleEvent*: FuncT
handleTextOverlayRender*: FuncT
proc mem(funcs: ExportedFuncs): WasmMemory =
if funcs.mMemory.get.kind == WASMTIME_EXTERN_SHAREDMEMORY:
return initWasmMemory(funcs.mMemory.get.of_field.sharedmemory)
elif funcs.mMemory.get.kind == WASMTIME_EXTERN_MEMORY:
return initWasmMemory(funcs.mContext, funcs.mMemory.get.of_field.memory.addr)
proc collectExports*(funcs: var ExportedFuncs; instance: InstanceT;
context: ptr ContextT): seq[string] =
funcs.mContext = context
funcs.mMemory = instance.getExport(context, "memory")
funcs.mRealloc = instance.getExport(context, "cabi_realloc")
funcs.mDealloc = instance.getExport(context, "cabi_dealloc")
funcs.mStackAlloc = instance.getExport(context, "mem_stack_alloc")
funcs.mStackSave = instance.getExport(context, "mem_stack_save")
funcs.mStackRestore = instance.getExport(context, "mem_stack_restore")
block:
let f = instance.getExport(context, "init_plugin")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.initPlugin = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"init_plugin" & "\'"
block:
let f = instance.getExport(context, "handle_command")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleCommand = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"handle_command" &
"\'"
block:
let f = instance.getExport(context, "handle_mode_changed")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleModeChanged = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"handle_mode_changed" &
"\'"
block:
let f = instance.getExport(context, "handle_view_render_callback")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleViewRenderCallback = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" &
$"handle_view_render_callback" &
"\'"
block:
let f = instance.getExport(context, "handle_channel_update")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleChannelUpdate = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" &
$"handle_channel_update" &
"\'"
block:
let f = instance.getExport(context, "notify_task_complete")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.notifyTaskComplete = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" &
$"notify_task_complete" &
"\'"
block:
let f = instance.getExport(context, "handle_move")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleMove = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"handle_move" & "\'"
block:
let f = instance.getExport(context, "save_plugin_state")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.savePluginState = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"save_plugin_state" &
"\'"
block:
let f = instance.getExport(context, "load_plugin_state")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.loadPluginState = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"load_plugin_state" &
"\'"
block:
let f = instance.getExport(context, "handle_event")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleEvent = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" & $"handle_event" & "\'"
block:
let f = instance.getExport(context, "handle_text_overlay_render")
if f.isSome:
assert f.get.kind == WASMTIME_EXTERN_FUNC
funcs.handleTextOverlayRender = f.get.of_field.func_field
else:
result.add "Failed to find exported function \'" &
$"handle_text_overlay_render" &
"\'"
proc initPlugin*(funcs: ExportedFuncs): WasmtimeResult[void] =
var args: array[max(1, 0), ValT]
var results: array[max(1, 0), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
let res = funcs.initPlugin.addr.call(funcs.mContext,
args.toOpenArray(0, 0 - 1),
results.toOpenArray(0, 0 - 1), trap.addr).toResult(
void)
if trap != nil:
return trap.toResult(void)
if res.isErr:
return res.toResult(void)
proc handleCommand*(funcs: ExportedFuncs; fun: uint32; data: uint32;
arguments: string): WasmtimeResult[string] =
var args: array[max(1, 4), ValT]
var results: array[max(1, 1), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
var dataPtrWasm0: WasmPtr
args[0] = toWasmVal(fun)
args[1] = toWasmVal(data)
if arguments.len > 0:
dataPtrWasm0 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (arguments.len * 1).int32, 4)
if temp.isErr:
return temp.toResult(string)
temp.val
args[2] = toWasmVal(cast[int32](dataPtrWasm0))
block:
for i0 in 0 ..< arguments.len:
memory[dataPtrWasm0 + i0] = cast[uint8](arguments[i0])
else:
args[2] = toWasmVal(0.int32)
args[3] = toWasmVal(cast[int32](arguments.len))
let res = funcs.handleCommand.addr.call(funcs.mContext,
args.toOpenArray(0, 4 - 1), results.toOpenArray(0, 1 - 1), trap.addr).toResult(
string)
if trap != nil:
return trap.toResult(string)
if res.isErr:
return res.toResult(string)
var retVal: string
let retArea: ptr UncheckedArray[uint8] = memory.getRawPtr(
results[0].to(WasmPtr))
block:
let p0 = cast[ptr UncheckedArray[char]](memory.getRawPtr(
cast[ptr int32](retArea[0].addr)[].WasmPtr))
retVal = newString(cast[ptr int32](retArea[4].addr)[])
for i0 in 0 ..< retVal.len:
retVal[i0] = p0[i0]
return wasmtime.ok(retVal)
proc handleModeChanged*(funcs: ExportedFuncs; fun: uint32; old: string;
new: string): WasmtimeResult[void] =
var args: array[max(1, 5), ValT]
var results: array[max(1, 0), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
var dataPtrWasm0: WasmPtr
var dataPtrWasm1: WasmPtr
args[0] = toWasmVal(fun)
if old.len > 0:
dataPtrWasm0 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (old.len * 1).int32, 4)
if temp.isErr:
return temp.toResult(void)
temp.val
args[1] = toWasmVal(cast[int32](dataPtrWasm0))
block:
for i0 in 0 ..< old.len:
memory[dataPtrWasm0 + i0] = cast[uint8](old[i0])
else:
args[1] = toWasmVal(0.int32)
args[2] = toWasmVal(cast[int32](old.len))
if new.len > 0:
dataPtrWasm1 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (new.len * 1).int32, 4)
if temp.isErr:
return temp.toResult(void)
temp.val
args[3] = toWasmVal(cast[int32](dataPtrWasm1))
block:
for i0 in 0 ..< new.len:
memory[dataPtrWasm1 + i0] = cast[uint8](new[i0])
else:
args[3] = toWasmVal(0.int32)
args[4] = toWasmVal(cast[int32](new.len))
let res = funcs.handleModeChanged.addr.call(funcs.mContext,
args.toOpenArray(0, 5 - 1), results.toOpenArray(0, 0 - 1), trap.addr).toResult(
void)
if trap != nil:
return trap.toResult(void)
if res.isErr:
return res.toResult(void)
proc handleViewRenderCallback*(funcs: ExportedFuncs; id: int32; fun: uint32;
data: uint32): WasmtimeResult[void] =
var args: array[max(1, 3), ValT]
var results: array[max(1, 0), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
args[0] = toWasmVal(id)
args[1] = toWasmVal(fun)
args[2] = toWasmVal(data)
let res = funcs.handleViewRenderCallback.addr.call(funcs.mContext,
args.toOpenArray(0, 3 - 1), results.toOpenArray(0, 0 - 1), trap.addr).toResult(
void)
if trap != nil:
return trap.toResult(void)
if res.isErr:
return res.toResult(void)
proc handleChannelUpdate*(funcs: ExportedFuncs; fun: uint32; data: uint32;
closed: bool): WasmtimeResult[ChannelListenResponse] =
var args: array[max(1, 3), ValT]
var results: array[max(1, 1), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
args[0] = toWasmVal(fun)
args[1] = toWasmVal(data)
args[2] = toWasmVal(closed)
let res = funcs.handleChannelUpdate.addr.call(funcs.mContext,
args.toOpenArray(0, 3 - 1), results.toOpenArray(0, 1 - 1), trap.addr).toResult(
ChannelListenResponse)
if trap != nil:
return trap.toResult(ChannelListenResponse)
if res.isErr:
return res.toResult(ChannelListenResponse)
var retVal: ChannelListenResponse
retVal = cast[ChannelListenResponse](results[0].to(int8))
return wasmtime.ok(retVal)
proc notifyTaskComplete*(funcs: ExportedFuncs; task: uint64; canceled: bool): WasmtimeResult[
void] =
var args: array[max(1, 2), ValT]
var results: array[max(1, 0), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
args[0] = toWasmVal(task)
args[1] = toWasmVal(canceled)
let res = funcs.notifyTaskComplete.addr.call(funcs.mContext,
args.toOpenArray(0, 2 - 1), results.toOpenArray(0, 0 - 1), trap.addr).toResult(
void)
if trap != nil:
return trap.toResult(void)
if res.isErr:
return res.toResult(void)
proc handleMove*(funcs: ExportedFuncs; fun: uint32; data: uint32; text: uint32;
selections: seq[Selection]; count: int32; eol: bool): WasmtimeResult[
seq[Selection]] =
var args: array[max(1, 7), ValT]
var results: array[max(1, 1), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
var dataPtrWasm0: WasmPtr
args[0] = toWasmVal(fun)
args[1] = toWasmVal(data)
args[2] = toWasmVal(text)
if selections.len > 0:
dataPtrWasm0 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (selections.len * 16).int32, 4)
if temp.isErr:
return temp.toResult(seq[Selection])
temp.val
args[3] = toWasmVal(cast[int32](dataPtrWasm0))
block:
for i0 in 0 ..< selections.len:
cast[ptr int32](memory[dataPtrWasm0 + i0 * 16 + 0].addr)[] = selections[
i0].first.line
cast[ptr int32](memory[dataPtrWasm0 + i0 * 16 + 4].addr)[] = selections[
i0].first.column
cast[ptr int32](memory[dataPtrWasm0 + i0 * 16 + 8].addr)[] = selections[
i0].last.line
cast[ptr int32](memory[dataPtrWasm0 + i0 * 16 + 12].addr)[] = selections[
i0].last.column
else:
args[3] = toWasmVal(0.int32)
args[4] = toWasmVal(cast[int32](selections.len))
args[5] = toWasmVal(count)
args[6] = toWasmVal(eol)
let res = funcs.handleMove.addr.call(funcs.mContext,
args.toOpenArray(0, 7 - 1),
results.toOpenArray(0, 1 - 1), trap.addr).toResult(
seq[Selection])
if trap != nil:
return trap.toResult(seq[Selection])
if res.isErr:
return res.toResult(seq[Selection])
var retVal: seq[Selection]
let retArea: ptr UncheckedArray[uint8] = memory.getRawPtr(
results[0].to(WasmPtr))
block:
let p0 = cast[ptr UncheckedArray[uint8]](memory.getRawPtr(
cast[ptr int32](retArea[0].addr)[].WasmPtr))
retVal = newSeq[typeof(retVal[0])](cast[ptr int32](retArea[4].addr)[])
for i0 in 0 ..< retVal.len:
retVal[i0].first.line = convert(cast[ptr int32](p0[i0 * 16 + 0].addr)[],
int32)
retVal[i0].first.column = convert(cast[ptr int32](p0[i0 * 16 + 4].addr)[],
int32)
retVal[i0].last.line = convert(cast[ptr int32](p0[i0 * 16 + 8].addr)[],
int32)
retVal[i0].last.column = convert(cast[ptr int32](p0[i0 * 16 + 12].addr)[],
int32)
return wasmtime.ok(retVal)
proc savePluginState*(funcs: ExportedFuncs): WasmtimeResult[seq[uint8]] =
var args: array[max(1, 0), ValT]
var results: array[max(1, 1), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
let res = funcs.savePluginState.addr.call(funcs.mContext,
args.toOpenArray(0, 0 - 1), results.toOpenArray(0, 1 - 1), trap.addr).toResult(
seq[uint8])
if trap != nil:
return trap.toResult(seq[uint8])
if res.isErr:
return res.toResult(seq[uint8])
var retVal: seq[uint8]
let retArea: ptr UncheckedArray[uint8] = memory.getRawPtr(
results[0].to(WasmPtr))
block:
let p0 = cast[ptr UncheckedArray[uint8]](memory.getRawPtr(
cast[ptr int32](retArea[0].addr)[].WasmPtr))
retVal = newSeq[typeof(retVal[0])](cast[ptr int32](retArea[4].addr)[])
for i0 in 0 ..< retVal.len:
retVal[i0] = convert(cast[ptr uint8](p0[i0 * 1 + 0].addr)[], uint8)
return wasmtime.ok(retVal)
proc loadPluginState*(funcs: ExportedFuncs; state: seq[uint8]): WasmtimeResult[
void] =
var args: array[max(1, 2), ValT]
var results: array[max(1, 0), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
var dataPtrWasm0: WasmPtr
if state.len > 0:
dataPtrWasm0 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (state.len * 1).int32, 4)
if temp.isErr:
return temp.toResult(void)
temp.val
args[0] = toWasmVal(cast[int32](dataPtrWasm0))
block:
for i0 in 0 ..< state.len:
cast[ptr uint8](memory[dataPtrWasm0 + i0 * 1 + 0].addr)[] = state[i0]
else:
args[0] = toWasmVal(0.int32)
args[1] = toWasmVal(cast[int32](state.len))
let res = funcs.loadPluginState.addr.call(funcs.mContext,
args.toOpenArray(0, 2 - 1), results.toOpenArray(0, 0 - 1), trap.addr).toResult(
void)
if trap != nil:
return trap.toResult(void)
if res.isErr:
return res.toResult(void)
proc handleEvent*(funcs: ExportedFuncs; fun: uint32; data: uint32;
event: string; payload: string): WasmtimeResult[void] =
var args: array[max(1, 6), ValT]
var results: array[max(1, 0), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
var dataPtrWasm0: WasmPtr
var dataPtrWasm1: WasmPtr
args[0] = toWasmVal(fun)
args[1] = toWasmVal(data)
if event.len > 0:
dataPtrWasm0 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (event.len * 1).int32, 4)
if temp.isErr:
return temp.toResult(void)
temp.val
args[2] = toWasmVal(cast[int32](dataPtrWasm0))
block:
for i0 in 0 ..< event.len:
memory[dataPtrWasm0 + i0] = cast[uint8](event[i0])
else:
args[2] = toWasmVal(0.int32)
args[3] = toWasmVal(cast[int32](event.len))
if payload.len > 0:
dataPtrWasm1 = block:
let temp = stackAlloc(funcs.mStackAlloc.get.of_field.func_field,
funcs.mContext, (payload.len * 1).int32, 4)
if temp.isErr:
return temp.toResult(void)
temp.val
args[4] = toWasmVal(cast[int32](dataPtrWasm1))
block:
for i0 in 0 ..< payload.len:
memory[dataPtrWasm1 + i0] = cast[uint8](payload[i0])
else:
args[4] = toWasmVal(0.int32)
args[5] = toWasmVal(cast[int32](payload.len))
let res = funcs.handleEvent.addr.call(funcs.mContext,
args.toOpenArray(0, 6 - 1),
results.toOpenArray(0, 0 - 1), trap.addr).toResult(
void)
if trap != nil:
return trap.toResult(void)
if res.isErr:
return res.toResult(void)
proc handleTextOverlayRender*(funcs: ExportedFuncs; fun: uint32; data: uint32;
id: int64; size: Vec2f; offset: int32): WasmtimeResult[
uint64] =
var args: array[max(1, 6), ValT]
var results: array[max(1, 1), ValT]
var trap: ptr WasmTrapT = nil
var memory = funcs.mem
let savePoint = stackSave(funcs.mStackSave.get.of_field.func_field,
funcs.mContext)
defer:
discard stackRestore(funcs.mStackRestore.get.of_field.func_field,
funcs.mContext, savePoint.val)
args[0] = toWasmVal(fun)
args[1] = toWasmVal(data)
args[2] = toWasmVal(id)
args[3] = toWasmVal(size.x)
args[4] = toWasmVal(size.y)
args[5] = toWasmVal(offset)
let res = funcs.handleTextOverlayRender.addr.call(funcs.mContext,
args.toOpenArray(0, 6 - 1), results.toOpenArray(0, 1 - 1), trap.addr).toResult(
uint64)
if trap != nil:
return trap.toResult(uint64)
if res.isErr:
return res.toResult(uint64)
var retVal: uint64
retVal = convert(results[0].to(uint64), uint64)
return wasmtime.ok(retVal)
proc coreApiVersion*(instance: ptr InstanceData): int32
proc coreGetTime*(instance: ptr InstanceData): float64
proc coreGetPlatform*(instance: ptr InstanceData): Platform
proc coreIsMainThread*(instance: ptr InstanceData): bool
proc coreGetArguments*(instance: ptr InstanceData): string
proc coreSpawnBackground*(instance: ptr InstanceData; args: sink string;
executor: BackgroundExecutor): void
proc coreFinishBackground*(instance: ptr InstanceData): void
proc coreSleepAsync*(instance: ptr InstanceData; task: uint64;
milliseconds: uint32): void
proc commandsDefineCommand*(instance: ptr InstanceData; name: sink string;
active: bool; docs: sink string;
params: sink seq[(string, string)];
returntype: sink string; context: sink string;
fun: uint32; data: uint32): void
proc commandsRunCommand*(instance: ptr InstanceData; name: sink string;
arguments: sink string): Result[string, CommandError]
proc commandsExitCommandLine*(instance: ptr InstanceData): void
proc settingsGetSettingRaw*(instance: ptr InstanceData; name: sink string): string
proc settingsSetSettingRaw*(instance: ptr InstanceData; name: sink string;
value: sink string): void
proc typesNewSharedBuffer*(instance: ptr InstanceData; size: int64): SharedBufferResource
proc typesCloneRef*(instance: ptr InstanceData; self: var SharedBufferResource): SharedBufferResource
proc typesLen*(instance: ptr InstanceData; self: var SharedBufferResource): int64
proc typesWriteString*(instance: ptr InstanceData;
self: var SharedBufferResource; index: int64;
data: sink string): void
proc typesWrite*(instance: ptr InstanceData; self: var SharedBufferResource;
index: int64; data: sink seq[uint8]): void
proc typesReadInto*(instance: ptr InstanceData; self: var SharedBufferResource;
index: int64; dst: uint32; len: int32): void
proc typesRead*(instance: ptr InstanceData; self: var SharedBufferResource;
index: int64; len: int32): seq[uint8]
proc typesSharedBufferOpen*(instance: ptr InstanceData; path: sink string): Option[
SharedBufferResource]
proc typesSharedBufferMount*(instance: ptr InstanceData;
buffer: sink SharedBufferResource;
path: sink string; unique: bool): string
proc typesNewRope*(instance: ptr InstanceData; content: sink string): RopeResource
proc typesClone*(instance: ptr InstanceData; self: var RopeResource): RopeResource
proc typesBytes*(instance: ptr InstanceData; self: var RopeResource): int64
proc typesRunes*(instance: ptr InstanceData; self: var RopeResource): int64
proc typesLines*(instance: ptr InstanceData; self: var RopeResource): int64
proc typesText*(instance: ptr InstanceData; self: var RopeResource): string
proc typesSlice*(instance: ptr InstanceData; self: var RopeResource; a: int64;
b: int64; inclusive: bool): RopeResource
proc typesSliceSelection*(instance: ptr InstanceData; self: var RopeResource;
s: Selection; inclusive: bool): RopeResource
proc typesFind*(instance: ptr InstanceData; self: var RopeResource;
sub: sink string; start: int64): Option[int64]
proc typesSlicePoints*(instance: ptr InstanceData; self: var RopeResource;
a: Cursor; b: Cursor): RopeResource
proc typesLineLength*(instance: ptr InstanceData; self: var RopeResource;
line: int64): int64
proc typesRuneAt*(instance: ptr InstanceData; self: var RopeResource; a: Cursor): Rune
proc typesByteAt*(instance: ptr InstanceData; self: var RopeResource; a: Cursor): uint8
proc typesFindAll*(instance: ptr InstanceData; self: var RopeResource;
regex: sink string): seq[Selection]
proc typesRopeOpen*(instance: ptr InstanceData; path: sink string): Option[
RopeResource]
proc typesRopeMount*(instance: ptr InstanceData; rope: sink RopeResource;
path: sink string; unique: bool): string
proc editorActiveEditor*(instance: ptr InstanceData; options: ActiveEditorFlags): Option[
Editor]
proc editorGetDocument*(instance: ptr InstanceData; editor: Editor): Option[
Document]
proc textEditorActiveTextEditor*(instance: ptr InstanceData;
options: ActiveEditorFlags): Option[TextEditor]
proc textEditorGetDocument*(instance: ptr InstanceData; editor: TextEditor): Option[
TextDocument]
proc textEditorAsTextEditor*(instance: ptr InstanceData; editor: Editor): Option[
TextEditor]
proc textEditorAsTextDocument*(instance: ptr InstanceData; document: Document): Option[
TextDocument]
proc textEditorAllTextEditors*(instance: ptr InstanceData): seq[TextEditor]
proc textEditorCommand*(instance: ptr InstanceData; editor: TextEditor;
name: sink string; arguments: sink string): Result[
string, CommandError]
proc textEditorRecordCurrentCommand*(instance: ptr InstanceData;
editor: TextEditor;
registers: sink seq[string]): void
proc textEditorHideCompletions*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorScrollToCursor*(instance: ptr InstanceData; editor: TextEditor;
behaviour: Option[ScrollBehaviour];
relativePosition: float32): void
proc textEditorUpdateTargetColumn*(instance: ptr InstanceData;
editor: TextEditor): void
proc textEditorGetUsage*(instance: ptr InstanceData; editor: TextEditor): string
proc textEditorGetRevision*(instance: ptr InstanceData; editor: TextEditor): int32
proc textEditorSetMode*(instance: ptr InstanceData; editor: TextEditor;
mode: sink string; exclusive: bool): void
proc textEditorMode*(instance: ptr InstanceData; editor: TextEditor): string
proc textEditorModes*(instance: ptr InstanceData; editor: TextEditor): seq[
string]
proc textEditorClearTabStops*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorUndo*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorRedo*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorStartTransaction*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorEndTransaction*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorCopy*(instance: ptr InstanceData; editor: TextEditor;
register: sink string; inclusiveEnd: bool): void
proc textEditorPaste*(instance: ptr InstanceData; editor: TextEditor;
selections: sink seq[Selection]; register: sink string;
inclusiveEnd: bool): void
proc textEditorAutoShowCompletions*(instance: ptr InstanceData;
editor: TextEditor): void
proc textEditorToggleLineComment*(instance: ptr InstanceData; editor: TextEditor): void
proc textEditorInsertText*(instance: ptr InstanceData; editor: TextEditor;
text: sink string; autoIndent: bool): void
proc textEditorOpenSearchBar*(instance: ptr InstanceData; editor: TextEditor;
query: sink string; scrollToPreview: bool;
selectResult: bool): void
proc textEditorSetSearchQueryFromMove*(instance: ptr InstanceData;
editor: TextEditor; move: sink string;
count: int32; prefix: sink string;
suffix: sink string): Selection
proc textEditorSetSearchQuery*(instance: ptr InstanceData; editor: TextEditor;
query: sink string; escapeRegex: bool;
prefix: sink string; suffix: sink string): bool
proc textEditorGetSearchQuery*(instance: ptr InstanceData; editor: TextEditor): string
proc textEditorApplyMove*(instance: ptr InstanceData; editor: TextEditor;
selection: Selection; move: sink string; count: int32;
wrap: bool; includeEol: bool): seq[Selection]
proc textEditorMultiMove*(instance: ptr InstanceData; editor: TextEditor;
selections: sink seq[Selection]; move: sink string;
count: int32; wrap: bool; includeEol: bool): seq[
Selection]
proc textEditorSetSelection*(instance: ptr InstanceData; editor: TextEditor;
s: Selection): void
proc textEditorSetSelections*(instance: ptr InstanceData; editor: TextEditor;
s: sink seq[Selection]): void
proc textEditorGetSelection*(instance: ptr InstanceData; editor: TextEditor): Selection
proc textEditorGetSelections*(instance: ptr InstanceData; editor: TextEditor): seq[
Selection]
proc textEditorLineLength*(instance: ptr InstanceData; editor: TextEditor;
line: int32): int32
proc textEditorAddModeChangedHandler*(instance: ptr InstanceData; fun: uint32): int32
proc textEditorGetSettingRaw*(instance: ptr InstanceData; editor: TextEditor;
name: sink string): string
proc textEditorSetSettingRaw*(instance: ptr InstanceData; editor: TextEditor;
name: sink string; value: sink string): void
proc textEditorEvaluateExpressions*(instance: ptr InstanceData;
editor: TextEditor;
selections: sink seq[Selection];
inclusive: bool; prefix: sink string;
suffix: sink string; addSelectionIndex: bool): void
proc textEditorIndent*(instance: ptr InstanceData; editor: TextEditor;
delta: int32): void
proc textEditorGetCommandCount*(instance: ptr InstanceData; editor: TextEditor): int32
proc textEditorSetCursorScrollOffset*(instance: ptr InstanceData;
editor: TextEditor; cursor: Cursor;
scrollOffset: float32): void
proc textEditorGetVisibleLineCount*(instance: ptr InstanceData;
editor: TextEditor): int32
proc textEditorCreateAnchors*(instance: ptr InstanceData; editor: TextEditor;
selections: sink seq[Selection]): seq[
(Anchor, Anchor)]
proc textEditorResolveAnchors*(instance: ptr InstanceData; editor: TextEditor;
anchors: sink seq[(Anchor, Anchor)]): seq[
Selection]
proc textEditorAddOverlay*(instance: ptr InstanceData; editor: TextEditor;
selections: Selection; text: sink string; id: int64;
scope: sink string; bias: Bias; renderId: int64;
location: OverlayRenderLocation): void
proc textEditorClearOverlays*(instance: ptr InstanceData; editor: TextEditor;
id: int64): void
proc textEditorAllocateOverlayId*(instance: ptr InstanceData; editor: TextEditor): int64
proc textEditorReleaseOverlayId*(instance: ptr InstanceData; editor: TextEditor;
id: int64): void
proc textEditorAddCustomRenderCallback*(instance: ptr InstanceData;
editor: TextEditor; fun: uint32;
data: uint32): int64
proc textEditorRemoveCustomRenderCallback*(instance: ptr InstanceData;
editor: TextEditor; cb: int64): void
proc textEditorEdit*(instance: ptr InstanceData; editor: TextEditor;
selections: sink seq[Selection];
contents: sink seq[string]; inclusive: bool): seq[Selection]
proc textEditorDefineMove*(instance: ptr InstanceData; move: sink string;
fun: uint32; data: uint32): void
proc textEditorContent*(instance: ptr InstanceData; editor: TextEditor): RopeResource
proc textDocumentContent*(instance: ptr InstanceData; document: TextDocument): RopeResource
proc textDocumentPath*(instance: ptr InstanceData; document: TextDocument): string
proc layoutShow*(instance: ptr InstanceData; v: View; slot: sink string;
focus: bool; addToHistory: bool): void
proc layoutClose*(instance: ptr InstanceData; v: View; keepHidden: bool;
restoreHidden: bool): void
proc layoutFocus*(instance: ptr InstanceData; slot: sink string): void
proc layoutCloseActiveView*(instance: ptr InstanceData; closeOpenPopup: bool;
restoreHidden: bool): void
proc renderNewRenderView*(instance: ptr InstanceData): RenderViewResource
proc renderRenderViewFromUserId*(instance: ptr InstanceData; id: sink string): Option[
RenderViewResource]
proc renderRenderViewFromView*(instance: ptr InstanceData; v: View): Option[
RenderViewResource]
proc renderView*(instance: ptr InstanceData; self: var RenderViewResource): View
proc renderId*(instance: ptr InstanceData; self: var RenderViewResource): int32
proc renderSize*(instance: ptr InstanceData; self: var RenderViewResource): Vec2f
proc renderKeyDown*(instance: ptr InstanceData; self: var RenderViewResource;
key: int64): bool
proc renderMousePos*(instance: ptr InstanceData; self: var RenderViewResource): Vec2f
proc renderMouseDown*(instance: ptr InstanceData; self: var RenderViewResource;
button: int64): bool
proc renderScrollDelta*(instance: ptr InstanceData; self: var RenderViewResource): Vec2f
proc renderSetRenderInterval*(instance: ptr InstanceData;
self: var RenderViewResource; ms: int32): void
proc renderSetRenderCommandsRaw*(instance: ptr InstanceData;
self: var RenderViewResource; buffer: uint32;
len: uint32): void
proc renderSetRenderCommands*(instance: ptr InstanceData;
self: var RenderViewResource;
data: sink seq[uint8]): void
proc renderSetRenderWhenInactive*(instance: ptr InstanceData;
self: var RenderViewResource; enabled: bool): void
proc renderSetPreventThrottling*(instance: ptr InstanceData;
self: var RenderViewResource; enabled: bool): void
proc renderSetUserId*(instance: ptr InstanceData; self: var RenderViewResource;
id: sink string): void
proc renderGetUserId*(instance: ptr InstanceData; self: var RenderViewResource): string
proc renderMarkDirty*(instance: ptr InstanceData; self: var RenderViewResource): void
proc renderSetRenderCallback*(instance: ptr InstanceData;
self: var RenderViewResource; fun: uint32;
data: uint32): void
proc renderSetModes*(instance: ptr InstanceData; self: var RenderViewResource;
modes: sink seq[string]): void
proc renderAddMode*(instance: ptr InstanceData; self: var RenderViewResource;
mode: sink string): void
proc renderRemoveMode*(instance: ptr InstanceData; self: var RenderViewResource;
mode: sink string): void
proc renderCreateTexture*(instance: ptr InstanceData; width: int32;
height: int32; data: uint32; format: TextureFormat;
dynamic: bool): uint64
proc renderCreateTextureBuffer*(instance: ptr InstanceData; width: int32;
height: int32; data: var SharedBufferResource;
offset: uint32; format: TextureFormat;
dynamic: bool): uint64
proc renderUpdateTexture*(instance: ptr InstanceData; id: uint64; width: int32;
height: int32; data: uint32; format: TextureFormat): void
proc renderUpdateTextureBuffer*(instance: ptr InstanceData; id: uint64;
width: int32; height: int32;
data: var SharedBufferResource; offset: uint32;
format: TextureFormat): void
proc renderDeleteTexture*(instance: ptr InstanceData; id: uint64): void
proc vfsReadSync*(instance: ptr InstanceData; path: sink string;
readFlags: ReadFlags): Result[string, VfsError]
proc vfsReadRopeSync*(instance: ptr InstanceData; path: sink string;
readFlags: ReadFlags): Result[RopeResource, VfsError]
proc vfsWriteSync*(instance: ptr InstanceData; path: sink string;
content: sink string): Result[bool, VfsError]
proc vfsWriteRopeSync*(instance: ptr InstanceData; path: sink string;
rope: sink RopeResource): Result[bool, VfsError]
proc vfsLocalize*(instance: ptr InstanceData; path: sink string): string
proc channelCanRead*(instance: ptr InstanceData; self: var ReadChannelResource): bool
proc channelAtEnd*(instance: ptr InstanceData; self: var ReadChannelResource): bool
proc channelPeek*(instance: ptr InstanceData; self: var ReadChannelResource): int32
proc channelFlushRead*(instance: ptr InstanceData; self: var ReadChannelResource): int32
proc channelReadString*(instance: ptr InstanceData;
self: var ReadChannelResource; num: int32): string
proc channelReadBytes*(instance: ptr InstanceData;
self: var ReadChannelResource; num: int32): seq[uint8]
proc channelReadAllString*(instance: ptr InstanceData;
self: var ReadChannelResource): string
proc channelReadAllBytes*(instance: ptr InstanceData;
self: var ReadChannelResource): seq[uint8]
proc channelListen*(instance: ptr InstanceData; self: var ReadChannelResource;
fun: uint32; data: uint32): void
proc channelWaitRead*(instance: ptr InstanceData; self: var ReadChannelResource;
task: uint64; num: int32): bool
proc channelReadChannelOpen*(instance: ptr InstanceData; path: sink string): Option[
ReadChannelResource]
proc channelReadChannelMount*(instance: ptr InstanceData;
channel: sink ReadChannelResource;
path: sink string; unique: bool): string
proc channelClose*(instance: ptr InstanceData; self: var WriteChannelResource): void
proc channelCanWrite*(instance: ptr InstanceData; self: var WriteChannelResource): bool
proc channelWriteString*(instance: ptr InstanceData;
self: var WriteChannelResource; data: sink string): void
proc channelWriteBytes*(instance: ptr InstanceData;
self: var WriteChannelResource; data: sink seq[uint8]): void
proc channelWriteChannelOpen*(instance: ptr InstanceData; path: sink string): Option[
WriteChannelResource]
proc channelWriteChannelMount*(instance: ptr InstanceData;
channel: sink WriteChannelResource;
path: sink string; unique: bool): string
proc channelNewInMemoryChannel*(instance: ptr InstanceData): (
ReadChannelResource, WriteChannelResource)
proc channelCreateTerminal*(instance: ptr InstanceData;
stdin: sink WriteChannelResource;
stdout: sink ReadChannelResource; group: sink string): void
proc processProcessStart*(instance: ptr InstanceData; name: sink string;
args: sink seq[string]): ProcessResource
proc processStderr*(instance: ptr InstanceData; self: var ProcessResource): ReadChannelResource
proc processStdout*(instance: ptr InstanceData; self: var ProcessResource): ReadChannelResource
proc processStdin*(instance: ptr InstanceData; self: var ProcessResource): WriteChannelResource
proc registersIsReplayingCommands*(instance: ptr InstanceData): bool
proc registersIsRecordingCommands*(instance: ptr InstanceData;
register: sink string): bool
proc registersSetRegisterText*(instance: ptr InstanceData; text: sink string;
register: sink string): void
proc registersGetRegisterText*(instance: ptr InstanceData; register: sink string): string
proc registersStartRecordingCommands*(instance: ptr InstanceData;
register: sink string): void
proc registersStopRecordingCommands*(instance: ptr InstanceData;
register: sink string): void
proc registersReplayCommands*(instance: ptr InstanceData; register: sink string): void
proc eventsListenEvent*(instance: ptr InstanceData; fun: uint32; data: uint32;
id: sink string; pattern: sink string): void
proc eventsStopListenEvent*(instance: ptr InstanceData; id: sink string;
pattern: sink string): void
proc eventsEmitEvent*(instance: ptr InstanceData; event: sink string;
payload: sink string): void
proc sessionGetSessionData*(instance: ptr InstanceData; name: sink string): string
proc sessionSetSessionData*(instance: ptr InstanceData; name: sink string;
value: sink string): void
proc defineComponent*(linker: ptr LinkerT): WasmtimeResult[void] =
block:
let e = block:
linker.defineFuncUnchecked("nev:plugins/types",
"[resource-drop]shared-buffer",
newFunctype([WasmValkind.I32], [])):
var instance = cast[ptr InstanceData](store.getData())
instance.resources.resourceDrop(parameters[0].i32, callDestroy = true)
if e.isErr:
return e
block:
let e = block:
linker.defineFuncUnchecked("nev:plugins/types", "[resource-drop]rope",
newFunctype([WasmValkind.I32], [])):
var instance = cast[ptr InstanceData](store.getData())
instance.resources.resourceDrop(parameters[0].i32, callDestroy = true)
if e.isErr:
return e
block:
let e = block:
linker.defineFuncUnchecked("nev:plugins/channel",
"[resource-drop]read-channel",
newFunctype([WasmValkind.I32], [])):
var instance = cast[ptr InstanceData](store.getData())
instance.resources.resourceDrop(parameters[0].i32, callDestroy = true)
if e.isErr:
return e
block:
let e = block:
linker.defineFuncUnchecked("nev:plugins/channel",
"[resource-drop]write-channel",
newFunctype([WasmValkind.I32], [])):
var instance = cast[ptr InstanceData](store.getData())
instance.resources.resourceDrop(parameters[0].i32, callDestroy = true)
if e.isErr:
return e
block:
let e = block:
linker.defineFuncUnchecked("nev:plugins/process",
"[resource-drop]process",
newFunctype([WasmValkind.I32], [])):
var instance = cast[ptr InstanceData](store.getData())
instance.resources.resourceDrop(parameters[0].i32, callDestroy = true)
if e.isErr:
return e
block:
let e = block:
linker.defineFuncUnchecked("nev:plugins/render",
"[resource-drop]render-view",
newFunctype([WasmValkind.I32], [])):
var instance = cast[ptr InstanceData](store.getData())
instance.resources.resourceDrop(parameters[0].i32, callDestroy = true)
if e.isErr:
return e
block:
let e = block:
var ty: ptr WasmFunctypeT = newFunctype([], [WasmValkind.I32])
linker.defineFuncUnchecked("nev:plugins/core", "api-version", ty):
var instance = cast[ptr InstanceData](store.getData())
let res = coreApiVersion(instance)
parameters[0].i32 = cast[int32](res)