| ... | @@ -7048,8 +7048,10 @@ test "foo" { | ... | @@ -7048,8 +7048,10 @@ test "foo" { |
| 7048 | <li>All variables are {#syntax#}comptime{#endsyntax#} variables.</li> | 7048 | <li>All variables are {#syntax#}comptime{#endsyntax#} variables.</li> |
| 7049 | <li>All {#syntax#}if{#endsyntax#}, {#syntax#}while{#endsyntax#}, {#syntax#}for{#endsyntax#}, and {#syntax#}switch{#endsyntax#} | 7049 | <li>All {#syntax#}if{#endsyntax#}, {#syntax#}while{#endsyntax#}, {#syntax#}for{#endsyntax#}, and {#syntax#}switch{#endsyntax#} |
| 7050 | expressions are evaluated at compile-time, or emit a compile error if this is not possible.</li> | 7050 | expressions are evaluated at compile-time, or emit a compile error if this is not possible.</li> |
| 7051 | <li>All function calls cause the compiler to interpret the function at compile-time, emitting a | 7051 | <li>All {#syntax#}return{#endsyntax#} and {#syntax#}try{#endsyntax#} expressions are invalid (unless the function itself is called at compile-time).</li> |
| 7052 | compile error if the function tries to do something that has global run-time side effects.</li> | 7052 | <li>All code with runtime side effects or depending on runtime values emits a compile error.</li> |
| | 7053 | <li>All function calls cause the compiler to interpret the function at compile-time, emitting a |
| | 7054 | compile error if the function tries to do something that has global runtime side effects.</li> |
| 7053 | </ul> | 7055 | </ul> |
| 7054 | <p> | 7056 | <p> |
| 7055 | This means that a programmer can create a function which is called both at compile-time and run-time, with | 7057 | This means that a programmer can create a function which is called both at compile-time and run-time, with |
| ... | @@ -7071,9 +7073,7 @@ test "fibonacci" { | ... | @@ -7071,9 +7073,7 @@ test "fibonacci" { |
| 7071 | try expect(fibonacci(7) == 13); | 7073 | try expect(fibonacci(7) == 13); |
| 7072 | | 7074 | |
| 7073 | // test fibonacci at compile-time | 7075 | // test fibonacci at compile-time |
| 7074 | comptime { | 7076 | try comptime expect(fibonacci(7) == 13); |
| 7075 | try expect(fibonacci(7) == 13); | | |
| 7076 | } | | |
| 7077 | } | 7077 | } |
| 7078 | {#code_end#} | 7078 | {#code_end#} |
| 7079 | <p> | 7079 | <p> |
| ... | @@ -7088,9 +7088,7 @@ fn fibonacci(index: u32) u32 { | ... | @@ -7088,9 +7088,7 @@ fn fibonacci(index: u32) u32 { |
| 7088 | } | 7088 | } |
| 7089 | | 7089 | |
| 7090 | test "fibonacci" { | 7090 | test "fibonacci" { |
| 7091 | comptime { | 7091 | try comptime expect(fibonacci(7) == 13); |
| 7092 | try expect(fibonacci(7) == 13); | | |
| 7093 | } | | |
| 7094 | } | 7092 | } |
| 7095 | {#code_end#} | 7093 | {#code_end#} |
| 7096 | <p> | 7094 | <p> |
| ... | @@ -7111,9 +7109,7 @@ fn fibonacci(index: i32) i32 { | ... | @@ -7111,9 +7109,7 @@ fn fibonacci(index: i32) i32 { |
| 7111 | } | 7109 | } |
| 7112 | | 7110 | |
| 7113 | test "fibonacci" { | 7111 | test "fibonacci" { |
| 7114 | comptime { | 7112 | try comptime assert(fibonacci(7) == 13); |
| 7115 | try assert(fibonacci(7) == 13); | | |
| 7116 | } | | |
| 7117 | } | 7113 | } |
| 7118 | {#code_end#} | 7114 | {#code_end#} |
| 7119 | <p> | 7115 | <p> |
| ... | @@ -7143,9 +7139,7 @@ fn fibonacci(index: i32) i32 { | ... | @@ -7143,9 +7139,7 @@ fn fibonacci(index: i32) i32 { |
| 7143 | } | 7139 | } |
| 7144 | | 7140 | |
| 7145 | test "fibonacci" { | 7141 | test "fibonacci" { |
| 7146 | comptime { | 7142 | try comptime assert(fibonacci(7) == 99999); |
| 7147 | try assert(fibonacci(7) == 99999); | | |
| 7148 | } | | |
| 7149 | } | 7143 | } |
| 7150 | {#code_end#} | 7144 | {#code_end#} |
| 7151 | | 7145 | |