forked from bonzini/smalltalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.st
117 lines (98 loc) · 2.97 KB
/
compiler.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"======================================================================
|
| Regression tests for the compiler
|
|
======================================================================"
"======================================================================
|
| Copyright (C) 2003 Free Software Foundation.
| Written by Paolo Bonzini
|
| This file is part of GNU Smalltalk.
|
| GNU Smalltalk is free software; you can redistribute it and/or modify it
| under the terms of the GNU General Public License as published by the Free
| Software Foundation; either version 2, or (at your option) any later version.
|
| GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| GNU Smalltalk; see the file COPYING. If not, write to the Free Software
| Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
======================================================================"
Object subclass: #BugTest
instanceVariableNames: 'value '
classVariableNames: ''
poolDictionaries: ''
category: 'Regression testing'!
!Object methodsFor: 'bugs'!
a: value
^[ undefVariable ]! !
!BugTest methodsFor: 'bugs'!
bugHere
"The scope for the above method isn't popped and a
bogus error is returned here."
value := 42! !
"Here is another one. In this case the temporaries inside the block
were not counted correctly and were overwritten by push bytecodes."
!String methodsFor: 'matching'!
phoneNumber
| s attempted |
attempted := false.
self keysAndValuesDo: [ :k :each |
| skip ok ch |
ok := false.
each = $( ifTrue: [
ok := self size - k >= 13 and: [ (self at: k + 4) = $) ].
skip := 1.
].
each isDigit ifTrue: [
ok := self size - k >= 11.
skip := 0.
].
ok := ok and: [ attempted not ].
attempted := skip notNil.
ok ifTrue: [
skip + k to: skip + 2 + k do: [ :i |
ok := ok and: [ (self at: i) isDigit ]
].
(skip * 2 + k + 4) to: (skip * 2 + k + 6) do: [ :i |
ok := ok and: [ (self at: i) isDigit ]
].
(skip * 2 + k + 8) to: (skip * 2 + k + 11) do: [ :i |
ok := ok and: [ (self at: i) isDigit ]
].
ch := self at: skip * 2 + k + 7.
ok := ok and: [ (ch = $ ) | (ch = $-) ].
ok ifTrue: [ ^{
self copyFrom: k + skip to: k + skip + 2.
self copyFrom: skip * 2 + k + 4 to: skip * 2 + k + 6.
self copyFrom: skip * 2 + k + 8 to: skip * 2 + k + 11.
} ]
].
].
^nil
! !
'(111) 111-1111' phoneNumber!
"Various errors in the recursive-descent parser"
!BugTest class methodsFor: 'bugs'!
c
^'No crashes'!
a
^#[]!
b
^{}!
c
<3 4>
^'foo'! !
^BugTest c!
"The lexer crashed on this because it returned a SYMBOL_LITERAL with
-123 in the ival. This gives a parse error..."
^#-123!
"... this does not."
^#(#-123) size!