Skip to content

Commit

Permalink
Rebranding
Browse files Browse the repository at this point in the history
  • Loading branch information
perimosocordiae committed Jan 5, 2011
1 parent 72b0fe8 commit 92d03b9
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 41 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

# CJSH #
# Plumbum #

Watch this space for pertinent info.
An experimental, pipe-oriented programming language, designed to fill the
gap between classic Unix shell one-liners and powerful general-purpose
programming languages.

## Dependencies ##
* Some flavor of Linux
Expand All @@ -10,11 +12,11 @@ Watch this space for pertinent info.
* PyParsing

## Usage ##
* Start up a REPL: `./cjsh`
* Eval one line: `./cjsh -e '"hello world" | println'`
* Run a program: `./cjsh foo.cj`
* Compile a program: `./cjsh -c foo.cjc foo.cj`
* Run a compiled program: `./cjsh foo.cjc`
* Start up a REPL: `./pb`
* Eval one line: `./pb -e '"hello world" | println'`
* Run a program: `./pb foo.cj`
* Compile a program: `./pb -c foo.cjc foo.cj`
* Run a compiled program: `./pb foo.cjc`

## Code Examples ##
Some 'real' code examples:
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ compile-time optimizations

even more test cases
scan/split
'prelude'-style stdlib in CJSH
'prelude'-style stdlib in Plumbum
1 change: 0 additions & 1 deletion cjsh

This file was deleted.

File renamed without changes.
Binary file added lib/ast_plumbum.pyc
Binary file not shown.
Binary file added lib/optimizer.pyc
Binary file not shown.
Binary file added lib/parser.pyc
Binary file not shown.
File renamed without changes.
26 changes: 13 additions & 13 deletions lib/cjsh.py → lib/plumbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@
from sys import argv,exit,exc_info
from itertools import chain
from optparse import OptionParser
from ast_cjsh import Program
from ast_plumbum import Program
from stdlib import stdlib

if __name__ == '__main__':
op = OptionParser('Usage: %prog [options] file.cj',version=VERSION)
op.add_option('-e','--eval',metavar='CODE',help='Run CODE with cjsh')
op.add_option('-e','--eval',metavar='CODE',help='Run CODE with plumbum')
op.add_option('-c','--compile',metavar='FILE',help='Compile to FILE')
op.add_option('-d','--debug', action='store_true', default=False,
help='Turn debug flags on')
(options, args) = op.parse_args()

if options.eval:
assert len(args) == 0, 'Additional args are meaningless with -e'
cjsh = Program(stdlib)
cjsh.parse_line(argv[2])
cjsh.run()
plumbum = Program(stdlib)
plumbum.parse_line(argv[2])
plumbum.run()
elif options.compile:
assert len(args) == 1, 'Need exactly 1 source file to compile'
cjsh = Program(stdlib)
cjsh.parse_file(argv[3])
cjsh.save_compiled(argv[2])
plumbum = Program(stdlib)
plumbum.parse_file(argv[3])
plumbum.save_compiled(argv[2])
elif len(args) == 0:
from repl import Repl
debugstr = ' (debug)' if options.debug else ''
welcome = 'Welcome to CJSH v%s%s'%(VERSION,debugstr)
welcome = 'Welcome to Plumbum v%s%s'%(VERSION,debugstr)
try: Repl(options.debug).cmdloop(welcome)
except KeyboardInterrupt: print() # move past the prompt
elif len(args) > 1:
op.error('Only one source file at a time')
else: #TODO: maybe use a flag to specify, or look at filename
cjsh = Program(stdlib)
try: cjsh.parse_file(args[0])
except: cjsh.load_compiled(args[0])
cjsh.run()
plumbum = Program(stdlib)
try: plumbum.parse_file(args[0])
except: plumbum.load_compiled(args[0])
plumbum.run()

16 changes: 8 additions & 8 deletions lib/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import cmd,imp
from glob import glob
from itertools import chain
from ast_cjsh import REPLProgram
from ast_plumbum import REPLProgram
from traceback import print_exc
import stdlib

