compiler/TCompiler.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 14 Sep 2015 15:03:03 +0100
changeset 9 569bf5707c7e
parent 8 eec72263ed75
child 16 17a2d1d9f205
permissions -rw-r--r--
Added support for special forms to parser and typechecker (somewhat)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'jv:tea/compiler' }"
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
"{ NameSpace: Smalltalk }"
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
Object subclass:#TCompiler
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
     6
	instanceVariableNames:'context'
1
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
	classVariableNames:''
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
	poolDictionaries:''
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
	category:'Languages-Tea-Compiler'
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
!
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    12
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    13
!TCompiler class methodsFor:'compilation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    14
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    15
compile: unit in: env
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    16
    self new compile: unit in: env.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    17
    "Created: / 29-08-2015 / 14:18:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    18
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    19
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    20
!TCompiler methodsFor:'accessing'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    21
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    22
context
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    23
    ^ context
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    24
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    25
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    26
context:aTCompilerContext
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    27
    context := aTCompilerContext.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    28
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    29
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    30
!TCompiler methodsFor:'compilation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    31
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    32
compile: unit
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    33
    context unit: unit.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    34
    self compile.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    35
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    36
    "Created: / 29-08-2015 / 21:53:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    37
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    38
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    39
compile: unit in: environment
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    40
    context := TCompilerContext new.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    41
    context environment: environment.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    42
    context unit: unit.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    43
    self context: context.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    44
    self compile: unit.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    45
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    46
    "Created: / 31-08-2015 / 12:27:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    47
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    48
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    49
!TCompiler methodsFor:'private'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    50
8
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    51
compile
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    52
    | unit |
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    53
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    54
    unit := context unit.
9
569bf5707c7e Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    55
    self assert:(unit isRingObject and:[ unit isCompilationUnit ]).
569bf5707c7e Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    56
    unit classes do:[:class | 
569bf5707c7e Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    57
        context environment addClass:class
569bf5707c7e Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    58
    ].
8
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    59
    self runPass:TSemanticAnalyser.
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    60
    self runPass:TTypechecker.
9
569bf5707c7e Added support for special forms to parser and typechecker (somewhat)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    61
    self runPass:TLLVMCodeGenerator.
8
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    62
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    63
    "Created: / 29-08-2015 / 14:22:41 / 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: 8
diff changeset
    64
    "Modified: / 14-09-2015 / 13:10:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
8
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    65
!
eec72263ed75 Introduced TEnvironment, a container object that keeps all (class) definition requiref for a compilation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7
diff changeset
    66
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    67
runPass: aClass
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    68
    aClass new
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    69
        context: context;
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    70
        run
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    71
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    72
    "Created: / 31-08-2015 / 10:51:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    73
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    74
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    75
!TCompiler class methodsFor:'documentation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    76
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    77
version
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    78
    ^ 'Path: jv/tea/compiler/TCompiler.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:55.136+01'
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    79
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    80
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    81
version_HG
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    82
    ^ 'Path: jv/tea/compiler/TCompiler.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:55.136+01'
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    83
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    84