m8ta
You are not authenticated, login.
text: sort by
tags: modified
type: chronology
{1574}
hide / / print
ref: -0 tags: ocaml application functional programming date: 10-11-2022 21:36 gmt revision:2 [1] [0] [head]

https://stackoverflow.com/questions/26475765/ocaml-function-with-variable-number-of-arguments

From this I learned that in ocaml you can return not just functions (e.g. currying) but appliations of yet-to-be named functions.

let sum f = f 0 ;;
let arg a b c = c ( b + a ) ;;
let z a = a ;;

then

sum (arg 1) ;; 

is well-typed as (int -> `a) -> `a = <fun> e.g. an application of a function that converts int to `a. Think of it as the application of Xa to argument ( 0 + 1 ), where Xa is the argument (per type signature). Zero is supplied by the definition of 'sum'.

 sum (arg 1) (arg 2);; 

can be parsed as

(sum (arg 1)) (arg 2) ;; 

'(arg 2)' outputs an application of an int & a yet-to be determined function to 'a,

E.g. it's typed as int -> (int -> `a) -> `a = <fun>. So, you can call it Xa passed to above.

Or, Xa = Xb( ( 0 + 1 ) + 2)

where, again, Xb is a yet-to-be defined function that is supplied as an argument.

Therefore, you can collapse the whole chain with the identity function z. But, of course, it could be anything else -- square root perhaps for MSE?

All very clever.

{464}
hide / / print
ref: notes-0 tags: Blackfin perl loopcounters registers ABI application-binary interface gcc assembly date: 10-19-2007 17:24 gmt revision:2 [1] [0] [head]

The problem: I have an interrupt status routine (ISR) which can interrupt the main, radio-servicing routine at any time. To keep the ISR from corrupting the register values of the main routine while it works, these registers must be pushed, and later popped, to the stack. Now, doing this takes time, so I'd prefer to pop / push as few registers as possible. Namely, I don't want to push/pop the hardware loop registers - LC0 (loop counter 0), LB0 (loop bottom 0, where the hardware loop starts) & LT0 (loop top 0, where the hardware loop ends).

Gcc seems to only touch bank 1, never bank 0, so I don't have to save the 3 regs above. However, to make sure, I've written a perl file to examine the assembled code:

my $file = "decompile.asm"; 
open(FH, $file); 
@j = <FH>; 
my $i=0; 
my @badregs = ("LC0", "LB0", "LT0"); 
foreach $reg (@badregs){
	foreach $k (@j){
		if($k =~ /$reg/){
			$i++;
			print "touch register $reg : $k";
		}
	}
}
#tell make if we found problems or not.
if($i>0){
	exit 1;
}else{
	exit 0;
}

'make' looks at the return value perl outputs, as instructed via the makefile (relevant portion below):

headstage.ldr:headstage.dxe
	rm -f *.ldr
	$(LDR) -T BF532 -c headstage.ldr $<
	bfin-elf-objdump -d headstage.dxe > decompile.asm
	perl register_check.pl

if it finds assembly which accesses the 'bad' registers, make fails.

{403}
hide / / print
ref: bookmark-0 tags: blackfin ELF freestanding applications boot date: 08-01-2007 14:40 gmt revision:0 [head]

http://www.johanforrer.net/BLACKFIN/index.html

very good, very instructive.