Created
December 13, 2012 16:25
-
-
Save joseanpg/4277629 to your computer and use it in GitHub Desktop.
init-order-super.cl compiled by coolc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- init-order-super.cl | |
-- Superclass attribute initializers must be evaluated before subclass | |
-- attribute initializers. | |
class Base inherits IO | |
{ | |
recite( value : Int ) : Object | |
{ | |
{ | |
out_int( value ); | |
out_string( "\n" ); | |
self; | |
} | |
}; | |
x : Object <- recite( 1 ); | |
b : Object <- recite( 2 ); | |
}; | |
class Main inherits Base | |
{ | |
y : Object <- recite( 3 ); | |
z : Object <- recite( 4 ); | |
c : Object <- recite( 5 ); | |
main() : Object | |
{ | |
self | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# init-order-super.s | |
################################################################################# | |
# DATA | |
################################################################################# | |
.data | |
.align 2 | |
################################################################################# | |
# Exported | |
################################################################################# | |
.globl class_nameTab | |
.globl Main_protObj | |
.globl Int_protObj | |
.globl String_protObj | |
.globl bool_const0 | |
.globl bool_const1 | |
.globl _int_tag | |
.globl _bool_tag | |
.globl _string_tag | |
################################################################################# | |
# _int_tag _bool_tag _string_tag | |
################################################################################# | |
_int_tag: | |
.word 4 | |
_bool_tag: | |
.word 5 | |
_string_tag: | |
.word 6 | |
################################################################################# | |
# GC | |
################################################################################# | |
.globl _MemMgr_INITIALIZER | |
_MemMgr_INITIALIZER: | |
.word _NoGC_Init | |
.globl _MemMgr_COLLECTOR | |
_MemMgr_COLLECTOR: | |
.word _NoGC_Collect | |
.globl _MemMgr_TEST | |
_MemMgr_TEST: | |
.word 0 | |
.word -1 | |
#################################################################################3 | |
# str_const | |
#################################################################################3 | |
str_const10: | |
.word 6 | |
.word 5 | |
.word String_dispTab | |
.word int_const5 | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const9: | |
.word 6 | |
.word 6 | |
.word String_dispTab | |
.word int_const6 | |
.ascii "String" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const8: | |
.word 6 | |
.word 6 | |
.word String_dispTab | |
.word int_const3 | |
.ascii "Bool" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const7: | |
.word 6 | |
.word 5 | |
.word String_dispTab | |
.word int_const2 | |
.ascii "Int" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const6: | |
.word 6 | |
.word 6 | |
.word String_dispTab | |
.word int_const3 | |
.ascii "Main" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const5: | |
.word 6 | |
.word 6 | |
.word String_dispTab | |
.word int_const3 | |
.ascii "Base" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const4: | |
.word 6 | |
.word 5 | |
.word String_dispTab | |
.word int_const1 | |
.ascii "IO" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const3: | |
.word 6 | |
.word 6 | |
.word String_dispTab | |
.word int_const6 | |
.ascii "Object" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const2: | |
.word 6 | |
.word 8 | |
.word String_dispTab | |
.word int_const7 | |
.ascii "<basic class>" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const1: | |
.word 6 | |
.word 9 | |
.word String_dispTab | |
.word int_const8 | |
.ascii "init-order-super.cl" | |
.byte 0 | |
.align 2 | |
.word -1 | |
str_const0: | |
.word 6 | |
.word 5 | |
.word String_dispTab | |
.word int_const0 | |
.ascii "\n" | |
.byte 0 | |
.align 2 | |
.word -1 | |
################################################################################# | |
# int_const | |
################################################################################# | |
int_const8: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 19 | |
.word -1 | |
int_const7: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 13 | |
.word -1 | |
int_const6: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 6 | |
.word -1 | |
int_const5: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 0 | |
.word -1 | |
int_const4: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 5 | |
.word -1 | |
int_const3: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 4 | |
.word -1 | |
int_const2: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 3 | |
.word -1 | |
int_const1: # 2 | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 2 | |
.word -1 | |
int_const0: # 1 | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 1 | |
.word -1 | |
################################################################################# | |
# bool_const | |
################################################################################# | |
bool_const0: | |
.word 5 | |
.word 4 | |
.word Bool_dispTab | |
.word 0 | |
.word -1 | |
bool_const1: | |
.word 5 | |
.word 4 | |
.word Bool_dispTab | |
.word 1 | |
################################################################################# | |
# class_name table | |
################################################################################# | |
class_nameTab: | |
.word str_const3 # Object | |
.word str_const4 # IO | |
.word str_const5 # Base | |
.word str_const6 # Main | |
.word str_const7 # Int | |
.word str_const8 # Bool | |
.word str_const9 # String | |
################################################################################# | |
# class_obj table | |
################################################################################# | |
class_objTab: | |
.word Object_protObj | |
.word Object_init | |
.word IO_protObj | |
.word IO_init | |
.word Base_protObj | |
.word Base_init | |
.word Main_protObj | |
.word Main_init | |
.word Int_protObj | |
.word Int_init | |
.word Bool_protObj | |
.word Bool_init | |
.word String_protObj | |
.word String_init | |
################################################################################# | |
# dispatch tables I | |
################################################################################# | |
Object_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
String_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
.word String.length | |
.word String.concat | |
.word String.substr | |
Bool_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
Int_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
IO_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
.word IO.out_string | |
.word IO.out_int | |
.word IO.in_string | |
.word IO.in_int | |
################################################################################# | |
# dispatch tables II | |
################################################################################# | |
Base_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
.word IO.out_string | |
.word IO.out_int | |
.word IO.in_string | |
.word IO.in_int | |
.word Base.recite | |
Main_dispTab: | |
.word Object.abort | |
.word Object.type_name | |
.word Object.copy | |
.word IO.out_string | |
.word IO.out_int | |
.word IO.in_string | |
.word IO.in_int | |
.word Base.recite | |
.word Main.main | |
.word -1 | |
################################################################################# | |
# prototypes I | |
################################################################################# | |
Object_protObj: | |
.word 0 | |
.word 3 | |
.word Object_dispTab | |
.word -1 | |
String_protObj: | |
.word 6 | |
.word 5 | |
.word String_dispTab | |
.word int_const5 | |
.word 0 | |
.word -1 | |
Bool_protObj: | |
.word 5 | |
.word 4 | |
.word Bool_dispTab | |
.word 0 | |
.word -1 | |
Int_protObj: | |
.word 4 | |
.word 4 | |
.word Int_dispTab | |
.word 0 | |
.word -1 | |
IO_protObj: | |
.word 1 | |
.word 3 | |
.word IO_dispTab | |
.word -1 | |
################################################################################# | |
# prototypes II | |
################################################################################# | |
Base_protObj: | |
.word 2 | |
.word 5 | |
.word Base_dispTab | |
.word 0 # x : Object | |
.word 0 # b : Object | |
.word -1 | |
Main_protObj: | |
.word 3 | |
.word 8 | |
.word Main_dispTab | |
.word 0 # y : Object | |
.word 0 # z : Object | |
.word 0 # c : Object | |
.word 0 | |
.word 0 | |
################################################################################# | |
# heap | |
################################################################################# | |
.globl heap_start | |
heap_start: | |
.word 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# init-order-super.s TEXT | |
.text | |
################################################################################# | |
# Exported | |
################################################################################# | |
.globl Main_init | |
.globl Int_init | |
.globl String_init | |
.globl Bool_init | |
.globl Main.main | |
################################################################################# | |
# init I | |
# | |
# addiu $sp $sp -12 | |
# sw $fp 12($sp) | |
# sw $s0 8($sp) | |
# sw $ra 4($sp) | |
# addiu $fp $sp 4 | |
# move $s0 $a0 | |
# | |
# jal Object_init | |
# | |
# move $a0 $s0 | |
# lw $fp 12($sp) | |
# lw $s0 8($sp) | |
# lw $ra 4($sp) | |
# addiu $sp $sp 12 | |
# | |
# jr $ra | |
# | |
################################################################################# | |
Object_init: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
String_init: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
jal Object_init | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
Bool_init: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
jal Object_init | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
Int_init: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
jal Object_init | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
IO_init: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
jal Object_init | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
################################################################################# | |
# Base_init | |
################################################################################# | |
Base_init: | |
# a0 <- self | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 # s0 <- self, salvamos momentaneamente a0 | |
jal IO_init # Parent class init, no toma argumentos | |
la $a0 int_const0 # push int_const0, es decir Int(1) | |
sw $a0 0($sp) # argumento de la siguiente llamada a Base.recipe | |
addiu $sp $sp -4 # se usa el stack para pasar argumentos | |
move $a0 $s0 # restore a0, vuelve a ser self | |
# a0 es puntero al nuevo objeto | |
bne $a0 $zero label0 | |
la $a0 str_const1 # if a0 == zero | |
li $t1 1 # t1 <- 1 | |
jal _dispatch_abort # _dispatch_abort | |
label0: # else | |
# a0 <- self | |
lw $t1 8($a0) # t1 <- [self+2] , es decir: Base_dispTab | |
lw $t1 28($t1) # t1 <- [Base_dispTab + 7] , es decir: Base.recite | |
jalr $t1 # call Base.recite | |
sw $a0 12($s0) # a0 -> [s0+3], es decir return value (Base object) a self.x | |
la $a0 int_const1 # push argument 2 | |
sw $a0 0($sp) | |
addiu $sp $sp -4 | |
move $a0 $s0 | |
bne $a0 $zero label1 | |
la $a0 str_const1 | |
li $t1 1 | |
jal _dispatch_abort | |
label1: | |
lw $t1 8($a0) # call Base.recite | |
lw $t1 28($t1) | |
jalr $t1 | |
sw $a0 16($s0) # $a -> [s0+4] , es decir return value (Base object) en self.b | |
move $a0 $s0 #return | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
#################################################################################3 | |
Main_init: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
jal Base_init | |
la $a0 int_const2 | |
sw $a0 0($sp) | |
addiu $sp $sp -4 | |
move $a0 $s0 | |
bne $a0 $zero label2 | |
la $a0 str_const1 | |
li $t1 1 | |
jal _dispatch_abort | |
label2: | |
lw $t1 8($a0) | |
lw $t1 28($t1) | |
jalr $t1 | |
sw $a0 20($s0) | |
la $a0 int_const3 | |
sw $a0 0($sp) | |
addiu $sp $sp -4 | |
move $a0 $s0 | |
bne $a0 $zero label3 | |
la $a0 str_const1 | |
li $t1 1 | |
jal _dispatch_abort | |
label3: | |
lw $t1 8($a0) | |
lw $t1 28($t1) | |
jalr $t1 | |
sw $a0 24($s0) | |
la $a0 int_const4 | |
sw $a0 0($sp) | |
addiu $sp $sp -4 | |
move $a0 $s0 | |
bne $a0 $zero label4 | |
la $a0 str_const1 | |
li $t1 1 | |
jal _dispatch_abort | |
label4: | |
lw $t1 8($a0) | |
lw $t1 28($t1) | |
jalr $t1 | |
sw $a0 28($s0) | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra | |
#################################################################################3 | |
Base.recite: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
lw $a0 12($fp) | |
sw $a0 0($sp) | |
addiu $sp $sp -4 | |
move $a0 $s0 | |
bne $a0 $zero label5 | |
la $a0 str_const1 | |
li $t1 1 | |
jal _dispatch_abort | |
label5: | |
lw $t1 8($a0) | |
lw $t1 16($t1) | |
jalr $t1 | |
la $a0 str_const0 | |
sw $a0 0($sp) | |
addiu $sp $sp -4 | |
move $a0 $s0 | |
bne $a0 $zero label6 | |
la $a0 str_const1 | |
li $t1 1 | |
jal _dispatch_abort | |
label6: | |
lw $t1 8($a0) | |
lw $t1 12($t1) | |
jalr $t1 | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 16 | |
jr $ra | |
#################################################################################3 | |
Main.main: | |
addiu $sp $sp -12 | |
sw $fp 12($sp) | |
sw $s0 8($sp) | |
sw $ra 4($sp) | |
addiu $fp $sp 4 | |
move $s0 $a0 | |
move $a0 $s0 | |
lw $fp 12($sp) | |
lw $s0 8($sp) | |
lw $ra 4($sp) | |
addiu $sp $sp 12 | |
jr $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment