A Compiler for the Popr Language
Clone or download
Latest commit db45978 Nov 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
afl renamed and simplified commands Jun 16, 2017
cgen set type when allocating a new parameter Nov 19, 2018
css fix web terminal Jan 23, 2018
linenoise @ 4a961c0 update Linenoise Nov 3, 2018
lldb move alt_set into context Oct 13, 2018
org update issues.org Nov 18, 2018
patches added a Coccinelle patch that was used May 3, 2017
scripts dark color scheme for graphs Aug 21, 2018
startle set type when allocating a new parameter Nov 19, 2018
test_output add a simple C FFI Nov 20, 2018
tex added typing rules Aug 26, 2017
.gdbinit added my .gdbinit Sep 14, 2013
.gitignore add save/diff-trees commands to lldb Oct 1, 2018
.gitmodules added linenoise for line editing, a few bug fixes, cleaned up measure… May 5, 2013
.lldbinit added commands to lldb Sep 4, 2016
.travis.yml add .travis.yml May 19, 2017
.ycm_extra_conf.py fixed some warnings and ycmd configuration Mar 23, 2015
LICENSE updated license info Oct 7, 2012
Makefile integrate cgen/primitives.c into build system Nov 11, 2018
README.md add web version link to README.md Jul 25, 2017
builders.h add auto-generated builders Jun 14, 2018
byte_compile.c improved last_use_analysis (was keep_analysis) Nov 16, 2018
cells.c make FLAG macros safer Nov 16, 2018
cgen.c add a simple C FFI Nov 20, 2018
eval.c re-enable watch during get_arity() Nov 18, 2018
eval.html fix eval.js Oct 2, 2018
lex.c update copyright notices Jun 19, 2018
lib.ppr prevent `otherwise` from forcing quotes Oct 30, 2018
lib_tests.txt prevent `otherwise` from forcing quotes Oct 30, 2018
list.c make FLAG macros safer Nov 16, 2018
log_tree.c avoid error loops Nov 4, 2018
macros.h make FLAG macros safer Nov 16, 2018
module.c clean up allocation of values Nov 9, 2018
package.json upgrade jquery.terminal, use yarn Jun 11, 2017
parse.c add a simple C FFI Nov 20, 2018
popr update scripts Nov 18, 2018
popr-mode.el work on emacs mode and watch script May 31, 2017
poprc add typed suffixes to cgen Nov 19, 2018
poprc-mode.el added poprc-mode.el Mar 25, 2015
primitive.c add a simple C FFI Nov 20, 2018
print.c add typed suffixes to cgen Nov 19, 2018
rt.c make FLAG macros safer Nov 16, 2018
rt_types.h add a simple C FFI Nov 20, 2018
special.c add a simple C FFI Nov 20, 2018
staging.ppr move length and some tests out of staging Jun 29, 2017
tags.c add a way to tag a pointer with a string Sep 13, 2018
tests.ppr add a simple C FFI Nov 20, 2018
tests.txt work on cgen, tests.hello works Nov 11, 2018
tok.c add string literals Oct 18, 2018
trace.c add a simple C FFI Nov 20, 2018
user_func.c improved last_use_analysis (was keep_analysis) Nov 16, 2018
yarn.lock fix web terminal Jan 23, 2018

README.md

Popr Compiler Build Status

This project is to implement a compiler for the Popr (previously Peg) language. The language has changed somewhat to support efficient compilation and type checking.

Please see this presentation for more information.

The following expressions can be evaluated online using the PoprC web version.

Here is a quick description of the language as it is currently. Lines beginning with ":" are user input, the following lines are output from the interpreter.

: 1 2 +
  3

Popr is a post-fix concatenative language. + is an operator that takes two integers and returns one. There are several similar operators, with the same meaning as in C: -, *, <, <=, ==, >, >=. Booleans are represented as the symbols True and False.

: 1 2 | 3 +
  4
  5
: 2 5 | dup 3 >= !
  5

| creates alternative execution paths. ! takes two values. If the second argument is False, the it fails, otherwise the first value is returned. These primitives provide a more general mechanism than if/else, similar to speculative execution, or Prolog inference.

: [ 1 2 + 3 4 + ] popr
  [ 1 2 + ] 7
: 1 [ 2 + ] pushl
  [ 1 2 + ]
: 1 [ 2 + ] pushl popr
  [] 3

[ ... ] denotes a quote, which can be used for constructing functions or for aggregating values. popr pops the rightmost element and forces evaluation. pushl takes its first argument and pushes it onto the left of the fragment. The two primitives can be combined to evaluate a fragment. Notice that Popr is lazy, and only reduces functions in quotes when required.

: 1 2 | dup
  1 1
  2 2
: 1 2 swap
  2 1
: 1 2 drop
  1

Some other primitives. dup duplicates a value; notice how it respects the constraints introduced by alternatives. swap swaps two values. drop drops a value.

 : 1 2 [3+] dip11
   4 2
 : 1 2 [3] dip12
   1 3 2
 : 1 3 2 [+] dip21
   4 2
 : [1] 2 pushr
   [ 1 2 ]

Some other functions.

License

The license for the Popr Compiler is GPL3. See LICENSE for more information.