class Repl(cmd.Cmd):
def __init__(self,debug=False):
super().__init__()
self.cjsh = REPLProgram(stdlib.stdlib)
self.plumbum = REPLProgram(stdlib.stdlib)
self.debug = debug
self.prompt = '>> '
if not debug: # use a terser exception printer
Expand All @@ -19,17 +19,17 @@ def do_reload(self,line):
'Reload the stdlib module'
try:
imp.reload(stdlib)
self.cjsh.refresh_stdlib(stdlib.stdlib)
self.plumbum.refresh_stdlib(stdlib.stdlib)
except:
print('Error reloading stdlib:')
print_exc()
else:
print('Success: stdlib reloaded')

def do_run(self,line):
'Run a CJSH source file'
self.cjsh.parse_file(line.strip())
self.cjsh.run(self.debug)
'Run a Plumbum source file'
self.plumbum.parse_file(line.strip())
self.plumbum.run(self.debug)

def complete_run(self,text,line,beg,end):
return glob(text+'*')
Expand All @@ -40,13 +40,13 @@ def do_EOF(self,line):

def default(self,line):
try:
self.cjsh.parse_line(line)
self.plumbum.parse_line(line)
except:
print("Error parsing:",line)
print_exc()
return
try:
res = self.cjsh.run(self.debug)
res = self.plumbum.run(self.debug)
if not res: return
if hasattr(res,'__iter__'): print(list(res))
else: print(res)
Expand Down
Binary file added lib/repl.pyc
Binary file not shown.
14 changes: 7 additions & 7 deletions lib/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def shellexec(seq,cmd):
line = ''
else: line += c

def cjsh_print(seq,*args):
def pb_print(seq,*args):
sep = re.sub(r'\\n',"\n",args[0]) if len(args) > 0 else '' #hax
for x in seq:
print(x,sep='',end=sep)
def cjsh_println(seq,*args):
cjsh_print(seq,*args)
def pb_println(seq,*args):
pb_print(seq,*args)
print()

def flatten(seq,*args):
Expand Down Expand Up @@ -79,7 +79,7 @@ def lazy_uniq(seq,*_):
yield x
last = x

def cjsh_map(seq,*args):
def pb_map(seq,*args):
assert len(args) == 1, "can only map single fns, for now"
assert args[0] in stdlib, "can only map stdlib fns, for now."
return (map(stdlib[args[0]],x) for x in seq)
Expand All @@ -104,7 +104,7 @@ def join(seq,*args):
'flatten': flatten,
'select': seq_select,
'luniq': lazy_uniq,
'map': cjsh_map,
'map': pb_map,
'join': join,
# inlines
'inc': 'lambda seq: (int(x)+1 for x in seq)',
Expand All @@ -114,8 +114,8 @@ def join(seq,*args):
'range': 'lambda _,*args: range(*map(int,args))',
'compact': 'lambda seq: (x for x in seq if x)',
# non-lazy
'print': cjsh_print,
'println': cjsh_println,
'print': pb_print,
'println': pb_println,
# inlines
'sort': 'sorted',
'uniq': 'set',
Expand Down
Binary file added lib/stdlib.pyc
Binary file not shown.
Binary file added lib/unparse.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions pb
8 changes: 4 additions & 4 deletions test/compilation.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
set -e
PROGRAM='[1,5,3,7,2,4,2,1] | sort | println ","'
dashE=`../cjsh -e "$PROGRAM"`
echo $PROGRAM | ../cjsh -c ctest.cjc -
comp=`../cjsh ctest.cjc`
dashE=`../pb -e "$PROGRAM"`
echo $PROGRAM | ../pb -c ctest.pbc -
comp=`../pb ctest.pbc`
if [ $comp != $dashE ]; then
echo "Compilation test fail"
echo $dashE
echo $comp
else
echo "Compilation test success"
fi
rm -f ctest.cjc
rm -f ctest.pbc
File renamed without changes.

0 comments on commit 92d03b9

Please sign in to comment.