Skip to content

Instantly share code, notes, and snippets.

@sfpgmr
Last active April 22, 2018 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfpgmr/4aceecfcc36c6763ca564e701c269502 to your computer and use it in GitHub Desktop.
Save sfpgmr/4aceecfcc36c6763ca564e701c269502 to your computer and use it in GitHub Desktop.
オレオレ言語のコンパイルテスト(3)function call
i32 mul(i32 a,i32 b){
return a * b;
}
export i32 main(){
i32 c = 2,a = 2;
// a -= 2;
++a;
if(c == 1){
c = 10;
a += c;
} else {
c = 20;
a += c;
}
c = mul(a,c) + 2;
return c;
}
(module
(type $mul (func (param i32 i32) (result i32)))
(type $main (func (result i32)))
(export "main" (func $main))
(func $mul (; 0 ;) (type $mul) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.mul
(get_local $0)
(get_local $1)
)
)
)
(func $main (; 1 ;) (type $main) (result i32)
(local $0 i32)
(local $1 i32)
(set_local $0
(i32.const 2)
)
(set_local $1
(i32.const 2)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
(if
(i32.eq
(get_local $0)
(i32.const 1)
)
(block
(set_local $0
(i32.const 10)
)
(set_local $1
(i32.add
(get_local $1)
(get_local $0)
)
)
)
(block
(set_local $0
(i32.const 20)
)
(set_local $1
(i32.add
(get_local $1)
(get_local $0)
)
)
)
)
(set_local $0
(i32.add
(call $mul
(get_local $1)
(get_local $0)
)
(i32.const 2)
)
)
(return
(get_local $0)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment