Skip to content

Commit

Permalink
Adds initial Arduino LEONARDO support, improved function call, releas…
Browse files Browse the repository at this point in the history
…e build scripts

Features

* Arduino LEONARDO compatible compilation profile (#3)
  * Detect that we are in a profile mode from a command line switch (#3.1)
  * Code generation is called with current profile (#3.2)
  * Code generation outputs code targetting "setup" instead of "main" (#3.3)
  * Makefile uses the arduino makefile #arduino leonardo (#3.4)
* Compilation profiles support removal of elements of the clib (#4.1)

* Function calls that do not require arguments work (#2)

Docs

* Docs in README.md, setup.py and docs/ are generated from website. (#66)
* Documentation in /docs is generated from website source documentation
* (#63)
* Docs on usage #docs (#64)
* Man page for pyxie (#65)

Other

* Make Release Script (#61)
* build release script (#62)

Other

* Clean up build local script
* Man file added (not installed yet though)
* Build distributed docs from the same source as the website
* Added pyxie-dev script to assist in release automation
* Re-enable doc building
  • Loading branch information
sparkslabs committed Aug 2, 2015
1 parent 965cd5a commit 0e41f05
Show file tree
Hide file tree
Showing 58 changed files with 3,387 additions and 636 deletions.
46 changes: 46 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,52 @@ reason.

### In progress

## [0.0.16] - UNRELEASED

Summary: Adds initial Arduino LEONARDO support, improved function call, release build scripts

In particular, to compile for a compilation target you do this:

pyxie --profile arduino some_program.pyxie

This will generate some_program.hex. You then need to load this onto your
arduino. Support for assisting with this will probably be in a largert
version. Requires Arduino.mk to be installed in a standard place. Docs TBD
as functionality stabilises.

### Features

* Arduino LEONARDO compatible compilation profile (#3)
* Detect that we are in a profile mode from a command line switch (#3.1)
* Code generation is called with current profile (#3.2)
* Code generation outputs code targetting "setup" instead of "main" (#3.3)
* Makefile uses the arduino makefile #arduino leonardo (#3.4)
* Compilation profiles support removal of elements of the clib (#4.1)

* Function calls that do not require arguments work (#2)

### Docs

* Docs in README.md, setup.py and docs/ are generated from website. (#66)
* Documentation in /docs is generated from website source documentation (#63)
* Docs on usage #docs (#64)
* Man page for pyxie (#65)

### Other

* Make Release Script (#61)
* build_release_script.py (#62)
* Core setup.py files/etc now auto-generated from templates

### Other

* Clean up build local script
* Man file added (not installed yet though)
* Build distributed docs from the same source as the website
* Added pyxie-dev script to assist in release automation
* Re-enable doc building


## [0.0.15] - 2015-07-18

* clib converted to py clib for adding to build directory
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PYTHON=`which python`
DESTDIR=/
PROJECT=pyxie
VERSION=0.0.15
VERSION=0.0.16

all:
@echo "make source - Create source package"
Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ Release History

Release History:

- 0.0.16 - UNRELEASED - TBD
- 0.0.15 - 2015-07-18 - clib converted to py clib for adding to build
directory
- 0.0.14 - 2015-07-18 - For loops implemented. Added clib code, C++
Expand Down Expand Up @@ -345,6 +346,7 @@ Language Status
| arith_expression '/' expression_atom

expression_atom : value_literal
| IDENTIFIER '(' ')' # Function call, with no arguments
| IDENTIFIER '(' expr_list ')' # Function call
| '(' general_expression ')'

Expand Down Expand Up @@ -398,4 +400,4 @@ around version 0.0.15, based on current rate of progress.

Keeping it for now also simplifies "yield" later

Michael Sparks, July 2015
Michael Sparks, August 2015
85 changes: 63 additions & 22 deletions bin/pyxie
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ from pyxie.parsing.lexer import build_lexer
from pyxie.parsing.grammar import parse
from pyxie.model.transform import ast_to_cst
from pyxie.model.pynode import jdump
from pyxie.codegen.simple_cpp import C_Program, source, makefile_tmpl, reset_parser
from pyxie.codegen.simple_cpp import C_Program, source, reset_parser
import pyxie.codegen.profiles as profiles
import pyxie.codegen.simple_cpp

# profiles.makefile_templates

from pyxie.codegen.clib import files as clib_files

import os
Expand All @@ -29,12 +32,25 @@ import time

import sys

# This is to support compilation profiles. This may or may not turn out to
# be a good approach. (#3/#3.x)
profile = "default"
testdir = "test-data"
testprogs_dir = os.path.join(testdir, "progs")


class BadArguments(Exception):
pass

def remove_directory(build_dir):
for filename in os.listdir(build_dir):
try:
os.unlink(os.path.join(build_dir, filename))
except OSError, e:
if e.errno == 21:
remove_directory(os.path.join(build_dir, filename))
os.rmdir(build_dir)

def get_test_programs(program_suffix):
testprogs = [x for x in os.listdir(testprogs_dir) ]
testprogs = [x for x in testprogs if x.endswith(program_suffix) ]
Expand Down Expand Up @@ -71,7 +87,7 @@ def generate_code(cname, AST, debug=False):
print pprint.pformat(CST)
print "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
program = C_Program.fromjson(CST)
program.generate()
program.generate(profile)
return pyxie.codegen.simple_cpp.source[:]

def compile_testfile(testprogs_dir, testfile):
Expand Down Expand Up @@ -120,18 +136,34 @@ def build_program(source, work_dir, name):
pprint.pprint(source, width=200)
print

f = open(os.path.join(work_dir,name+".c"), "w")
extension = profiles.mainfile_extensions.get(profile,"c")

f = open(os.path.join(work_dir,name+"." +extension), "w")
for line in source:
f.write(line)
f.write("\n")
f.close()


try:
makefile_tmpl = profiles.makefile_templates[profile]
except KeyError:
makefile_tmpl = profiles.makefile_templates["default"]

makefile = makefile_tmpl % {"filename": name }
f = open(os.path.join(work_dir,"Makefile"), "w")
f.write(makefile)
f.close()

exclusions = profiles.clib_exclusions.get(profile, [])
for filename in clib_files:
if filename.endswith("_test.cpp"):
# Skip main programs to avoid confusing profiles
continue
if filename in exclusions:
print "Skipping", filename, "for profile", profile
continue

f = open( os.path.join(work_dir,filename), "w")
f.write(clib_files[filename])
f.close()
Expand Down Expand Up @@ -230,6 +262,7 @@ def codegen_phase(filename, result_filename):
return c_code



def compile_file(filename, result_filename=None):

build_env = get_build_environment(filename, result_filename)
Expand Down Expand Up @@ -259,17 +292,19 @@ def compile_file(filename, result_filename=None):

os.chdir(rootdir)

actual_result_file = (profiles.result_file[profile])(build_dir, cname)

result_filename = (profiles.modify_result_file[profile])(result_filename)

print "BUILD DIR", build_dir
print "RESULT FILE", os.path.join(build_dir, cname)
print "RESULT FILE", actual_result_file
print "DEST FILE", result_filename
print "CWD", os.getcwd()

os.rename(os.path.join(build_dir, cname),result_filename)
os.rename(actual_result_file,result_filename)
clean = True
if clean:
for filename in os.listdir(build_dir):
os.unlink(os.path.join(build_dir,filename))
os.removedirs(build_dir)
remove_directory(build_dir)
if base_dir == ".":
os.unlink("parsetab.py")
os.unlink("parser.out")
Expand Down Expand Up @@ -297,7 +332,7 @@ def handle_tests(argv):
pprint.pprint(AST.__json__())
return

elif argv[2] == "compile" and len(sys.argv) == 4:
elif argv[2] == "compile" and len(argv) == 4:
filename = argv[3]
compile_testfile(testprogs_dir, filename)
return
Expand Down Expand Up @@ -343,24 +378,30 @@ def compile_option(argv):
compile_file(filename, result_filename)


def main():
if len(sys.argv) < 2:
def main(argv):
global profile
if len(argv) < 2:
raise BadArguments()

if sys.argv[1] == "--test":
handle_tests(sys.argv)
# If a profile is pulled defined, use that
if argv[1] == "--profile" and len(argv)> 2:
profile = argv[2]
argv[1:3] = []

if argv[1] == "--test":
handle_tests(argv)

elif sys.argv[1] == "parse" and len(sys.argv) == 3:
parse_option(sys.argv)
elif argv[1] == "parse" and len(argv) == 3:
parse_option(argv)

elif sys.argv[1] == "analyse" and len(sys.argv) == 3:
analyse_option(sys.argv)
elif argv[1] == "analyse" and len(argv) == 3:
analyse_option(argv)

elif sys.argv[1] == "codegen" and len(sys.argv) == 3 or len(sys.argv) == 4:
codegen_option(sys.argv)
elif argv[1] == "codegen" and len(argv) == 3 or len(argv) == 4:
codegen_option(argv)

elif sys.argv[1] == "compile" and len(sys.argv) == 3 or len(sys.argv) == 4:
compile_option(sys.argv)
elif argv[1] == "compile" and len(argv) == 3 or len(argv) == 4:
compile_option(argv)

else:
raise BadArguments()
Expand All @@ -382,7 +423,7 @@ def show_help():

if __name__ == "__main__":
try:
main()
main(argv = sys.argv[:])
except BadArguments:
show_help()

Loading

0 comments on commit 0e41f05

Please sign in to comment.