Skip to content

Commit

Permalink
Code generator is mostly complete, major parts missing are function c…
Browse files Browse the repository at this point in the history
…alls and strings,

but it successfully compiles and runs the 'artisanal-titan' examples, collected under
'examples/artisanal.titan'. Included patched Lua from 'artisanal-titan' to run the
examples, but it is better if we tweak the build process to run with stock Lua.
  • Loading branch information
mascarenhas committed Oct 15, 2017
1 parent 480b3ae commit a1d34da
Show file tree
Hide file tree
Showing 83 changed files with 37,371 additions and 142 deletions.
6 changes: 0 additions & 6 deletions examples/add.titan

This file was deleted.

69 changes: 69 additions & 0 deletions examples/artisanal.titan
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- Add two numbers

function foo(x: integer, y: integer): integer
return x + y
end

function filltable(N: integer): { integer }
local xs: { integer } = {}
for i: integer = 1,N do
xs[i] = 10*i
end
return xs
end


function sieve(N: integer): {integer}

local is_prime: {boolean} = {}
is_prime[1] = false
for n: integer=2,N do
is_prime[n] = true
end

local nprimes: integer = 0
local primes: {integer} = {}

for n: integer=1,N do
if is_prime[n] then
nprimes = nprimes + 1;
primes[nprimes] = n
for m:integer = n+n, N, n do
is_prime[m] = false
end
end
end

return primes
end


function sort(xs: {integer}): nil
local N: integer = #xs
for i: integer=1,N do

-- Find minimum
local min_i: integer = i
local min_x: integer = xs[i]
for j: integer = i+1, N do
local y: integer = xs[j]
if y < min_x then
min_i = j
min_x = y
end
end

-- Move it to the front
local tmp: integer = xs[i]
xs[i] = xs[min_i]
xs[min_i] = tmp
end
end

function sum(N: integer): integer
local res = 0
for i: integer=1,N do
res = res + i
end
return res
end
9 changes: 9 additions & 0 deletions examples/test_fill_table.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local mod = require "artisanal"

local f = mod.filltable

local N = arg[1] and tonumber(arg[1]) or 1000

print("N="..N)
local r = f(N)
print(type(r))
29 changes: 29 additions & 0 deletions examples/test_selection_sort.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local N = arg[1] and tonumber(arg[1]) or 5000

local sort = require("artisanal").sort

local function make_input(N)
local xs = {}
for i=1,N do
xs[i] = N - i + 1
end
return xs
end

local function print_array(xs)
print( "{" .. table.concat(xs, ", ") .. "}" )
end

local function is_sorted(xs)
for i=2,#xs do
if xs[i-1] > xs[i] then
return false
end
end
return true
end

local xs = make_input(N)
print('before', is_sorted(xs))
sort(xs)
print('after', is_sorted(xs))
6 changes: 6 additions & 0 deletions examples/test_sieve.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local N = arg[1] and tonumber(arg[1]) or 100

local f = require("artisanal").sieve

local ps = f(N)
print(#ps)
8 changes: 8 additions & 0 deletions examples/test_sum_1_N.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local N = arg[1] and tonumber(arg[1]) or 500000000

local f = require("artisanal").sum

print("N="..N)
local r = f(N)
print(r)

114 changes: 114 additions & 0 deletions lua/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Makefile for installing Lua
# See doc/readme.html for installation and customization instructions.

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

# Where to install. The installation starts in the src and doc directories,
# so take care if INSTALL_TOP is not an absolute path. See the local target.
# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V

# How to install. If your install program does not support "-p", then
# you may have to run ranlib on the installed liblua.a.
INSTALL= install -p
INSTALL_EXEC= $(INSTALL) -m 0755
INSTALL_DATA= $(INSTALL) -m 0644
#
# If you don't have "install" you can use "cp" instead.
# INSTALL= cp -p
# INSTALL_EXEC= $(INSTALL)
# INSTALL_DATA= $(INSTALL)

# Other utilities.
MKDIR= mkdir -p
RM= rm -f

# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======

# Convenience platforms targets.
PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris

# What to install.
TO_BIN= lua luac
TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp
TO_LIB= liblua.a
TO_MAN= lua.1 luac.1

# Lua version and release.
V= 5.3
R= $V.4

# Targets start here.
all: $(PLAT)

$(PLATS) clean:
cd src && $(MAKE) $@

test: dummy
src/lua -v

install: dummy
cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)

uninstall:
cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)
cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)
cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)
cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)

local:
$(MAKE) install INSTALL_TOP=../install

none:
@echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
@echo " $(PLATS)"
@echo "See doc/readme.html for complete instructions."

# make may get confused with test/ and install/
dummy:

# echo config parameters
echo:
@cd src && $(MAKE) -s echo
@echo "PLAT= $(PLAT)"
@echo "V= $V"
@echo "R= $R"
@echo "TO_BIN= $(TO_BIN)"
@echo "TO_INC= $(TO_INC)"
@echo "TO_LIB= $(TO_LIB)"
@echo "TO_MAN= $(TO_MAN)"
@echo "INSTALL_TOP= $(INSTALL_TOP)"
@echo "INSTALL_BIN= $(INSTALL_BIN)"
@echo "INSTALL_INC= $(INSTALL_INC)"
@echo "INSTALL_LIB= $(INSTALL_LIB)"
@echo "INSTALL_MAN= $(INSTALL_MAN)"
@echo "INSTALL_LMOD= $(INSTALL_LMOD)"
@echo "INSTALL_CMOD= $(INSTALL_CMOD)"
@echo "INSTALL_EXEC= $(INSTALL_EXEC)"
@echo "INSTALL_DATA= $(INSTALL_DATA)"

# echo pkg-config data
pc:
@echo "version=$R"
@echo "prefix=$(INSTALL_TOP)"
@echo "libdir=$(INSTALL_LIB)"
@echo "includedir=$(INSTALL_INC)"

# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho

# (end of Makefile)
6 changes: 6 additions & 0 deletions lua/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

This is Lua 5.3.4, released on 12 Jan 2017.

For installation instructions, license details, and
further information about Lua, see doc/readme.html.

Loading

0 comments on commit a1d34da

Please sign in to comment.