Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created September 5, 2018 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/e82d35e40455a49372f449769fedf684 to your computer and use it in GitHub Desktop.
Save MasterDuke17/e82d35e40455a49372f449769fedf684 to your computer and use it in GitHub Desktop.
diff --git a/src/jit/core_templates.expr b/src/jit/core_templates.expr
index 0575c4d55..3edc1c47e 100644
--- a/src/jit/core_templates.expr
+++ b/src/jit/core_templates.expr
@@ -2291,3 +2291,13 @@
(carg (tc) ptr)
(carg (^spesh_slot_value $1) ptr)
(carg $2 int)) ptr_sz))
+
+(template: decodertakebytes
+ (do
+ (^decoder_ensure_decoder (tc) $1 "decodertakebytes")
+ (call (^func &MVM_decoder_take_bytes)
+ (arglist
+ (carg (tc) ptr)
+ (carg $1 ptr)
+ (carg $2 ptr)
+ (carg $3 int)) ptr_sz) $0))
diff --git a/src/jit/macro.expr b/src/jit/macro.expr
index 36e7e970b..6fc69a81a 100644
--- a/src/jit/macro.expr
+++ b/src/jit/macro.expr
@@ -88,3 +88,13 @@
(macro: ^body (,a) (addr ,a (&offsetof MVMObjectStooge data)))
(macro: ^nullptr () (const 0 ptr_sz))
+
+(macro: ^decoder_ensure_decoder (,tc ,decoder ,op)
+ (ifv (any
+ (ne (^getf (^repr ,decoder) MVMREPROps ID) (const (&QUOTE MVM_REPR_ID_Decoder) (&sizeof MVMuint32)))
+ (not (^is_conc_obj ,decoder)))
+ (callv (^func &MVM_exception_throw_adhoc)
+ (arglist
+ (carg ,tc ptr)
+ (carg (const_ptr "Operation '%s' can only work on an object with the Decoder representation") ptr)
+ (carg ,op ptr)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment