Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .equiv @sbrk, 9
- .equiv @print_string, 4
- .equiv @print_char, 11
- .equiv @print_int, 1
- .equiv @exit2, 17
- .equiv @.__obj_size__, 4
- .equiv @.__len__, 12
- .equiv @.__int__, 12
- .equiv @.__bool__, 12
- .equiv @.__str__, 16
- .equiv @.__elts__, 16
- .equiv @error_div_zero, 2
- .equiv @error_arg, 1
- .equiv @error_oob, 3
- .equiv @error_none, 4
- .equiv @error_oom, 5
- .equiv @error_nyi, 6
- .data
- .globl $object$prototype
- $object$prototype:
- .word 0 # Type tag for class: object
- .word 3 # Object size
- .word $object$dispatchTable # Pointer to dispatch table
- .align 2
- .globl $int$prototype
- $int$prototype:
- .word 1 # Type tag for class: int
- .word 4 # Object size
- .word $int$dispatchTable # Pointer to dispatch table
- .word 0 # Initial value of attribute: __int__
- .align 2
- .globl $bool$prototype
- $bool$prototype:
- .word 2 # Type tag for class: bool
- .word 4 # Object size
- .word $bool$dispatchTable # Pointer to dispatch table
- .word 0 # Initial value of attribute: __bool__
- .align 2
- .globl $str$prototype
- $str$prototype:
- .word 3 # Type tag for class: str
- .word 5 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 0 # Initial value of attribute: __len__
- .word 0 # Initial value of attribute: __str__
- .align 2
- .globl $.list$prototype
- $.list$prototype:
- .word -1 # Type tag for class: .list
- .word 4 # Object size
- .word 0 # Pointer to dispatch table
- .word 0 # Initial value of attribute: __len__
- .align 2
- .globl $object$dispatchTable
- $object$dispatchTable:
- .word $object.__init__ # Implementation for method: object.__init__
- .globl $int$dispatchTable
- $int$dispatchTable:
- .word $object.__init__ # Implementation for method: int.__init__
- .globl $bool$dispatchTable
- $bool$dispatchTable:
- .word $object.__init__ # Implementation for method: bool.__init__
- .globl $str$dispatchTable
- $str$dispatchTable:
- .word $object.__init__ # Implementation for method: str.__init__
- .globl $g
- $g:
- .word 1 # Initial value of global var: g
- .globl $h
- $h:
- .word 1 # Initial value of global var: h
- .globl $a
- $a:
- .word 0 # Initial value of global var: a
- .globl $b
- $b:
- .word 0 # Initial value of global var: b
- .globl $c
- $c:
- .word 0 # Initial value of global var: c
- .globl $d
- $d:
- .word 0 # Initial value of global var: d
- .globl $e
- $e:
- .word 0 # Initial value of global var: e
- .globl $f
- $f:
- .word 0 # Initial value of global var: f
- .text
- .globl main
- main:
- lui a0, 8192 # Initialize heap size (in multiples of 4KB)
- add s11, s11, a0 # Save heap size
- jal heap.init # Call heap.init routine
- mv gp, a0 # Initialize heap pointer
- mv s10, gp # Set beginning of heap
- add s11, s10, s11 # Set end of heap (= start of heap + heap size)
- mv ra, zero # No normal return from main program.
- mv fp, zero # No preceding frame.
- mv fp, zero # Top saved FP is 0.
- mv ra, zero # No function return from top level.
- addi sp, sp, -@..main.size # Reserve space for stack frame.
- sw ra, @..main.size-4(sp) # return address
- sw fp, @..main.size-8(sp) # control link
- addi fp, sp, @..main.size # New fp is at old SP.
- lw a0, $g # Load global: g
- sw a0, @..main.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @..main.negsize # Set SP to last argument.
- jal $foo # Invoke function: foo
- addi sp, fp, @..main.negsize # Set SP to stack frame top.
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @..main.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @..main.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @..main.negsize # Set SP to stack frame top.
- .equiv @..main.size, 16
- .equiv @..main.negsize, -16
- label_0: # End of program
- li a0, 10 # Code for ecall: exit
- ecall
- .globl $object.__init__
- $object.__init__:
- # Init method for type object.
- mv a0, zero # `None` constant
- jr ra # Return
- .globl $print
- $print:
- # Function print
- lw a0, 0(sp) # Load arg
- beq a0, zero, print_6 # None is an illegal argument
- lw t0, 0(a0) # Get type tag of arg
- li t1, 1 # Load type tag of `int`
- beq t0, t1, print_7 # Go to print(int)
- li t1, 3 # Load type tag of `str`
- beq t0, t1, print_8 # Go to print(str)
- li t1, 2 # Load type tag of `bool`
- beq t0, t1, print_9 # Go to print(bool)
- print_6: # Invalid argument
- li a0, 1 # Exit code for: Invalid argument
- la a1, const_2 # Load error message as str
- addi a1, a1, @.__str__ # Load address of attribute __str__
- j abort # Abort
- # Printing bools
- print_9: # Print bool object in A0
- lw a0, @.__bool__(a0) # Load attribute __bool__
- beq a0, zero, print_10 # Go to: print(False)
- la a0, const_3 # String representation: True
- j print_8 # Go to: print(str)
- print_10: # Print False object in A0
- la a0, const_4 # String representation: False
- j print_8 # Go to: print(str)
- # Printing strs.
- print_8: # Print str object in A0
- addi a1, a0, @.__str__ # Load address of attribute __str__
- j print_11 # Print the null-terminated string is now in A1
- mv a0, zero # Load None
- j print_5 # Go to return
- print_11: # Print null-terminated string in A1
- li a0, @print_string # Code for ecall: print_string
- ecall # Print string
- li a1, 10 # Load newline character
- li a0, @print_char # Code for ecall: print_char
- ecall # Print character
- j print_5 # Go to return
- # Printing ints.
- print_7: # Print int object in A0
- lw a1, @.__int__(a0) # Load attribute __int__
- li a0, @print_int # Code for ecall: print_int
- ecall # Print integer
- li a1, 10 # Load newline character
- li a0, 11 # Code for ecall: print_char
- ecall # Print character
- print_5: # End of function
- mv a0, zero # Load None
- jr ra # Return to caller
- .globl $len
- $len:
- # Function len
- # We do not save/restore fp/ra for this function
- # because we know that it does not use the stack or does not
- # call other functions.
- lw a0, 0(sp) # Load arg
- beq a0, zero, len_12 # None is an illegal argument
- lw t0, 0(a0) # Get type tag of arg
- li t1, 3 # Load type tag of `str`
- beq t0, t1, len_13 # Go to len(str)
- li t1, -1 # Load type tag for list objects
- beq t0, t1, len_13 # Go to len(list)
- len_12: # Invalid argument
- li a0, @error_arg # Exit code for: Invalid argument
- la a1, const_2 # Load error message as str
- addi a1, a1, @.__str__ # Load address of attribute __str__
- j abort # Abort
- len_13: # Get length of string
- lw a0, @.__len__(a0) # Load attribute: __len__
- jr ra # Return to caller
- .globl $input
- $input:
- # Function input
- li a0, @error_nyi # Exit code for: Unsupported operation
- la a1, const_5 # Load error message as str
- addi a1, a1, @.__str__ # Load address of attribute __str__
- j abort # Abort
- .globl $foo.bar.baz.caz.jaz
- $foo.bar.baz.caz.jaz:
- addi sp, sp, -@foo.bar.baz.caz.jaz.size # Reserve space for stack frame.
- sw ra, @foo.bar.baz.caz.jaz.size-4(sp) # return address
- sw fp, @foo.bar.baz.caz.jaz.size-8(sp) # control link
- addi fp, sp, @foo.bar.baz.caz.jaz.size # New fp is at old SP.
- la a0, const_6 # Load string literal
- sw a0, @foo.bar.baz.caz.jaz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.caz.jaz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.caz.jaz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.baz.caz.jaz to foo.bar.baz.caz
- lw t0, 0(t0) # Load static link from foo.bar.baz.caz to foo.bar.baz
- lw t0, 4(t0) # Load static link from foo.bar.baz to foo.bar
- lw a0, -12(t0) # Load var: foo.bar.z
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.baz.caz.jaz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.caz.jaz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.caz.jaz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.baz.caz.jaz to foo.bar.baz.caz
- lw t0, 0(t0) # Load static link from foo.bar.baz.caz to foo.bar.baz
- lw t0, 4(t0) # Load static link from foo.bar.baz to foo.bar
- lw t0, 8(t0) # Load static link from foo.bar to foo
- lw a0, -16(t0) # Load var: foo.y
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.baz.caz.jaz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.caz.jaz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.caz.jaz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.baz.caz.jaz to foo.bar.baz.caz
- lw t0, 0(t0) # Load static link from foo.bar.baz.caz to foo.bar.baz
- lw t0, 4(t0) # Load static link from foo.bar.baz to foo.bar
- lw a0, -12(t0) # Load var: foo.bar.z
- j label_1 # Go to return
- mv a0, zero # Load None
- j label_1 # Jump to function epilogue
- label_1: # Epilogue
- .equiv @foo.bar.baz.caz.jaz.size, 16
- .equiv @foo.bar.baz.caz.jaz.negsize, -16
- lw ra, -4(fp) # Get return address
- lw fp, -8(fp) # Use control link to restore caller's fp
- addi sp, sp, @foo.bar.baz.caz.jaz.size # Restore stack pointer
- jr ra # Return to caller
- .globl $foo.bar.baz.caz
- $foo.bar.baz.caz:
- addi sp, sp, -@foo.bar.baz.caz.size # Reserve space for stack frame.
- sw ra, @foo.bar.baz.caz.size-4(sp) # return address
- sw fp, @foo.bar.baz.caz.size-8(sp) # control link
- addi fp, sp, @foo.bar.baz.caz.size # New fp is at old SP.
- la a0, const_7 # Load string literal
- sw a0, @foo.bar.baz.caz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to stack frame top.
- mv t0, fp # Get static link to foo.bar.baz.caz
- sw t0, @foo.bar.baz.caz.negsize+0(fp) # Push argument 0 from last (this was fp)
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to last argument.
- jal $foo.bar.baz.caz.jaz # Invoke function: foo.bar.baz.caz.jaz
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to stack frame top.
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.baz.caz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.baz.caz to foo.bar.baz
- lw t0, 4(t0) # Load static link from foo.bar.baz to foo.bar
- lw a0, -12(t0) # Load var: foo.bar.z
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.baz.caz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.caz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.baz.caz to foo.bar.baz
- lw t0, 4(t0) # Load static link from foo.bar.baz to foo.bar
- lw a0, -12(t0) # Load var: foo.bar.z
- j label_2 # Go to return
- mv a0, zero # Load None
- j label_2 # Jump to function epilogue
- label_2: # Epilogue
- .equiv @foo.bar.baz.caz.size, 16
- .equiv @foo.bar.baz.caz.negsize, -16
- lw ra, -4(fp) # Get return address
- lw fp, -8(fp) # Use control link to restore caller's fp
- addi sp, sp, @foo.bar.baz.caz.size # Restore stack pointer
- jr ra # Return to caller
- .globl $foo.bar.baz
- $foo.bar.baz:
- addi sp, sp, -@foo.bar.baz.size # Reserve space for stack frame.
- sw ra, @foo.bar.baz.size-4(sp) # return address
- sw fp, @foo.bar.baz.size-8(sp) # control link
- addi fp, sp, @foo.bar.baz.size # New fp is at old SP.
- la a0, const_8 # Load string literal
- sw a0, @foo.bar.baz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.negsize # Set SP to stack frame top.
- mv t0, fp # Get static link to foo.bar.baz
- sw t0, @foo.bar.baz.negsize+0(fp) # Push argument 0 from last (this was fp)
- addi sp, fp, @foo.bar.baz.negsize # Set SP to last argument.
- jal $foo.bar.baz.caz # Invoke function: foo.bar.baz.caz
- addi sp, fp, @foo.bar.baz.negsize # Set SP to stack frame top.
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.baz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.negsize # Set SP to stack frame top.
- lw t0, 4(fp) # Load static link from foo.bar.baz to foo.bar
- lw t0, 8(t0) # Load static link from foo.bar to foo
- lw a0, -16(t0) # Load var: foo.y
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.baz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.baz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.baz.negsize # Set SP to stack frame top.
- lw t0, 4(fp) # Load static link from foo.bar.baz to foo.bar
- lw t0, 8(t0) # Load static link from foo.bar to foo
- lw a0, -16(t0) # Load var: foo.y
- j label_3 # Go to return
- mv a0, zero # Load None
- j label_3 # Jump to function epilogue
- label_3: # Epilogue
- .equiv @foo.bar.baz.size, 16
- .equiv @foo.bar.baz.negsize, -16
- lw ra, -4(fp) # Get return address
- lw fp, -8(fp) # Use control link to restore caller's fp
- addi sp, sp, @foo.bar.baz.size # Restore stack pointer
- jr ra # Return to caller
- .globl $foo.bar.caz
- $foo.bar.caz:
- addi sp, sp, -@foo.bar.caz.size # Reserve space for stack frame.
- sw ra, @foo.bar.caz.size-4(sp) # return address
- sw fp, @foo.bar.caz.size-8(sp) # control link
- addi fp, sp, @foo.bar.caz.size # New fp is at old SP.
- la a0, const_9 # Load string literal
- sw a0, @foo.bar.caz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.caz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.caz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.caz to foo.bar
- lw a0, -12(t0) # Load var: foo.bar.z
- sw a0, -20(fp) # Push on stack slot 5
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -20(fp) # Pop stack slot 5
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.caz.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.caz.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.caz.negsize # Set SP to stack frame top.
- lw t0, 0(fp) # Load static link from foo.bar.caz to foo.bar
- lw a0, -12(t0) # Load var: foo.bar.z
- j label_4 # Go to return
- mv a0, zero # Load None
- j label_4 # Jump to function epilogue
- label_4: # Epilogue
- .equiv @foo.bar.caz.size, 16
- .equiv @foo.bar.caz.negsize, -16
- lw ra, -4(fp) # Get return address
- lw fp, -8(fp) # Use control link to restore caller's fp
- addi sp, sp, @foo.bar.caz.size # Restore stack pointer
- jr ra # Return to caller
- .globl $foo.bar
- $foo.bar:
- addi sp, sp, -@foo.bar.size # Reserve space for stack frame.
- sw ra, @foo.bar.size-4(sp) # return address
- sw fp, @foo.bar.size-8(sp) # control link
- addi fp, sp, @foo.bar.size # New fp is at old SP.
- li a0, 3 # Load integer literal 3
- sw a0, -12(fp) # local variable z
- la a0, const_10 # Load string literal
- sw a0, @foo.bar.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.negsize # Set SP to stack frame top.
- lw a0, 4(fp) # Load var: foo.bar.a
- sw a0, @foo.bar.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.negsize # Set SP to stack frame top.
- mv t0, fp # Get static link to foo.bar
- sw t0, @foo.bar.negsize+4(fp) # Push argument 1 from last (this was fp)
- li a0, 1 # Load boolean literal: true
- la t0, const_0 # Address of False object
- slli a0, a0, 4 # Get offset of the correct boolean object
- add a0, t0, a0 # Get address of the correct boolean object
- sw a0, @foo.bar.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.negsize # Set SP to last argument.
- jal $foo.bar.baz # Invoke function: foo.bar.baz
- addi sp, fp, @foo.bar.negsize # Set SP to stack frame top.
- sw a0, -24(fp) # Push on stack slot 6
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -24(fp) # Pop stack slot 6
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.bar.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.bar.negsize # Set SP to stack frame top.
- li a0, 6 # Load integer literal 6
- sw a0, -12(fp) # Assign var: foo.bar.z
- mv t0, fp # Get static link to foo.bar
- sw t0, @foo.bar.negsize+4(fp) # Push argument 1 from last (this was fp)
- li a0, 0 # Load boolean literal: false
- la t0, const_0 # Address of False object
- slli a0, a0, 4 # Get offset of the correct boolean object
- add a0, t0, a0 # Get address of the correct boolean object
- sw a0, @foo.bar.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.bar.negsize # Set SP to last argument.
- jal $foo.bar.baz # Invoke function: foo.bar.baz
- addi sp, fp, @foo.bar.negsize # Set SP to stack frame top.
- j label_5 # Go to return
- mv a0, zero # Load None
- j label_5 # Jump to function epilogue
- label_5: # Epilogue
- .equiv @foo.bar.size, 32
- .equiv @foo.bar.negsize, -32
- lw ra, -4(fp) # Get return address
- lw fp, -8(fp) # Use control link to restore caller's fp
- addi sp, sp, @foo.bar.size # Restore stack pointer
- jr ra # Return to caller
- .globl $foo
- $foo:
- addi sp, sp, -@foo.size # Reserve space for stack frame.
- sw ra, @foo.size-4(sp) # return address
- sw fp, @foo.size-8(sp) # control link
- addi fp, sp, @foo.size # New fp is at old SP.
- la a0, const_11 # Load string literal
- sw a0, -12(fp) # local variable z
- li a0, 2 # Load integer literal 2
- sw a0, -16(fp) # local variable y
- mv t0, fp # Get static link to foo
- sw t0, @foo.negsize+8(fp) # Push argument 2 from last (this was fp)
- lw a0, -12(fp) # Load var: foo.z
- sw a0, @foo.negsize+4(fp) # Push argument 1 from last.
- li a0, 1 # Load integer literal 1
- sw a0, @foo.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.negsize # Set SP to last argument.
- jal $foo.bar # Invoke function: foo.bar
- addi sp, fp, @foo.negsize # Set SP to stack frame top.
- li a0, 5 # Load integer literal 5
- sw a0, -16(fp) # Assign var: foo.y
- li a0, 5 # Load integer literal 5
- sw a0, -16(fp) # Assign var: foo.y
- li a0, 5 # Load integer literal 5
- sw a0, -16(fp) # Assign var: foo.y
- li a0, 93838 # Load integer literal 93838
- sw a0, -16(fp) # Assign var: foo.y
- mv t0, fp # Get static link to foo
- sw t0, @foo.negsize+8(fp) # Push argument 2 from last (this was fp)
- li a0, 5 # Load integer literal 5
- sw a0, -36(fp) # Push on stack slot 9
- li a0, 3 # Load integer literal 3
- sw a0, -40(fp) # Push on stack slot 10
- li a0, 9 # Load integer literal 9
- lw t0, -40(fp) # Pop stack slot 10
- mul a0, t0, a0 # Operator *
- sw a0, -40(fp) # Push on stack slot 10
- li a0, 4 # Load integer literal 4
- lw t0, -40(fp) # Pop stack slot 10
- bnez a0, label_7 # Ensure non-zero divisor
- j error.Div # Go to error handler
- label_7: # Divisor is non-zero
- xor t2, t0, a0 # Check for same sign
- bltz t2, label_9 # If !=, need to adjust left operand
- div a0, t0, a0 # Operator //
- j label_8 # Jump to end of division
- label_9: # Operands have differing signs
- slt t2, zero, a0 # tmp = 1 if right > 0 else 0
- add t2, t2, t2 # tmp *= 2
- addi t2, t2, -1 # tmp = 1 if right>=0 else -1
- add t2, t0, t2 # Adjust left operand
- div t2, t2, a0 # Adjusted division, toward 0
- addi a0, t2, -1 # Complete division when signs !=
- label_8: # End of //
- sw a0, -40(fp) # Push on stack slot 10
- li a0, 7 # Load integer literal 7
- lw t0, -40(fp) # Pop stack slot 10
- bnez a0, label_10 # Ensure non-zero divisor
- j error.Div # Go to error handler
- label_10: # Divisor is non-zero
- rem t2, t0, a0 # Operator rem
- beqz t2, label_11 # If no remainder, no adjustment
- xor t3, t2, a0 # Check for differing signs.
- bgez t3, label_11 # Don't adjust if signs equal.
- add a0, t2, a0 # Adjust
- j label_12 # Jump to end of mod
- label_11: # Store result
- mv a0, t2
- label_12: # End of %
- lw t0, -36(fp) # Pop stack slot 9
- add a0, t0, a0 # Operator +
- sw a0, -36(fp) # Push on stack slot 9
- li a0, 4 # Load integer literal 4
- lw t0, -36(fp) # Pop stack slot 9
- sub a0, t0, a0 # Operator -
- sw a0, -36(fp) # Push on stack slot 9
- li a0, 90 # Load integer literal 90
- sub a0, zero, a0 # Unary negation
- sw a0, -40(fp) # Push on stack slot 10
- li a0, 49 # Load integer literal 49
- lw t0, -40(fp) # Pop stack slot 10
- mul a0, t0, a0 # Operator *
- sw a0, -40(fp) # Push on stack slot 10
- li a0, 7374 # Load integer literal 7374
- lw t0, -40(fp) # Pop stack slot 10
- bnez a0, label_13 # Ensure non-zero divisor
- j error.Div # Go to error handler
- label_13: # Divisor is non-zero
- xor t2, t0, a0 # Check for same sign
- bltz t2, label_15 # If !=, need to adjust left operand
- div a0, t0, a0 # Operator //
- j label_14 # Jump to end of division
- label_15: # Operands have differing signs
- slt t2, zero, a0 # tmp = 1 if right > 0 else 0
- add t2, t2, t2 # tmp *= 2
- addi t2, t2, -1 # tmp = 1 if right>=0 else -1
- add t2, t0, t2 # Adjust left operand
- div t2, t2, a0 # Adjusted division, toward 0
- addi a0, t2, -1 # Complete division when signs !=
- label_14: # End of //
- lw t0, -36(fp) # Pop stack slot 9
- add a0, t0, a0 # Operator +
- sw a0, -36(fp) # Push on stack slot 9
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -36(fp) # Pop stack slot 9
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.negsize+4(fp) # Push argument 1 from last.
- li a0, 9001 # Load integer literal 9001
- sw a0, @foo.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.negsize # Set SP to last argument.
- jal $foo.bar # Invoke function: foo.bar
- addi sp, fp, @foo.negsize # Set SP to stack frame top.
- li a0, 69 # Load integer literal 69
- sw a0, -16(fp) # Assign var: foo.y
- la a0, const_12 # Load string literal
- sw a0, -12(fp) # Assign var: foo.z
- la a0, const_13 # Load string literal
- sw a0, @foo.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.negsize # Set SP to stack frame top.
- mv t0, fp # Get static link to foo
- sw t0, @foo.negsize+8(fp) # Push argument 2 from last (this was fp)
- li a0, 5 # Load integer literal 5
- sw a0, -40(fp) # Push on stack slot 10
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -40(fp) # Pop stack slot 10
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.negsize+4(fp) # Push argument 1 from last.
- li a0, 9001 # Load integer literal 9001
- sw a0, @foo.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.negsize # Set SP to last argument.
- jal $foo.bar # Invoke function: foo.bar
- addi sp, fp, @foo.negsize # Set SP to stack frame top.
- sw a0, -28(fp) # Push on stack slot 7
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -28(fp) # Pop stack slot 7
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.negsize # Set SP to last argument.
- jal $print # Invoke function: print
- addi sp, fp, @foo.negsize # Set SP to stack frame top.
- mv t0, fp # Get static link to foo
- sw t0, @foo.negsize+8(fp) # Push argument 2 from last (this was fp)
- li a0, 5 # Load integer literal 5
- sw a0, -36(fp) # Push on stack slot 9
- la a0, $int$prototype # Load pointer to prototype of: int
- jal alloc # Allocate new object
- lw t0, -36(fp) # Pop stack slot 9
- sw t0, 12(a0) # Set attribute: __int__
- sw a0, @foo.negsize+4(fp) # Push argument 1 from last.
- li a0, 9001 # Load integer literal 9001
- sw a0, @foo.negsize+0(fp) # Push argument 0 from last.
- addi sp, fp, @foo.negsize # Set SP to last argument.
- jal $foo.bar # Invoke function: foo.bar
- addi sp, fp, @foo.negsize # Set SP to stack frame top.
- j label_6 # Go to return
- mv a0, zero # Load None
- j label_6 # Jump to function epilogue
- label_6: # Epilogue
- .equiv @foo.size, 48
- .equiv @foo.negsize, -48
- lw ra, -4(fp) # Get return address
- lw fp, -8(fp) # Use control link to restore caller's fp
- addi sp, sp, @foo.size # Restore stack pointer
- jr ra # Return to caller
- .globl alloc
- alloc:
- # Runtime support function alloc.
- # Prototype address is in a0.
- lw a1, 4(a0) # Get size of object in words
- j alloc2 # Allocate object with exact size
- .globl alloc2
- alloc2:
- # Runtime support function alloc2 (realloc).
- # Prototype address is in a0.
- # Number of words to allocate is in a1.
- li a2, 4 # Word size in bytes
- mul a2, a1, a2 # Calculate number of bytes to allocate
- add a2, gp, a2 # Estimate where GP will move
- bgeu a2, s11, alloc2_15 # Go to OOM handler if too large
- lw t0, @.__obj_size__(a0) # Get size of object in words
- mv t2, a0 # Initialize src ptr
- mv t3, gp # Initialize dest ptr
- alloc2_16: # Copy-loop header
- lw t1, 0(t2) # Load next word from src
- sw t1, 0(t3) # Store next word to dest
- addi t2, t2, 4 # Increment src
- addi t3, t3, 4 # Increment dest
- addi t0, t0, -1 # Decrement counter
- bne t0, zero, alloc2_16 # Loop if more words left to copy
- mv a0, gp # Save new object's address to return
- sw a1, @.__obj_size__(a0) # Set size of new object in words
- # (same as requested size)
- mv gp, a2 # Set next free slot in the heap
- jr ra # Return to caller
- alloc2_15: # OOM handler
- li a0, @error_oom # Exit code for: Out of memory
- la a1, const_14 # Load error message as str
- addi a1, a1, @.__str__ # Load address of attribute __str__
- j abort # Abort
- .globl abort
- abort:
- # Runtime support function abort (does not return).
- mv t0, a0 # Save exit code in temp
- li a0, @print_string # Code for print_string ecall
- ecall # Print error message in a1
- li a1, 10 # Load newline character
- li a0, @print_char # Code for print_char ecall
- ecall # Print newline
- mv a1, t0 # Move exit code to a1
- li a0, @exit2 # Code for exit2 ecall
- ecall # Exit with code
- abort_17: # Infinite loop
- j abort_17 # Prevent fallthrough
- .globl heap.init
- heap.init:
- # Runtime support function heap.init.
- mv a1, a0 # Move requested size to A1
- li a0, @sbrk # Code for ecall: sbrk
- ecall # Request A1 bytes
- jr ra # Return to caller
- .globl error.None
- error.None:
- li a0, 4 # Exit code for: Operation on None
- la a1, const_15 # Load error message as str
- addi a1, a1, 16 # Load address of attribute __str__
- j abort # Abort
- .globl error.Div
- error.Div:
- li a0, 2 # Exit code for: Divison by zero
- la a1, const_16 # Load error message as str
- addi a1, a1, 16 # Load address of attribute __str__
- j abort # Abort
- .globl error.OOB
- error.OOB:
- li a0, 3 # Exit code for: Index out of bounds
- la a1, const_17 # Load error message as str
- addi a1, a1, 16 # Load address of attribute __str__
- j abort # Abort
- .data
- .globl const_0
- const_0:
- .word 2 # Type tag for class: bool
- .word 4 # Object size
- .word $bool$dispatchTable # Pointer to dispatch table
- .word 0 # Constant value of attribute: __bool__
- .align 2
- .globl const_1
- const_1:
- .word 2 # Type tag for class: bool
- .word 4 # Object size
- .word $bool$dispatchTable # Pointer to dispatch table
- .word 1 # Constant value of attribute: __bool__
- .align 2
- .globl const_12
- const_12:
- .word 3 # Type tag for class: str
- .word 6 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 6 # Constant value of attribute: __len__
- .string "jfjfjf" # Constant value of attribute: __str__
- .align 2
- .globl const_14
- const_14:
- .word 3 # Type tag for class: str
- .word 8 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 13 # Constant value of attribute: __len__
- .string "Out of memory" # Constant value of attribute: __str__
- .align 2
- .globl const_6
- const_6:
- .word 3 # Type tag for class: str
- .word 9 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 19 # Constant value of attribute: __len__
- .string "foo.bar.baz.caz.jaz" # Constant value of attribute: __str__
- .align 2
- .globl const_9
- const_9:
- .word 3 # Type tag for class: str
- .word 7 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 11 # Constant value of attribute: __len__
- .string "foo.bar.caz" # Constant value of attribute: __str__
- .align 2
- .globl const_8
- const_8:
- .word 3 # Type tag for class: str
- .word 7 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 11 # Constant value of attribute: __len__
- .string "foo.bar.baz" # Constant value of attribute: __str__
- .align 2
- .globl const_13
- const_13:
- .word 3 # Type tag for class: str
- .word 5 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 3 # Constant value of attribute: __len__
- .string "foo" # Constant value of attribute: __str__
- .align 2
- .globl const_3
- const_3:
- .word 3 # Type tag for class: str
- .word 6 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 4 # Constant value of attribute: __len__
- .string "True" # Constant value of attribute: __str__
- .align 2
- .globl const_4
- const_4:
- .word 3 # Type tag for class: str
- .word 6 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 5 # Constant value of attribute: __len__
- .string "False" # Constant value of attribute: __str__
- .align 2
- .globl const_11
- const_11:
- .word 3 # Type tag for class: str
- .word 6 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 6 # Constant value of attribute: __len__
- .string "jfdkjf" # Constant value of attribute: __str__
- .align 2
- .globl const_10
- const_10:
- .word 3 # Type tag for class: str
- .word 6 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 7 # Constant value of attribute: __len__
- .string "foo.bar" # Constant value of attribute: __str__
- .align 2
- .globl const_17
- const_17:
- .word 3 # Type tag for class: str
- .word 9 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 19 # Constant value of attribute: __len__
- .string "Index out of bounds" # Constant value of attribute: __str__
- .align 2
- .globl const_16
- const_16:
- .word 3 # Type tag for class: str
- .word 8 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 15 # Constant value of attribute: __len__
- .string "Divison by zero" # Constant value of attribute: __str__
- .align 2
- .globl const_15
- const_15:
- .word 3 # Type tag for class: str
- .word 9 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 17 # Constant value of attribute: __len__
- .string "Operation on None" # Constant value of attribute: __str__
- .align 2
- .globl const_2
- const_2:
- .word 3 # Type tag for class: str
- .word 9 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 16 # Constant value of attribute: __len__
- .string "Invalid argument" # Constant value of attribute: __str__
- .align 2
- .globl const_5
- const_5:
- .word 3 # Type tag for class: str
- .word 10 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 21 # Constant value of attribute: __len__
- .string "Unsupported operation" # Constant value of attribute: __str__
- .align 2
- .globl const_7
- const_7:
- .word 3 # Type tag for class: str
- .word 8 # Object size
- .word $str$dispatchTable # Pointer to dispatch table
- .word 15 # Constant value of attribute: __len__
- .string "foo.bar.baz.caz" # Constant value of attribute: __str__
- .align 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement