@@ -21,18 +21,18 @@ pub fn default_defines(defines: &mut DefineMap) {
2121
2222 // #define EXCEPTION(value) new /exception(value)
2323 defines. insert (
24- "EXCEPTION" . into ( ) ,
24+ ident ! ( "EXCEPTION" ) ,
2525 (
2626 location,
2727 Define :: Function {
28- params : vec ! [ "value" . into ( ) ] ,
28+ params : vec ! [ ident! ( "value" ) ] ,
2929 variadic : false ,
3030 subst : vec ! [
31- Ident ( "new" . into ( ) , true ) ,
31+ Ident ( ident! ( "new" ) , true ) ,
3232 Punct ( Punctuation :: Slash ) ,
33- Ident ( "exception" . into ( ) , false ) ,
33+ Ident ( ident! ( "exception" ) , false ) ,
3434 Punct ( Punctuation :: LParen ) ,
35- Ident ( "value" . into ( ) , false ) ,
35+ Ident ( ident! ( "value" ) , false ) ,
3636 Punct ( Punctuation :: RParen ) ,
3737 ] ,
3838 docs : Default :: default ( ) ,
@@ -42,30 +42,30 @@ pub fn default_defines(defines: &mut DefineMap) {
4242
4343 // #define ASSERT(expression) if (!(expression)) { CRASH("[__FILE__]:[__LINE__]:Assertion Failed: [#X]") }
4444 defines. insert (
45- "ASSERT" . into ( ) ,
45+ ident ! ( "ASSERT" ) ,
4646 (
4747 location,
4848 Define :: Function {
49- params : vec ! [ "expression" . into ( ) ] ,
49+ params : vec ! [ ident! ( "expression" ) ] ,
5050 variadic : false ,
5151 subst : vec ! [
52- Ident ( "if" . into ( ) , true ) ,
52+ Ident ( ident! ( "if" ) , true ) ,
5353 Punct ( Punctuation :: LParen ) ,
5454 Punct ( Punctuation :: Not ) ,
5555 Punct ( Punctuation :: LParen ) ,
56- Ident ( "expression" . into ( ) , false ) ,
56+ Ident ( ident! ( "expression" ) , false ) ,
5757 Punct ( Punctuation :: RParen ) ,
5858 Punct ( Punctuation :: RParen ) ,
5959 Punct ( Punctuation :: LBrace ) ,
60- Ident ( "CRASH" . into ( ) , false ) ,
60+ Ident ( ident! ( "CRASH" ) , false ) ,
6161 Punct ( Punctuation :: LParen ) ,
6262 InterpStringBegin ( "" . to_owned( ) ) ,
63- Ident ( "__FILE__" . into ( ) , false ) ,
64- InterpStringPart ( ":" . into ( ) ) ,
65- Ident ( "__LINE__" . into ( ) , false ) ,
63+ Ident ( ident! ( "__FILE__" ) , false ) ,
64+ InterpStringPart ( ":" . to_owned ( ) ) ,
65+ Ident ( ident! ( "__LINE__" ) , false ) ,
6666 InterpStringPart ( ":Assertion Failed: " . to_owned( ) ) ,
6767 Punct ( Punctuation :: Hash ) ,
68- Ident ( "expression" . into ( ) , false ) ,
68+ Ident ( ident! ( "expression" ) , false ) ,
6969 InterpStringEnd ( "" . to_owned( ) ) ,
7070 Punct ( Punctuation :: RParen ) ,
7171 Punct ( Punctuation :: RBrace ) ,
@@ -76,14 +76,26 @@ pub fn default_defines(defines: &mut DefineMap) {
7676 ) ;
7777
7878 // constants
79+ fn constants ( defines : & mut DefineMap , values : & [ ( & ' static str , [ Token ; 1 ] ) ] ) {
80+ for & ( name, ref value) in values {
81+ let previous = defines. insert (
82+ crate :: ast:: Ident :: from_static ( name) ,
83+ (
84+ Location :: builtins ( ) ,
85+ Define :: Constant {
86+ subst : value. to_vec ( ) ,
87+ docs : Default :: default ( ) ,
88+ } ,
89+ ) ,
90+ ) ;
91+ assert ! ( previous. is_none( ) , "redefined: {}" , name) ;
92+ }
93+ }
7994 macro_rules! c {
8095 ( $( $i: ident = $( $x: expr) ,* ; ) * ) => {
81- for & ( name , ref value ) in & [
96+ constants ( defines , & [
8297 $( ( stringify!( $i) , [ $( $x, ) * ] ) , ) *
83- ] {
84- let previous = defines. insert( name. into( ) , ( location, Define :: Constant { subst: value. to_vec( ) , docs: Default :: default ( ) } ) ) ;
85- assert!( previous. is_none( ) , "redefined: {}" , name) ;
86- }
98+ ] ) ;
8799 }
88100 }
89101 c ! {
@@ -213,7 +225,6 @@ pub fn default_defines(defines: &mut DefineMap) {
213225 LINEAR_RAND = Int ( 2 ) ;
214226 SQUARE_RAND = Int ( 3 ) ;
215227
216-
217228 // json encode flags (515)
218229 JSON_PRETTY_PRINT = Int ( 1 ) ;
219230
@@ -227,7 +238,11 @@ pub fn default_defines(defines: &mut DefineMap) {
227238pub fn register_builtins ( tree : & mut ObjectTreeBuilder ) {
228239 fn path ( path : & ' static [ & ' static str ] ) -> Constant {
229240 Constant :: Prefab ( Box :: new ( super :: constants:: Pop {
230- path : path. iter ( ) . copied ( ) . map ( Ident :: from) . collect :: < Box < [ _ ] > > ( ) ,
241+ path : path
242+ . iter ( )
243+ . copied ( )
244+ . map ( Ident :: from_static)
245+ . collect :: < Box < [ _ ] > > ( ) ,
231246 vars : Default :: default ( ) ,
232247 } ) )
233248 }
@@ -244,7 +259,7 @@ pub fn register_builtins(tree: &mut ObjectTreeBuilder) {
244259 }
245260 macro_rules! string {
246261 ( $e: expr) => {
247- Constant :: String ( $e . into ( ) )
262+ Constant :: String ( ident! ( $e ) )
248263 } ;
249264 }
250265
0 commit comments