author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 16 Sep 2015 05:29:43 +0100 | |
changeset 11 | 6d39860d0fdb |
parent 9 | 569bf5707c7e |
child 13 | 97090c2baa33 |
permissions | -rw-r--r-- |
3
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
1 |
"{ Package: 'jv:tea/compiler' }" |
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
2 |
|
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
4 |
|
6
0c806a7f1888
Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4
diff
changeset
|
5 |
TCompilerPass subclass:#TTypechecker |
3
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
6 |
instanceVariableNames:'' |
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
7 |
classVariableNames:'' |
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
8 |
poolDictionaries:'' |
9
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
9 |
category:'Languages-Tea-Compiler-Internals' |
3
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
10 |
! |
97ee341d3e9f
Initial shot of scopes & bindings and type checking. Must be rethought.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
11 |
|
6
0c806a7f1888
Initial support for inline assembly
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4
diff
changeset
|
12 |
!TTypechecker methodsFor:'visitor-double dispatching'! |
4
3d80069ea3e2
More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3
diff
changeset
|
13 |
|
9
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
14 |
acceptIfTrueIfFalseNode: node |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
15 |
| receiverType booleanType | |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
16 |
|
11
6d39860d0fdb
First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
9
diff
changeset
|
17 |
receiverType := node receiver binding type. |
6d39860d0fdb
First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
9
diff
changeset
|
18 |
booleanType := context environment binding lookupClassBoolean type. |
9
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
19 |
|
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
20 |
receiverType = booleanType ifFalse:[ |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
21 |
context reportTypeError: 'receiver of ifTrue:ifFalse: special form must be of type tBoolean (is ' , receiverType printString. |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
22 |
]. |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
23 |
|
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
24 |
"Created: / 14-09-2015 / 14:24:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
11
6d39860d0fdb
First shot on #ifTrie:ifFalse: special form
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
9
diff
changeset
|
25 |
"Modified: / 15-09-2015 / 08:29:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
26 |
! |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
27 |
|
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
28 |
acceptIfTrueNode: node |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
29 |
| receiverType booleanType | |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
30 |
|
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
31 |
receiverType := node binding type. |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
32 |
booleanType := context environment binding lookupClassBoolean. |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
33 |
|
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
34 |
receiverType = booleanType ifFalse:[ |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
35 |
context reportTypeError: 'receiver of ifTrue: special form must be of type tBoolean (is ' , receiverType printString. |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
36 |
]. |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
37 |
|
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
38 |
"Created: / 14-09-2015 / 14:18:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
39 |
! |
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
40 |
|
7
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
41 |
acceptMessageNode: aMessageNode |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
42 |
| receiverType receiverBinding methodBinding | |
4
3d80069ea3e2
More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3
diff
changeset
|
43 |
|
7
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
44 |
super acceptMessageNode: aMessageNode. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
45 |
receiverType := aMessageNode receiver binding type. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
46 |
receiverType isSimpleType ifTrue:[ |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
47 |
receiverBinding := context environment binding lookupClassNamed: receiverType name. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
48 |
methodBinding := receiverBinding lookupMethodNamed: aMessageNode selector. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
49 |
1 to: aMessageNode arguments size do:[:paramIdx | |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
50 |
| actualParamType formalParamType | |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
51 |
actualParamType := (aMessageNode arguments at: paramIdx) binding type. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
52 |
formalParamType := methodBinding parameterTypes at: paramIdx. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
53 |
(actualParamType isSubtypeOf: formalParamType) ifFalse:[ |
9
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
54 |
context reportTypeError: ('Type mismatch for parameter %1 (expected %2, got %3)' bindWith: paramIdx with: formalParamType with: actualParamType). |
7
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
55 |
^ self. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
56 |
]. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
57 |
]. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
58 |
aMessageNode binding: methodBinding. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
59 |
^ self. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
60 |
]. |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
61 |
self notYetImplemented |
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
62 |
|
7556e3d41d80
Make 3 + 4 working, though the code is rather messy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
6
diff
changeset
|
63 |
"Created: / 02-09-2015 / 10:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9
569bf5707c7e
Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7
diff
changeset
|
64 |
"Modified: / 14-09-2015 / 14:22:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4
3d80069ea3e2
More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3
diff
changeset
|
65 |
! ! |
3d80069ea3e2
More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3
diff
changeset
|
66 |