First shot of libt and some examples
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sun, 27 Sep 2015 07:07:46 +0100
changeset 197597503194b8
parent 18 e2168260b75a
child 20 2f28df70181a
First shot of libt and some examples

libt serves (well, might serve at some point) as a basic
library for Tea language. Added directory with examples
demostration Tea (and libt)

Both includes makefiles to compile libt and examples to
compile them down to machine code. This also demonstrates
how to use `teak`, a standalone Tea compiler.
.hgignore
examples/FactorialI.tea
examples/Makefile
libt/Makefile
libt/tBoolean.tea
libt/tSIntegerW.tea
     1.1 --- a/.hgignore	Sat Sep 26 08:59:11 2015 +0100
     1.2 +++ b/.hgignore	Sun Sep 27 07:07:46 2015 +0100
     1.3 @@ -14,3 +14,22 @@
     1.4  java/libs-src/*.jar
     1.5  *-Test.xml
     1.6  st.chg
     1.7 +
     1.8 +# teak compilation by-products
     1.9 +compiler/cli/makefile.bak
    1.10 +compiler/cli/resources/stx/*
    1.11 +compiler/cli/resources/jv/*
    1.12 +compiler/cli/teak
    1.13 +
    1.14 +# libt compilation by-products
    1.15 +libt/*.ll
    1.16 +libt/libt*
    1.17 +libt/*.bc
    1.18 +
    1.19 +
    1.20 +# examles compilation by-products
    1.21 +examples/*.ll
    1.22 +
    1.23 +
    1.24 +
    1.25 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/examples/FactorialI.tea	Sun Sep 27 07:07:46 2015 +0100
     2.3 @@ -0,0 +1,18 @@
     2.4 +nil subclass: #FactorialI
     2.5 +    category: 't-Examples'
     2.6 +!
     2.7 +
     2.8 +!FactorialI class methodsFor:'examples'!
     2.9 +factorialI:v <tSIntegerW> <^ tSIntegerW>
    2.10 +    | result <tSIntegerW> 
    2.11 +      i <tSIntegerW> |
    2.12 +
    2.13 +    result := 0.
    2.14 +    i := v.
    2.15 +
    2.16 +    [ i > 1 ] whileTrue:[ 
    2.17 +        result := result * i.
    2.18 +        i := i - 1
    2.19 +    ].
    2.20 +    ^ result
    2.21 +! !       
    2.22 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/examples/Makefile	Sun Sep 27 07:07:46 2015 +0100
     3.3 @@ -0,0 +1,40 @@
     3.4 +# Sources 
     3.5 +SOURCES = $(wildcard *.tea)
     3.6 +OBJECTS = $(patsubst %.tea,%.o,$(SOURCES))
     3.7 +
     3.8 +LIBT = ../libt/libt.bc
     3.9 +
    3.10 +# Tools
    3.11 +AR=ar
    3.12 +LD=ld
    3.13 +CC=gcc
    3.14 +TEAK = ../compiler/cli/teak
    3.15 +LLVM_CONFIG ?= llvm-config-3.8
    3.16 +LLVM_BINDIR  = $(shell $(LLVM_CONFIG) --bindir)
    3.17 +LLVM_LLC  = $(LLVM_BINDIR)/llc
    3.18 +LLVM_LINK = $(LLVM_BINDIR)/llvm-link
    3.19 +LLVM_OPT  = $(LLVM_BINDIR)/opt
    3.20 +
    3.21 +# Flags
    3.22 +LLVM_OPT_FLAGS = -O2
    3.23 +
    3.24 +
    3.25 +all: $(OBJECTS)
    3.26 +
    3.27 +
    3.28 +# ----------vvvvvvvvvv should be replace by real dependendies of .tea file
    3.29 +%.bc: %.tea
    3.30 +	$(TEAK) $(SOURCES)
    3.31 +
    3.32 +%.all.bc: %.bc
    3.33 +	$(LLVM_LINK) -o=$@ $< $(LIBT)
    3.34 +
    3.35 +%.opt.bc: %.all.bc	
    3.36 +	$(LLVM_OPT) $(LLVM_OPT_FLAGS) -o=$@ $<	
    3.37 +
    3.38 +
    3.39 +%.o: %.opt.bc
    3.40 +	$(LLVM_LLC) -filetype=obj -o=$@ $<
    3.41 +        
    3.42 +clean:
    3.43 +	rm -f *.bc *.o
    3.44 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/libt/Makefile	Sun Sep 27 07:07:46 2015 +0100
     4.3 @@ -0,0 +1,46 @@
     4.4 +# Sources 
     4.5 +SOURCES = $(wildcard *.tea)
     4.6 +BITCODES = $(patsubst %.tea,%.bc,$(SOURCES))
     4.7 +
     4.8 +# Tools
     4.9 +AR=ar
    4.10 +LD=ld
    4.11 +CC=gcc
    4.12 +TEAK = ../compiler/cli/teak
    4.13 +LLVM_CONFIG ?= llvm-config-3.8
    4.14 +LLVM_BINDIR  = $(shell $(LLVM_CONFIG) --bindir)
    4.15 +LLVM_LLC  = $(LLVM_BINDIR)/llc
    4.16 +LLVM_LINK  = $(LLVM_BINDIR)/llvm-link
    4.17 +
    4.18 +# Artifacts...
    4.19 +LIBRARY_NAME=libt
    4.20 +LIBRARY = $(LIBRARY_NAME).so
    4.21 +ARCHIVE = $(LIBRARY_NAME).a
    4.22 +
    4.23 +
    4.24 +
    4.25 +all: $(LIBRARY) $(ARCHIVE)	
    4.26 +
    4.27 +$(LIBRARY): $(LIBRARY_NAME).o
    4.28 +	ld -shared -o $@ $<
    4.29 +
    4.30 +$(ARCHIVE): $(LIBRARY_NAME).o	
    4.31 +	$(AR) r $@ $<
    4.32 +
    4.33 +$(LIBRARY_NAME).o: $(LIBRARY_NAME).bc
    4.34 +	$(LLVM_LLC) -filetype=obj -o=$@ $<
    4.35 +
    4.36 +$(LIBRARY_NAME).bc: $(BITCODES)
    4.37 +	$(LLVM_LINK) -o=$@ $(BITCODES)
    4.38 +
    4.39 +
    4.40 +# ----------vvvvvvvvvv should be replace by real dependendies of .tea file
    4.41 +%.bc: %.tea $(SOURCES)
    4.42 +	$(TEAK) $(SOURCES)
    4.43 +
    4.44 +%.ll: %.tea $(SOURCES)
    4.45 +	$(TEAK) --output=$@ --emit-llvm-ir $<
    4.46 +
    4.47 +        
    4.48 +clean:
    4.49 +	rm -f *.ll $(BITCODES) $(LIBRARY_NAME).o $(LIBRARY_NAME).bc $(LIBRARY) $(ARCHIVE) 
    4.50 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/libt/tBoolean.tea	Sun Sep 27 07:07:46 2015 +0100
     5.3 @@ -0,0 +1,3 @@
     5.4 +nil subclass: #tBoolean
     5.5 +    category: 't-Kernel'
     5.6 +!
     5.7 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/libt/tSIntegerW.tea	Sun Sep 27 07:07:46 2015 +0100
     6.3 @@ -0,0 +1,41 @@
     6.4 +nil subclass: #tSIntegerW
     6.5 +    category: 't-Kernel'
     6.6 +!
     6.7 +
     6.8 +!tSIntegerW methodsFor: 'comparing'!
     6.9 +< another <tSIntegerW> <^tBoolean>
    6.10 +    <primitive: [:asm |
    6.11 +    	asm ret: (asm icmp: self _: another cond: LLVMIntSLT)
    6.12 +    ]>
    6.13 +!
    6.14 +
    6.15 +> another <tSIntegerW> <^tBoolean>
    6.16 +    <primitive: [:asm |
    6.17 +    	asm ret: (asm icmp: self _: another cond: LLVMIntSGT)
    6.18 +    ]>
    6.19 +!
    6.20 +
    6.21 += another <tSIntegerW> <^tBoolean>
    6.22 +    <primitive: [:asm |
    6.23 +    	asm ret: (asm icmp: self _: another cond: LLVMIntEQ)
    6.24 +    ]>
    6.25 +! !
    6.26 +
    6.27 +!tSIntegerW methodsFor: 'arithmetic'!
    6.28 ++ another <tSIntegerW> <^tSIntegerW>
    6.29 +    <primitive: [:asm |
    6.30 +    	asm ret: (asm add: self _: another)
    6.31 +    ]>
    6.32 +!
    6.33 +
    6.34 +- another <tSIntegerW> <^tSIntegerW>
    6.35 +    <primitive: [:asm |
    6.36 +    	asm ret: (asm sub: self _: another)
    6.37 +    ]>    
    6.38 +!
    6.39 +
    6.40 +* another <tSIntegerW> <^tSIntegerW>
    6.41 +    <primitive: [:asm |
    6.42 +    	asm ret: (asm mul: self _: another)
    6.43 +    ]>        
    6.44 +! !