compiler/TCompiler.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 28 Sep 2015 14:39:57 +0100
changeset 20 2f28df70181a
parent 16 17a2d1d9f205
permissions -rw-r--r--
Added README, license and copyright notice
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     1
"
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     2
    Copyright (C) 2015-now Jan Vrany
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     3
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     4
    This code is not an open-source (yet). You may use this code
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     5
    for your own experiments and projects, given that:
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     6
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     7
    * all modification to the code will be sent to the
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     8
      original author for inclusion in future releases
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
     9
    * this is not used in any commercial software
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    10
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    11
    This license is provisional and may (will) change in
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    12
    a future.
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    13
"
1
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
"{ Package: 'jv:tea/compiler' }"
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
Object subclass:#TCompiler
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    19
	instanceVariableNames:'context'
1
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
	classVariableNames:''
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
	poolDictionaries:''
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
	category:'Languages-Tea-Compiler'
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
!
18b4a3b98e96 Creates subpackage jv:tea/compiler
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
16
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    25
!TCompiler class methodsFor:'documentation'!
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    26
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    27
copyright
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    28
"
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    29
    Copyright (C) 2015-now Jan Vrany
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    30
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    31
    This code is not an open-source (yet). You may use this code
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    32
    for your own experiments and projects, given that:
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    33
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    34
    * all modification to the code will be sent to the
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    35
      original author for inclusion in future releases
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    36
    * this is not used in any commercial software
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    37
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    38
    This license is provisional and may (will) change in
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    39
    a future.
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    40
"
17a2d1d9f205 Added standalone Tea compiler - teak
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 9
diff changeset
    41
! !
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    42
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    43
!TCompiler class methodsFor:'compilation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    44
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    45
compile: unit in: env
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    46
    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
    47
    "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
    48
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    49
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    50
!TCompiler methodsFor:'accessing'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    51
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    52
context
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    53
    ^ context
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    54
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    55
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    56
context:aTCompilerContext
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    57
    context := aTCompilerContext.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    58
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    59
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    60
!TCompiler methodsFor:'compilation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    61
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    62
compile: unit
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    63
    context unit: unit.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    64
    self compile.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    65
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    66
    "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
    67
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    68
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    69
compile: unit in: environment
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    70
    context := TCompilerContext new.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    71
    context environment: environment.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    72
    context unit: unit.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    73
    self context: context.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    74
    self compile: unit.
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    75
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    76
    "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
    77
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    78
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    79
!TCompiler methodsFor:'private'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    80
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
    81
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
    82
    | 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
    83
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
    84
    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
    85
    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
    86
    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
    87
        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
    88
    ].
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
    89
    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
    90
    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
    91
    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
    92
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
    93
    "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
    94
    "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
    95
!
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
    96
4
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    97
runPass: aClass
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    98
    aClass new
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
    99
        context: context;
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   100
        run
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   101
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   102
    "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
   103
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   104
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   105
!TCompiler class methodsFor:'documentation'!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   106
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   107
version
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   108
    ^ '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
   109
!
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   110
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   111
version_HG
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   112
    ^ '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
   113
! !
3d80069ea3e2 More work on basic infrastructure - types, bindings & compilation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1
diff changeset
   114