add existing documentation
This commit is contained in:
241
doc/example.asm
Executable file
241
doc/example.asm
Executable file
@@ -0,0 +1,241 @@
|
||||
@msgh (net.doorstuck.test.Person) [-init(name:age:)]
|
||||
ldr x0, [bp, #-1]
|
||||
str x0, [self, #0]
|
||||
|
||||
ldr x0, [bp, #-2]
|
||||
str x0, [self, #1]
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
@msgh (net.doorstuck.test.Person) [-name]
|
||||
ldr x0, [self, #0]
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
|
||||
@msgh (net.doorstuck.test.Person) [-age]
|
||||
ldr x0, [self, #1]
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
@msgh (net.doorstuck.test.Person) [-ageInMonths]
|
||||
ldr x0, [self, #1]
|
||||
ldr x1, #12
|
||||
mul x0, x0, x1
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
@msgh (net.doorstuck.test.Person) [-setName:]
|
||||
ldr x0, [bp, #-1]
|
||||
str x0, [self, #0]
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
@msgh (net.doorstuck.test.Person) [-setAge:]
|
||||
ldr x0, [bp, #-1]
|
||||
str x0, [self, #1]
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
@msgh (net.doorstuck.test.Person) [-setAge:in:]
|
||||
ldr x0, [bp, #-1]
|
||||
|
||||
ldr x1, "years"
|
||||
cmp x0, x1
|
||||
b.eq $L0001
|
||||
|
||||
ldr x1, "months"
|
||||
cmp x0, x1
|
||||
b.eq $L0002
|
||||
|
||||
ldr x1, "days"
|
||||
cmp x0, x1
|
||||
b.eq $L0003
|
||||
|
||||
; else
|
||||
ldr x2, #0
|
||||
str x2, [self, #1]
|
||||
br $L0004
|
||||
|
||||
; if units == "years"
|
||||
L0001: str x0, [self, #1]
|
||||
br $L0004
|
||||
|
||||
; if units == "months"
|
||||
L0002: ldr x2, #12
|
||||
div x0, x0, x2
|
||||
str x0, [self, #1]
|
||||
br $L0004
|
||||
|
||||
; if units == "days"
|
||||
L0003: ldr x2, #365
|
||||
div x0, x0, x2
|
||||
str x0, [self, #1]
|
||||
|
||||
; end
|
||||
L0004:
|
||||
ret
|
||||
@end
|
||||
|
||||
@lambda (Lx0001) [_:]
|
||||
ldr x1, @ident[cout]
|
||||
ldr x2, [bp, #-1]
|
||||
|
||||
ldr x3, "Count is "
|
||||
add x3, x3, x2
|
||||
|
||||
push x3
|
||||
msg x1, @selector[-put:]
|
||||
|
||||
ret
|
||||
@end
|
||||
|
||||
@lambda (Lx0002) []
|
||||
ldr x1, @ident[cout]
|
||||
|
||||
ldr x2, "True!"
|
||||
push x2
|
||||
|
||||
msg x1, @selector[-put:]
|
||||
@end
|
||||
|
||||
@lambda (Lx0003) []
|
||||
ldr x1, @ident[cout]
|
||||
|
||||
ldr x2, "False!"
|
||||
push x2
|
||||
|
||||
msg x1, @selector[-put:]
|
||||
@end
|
||||
|
||||
@init
|
||||
rsv #3 ; 3 local variables
|
||||
/* stack layout is now this:
|
||||
bp[1] = p1
|
||||
bp[2] = i
|
||||
bp[3] = j
|
||||
*/
|
||||
|
||||
; p1 = Person new(name:"John Doe", age:34)
|
||||
ldr x0, #34
|
||||
push x0
|
||||
|
||||
ldr x0, "John Doe"
|
||||
push x0
|
||||
|
||||
ob.c x1, x1
|
||||
msg x1, @selector[-init(name:age:)] ; x0 = new Person object
|
||||
str x1, [bp, #1] ; p1 = new Person object
|
||||
|
||||
; p1 setAge:100 in:"months"
|
||||
|
||||
; p1 is already loaded in x1, no need to load it again
|
||||
ldr x2, @selector[-setAge:in:]
|
||||
|
||||
ldr x3, "months"
|
||||
push x3
|
||||
|
||||
ldr x3, #100
|
||||
push x3
|
||||
|
||||
msg x1, @selector[-setAge:in:] ; x0 = null
|
||||
|
||||
ldr x3, #0
|
||||
str x3, [bp, #2] ; i = 0
|
||||
|
||||
; (while i < 10) begin
|
||||
L0001: ldr x2, @ident[cout] ; x5 = cout
|
||||
ldr x4, "Count is "
|
||||
|
||||
add x4, x4, x3 ; append i (in x4) to "Count is " (in x7)
|
||||
|
||||
push x4
|
||||
msg x2, @selector[-put:]
|
||||
|
||||
add x3, x3, #2
|
||||
|
||||
cmp x3, #100
|
||||
b.lt $L0001
|
||||
; (while i < 0) end
|
||||
|
||||
; for i in 0 to:100 step:2
|
||||
ldr x4, #2
|
||||
push x4
|
||||
|
||||
ldr x4, #100
|
||||
push x4
|
||||
|
||||
ldr x4, #0
|
||||
|
||||
msg x5, @selector[-to:step:]
|
||||
mov x5, x0 ; x5 = (0 to:100 step:2) -> iterator
|
||||
|
||||
; (for i in 0 to:100 step:2) begin
|
||||
L0002: it.v x5 ; is iterator still valid?
|
||||
b.z $L0003
|
||||
|
||||
it.g x4, x5 ; get current iterator value
|
||||
|
||||
ldr x6, "Count is "
|
||||
add x6, x6, x4 ; append i (in x4) to "Count is " (in x6)
|
||||
|
||||
ldr x7, @ident[cout]
|
||||
|
||||
push x6
|
||||
msg x7, @selector[-put:]
|
||||
|
||||
it.n x5 ; Advance iterator
|
||||
br $L0002
|
||||
; (for i in 0 to:100 step:2) end
|
||||
|
||||
L0003: ob.e x5 ; Clean up iterator
|
||||
|
||||
lam.c x5, @lambda[Lx0001] ; x5 = [ _:i | cout put:'Count: {i}' ],
|
||||
|
||||
push x5
|
||||
|
||||
ldr x5, #2
|
||||
push x5
|
||||
|
||||
ldr x5, #100
|
||||
push x5
|
||||
|
||||
ldr x5, #0
|
||||
msg x5, @selector[-to:step:do:]
|
||||
|
||||
ldr x5, #32
|
||||
str x5, [bp, #3] ; (x5) j = 32
|
||||
|
||||
ldr x6, [bp, #1] ; (x6) i
|
||||
|
||||
c.lt x5, x6, x5
|
||||
|
||||
lam.c x6, @lambda[Lx0003]
|
||||
push x6
|
||||
|
||||
lam.c x6, @lambda[Lx0002]
|
||||
push x6
|
||||
|
||||
msg x5, @selector[-if:else:]
|
||||
|
||||
ldr x5, [bp, #2] ; (x5) j
|
||||
ldr x6, [bp, #1] ; (x6) i
|
||||
|
||||
cmp x6, x5
|
||||
b.ge $L0004
|
||||
|
||||
ldr x5, "True!"
|
||||
push x5
|
||||
|
||||
ldr x5, @ident[cout]
|
||||
|
||||
msg x5, @selector[-put:]
|
||||
|
||||
L0004: ret
|
||||
@end
|
||||
Reference in New Issue
Block a user