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.
--- a/.hgignore Sat Sep 26 08:59:11 2015 +0100
+++ b/.hgignore Sun Sep 27 07:07:46 2015 +0100
@@ -14,3 +14,22 @@
java/libs-src/*.jar
*-Test.xml
st.chg
+
+# teak compilation by-products
+compiler/cli/makefile.bak
+compiler/cli/resources/stx/*
+compiler/cli/resources/jv/*
+compiler/cli/teak
+
+# libt compilation by-products
+libt/*.ll
+libt/libt*
+libt/*.bc
+
+
+# examles compilation by-products
+examples/*.ll
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/FactorialI.tea Sun Sep 27 07:07:46 2015 +0100
@@ -0,0 +1,18 @@
+nil subclass: #FactorialI
+ category: 't-Examples'
+!
+
+!FactorialI class methodsFor:'examples'!
+factorialI:v <tSIntegerW> <^ tSIntegerW>
+ | result <tSIntegerW>
+ i <tSIntegerW> |
+
+ result := 0.
+ i := v.
+
+ [ i > 1 ] whileTrue:[
+ result := result * i.
+ i := i - 1
+ ].
+ ^ result
+! !
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/Makefile Sun Sep 27 07:07:46 2015 +0100
@@ -0,0 +1,40 @@
+# Sources
+SOURCES = $(wildcard *.tea)
+OBJECTS = $(patsubst %.tea,%.o,$(SOURCES))
+
+LIBT = ../libt/libt.bc
+
+# Tools
+AR=ar
+LD=ld
+CC=gcc
+TEAK = ../compiler/cli/teak
+LLVM_CONFIG ?= llvm-config-3.8
+LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir)
+LLVM_LLC = $(LLVM_BINDIR)/llc
+LLVM_LINK = $(LLVM_BINDIR)/llvm-link
+LLVM_OPT = $(LLVM_BINDIR)/opt
+
+# Flags
+LLVM_OPT_FLAGS = -O2
+
+
+all: $(OBJECTS)
+
+
+# ----------vvvvvvvvvv should be replace by real dependendies of .tea file
+%.bc: %.tea
+ $(TEAK) $(SOURCES)
+
+%.all.bc: %.bc
+ $(LLVM_LINK) -o=$@ $< $(LIBT)
+
+%.opt.bc: %.all.bc
+ $(LLVM_OPT) $(LLVM_OPT_FLAGS) -o=$@ $<
+
+
+%.o: %.opt.bc
+ $(LLVM_LLC) -filetype=obj -o=$@ $<
+
+clean:
+ rm -f *.bc *.o
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libt/Makefile Sun Sep 27 07:07:46 2015 +0100
@@ -0,0 +1,46 @@
+# Sources
+SOURCES = $(wildcard *.tea)
+BITCODES = $(patsubst %.tea,%.bc,$(SOURCES))
+
+# Tools
+AR=ar
+LD=ld
+CC=gcc
+TEAK = ../compiler/cli/teak
+LLVM_CONFIG ?= llvm-config-3.8
+LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir)
+LLVM_LLC = $(LLVM_BINDIR)/llc
+LLVM_LINK = $(LLVM_BINDIR)/llvm-link
+
+# Artifacts...
+LIBRARY_NAME=libt
+LIBRARY = $(LIBRARY_NAME).so
+ARCHIVE = $(LIBRARY_NAME).a
+
+
+
+all: $(LIBRARY) $(ARCHIVE)
+
+$(LIBRARY): $(LIBRARY_NAME).o
+ ld -shared -o $@ $<
+
+$(ARCHIVE): $(LIBRARY_NAME).o
+ $(AR) r $@ $<
+
+$(LIBRARY_NAME).o: $(LIBRARY_NAME).bc
+ $(LLVM_LLC) -filetype=obj -o=$@ $<
+
+$(LIBRARY_NAME).bc: $(BITCODES)
+ $(LLVM_LINK) -o=$@ $(BITCODES)
+
+
+# ----------vvvvvvvvvv should be replace by real dependendies of .tea file
+%.bc: %.tea $(SOURCES)
+ $(TEAK) $(SOURCES)
+
+%.ll: %.tea $(SOURCES)
+ $(TEAK) --output=$@ --emit-llvm-ir $<
+
+
+clean:
+ rm -f *.ll $(BITCODES) $(LIBRARY_NAME).o $(LIBRARY_NAME).bc $(LIBRARY) $(ARCHIVE)
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libt/tBoolean.tea Sun Sep 27 07:07:46 2015 +0100
@@ -0,0 +1,3 @@
+nil subclass: #tBoolean
+ category: 't-Kernel'
+!
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libt/tSIntegerW.tea Sun Sep 27 07:07:46 2015 +0100
@@ -0,0 +1,41 @@
+nil subclass: #tSIntegerW
+ category: 't-Kernel'
+!
+
+!tSIntegerW methodsFor: 'comparing'!
+< another <tSIntegerW> <^tBoolean>
+ <primitive: [:asm |
+ asm ret: (asm icmp: self _: another cond: LLVMIntSLT)
+ ]>
+!
+
+> another <tSIntegerW> <^tBoolean>
+ <primitive: [:asm |
+ asm ret: (asm icmp: self _: another cond: LLVMIntSGT)
+ ]>
+!
+
+= another <tSIntegerW> <^tBoolean>
+ <primitive: [:asm |
+ asm ret: (asm icmp: self _: another cond: LLVMIntEQ)
+ ]>
+! !
+
+!tSIntegerW methodsFor: 'arithmetic'!
++ another <tSIntegerW> <^tSIntegerW>
+ <primitive: [:asm |
+ asm ret: (asm add: self _: another)
+ ]>
+!
+
+- another <tSIntegerW> <^tSIntegerW>
+ <primitive: [:asm |
+ asm ret: (asm sub: self _: another)
+ ]>
+!
+
+* another <tSIntegerW> <^tSIntegerW>
+ <primitive: [:asm |
+ asm ret: (asm mul: self _: another)
+ ]>
+! !