@@ -577,7 +577,6 @@ export namespace BuiltinNames {
577577 export const INFO = "~lib/diagnostics/INFO" ;
578578
579579 // std/memory.ts
580- export const memory = "~lib/memory/memory" ;
581580 export const memory_size = "~lib/memory/memory.size" ;
582581 export const memory_grow = "~lib/memory/memory.grow" ;
583582 export const memory_copy = "~lib/memory/memory.copy" ;
@@ -2476,67 +2475,6 @@ builtins.set(BuiltinNames.unreachable, builtin_unreachable);
24762475
24772476// === Memory =================================================================================
24782477
2479- // memory(size[, align]) -> usize
2480- function builtin_memory ( ctx : BuiltinContext ) : ExpressionRef {
2481- var compiler = ctx . compiler ;
2482- var module = compiler . module ;
2483- compiler . currentType = Type . i32 ;
2484- if (
2485- checkTypeAbsent ( ctx ) |
2486- checkArgsOptional ( ctx , 1 , 2 )
2487- ) return module . unreachable ( ) ;
2488- var operands = ctx . operands ;
2489- var numOperands = operands . length ;
2490- var usizeType = compiler . options . usizeType ;
2491- var arg0 = compiler . precomputeExpression ( operands [ 0 ] , Type . i32 , Constraints . CONV_IMPLICIT ) ;
2492- compiler . currentType = usizeType ;
2493- if ( getExpressionId ( arg0 ) != ExpressionId . Const ) {
2494- compiler . error (
2495- DiagnosticCode . Expression_must_be_a_compile_time_constant ,
2496- operands [ 0 ] . range
2497- ) ;
2498- return module . unreachable ( ) ;
2499- }
2500- var size = getConstValueI32 ( arg0 ) ;
2501- if ( size < 1 ) {
2502- compiler . error (
2503- DiagnosticCode . _0_must_be_a_value_between_1_and_2_inclusive ,
2504- operands [ 0 ] . range , "1" , i32 . MAX_VALUE . toString ( )
2505- ) ;
2506- return module . unreachable ( ) ;
2507- }
2508- var align = 16 ;
2509- if ( numOperands == 2 ) {
2510- align = evaluateImmediateOffset ( operands [ 1 ] , compiler ) ;
2511- compiler . currentType = usizeType ;
2512- if ( align < 0 ) {
2513- return module . unreachable ( ) ;
2514- }
2515- if ( align < 1 || align > 16 ) {
2516- compiler . error (
2517- DiagnosticCode . _0_must_be_a_value_between_1_and_2_inclusive ,
2518- operands [ 1 ] . range , "Alignment" , "1" , "16"
2519- ) ;
2520- return module . unreachable ( ) ;
2521- }
2522- if ( ! isPowerOf2 ( align ) ) {
2523- compiler . error (
2524- DiagnosticCode . _0_must_be_a_power_of_two ,
2525- operands [ 1 ] . range , "Alignment"
2526- ) ;
2527- return module . unreachable ( ) ;
2528- }
2529- }
2530- // FIXME: what if recompiles happen? recompiles are bad.
2531- var offset = compiler . addMemorySegment ( new Uint8Array ( size ) , align ) . offset ;
2532- if ( usizeType == Type . usize32 ) {
2533- assert ( ! i64_high ( offset ) ) ;
2534- return module . i32 ( i64_low ( offset ) ) ;
2535- }
2536- return module . i64 ( i64_low ( offset ) , i64_high ( offset ) ) ;
2537- }
2538- builtins . set ( BuiltinNames . memory , builtin_memory ) ;
2539-
25402478// memory.size() -> i32
25412479function builtin_memory_size ( ctx : BuiltinContext ) : ExpressionRef {
25422480 var compiler = ctx . compiler ;
@@ -2618,6 +2556,67 @@ function builtin_memory_fill(ctx: BuiltinContext): ExpressionRef {
26182556}
26192557builtins . set ( BuiltinNames . memory_fill , builtin_memory_fill ) ;
26202558
2559+ // memory.data(size[, align]) -> usize
2560+ function builtin_memory_data ( ctx : BuiltinContext ) : ExpressionRef {
2561+ var compiler = ctx . compiler ;
2562+ var module = compiler . module ;
2563+ compiler . currentType = Type . i32 ;
2564+ if (
2565+ checkTypeAbsent ( ctx ) |
2566+ checkArgsOptional ( ctx , 1 , 2 )
2567+ ) return module . unreachable ( ) ;
2568+ var operands = ctx . operands ;
2569+ var numOperands = operands . length ;
2570+ var usizeType = compiler . options . usizeType ;
2571+ var arg0 = compiler . precomputeExpression ( operands [ 0 ] , Type . i32 , Constraints . CONV_IMPLICIT ) ;
2572+ compiler . currentType = usizeType ;
2573+ if ( getExpressionId ( arg0 ) != ExpressionId . Const ) {
2574+ compiler . error (
2575+ DiagnosticCode . Expression_must_be_a_compile_time_constant ,
2576+ operands [ 0 ] . range
2577+ ) ;
2578+ return module . unreachable ( ) ;
2579+ }
2580+ var size = getConstValueI32 ( arg0 ) ;
2581+ if ( size < 1 ) {
2582+ compiler . error (
2583+ DiagnosticCode . _0_must_be_a_value_between_1_and_2_inclusive ,
2584+ operands [ 0 ] . range , "1" , i32 . MAX_VALUE . toString ( )
2585+ ) ;
2586+ return module . unreachable ( ) ;
2587+ }
2588+ var align = 16 ;
2589+ if ( numOperands == 2 ) {
2590+ align = evaluateImmediateOffset ( operands [ 1 ] , compiler ) ;
2591+ compiler . currentType = usizeType ;
2592+ if ( align < 0 ) {
2593+ return module . unreachable ( ) ;
2594+ }
2595+ if ( align < 1 || align > 16 ) {
2596+ compiler . error (
2597+ DiagnosticCode . _0_must_be_a_value_between_1_and_2_inclusive ,
2598+ operands [ 1 ] . range , "Alignment" , "1" , "16"
2599+ ) ;
2600+ return module . unreachable ( ) ;
2601+ }
2602+ if ( ! isPowerOf2 ( align ) ) {
2603+ compiler . error (
2604+ DiagnosticCode . _0_must_be_a_power_of_two ,
2605+ operands [ 1 ] . range , "Alignment"
2606+ ) ;
2607+ return module . unreachable ( ) ;
2608+ }
2609+ }
2610+ // FIXME: what if recompiles happen? recompiles are bad.
2611+ var offset = compiler . addMemorySegment ( new Uint8Array ( size ) , align ) . offset ;
2612+ if ( usizeType == Type . usize32 ) {
2613+ assert ( ! i64_high ( offset ) ) ;
2614+ return module . i32 ( i64_low ( offset ) ) ;
2615+ }
2616+ return module . i64 ( i64_low ( offset ) , i64_high ( offset ) ) ;
2617+ }
2618+ builtins . set ( BuiltinNames . memory_data , builtin_memory_data ) ;
2619+
26212620// === Helpers ================================================================================
26222621
26232622// changetype<T!>(value: *) -> T
0 commit comments