Use ##local-allot to simplify longlong unboxing
							parent
							
								
									0a0ebcd71d
								
							
						
					
					
						commit
						91cd3b854d
					
				| 
						 | 
				
			
			@ -114,12 +114,10 @@ M: #alien-invoke emit-node
 | 
			
		|||
M:: #alien-indirect emit-node ( node -- )
 | 
			
		||||
    node [
 | 
			
		||||
        D 0 ^^peek -1 ##inc-d ^^unbox-any-c-ptr :> src
 | 
			
		||||
        {
 | 
			
		||||
            [ caller-parameters ]
 | 
			
		||||
            [ drop src ##alien-indirect ]
 | 
			
		||||
            [ emit-stack-frame ]
 | 
			
		||||
            [ box-return* ]
 | 
			
		||||
        } cleave
 | 
			
		||||
        [ caller-parameters src ##alien-indirect ]
 | 
			
		||||
        [ emit-stack-frame ]
 | 
			
		||||
        [ box-return* ]
 | 
			
		||||
        tri
 | 
			
		||||
    ] emit-alien-block ;
 | 
			
		||||
 | 
			
		||||
M: #alien-assembly emit-node
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,7 +49,7 @@ M: c-type unbox
 | 
			
		|||
    [ ^^unbox 1array ] [ nip f 2array 1array ] 2bi ;
 | 
			
		||||
 | 
			
		||||
M: long-long-type unbox
 | 
			
		||||
    unboxer>> int-rep ^^unbox
 | 
			
		||||
    [ 8 f ^^local-allot ] dip '[ _ unboxer>> ##unbox-long-long ] keep
 | 
			
		||||
    0 cell [ int-rep f ^^load-memory-imm ] bi-curry@ bi 2array
 | 
			
		||||
    int-rep long-long-on-stack? 2array dup 2array ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -638,6 +638,10 @@ def: dst
 | 
			
		|||
use: src/tagged-rep
 | 
			
		||||
literal: unboxer rep ;
 | 
			
		||||
 | 
			
		||||
INSN: ##unbox-long-long
 | 
			
		||||
use: src/tagged-rep out/int-rep
 | 
			
		||||
literal: unboxer ;
 | 
			
		||||
 | 
			
		||||
INSN: ##store-reg-param
 | 
			
		||||
use: src
 | 
			
		||||
literal: reg rep ;
 | 
			
		||||
| 
						 | 
				
			
			@ -870,6 +874,7 @@ hairy-clobber-insn
 | 
			
		|||
##unary-float-function
 | 
			
		||||
##binary-float-function
 | 
			
		||||
##unbox
 | 
			
		||||
##unbox-long-long
 | 
			
		||||
##box
 | 
			
		||||
##box-long-long
 | 
			
		||||
##allot-byte-array ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -286,6 +286,7 @@ CONDITIONAL: ##fixnum-mul %fixnum-mul
 | 
			
		|||
 | 
			
		||||
! FFI
 | 
			
		||||
CODEGEN: ##unbox %unbox
 | 
			
		||||
CODEGEN: ##unbox-long-long %unbox-long-long
 | 
			
		||||
CODEGEN: ##store-reg-param %store-reg-param
 | 
			
		||||
CODEGEN: ##store-stack-param %store-stack-param
 | 
			
		||||
CODEGEN: ##load-reg-param %load-reg-param
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -580,6 +580,8 @@ HOOK: struct-return-on-stack? cpu ( -- ? )
 | 
			
		|||
! can be passed to a C function, or returned from a callback
 | 
			
		||||
HOOK: %unbox cpu ( dst src func rep -- )
 | 
			
		||||
 | 
			
		||||
HOOK: %unbox-long-long cpu ( src out func -- )
 | 
			
		||||
 | 
			
		||||
HOOK: %store-reg-param cpu ( src reg rep -- )
 | 
			
		||||
 | 
			
		||||
HOOK: %store-stack-param cpu ( src n rep -- )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -154,6 +154,14 @@ M:: x86.32 %unbox ( dst src func rep -- )
 | 
			
		|||
    src func call-unbox-func
 | 
			
		||||
    dst rep %load-return ;
 | 
			
		||||
 | 
			
		||||
M:: x86.32 %unbox-long-long cpu ( src out func -- )
 | 
			
		||||
    EAX src int-rep %copy
 | 
			
		||||
    0 stack@ EAX MOV
 | 
			
		||||
    EAX out int-rep %copy
 | 
			
		||||
    4 stack@ EAX MOV
 | 
			
		||||
    8 save-vm-ptr
 | 
			
		||||
    func f %alien-invoke ;
 | 
			
		||||
 | 
			
		||||
M:: x86.32 %box ( dst src func rep -- )
 | 
			
		||||
    rep rep-size save-vm-ptr
 | 
			
		||||
    src rep %store-return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,9 +36,6 @@ struct context {
 | 
			
		|||
	set-context-object primitives */
 | 
			
		||||
	cell context_objects[context_object_count];
 | 
			
		||||
 | 
			
		||||
	/* temporary area used by FFI code generation */
 | 
			
		||||
	s64 long_long_return;
 | 
			
		||||
 | 
			
		||||
	context(cell datastack_size, cell retainstack_size, cell callstack_size);
 | 
			
		||||
	~context();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								vm/math.cpp
								
								
								
								
							
							
						
						
									
										10
									
								
								vm/math.cpp
								
								
								
								
							| 
						 | 
				
			
			@ -491,10 +491,9 @@ s64 factor_vm::to_signed_8(cell obj)
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VM_C_API s64 *to_signed_8(cell obj, factor_vm *parent)
 | 
			
		||||
VM_C_API void to_signed_8(cell obj, s64 *out, factor_vm *parent)
 | 
			
		||||
{
 | 
			
		||||
	parent->ctx->long_long_return = parent->to_signed_8(obj);
 | 
			
		||||
	return &parent->ctx->long_long_return;
 | 
			
		||||
	*out = parent->to_signed_8(obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
cell factor_vm::from_unsigned_8(u64 n)
 | 
			
		||||
| 
						 | 
				
			
			@ -525,10 +524,9 @@ u64 factor_vm::to_unsigned_8(cell obj)
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VM_C_API s64 *to_unsigned_8(cell obj, factor_vm *parent)
 | 
			
		||||
VM_C_API void to_unsigned_8(cell obj, u64 *out, factor_vm *parent)
 | 
			
		||||
{
 | 
			
		||||
	parent->ctx->long_long_return = parent->to_unsigned_8(obj);
 | 
			
		||||
	return &parent->ctx->long_long_return;
 | 
			
		||||
	*out = parent->to_unsigned_8(obj);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
VM_C_API cell from_float(float flo, factor_vm *parent)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -90,8 +90,8 @@ VM_C_API cell from_unsigned_cell(cell integer, factor_vm *vm);
 | 
			
		|||
VM_C_API cell from_signed_8(s64 n, factor_vm *vm);
 | 
			
		||||
VM_C_API cell from_unsigned_8(u64 n, factor_vm *vm);
 | 
			
		||||
 | 
			
		||||
VM_C_API s64 *to_signed_8(cell obj, factor_vm *vm);
 | 
			
		||||
VM_C_API s64 *to_unsigned_8(cell obj, factor_vm *vm);
 | 
			
		||||
VM_C_API void to_signed_8(cell obj, s64 *out, factor_vm *parent);
 | 
			
		||||
VM_C_API void to_unsigned_8(cell obj, u64 *out, factor_vm *parent);
 | 
			
		||||
 | 
			
		||||
VM_C_API fixnum to_fixnum(cell tagged, factor_vm *vm);
 | 
			
		||||
VM_C_API cell to_cell(cell tagged, factor_vm *vm);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue