Spin2 Syntax

RaymanRayman Posts: 9,716
edited 2019-05-24 - 22:33:17 in Propeller 2
Now that Chip is working on Spin2 (and maybe before FastSpin solidifies), I have questions...

There was talk about making things like "=>" more like the C ">=".
What is decided on this? Is it maybe better to keep it like Spin1? (even though it is one my main gripes)…

My other main complaint was things like "repeat x from 1000 to 10 step -10".
This looks like it should work, but it doesn't...

There were a million other things... Time for review? (before it's done)
Prop Info and Apps: http://www.rayslogic.com/

Comments

  • Rayman, here are our current Spin2 operators:
    		Instruction/
    Operator	Term Assign	Priority	Term		Priority	Type		Description
    -------------------------------------------------------------------------------------------------------------------------------------------------
    ++ (pre)	++var		1		++var		1		var prefix	Pre-increment
    -- (pre)	--var		1		--var		1		var prefix	Pre-decrement
    ?? (pre)	??var		1		??var		1		var prefix	XORO32, iterate x and return pseudo-random
    
    ++ (post)	var++		1		var++		1		var postfix	Post-increment
    -- (post)	var--		1		var--		1		var postfix	Post-decrement
    !! (post)	var!!		1		var!!		1		var postfix	Post-logical NOT
    !  (post)	var!		1		var!		1		var postfix	Post-bitwise NOT
    \  (post)	var\x		1		var\x		1		var postfix	Post-set to y
    
    !		!= var		1		!x		2		unary		Bitwise NOT, 1's complement
    -		-= var		1		-x		2		unary		Negation, 2's complement
    ABS		ABS= var	1		ABS x		2		unary		Absolute value
    ENCOD		ENCOD= var	1		ENCOD x		2		unary		Encode MSB, 31..0
    DECOD		DECOD= var	1		DECOD x		2		unary		Decode, 1 << (x & $1F)
    ONES		ONES= var	1		ONES x		2		unary		Count ones
    SQRT		SQRT= var	1		SQRT x		2		unary		Square root of unsigned x
    QLOG		QLOG= var	1		QLOG x		2		unary		Unsigned to logarithm
    QEXP		QEXP= var	1		QEXP x		2		unary		Logarithm to unsigned
    
    >>		var >>= x	16		x >> y		3		binary		Shift right, insert 0's
    <<		var <<= x	16		x << y		3		binary		Shift left, insert 0's
    SAR		var SAR= x	16		x SAR y		3		binary		Shift right, insert MSB's
    ROR		var ROR= x	16		x ROR y		3		binary		Rotate right
    ROL		var ROL= x	16		x ROL y		3		binary		Rotate left
    REV		var REV= x	16		x REV y		3		binary		Reverse y LSBs of x and zero-extend
    ZEROX		var ZEROX= x	16		x ZEROX y	3		binary		Zero-extend above bit y
    SIGNX		var SIGNX= x	16		x SIGNX y	3		binary		Sign-extend from bit y
    
    &		var &= x	16		x & y		4		binary		Bitwise AND
    ^		var ^= x	16		x ^ y		5		binary		Bitwise XOR
    |		var |= x	16		x | y		6		binary		Bitwise OR
    
    *		var *= x	16		x * y		7		binary		Signed multiply
    /		var /= x	16		x / y		7		binary		Signed divide, return quotient
    +/		var +/= x	16		x +/ y		7		binary		Unsigned divide, return quotient
    //		var //= x	16		x // y		7		binary		Signed divide, return remainder
    +//		var +//= x	16		x +// y		7		binary		Unsigned divide, return remainder
    SCA		var SCA= x	16		x SCA y		7		binary		Unsigned scale (x * y) >> 32
    SCAS		var SCAS= x	16		x SCAS y	7		binary		Signed scale (x * y) >> 30
    FRAC		var FRAC= x	16		x FRAC y	7		binary		Unsigned fraction {x, 32'b0} / y
    
    +		var += x	16		x + y		8		binary		Add
    -		var -= x	16		x - y		8		binary		Subtract
    
    #>		var #>= x	16		x #> y		9		binary		Ensure x => y, signed
    <#		var <#= x	16		x <# y		9		binary		Ensure x <= y, signed
    
    <				-		x < y		10		binary		Signed less than		(returns 0 or -1)
    +<				-		x +< y		10		binary		Unsigned less than		(returns 0 or -1)
    <=				-		x <= y		10		binary		Signed less than or equal	(returns 0 or -1)
    +<=				-		x +<= y		10		binary		Unsigned less than or equal	(returns 0 or -1)
    ==				-		x == y		10		binary		Equal				(returns 0 or -1)
    <>				-		x <> y		10		binary		Not equal			(returns 0 or -1)
    >=				-		x >= y		10		binary		Signed greater than or equal	(returns 0 or -1)
    +>=				-		x +>= y		10		binary		Unsigned greater than or equal	(returns 0 or -1)
    >				-		x > y		10		binary		Signed greater than		(returns 0 or -1)
    +>				-		x +> y		10		binary		Unsigned greater than		(returns 0 or -1)
    <=>				-		x <=> y		10		binary		Signed comparison	   (<,=,> returns -1,0,1)
    
    !!, NOT		!!= var		1		!!x		11		unary		Logical NOT  (x == 0,            returns 0 or -1)
    &&, AND		var &&= x	16		x && y		12		binary		Logical AND  (x <> 0 AND y <> 0, returns 0 or -1)
    ^^, XOR		var ^^= x	16		x ^^ y		13		binary		Logical XOR  (x <> 0 XOR y <> 0, returns 0 or -1)
    ||, OR		var ||= x	16		x || y		14		binary		Logical OR   (x <> 0 OR  y <> 0, returns 0 or -1)
    
    ? :						x ? y : z	15		ternary		Choose between y and z
    
    :=		var := x	16						assign		Set var to x
    
    (,,,) :=	(x,y) := (a,b)							assign		set (x,y) to (a,b), 2..16 variables
    
    
    Math functions
    ---------------------------------------------------------------------------------------------
    (x,y) := ROTXY(x,y,t)		Rotate cartesian (x,y) by t and assign resultant (x,y)
    (r,t) := XYPOL(x,y)		Convert cartesian (x,y) to polar and assign resultant (r,t)
    (x,y) := POLXY(r,t)		Convert polar (r,t) to cartesian and assign resultant (x,y)
    
    Miscellaneous
    ---------------------------------------------------------------------------------------------
    SWAP(x,y)			Swap variables x and y (uses '\' bytecode for efficiency)
    
  • cgraceycgracey Posts: 11,710
    edited 2019-05-24 - 22:20:08
    My other main complaint was how things like "repeat x from 1000 to 10 step -10".
    This looks like it should work, but it doesn't...

    That's different now. Before the loop body, the FROM and TO values are checked for direction. Then, the STEP value is made absolute (positive) and optionally negated if FROM is greater than TO. On each loop iteration, the modified STEP value is added to an in-stack accumulator and the accumulator is copied to the variable, for reference during the REPEAT.
  • RaymanRayman Posts: 9,716
    edited 2019-05-24 - 22:35:48
    Thanks! I know this was discussed ad nauseam, but it's been a while...
    Prop Info and Apps: http://www.rayslogic.com/
Sign In or Register to comment.