IN: llvm.jit
-SYMBOL: thejit
-
TUPLE: jit ee mps ;
: empty-engine ( -- engine )
: <jit> ( -- jit )
jit new empty-engine >>ee H{ } clone >>mps ;
+: current-jit ( -- jit )
+ \ current-jit global [ drop <jit> ] cache ;
+
: (remove-functions) ( function -- )
- thejit get ee>> value>> over LLVMFreeMachineCodeForFunction
+ current-jit ee>> value>> over LLVMFreeMachineCodeForFunction
LLVMGetNextFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
: remove-functions ( module -- )
LLVMGetFirstFunction dup ALIEN: 0 = [ drop ] [ (remove-functions) ] if ;
: remove-provider ( provider -- )
- thejit get ee>> value>> swap value>> f <void*> f <void*>
+ current-jit ee>> value>> swap value>> f <void*> f <void*>
[ LLVMRemoveModuleProvider drop ] 2keep *void* [ llvm-throw ] when*
*void* module new swap >>value
[ value>> remove-functions ] with-disposal ;
: remove-module ( name -- )
- dup thejit get mps>> at [
+ dup current-jit mps>> at [
remove-provider
- thejit get mps>> delete-at
+ current-jit mps>> delete-at
] [ drop ] if* ;
: add-module ( module name -- )
[ <provider> ] dip [ remove-module ] keep
- thejit get ee>> value>> pick
+ current-jit ee>> value>> pick
[ [ value>> LLVMAddModuleProvider ] [ t >>disposed drop ] bi ] with-disposal
- thejit get mps>> set-at ;
+ current-jit mps>> set-at ;
: function-pointer ( name -- alien )
- thejit get ee>> value>> dup
+ current-jit ee>> value>> dup
rot f <void*> [ LLVMFindFunction drop ] keep
- *void* LLVMGetPointerToGlobal ;
-
-thejit [ <jit> ] initialize
\ No newline at end of file
+ *void* LLVMGetPointerToGlobal ;
\ No newline at end of file
VarArgs = WhiteSpace "..." WhiteSpace => [[ drop ... ]]
ParamListContinued = "," (Type | VarArgs):t => [[ t ]]
ParamList = "(" Type:t (ParamListContinued*):ts ")" => [[ ts t prefix ]]
-Function = T:t WhiteSpace ( ParamList | NoFunctionParams ):ts => [[ ... ts member? dup [ ... ts delete ] when t ts >array rot <function> ]]
+Function = T:t WhiteSpace ( ParamList | NoFunctionParams ):ts => [[ ... ts member? dup [ ... ts remove! drop ] when t ts >array rot <function> ]]
PackedStructure = "<" WhiteSpace "{" Type:ty (StructureTypesList)*:ts "}" WhiteSpace ">" => [[ ts ty prefix >array t <struct> ]]
UpReference = "\\" Number:n => [[ n <up-ref> ]]
Name = '%' ([a-zA-Z][a-zA-Z0-9]*):id => [[ id flatten >string ]]