# Ticket #562: test2.pir

File test2.pir, 3.4 KB (added by bsdz, 7 years ago) |
---|

Line | |
---|---|

1 | .sub '' :main |

2 | say 'START' |

3 | |

4 | .local pmc types, ops |

5 | types = split ' ', 'Integer Float Complex' |

6 | ops = split ' ', 'add sub mul div' |

7 | |

8 | .local pmc i1 |

9 | .local string base_type, derived_type |

10 | i1 = iter types |

11 | next_i1: |

12 | unless i1, end_i1 |

13 | base_type = shift i1 |

14 | derived_type = concat 'Foo', base_type |

15 | |

16 | $P0 = subclass base_type, derived_type |

17 | |

18 | .local pmc i2, cs |

19 | .local string op |

20 | i2 = iter ops |

21 | next_i2: |

22 | unless i2, end_i2 |

23 | op = shift i2 |

24 | |

25 | cs = new 'CodeString' |

26 | cs.'emit'("print '%0: 10 %1 2 = '", base_type, op) |

27 | cs.'emit'("$P0 = new '%0'", base_type) |

28 | cs.'emit'("$P0 = 10") |

29 | cs.'emit'("%0 $P1, $P0, 2", op) |

30 | cs.'emit'("say $P1") |

31 | eval(cs) |

32 | |

33 | cs = new 'CodeString' |

34 | cs.'emit'("print '%0: 10 %1 2 = '", derived_type, op) |

35 | cs.'emit'("$P0 = new '%0'", derived_type) |

36 | cs.'emit'("$P0 = 10") |

37 | cs.'emit'("%0 $P1, $P0, 2", op) |

38 | cs.'emit'("say $P1") |

39 | eval(cs) |

40 | |

41 | goto next_i2 |

42 | end_i2: |

43 | |

44 | goto next_i1 |

45 | end_i1: |

46 | |

47 | say 'FINISH' |

48 | .end |

49 | |

50 | .sub eval |

51 | .param string code |

52 | |

53 | .local pmc PIR |

54 | PIR = compreg 'PIR' |

55 | |

56 | .local pmc eh |

57 | eh = new 'ExceptionHandler' |

58 | set_addr eh, handler |

59 | push_eh eh |

60 | |

61 | .local pmc cs |

62 | cs = new ['CodeString'] |

63 | cs.'emit'(".sub '' :anon") |

64 | cs.'emit'(code) |

65 | cs.'emit'(".end") |

66 | $P0 = PIR(cs) |

67 | $P0() |

68 | pop_eh |

69 | goto end |

70 | |

71 | handler: |

72 | .local pmc ex |

73 | .local string msg |

74 | .get_results(ex) |

75 | msg = ex |

76 | say ex |

77 | |

78 | end: |

79 | .end |

80 | |

81 | =begin output |

82 | |

83 | START |

84 | Integer: 10 add 2 = 12 |

85 | FooInteger: 10 add 2 = Multiple Dispatch: No suitable candidate found for 'add_int', with signature 'PIP->P' |

86 | Integer: 10 sub 2 = 8 |

87 | FooInteger: 10 sub 2 = Multiple Dispatch: No suitable candidate found for 'subtract_int', with signature 'PIP->P' |

88 | Integer: 10 mul 2 = 20 |

89 | FooInteger: 10 mul 2 = Multiple Dispatch: No suitable candidate found for 'multiply_int', with signature 'PIP->P' |

90 | Integer: 10 div 2 = 5 |

91 | FooInteger: 10 div 2 = Multiple Dispatch: No suitable candidate found for 'divide_int', with signature 'PIP->P' |

92 | Float: 10 add 2 = 12 |

93 | FooFloat: 10 add 2 = Multiple Dispatch: No suitable candidate found for 'add_int', with signature 'PIP->P' |

94 | Float: 10 sub 2 = 8 |

95 | FooFloat: 10 sub 2 = Multiple Dispatch: No suitable candidate found for 'subtract_int', with signature 'PIP->P' |

96 | Float: 10 mul 2 = 20 |

97 | FooFloat: 10 mul 2 = Multiple Dispatch: No suitable candidate found for 'multiply_int', with signature 'PIP->P' |

98 | Float: 10 div 2 = 5 |

99 | FooFloat: 10 div 2 = Multiple Dispatch: No suitable candidate found for 'divide_int', with signature 'PIP->P' |

100 | Complex: 10 add 2 = 12+0i |

101 | FooComplex: 10 add 2 = Multiple Dispatch: No suitable candidate found for 'add_int', with signature 'PIP->P' |

102 | Complex: 10 sub 2 = 8+0i |

103 | FooComplex: 10 sub 2 = Multiple Dispatch: No suitable candidate found for 'subtract_int', with signature 'PIP->P' |

104 | Complex: 10 mul 2 = 20+0i |

105 | FooComplex: 10 mul 2 = Multiple Dispatch: No suitable candidate found for 'multiply_int', with signature 'PIP->P' |

106 | Complex: 10 div 2 = 5+0i |

107 | FooComplex: 10 div 2 = Multiple Dispatch: No suitable candidate found for 'divide_int', with signature 'PIP->P' |

108 | FINISH |

109 | |

110 | =end output |

111 |