shithub: mc

Download patch

ref: 64462bb36f34be7ab4aa1fcf7195739eb617a044
parent: 63f4ce6387dea9f943ecc9c9f9b7af147560839d
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jan 11 18:48:53 EST 2019

Keep partial indents better.

	Align to what I want it to align to.

--- a/lib/crypto/x25519.myr
+++ b/lib/crypto/x25519.myr
@@ -50,7 +50,7 @@
 use std
 
 pkg crypto =
-	const x25519	: (out : byte[:], inu : byte[:], inpt : byte[:] -> void)
+	const curve25519 : (pub : byte[:/*32*/], secret : byte[:/*32*/], basepoint : byte[:/*32*/] -> void)
 ;;
 
 type felem = uint64
@@ -237,7 +237,7 @@
 	fproduct(t[:], in, in2)
 	freducedegree(t[:])
 	freducecoeff(t[:])
-	std.slcp(out, t[:10])
+	std.slcp(out[:10], t[:10])
 }
 
 const fsquareinner = {out, in
@@ -302,10 +302,11 @@
 
 const fsquare = {out, in
 	var t : felem[19]
+
 	fsquareinner(t[:], in)
 	freducedegree(t[:])
 	freducecoeff(t[:])
-	std.slcp(out, t[:10])
+	std.slcp(out[:10], t[:10])
 }
 
 /* Take a little-endian, 32-byte number and expand it into polynomial form */
@@ -430,11 +431,11 @@
 	var zzzprime : felem[19]
 	var xxxprime : felem[19]
 
-	std.slcp(origx[:], x[:10])
+	std.slcp(origx[:10], x[:10])
 	fsum(x, z)
 	fdiff(z, origx[:]);  // does x - z
 
-	std.slcp(origxprime[:], xprime[:10])
+	std.slcp(origxprime[:10], xprime[:10])
 	fsum(xprime, zprime)
 	fdiff(zprime, origxprime[:])
 	fproduct(xxprime[:], xprime, z)
@@ -443,7 +444,7 @@
 	freducecoeff(xxprime[:])
 	freducedegree(zzprime[:])
 	freducecoeff(zzprime[:])
-	std.slcp(origxprime[:], xxprime[:10])
+	std.slcp(origxprime[:10], xxprime[:10])
 	fsum(xxprime[:], zzprime[:])
 	fdiff(zzprime[:], origxprime[:])
 	fsquare(xxxprime[:], xxprime[:])
@@ -451,8 +452,8 @@
 	fproduct(zzprime[:], zzzprime[:], qmqp)
 	freducedegree(zzprime[:])
 	freducecoeff(zzprime[:])
-	std.slcp(x3, xxxprime[:10])
-	std.slcp(z3, zzprime[:10])
+	std.slcp(x3[:10], xxxprime[:10])
+	std.slcp(z3[:10], zzprime[:10])
 
 	fsquare(xx[:], x)
 	fsquare(zz[:], z)
@@ -530,8 +531,8 @@
 		;;
 	;;
 
-	std.slcp(resultx, nqx[:10])
-	std.slcp(resultz, nqz[:10])
+	std.slcp(resultx[:10], nqx[:10])
+	std.slcp(resultz[:10], nqz[:10])
 }
 
 // -----------------------------------------------------------------------------
@@ -641,5 +642,3 @@
 	fcontract(pub[:], z[:])
 }
 
-const x25519 = {out, inu, inscalar
-}
--- a/support/vim/indent/myr.vim
+++ b/support/vim/indent/myr.vim
@@ -3,108 +3,113 @@
 " Maintainer: Ori Bernstein
 
 if exists("b:did_indent")
-    finish
+	finish
 endif
 
 function! Quoted(lnum, col)
-    let stk = synstack(a:lnum, a:col)
-    for id in stk
-        let a = synIDattr(id, "name") 
-        if a == "myrComment" || a == "myrString" || a == "myrChar"
-            return 1
-        endif
-    endfor
-    return 0
+	let stk = synstack(a:lnum, a:col)
+	for id in stk
+		let a = synIDattr(id, "name") 
+		if a == "myrComment" || a == "myrString" || a == "myrChar"
+			return 1
+		endif
+	endfor
+	return 0
 endfunction
 
 function! s:CountMatches(line, lnum, pats)
-    let matches = 0
-    for p in a:pats
-        let idx = 0
-        while idx >= 0
-            let idx = match(a:line, p, idx)
-            if idx >= 0
-                let ic = Quoted(a:lnum, idx+1)
-                if !ic
-                    let matches = matches + 1
-                endif
-                let idx = idx + strlen(p)
-            endif
-        endwhile
-    endfor
-    return matches
+	let matches = 0
+	for p in a:pats
+		let idx = 0
+		while idx >= 0
+			let idx = match(a:line, p, idx)
+			if idx >= 0
+				let ic = Quoted(a:lnum, idx+1)
+				if !ic
+					let matches = matches + 1
+				endif
+				let idx = idx + strlen(p)
+			endif
+		endwhile
+	endfor
+	return matches
 endfunction
 
 function! s:LineMatch(line, pats)
-    for p in a:pats
-        let pat = '^\s*'.p.'\s*$'
-        if match(a:line, pat, 0) >= 0
-            return 1
-        endif
-    endfor
-    return 0
+	for p in a:pats
+		let pat = '^\s*'.p.'\s*$'
+		if match(a:line, pat, 0) >= 0
+			return 1
+		endif
+	endfor
+	return 0
 endfunction
 
 function! s:Clamp(val, lo, hi)
-    if a:val < a:lo
-        return a:lo
-    elseif a:val > a:hi
-        return a:hi
-    endif
-    return a:val
+	if a:val < a:lo
+		return a:lo
+	elseif a:val > a:hi
+		return a:hi
+	endif
+	return a:val
 endfunction
 
 function! GetMyrIndent(ln)
-    let ln = a:ln
+	let ln = a:ln
 
-    if ln == 1
-        let ind = 0
-    else
-        let i = 1
-        let prevln = ''
-        while prevln =~ '^\s*$\|^:.*'
-            let prevln = getline(ln - i)
-            let ind = indent(ln - i)
-            let i = i + 1
-        endwhile
-        let i = i - 1
+	if ln == 1
+		let ind = 0
+	else
+		let i = 1
+		let prevln = ''
+		while prevln =~ '^\s*$\|^:.*'
+			let prevln = getline(ln - i)
+			let ind = indent(ln - i)
+			let i = i + 1
+		endwhile
+		let i = i - 1
 
-        let curln = getline(ln)
+		let curln = getline(ln)
 
-        if curln =~ '^\s*:.*'
-            let ind = 0
-        else
-            let inpat = ['\<if\>', '\<while\>','\<for\>', '\<match\>',
-                        \    '\<struct\>', '\<union\>', '{', '\[', '(', '=\s*$']
-            let outpat = ['}', ']', ')', ';;']
-            let outalone = ['].*', ').*', '}.*', ';;']
-            let inoutalone = ['\<else\>', '\<elif\>.*', '|.*']
-            let width = &tabstop
+		if curln =~ '^\s*:.*'
+			let ind = 0
+		else
+			let inpat = ['\<if\>', '\<while\>','\<for\>', '\<match\>',
+						\    '\<struct\>', '\<union\>', '{', '\[', '(', '=\s*$']
+			let outpat = ['}', ']', ')', ';;']
+			let outalone = ['].*', ').*', '}.*', ';;']
+			let inoutalone = ['\<else\>', '\<elif\>.*', '|.*']
+			let width = &tabstop
 
-            let n_in = s:CountMatches(prevln, ln - i, inpat)
-            if s:LineMatch(prevln, outalone) != 0
-                let n_out = 0
-            else
-                let n_out = s:CountMatches(prevln, ln - i, outpat)
-            endif
-            let n_in += s:LineMatch(prevln, inoutalone)
-            let n_out += s:LineMatch(curln, outalone)
-            let n_out += s:LineMatch(curln, inoutalone)
+			let n_in = s:CountMatches(prevln, ln - i, inpat)
+			if s:LineMatch(prevln, outalone) != 0
+				let n_out = 0
+			else
+				let n_out = s:CountMatches(prevln, ln - i, outpat)
+			endif
+			let n_in += s:LineMatch(prevln, inoutalone)
+			let n_out += s:LineMatch(curln, outalone)
+			let n_out += s:LineMatch(curln, inoutalone)
 
-            " indent escaped line endings
-            if prevln =~ '\\\s*$' && getline(ln - i - 1) !~ '\\\s*$'
-                let n_in = n_in + 1
-            endif
-            " if we break the set of indented line endings, outdent
-            if getline(ln - i - 1) =~ '\\\s*$' && getline(ln - i) !~ '\\\s*$'
-                let n_out = n_out + 1
-            endif
+			" indent escaped line endings
+			if prevln =~ '\\\s*$' && getline(ln - i - 1) !~ '\\\s*$'
+				let n_in = n_in + 1
+			endif
+			" if we break the set of indented line endings, outdent
+			if getline(ln - i - 1) =~ '\\\s*$' && getline(ln - i) !~ '\\\s*$'
+				let n_out = n_out + 1
+			endif
 
-            let delta = s:Clamp(n_in - n_out, -1, 1) 
-            let ind = ind + delta * &tabstop
-        endif
-    endif
-    return ind
+			let delta = s:Clamp(n_in - n_out, -1, 1) 
+			if delta != 0
+				let ind = ind + delta * &tabstop
+				if  ind % &tabstop != 0
+					let ind = ind + &tabstop - (ind % &tabstop)
+				endif
+			endif
+		endif
+	endif
+	return ind
 endfunction
 
 setlocal indentkeys+=,;\|]),=elif,=else,=: