Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix constant value #46

Merged
merged 6 commits into from
Oct 14, 2023
Merged

Fix constant value #46

merged 6 commits into from
Oct 14, 2023

Conversation

moeshin
Copy link
Contributor

@moeshin moeshin commented Oct 12, 2023

package test

const (
	N0 = iota
	N1
	N2
	N3 = 1 << iota
	N4
	N5
	N6 = 0xFF + 0x00ff
	N7 = 0b1010 | 0b0100
	N8 = 0664 & 0004

	T0 = 0 ^ 1&2 | 3%4*5/6 + 7<<8>>9 ^ 10 + -+-+-+-0
	// 15

	T1 = 15 & 10 / 3 % 2 << 4
	// 16

	T2 = 2 + 3*4 - 5/1&6 ^ 7 | ^8<<2>>1
	// -17

	T3 = (4-2)*5/3&6 ^ 7 | ^8<<2>>1
	// -17

	T4 = 2 + 3*(4-5)/1&6 ^ 7 | ^8<<2>>1
	// -17

	T5 = 2 + 3*4 - 5/(9&1) ^ 7 | ^8<<2>>1
	// -18

	T6 = 2 + 3*4 - 5/1&6 ^ (7|^8)<<2>>1
	// -28

	T7 = 2 + 3*4 - 5/1&6 ^ 7 | ^8<<(2>>1)
	// -17

	T8 = 2 + 3*4 - 5/1&(6^7|^8)<<2>>1
	// 4

	T9 = 2 + 3*4 - (5/1&6^7|^8)<<2>>1
	// 32

	T10 = 2 + 3*(4-5/1&6) ^ 7 | ^8<<2>>1
	// -17

	T11 = 2 + (3*4-5/1&6^7|^8)>>2
	// 1

	T12 = 2 + (3*4-5/1&6&^7|^8)>>2
	// 1

	S1        = "1"
	S2        = "1" + "2"
	S3 string = S2 + "3"
	S4        = "\\\u0023\\\uff01🍎\\\U0001F34E\\\\U0001F34E"

	B0 = true
	B1 = true && !false
	B2 = !(true || B1) && true

	C1 = '1'
	C2 = ^'2'&1*8 + 0xFF
	C3 = 'A' + iota
	C4
	C5
	C6  = '\u0023'
	C7  = '\uFF01'
	C8  = '\U0010FFFF'
	C9  = '\x32'
	C10 = '\b'
	C11 = '🍎'
)
// Code generated by tygo. DO NOT EDIT.

//////////
// source: test.go

export const N0 = 0;
export const N1 = 1;
export const N2 = 2;
export const N3 = 1 << 3;
export const N4 = 1 << 4;
export const N5 = 1 << 5;
export const N6 = 0xFF + 0x00ff;
export const N7 = 0b1010 | 0b0100;
export const N8 = 0o664 & 0o004;
export const T0 = (((0 ^ 1 & 2) | 3 % 4 * 5 / 6) + (7 << 8 >> 9) ^ 10) + -+-+-+-0;
export const T1 = (15 & 10) / 3 % 2 << 4;
export const T2 = (2 + 3 * 4 - (5 / 1 & 6) ^ 7) | ~8 << 2 >> 1;
export const T3 = ((4 - 2) * 5 / 3 & 6 ^ 7) | ~8 << 2 >> 1;
export const T4 = (2 + (3 * (4 - 5) / 1 & 6) ^ 7) | ~8 << 2 >> 1;
export const T5 = (2 + 3 * 4 - 5 / (9 & 1) ^ 7) | ~8 << 2 >> 1;
export const T6 = 2 + 3 * 4 - (5 / 1 & 6) ^ (7 | ~8) << 2 >> 1;
export const T7 = (2 + 3 * 4 - (5 / 1 & 6) ^ 7) | ~8 << (2 >> 1);
export const T8 = 2 + 3 * 4 - ((5 / 1 & ((6 ^ 7) | ~8)) << 2 >> 1);
export const T9 = 2 + 3 * 4 - (((5 / 1 & 6 ^ 7) | ~8) << 2 >> 1);
export const T10 = (2 + 3 * (4 - (5 / 1 & 6)) ^ 7) | ~8 << 2 >> 1;
export const T11 = 2 + (((3 * 4 - (5 / 1 & 6) ^ 7) | ~8) >> 2);
export const T12 = 2 + ((3 * 4 - (5 / 1 & 6 & ~7) | ~8) >> 2);
export const S1 = "1";
export const S2 = "1" + "2";
export const S3: string = S2 + "3";
export const S4 = "\\\u0023\\\uff01🍎\\\u{0001F34E}\\\\U0001F34E";
export const B0 = true;
export const B1 = true && !false;
export const B2 = !(true || B1) && true;
export const C1 = 0x0031 /* '1' */;
export const C2 = (~0x0032 /* '2' */ & 1) * 8 + 0xFF;
export const C3 = 0x0041 /* 'A' */ + 31;
export const C4 = 0x0041 /* 'A' */ + 32;
export const C5 = 0x0041 /* 'A' */ + 33;
export const C6 = 0x0023 /* '\u0023' */;
export const C7 = 0xFF01 /* '\uFF01' */;
export const C8 = 0x0010FFFF /* '\U0010FFFF' */;
export const C9 = 0x0032 /* '\x32' */;
export const C10 = 0x0008 /* '\b' */;
export const C11 = 0x0001F34E /* '🍎' */;

@moeshin moeshin marked this pull request as draft October 13, 2023 09:14
@moeshin moeshin marked this pull request as ready for review October 13, 2023 10:01
@gzuidhof
Copy link
Owner

This is really fantastic, I never needed such constants to be carried across typings - but it definitely doesn't hurt to have more consistent behavior even with complicated expressions.

I hope to never see this in real code ;) -+-+-+-0

Thank you!

@gzuidhof gzuidhof merged commit 1e537aa into gzuidhof:main Oct 14, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants