Giter VIP home page Giter VIP logo

cardinal's Introduction

Cardinal - Ruby for the Parrot VM

Cardinal is a Ruby compiler for Parrot Virtual Machine.

The parser is fairly complete. The standard library exists, but still needs filling out.

Cardinal’s parser is very very slow. You can precompile to PIR with –target=pir and run the result with Parrot directly to skip the parsing phase. (You may need cardinal.pbc in the same directory for this to work.)

Getting Started with Cardinal

Downloding Cardinal

Get a copy of Cardinal (read only):

git clone git://github.com/parrot/cardinal.git

Build with Rake

After obtaining the source code, run:

rake cardinal

To run some tests run:

rake test:all
rake test:[name]

You might get all rake tasks with:

rake -T

Build with Parrot

You can also build cardinal with Winxed (which comes with Parrot)

winxed setup.winxed build

Testing:

winxed setup.winxed test

Note that some of them will probably fail, as Cardinal is not yet complete

If you want to install Cardinal to your Parrot install directory, run:

winxed setup.winxed install

The compiler will be available as parrot-cardinal

Contributing

Follow the documentations to start developing cardinal.

Latest Parrot Documentation

Parrot Baby Steps

You are also invited to #parrot on irc.parrot.org

cardinal's People

Contributors

allisonrandal avatar ambs avatar bacek avatar bschmalhofer avatar bubaflub avatar cardinal avatar chromatic avatar coke avatar dtm avatar fperrad avatar hackbinary avatar jkeenan avatar joeri avatar kjs avatar leto avatar moritz avatar notfound avatar nunorc avatar particle avatar paultcochrane avatar perlpilot avatar petdance avatar pmichaud avatar rurban avatar tene avatar tewk avatar treed avatar whiteknight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cardinal's Issues

parse error with unary operators +-*/%

our parser does not allows something weird but ruby does:

------1

  •     -1
    

actually, ruby op are works different ways in some cases.
in this case it will call method -@ of 1(Integer).

but our parser cannot handle these weird case.
because it would not call the method or do something near behavior.

we need to try proto prefix or some other way.

Doesn't compile

I get this:

~/Repositories/cardinal (git: master) ☃〠 parrot setup.pir
/usr/local/Cellar/parrot/2.9.1/bin/parrot /usr/local/Cellar/parrot/2.9.1/lib/library/PGE/Perl6Grammar.pbc --output=src/gen_grammar.pir  src/parser/grammar.pg
/usr/local/Cellar/parrot/2.9.1/bin/parrot-nqp --target=pir --output=src/gen_actions.pir  src/parser/actions.pm
creat src/gen_builtins.pir
/usr/local/Cellar/parrot/2.9.1/bin/parrot -o cardinal.pbc cardinal.pir
/usr/local/Cellar/parrot/2.9.1/bin/pbc_to_exe cardinal.pbc --install && strip installable_cardinal
/usr/bin/cc -o cardinal.o -I/usr/local/Cellar/parrot/2.9.1/include -pipe -fno-common  -DHASATTRIBUTE_CONST  -DHASATTRIBUTE_DEPRECATED  -DHASATTRIBUTE_MALLOC  -DHASATTRIBUTE_NONNULL  -DHASATTRIBUTE_NORETURN  -DHASATTRIBUTE_PURE  -DHASATTRIBUTE_UNUSED  -DHASATTRIBUTE_WARN_UNUSED_RESULT  -I /usr/local/Cellar/icu4c/4.4.1/include  -c cardinal.c
Compiled: cardinal.o
c++ -o installable_cardinal cardinal.o /usr/local/Cellar/parrot/2.9.1/lib/parrot_config.o -L/usr/local/Cellar/parrot/2.9.1/lib -L/usr/local/Cellar/parrot/2.9.1/lib -lparrot   -undefined dynamic_lookup -lm -lutil -lgmp -lreadline -headerpad_max_install_names  -lpthread -lm   -L/usr/local/Cellar/icu4c/4.4.1/lib  -licuuc -licudata  -lpthread -lm   
Linked: installable_cardinal
/usr/local/Cellar/parrot/2.9.1/bin/parrot cardinal.pbc --target=pir --output=Test.pir Test.rb
Method 'stdout_handle' not found for invocant of class 'ParrotInterpreter'
current instr.: 'onload' pc 12254 (src/classes/Array.pir:51)
called from Sub 'cardinal;cardinal;Compiler;main' pc 78754 (src/gen_grammar.pir:5346)
... call repeated 1 times
exit status: 256
command: /usr/local/Cellar/parrot/2.9.1/bin/parrot cardinal.pbc --target=pir --output=Test.pir Test.rb

current instr.: 'setup' pc 883 (runtime/parrot/library/distutils.pir:387)

Trying with parrot 2.9.1, as you can see and on OSX 10.6.

Parsing Error: negative number in parentheses like "(-1)"

see log:

$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ ruby -e "(-1)"
$ ruby -e "puts (-1).class"
Fixnum

$ ./cardinal -e "(-1)"
unterminated statement at line 1, near ")"

current instr.: 'cardinal;PGE;Util;die' pc 80 (runtime/parrot/library/PGE/Util.pir:67)
called from Sub 'cardinal;cardinal;Grammar;stmts' pc 15177 (src/classes/Array.pir:777)
called from Sub 'cardinal;cardinal;Grammar;comp_stmt' pc 13769 (src/classes/Array.pir:249)
called from Sub 'cardinal;cardinal;Grammar;pcomp_stmt' pc 38698 (src/builtins/globals.pir:9619)
called from Sub 'cardinal;cardinal;Grammar;basic_primary' pc 37165 (src/classes/FileStat.pir:9056)
called from Sub 'cardinal;cardinal;Grammar;indexed_assignment' pc 22668 (src/classes/Array.pir:3607)
called from Sub 'cardinal;cardinal;Grammar;basic_stmt' pc 17293 (src/classes/Array.pir:1577)
called from Sub 'cardinal;cardinal;Grammar;stmt' pc 19096 (src/classes/Array.pir:2227)
called from Sub 'cardinal;cardinal;Grammar;stmts' pc 14288 (src/classes/Array.pir:448)
called from Sub 'cardinal;cardinal;Grammar;comp_stmt' pc 13769 (src/classes/Array.pir:249)
called from Sub 'cardinal;cardinal;Grammar;TOP' pc 13424 (src/classes/Array.pir:115)
called from Sub 'cardinal;PCT;HLLCompiler;parse' pc 826 (compilers/pct/src/PCT/HLLCompiler.pir:463)
called from Sub 'cardinal;PCT;HLLCompiler;compile' pc 464 (compilers/pct/src/PCT/HLLCompiler.pir:331)
called from Sub 'cardinal;PCT;HLLCompiler;eval' pc 1081 (compilers/pct/src/PCT/HLLCompiler.pir:582)
called from Sub 'cardinal;PCT;HLLCompiler;command_line' pc 1759 (compilers/pct/src/PCT/HLLCompiler.pir:884)
called from Sub 'cardinal;cardinal;Compiler;main' pc 78838 (src/gen_grammar.pir:5369)

Cardinal crashes on "require Test"

Turns out a lex_lookup may return something that triggers a NULL PMC Access when trying to check its value. Here's a piece of code I added to actions.pm

src/gen_diff --git a/src/parser/actions.pm b/src/parser/actions.pm
index cd49492..f706b95 100644
--- a/src/parser/actions.pm
+++ b/src/parser/actions.pm
@@ -905,6 +905,9 @@ sub is_a_sub($name) {
         }
     }
     my $lex := lex_lookup($name);
+    print("is_a_sub('"); print($name); print("'), here we crash\n");
+    if $lex { print("lex ok\n"); }
+    print("never happens\n");
     if $lex && ~lookup_class($lex) eq 'Sub' { return 1; }
     return 0;
 }

Running ./installable_cardinal t/02-functions.t results in:

is_a_sub('Test'), here we crash
Null PMC access in get_bool()
current instr.: 'cardinal;cardinal;Grammar;Actions;is_a_sub' pc 64437 (src/gen_grammar.pir:288)
called from Sub 'cardinal;cardinal;Grammar;Actions;variable' pc 68543 (src/gen_grammar.pir:1720)
called from Sub 'cardinal;cardinal;Grammar;variable' pc 34593 (src/classes/File.pir:8150)
called from Sub 'cardinal;cardinal;Grammar;basic_primary' pc 36938 (src/classes/FileStat.pir:9021)
called from Sub 'cardinal;cardinal;Grammar;primary' pc 37455 (src/classes/Dir.pir:9206)
called from Sub 'cardinal;PGE;OPTable;parse' pc 1940 (compilers/pge/PGE/OPTable.pir:566)
called from Sub 'cardinal;cardinal;Grammar;args' pc 35975 (src/classes/FileStat.pir:8665)
called from Sub 'cardinal;cardinal;Grammar;call_args' pc 29791 (src/classes/Kernel.pir:6346)
called from Sub 'cardinal;cardinal;Grammar;post_primary_expr' pc 37995 (src/classes/Dir.pir:9406)
called from Sub 'cardinal;cardinal;Grammar;primary' pc 37567 (src/classes/Dir.pir:9246)
called from Sub 'cardinal;PGE;OPTable;parse' pc 1940 (compilers/pge/PGE/OPTable.pir:566)
called from Sub 'cardinal;cardinal;Grammar;expr' pc 20368 (src/classes/Array.pir:2777)
called from Sub 'cardinal;cardinal;Grammar;basic_stmt' pc 17591 (src/classes/Array.pir:1717)
called from Sub 'cardinal;cardinal;Grammar;stmt' pc 18974 (src/classes/Array.pir:2227)
called from Sub 'cardinal;cardinal;Grammar;stmts' pc 14166 (src/classes/Array.pir:448)
called from Sub 'cardinal;cardinal;Grammar;comp_stmt' pc 13647 (src/classes/Array.pir:249)
called from Sub 'cardinal;cardinal;Grammar;TOP' pc 13302 (src/classes/Array.pir:115)
called from Sub 'cardinal;PCT;HLLCompiler;parse' pc 826 (compilers/pct/src/PCT/HLLCompiler.pir:463)
called from Sub 'cardinal;PCT;HLLCompiler;compile' pc 464 (compilers/pct/src/PCT/HLLCompiler.pir:331)
called from Sub 'cardinal;PCT;HLLCompiler;eval' pc 1081 (compilers/pct/src/PCT/HLLCompiler.pir:582)
called from Sub 'cardinal;PCT;HLLCompiler;evalfiles' pc 1501 (compilers/pct/src/PCT/HLLCompiler.pir:764)
called from Sub 'cardinal;PCT;HLLCompiler;command_line' pc 1712 (compilers/pct/src/PCT/HLLCompiler.pir:873)
called from Sub 'cardinal;cardinal;Compiler;main' pc 78706 (src/gen_grammar.pir:5354)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.