compiler/TCompiler.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 25 Sep 2015 03:51:15 +0100
changeset 16 17a2d1d9f205
parent 9 569bf5707c7e
permissions -rw-r--r--
Added standalone Tea compiler - teak It allows for compilation of .tea files from the command line.

"
    Copyright (C) 2015-now Jan Vrany

    This code is not an open-source (yet). You may use this code
    for your own experiments and projects, given that:

    * all modification to the code will be sent to the
      original author for inclusion in future releases
    * this is not used in any commercial software

    This license is provisional and may (will) change in
    a future.
"
"{ Package: 'jv:tea/compiler' }"

"{ NameSpace: Smalltalk }"

Object subclass:#TCompiler
	instanceVariableNames:'context'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler'
!

!TCompiler class methodsFor:'documentation'!

copyright
"
    Copyright (C) 2015-now Jan Vrany

    This code is not an open-source (yet). You may use this code
    for your own experiments and projects, given that:

    * all modification to the code will be sent to the
      original author for inclusion in future releases
    * this is not used in any commercial software

    This license is provisional and may (will) change in
    a future.
"
! !

!TCompiler class methodsFor:'compilation'!

compile: unit in: env
    self new compile: unit in: env.
    "Created: / 29-08-2015 / 14:18:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompiler methodsFor:'accessing'!

context
    ^ context
!

context:aTCompilerContext
    context := aTCompilerContext.
! !

!TCompiler methodsFor:'compilation'!

compile: unit
    context unit: unit.
    self compile.

    "Created: / 29-08-2015 / 21:53:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

compile: unit in: environment
    context := TCompilerContext new.
    context environment: environment.
    context unit: unit.
    self context: context.
    self compile: unit.

    "Created: / 31-08-2015 / 12:27:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompiler methodsFor:'private'!

compile
    | unit |

    unit := context unit.
    self assert:(unit isRingObject and:[ unit isCompilationUnit ]).
    unit classes do:[:class | 
        context environment addClass:class
    ].
    self runPass:TSemanticAnalyser.
    self runPass:TTypechecker.
    self runPass:TLLVMCodeGenerator.

    "Created: / 29-08-2015 / 14:22:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-09-2015 / 13:10:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

runPass: aClass
    aClass new
        context: context;
        run

    "Created: / 31-08-2015 / 10:51:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompiler class methodsFor:'documentation'!

version
    ^ 'Path: jv/tea/compiler/TCompiler.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:55.136+01'
!

version_HG
    ^ 'Path: jv/tea/compiler/TCompiler.st, Version: 1.0, User: jv, Time: 2015-08-31T13:47:55.136+01'
! !