Compiling the C++ VM

92 views
Skip to first unread message

Antal Szabó

unread,
Oct 28, 2012, 5:51:05 PM10/28/12
to magpi...@googlegroups.com
Hi!

How can I compile the C++ magpie VM?
Or is it not functional yet? I would like to try it.

BTW, I like the design of magpie a lot, although I woul like if it would be compiled :)

Bob Nystrom

unread,
Oct 29, 2012, 10:09:52 AM10/29/12
to magpi...@googlegroups.com
On Sun, Oct 28, 2012 at 2:51 PM, Antal Szabó <szabo.a...@gmail.com> wrote:
Hi!

How can I compile the C++ magpie VM?

Great question. I should write some docs on that. :)

The C++ VM generally uses gyp to generate project files / makefiles for your OS. However, I'm in the process of moving to OS X Mountain Lion my machine so right now there's a hand-maintained xcodeproject in the repo. If you're on Mountain Lion, just open that and build and you should be good to go. It builds into build/.

If you're on Windows or Linux:

1. Download gyp. Magpie uses that to generate project files / makefiles for your OS. I think I usually just the clone the repo from here: https://github.com/martine/gyp.
2. Run gyp from within the root directory of the magpie repo:

$ cd path/to/magpie
$ path/to/gyp/gyp --depth=1

That should create a Makefile, Visual Studio solution that you can use. Let me know if you run into any problems. :)

Or is it not functional yet? I would like to try it.

It's getting there, but there's still a long ways to go. The test/ directory has all of the tests that pass on the VM, so that gives you an idea of its capabilities.
 

BTW, I like the design of magpie a lot, although I woul like if it would be compiled :)

Thanks! I really like having a VM that doesn't require ahead-of-time compilation. It makes it feel more like a quick scripting language to me.

However, I have thought about also having some ahead-of-time compilation. The VM itself uses bytecode internally, so one option would be compile to bytecode and then having a runtime that can handle that but doesn't include the parser, compiler, etc.

It's not a high priority right now, but it could be fun.

Cheers!

- bob

Szabó Antal

unread,
Oct 29, 2012, 6:23:42 PM10/29/12
to magpi...@googlegroups.com
Hi!

Thanks for the help!

I made some changes, and now it works perfectly on Windows!
I made a pull request, so you can review the changes.

I also opened a new issue, which I found while compiling magpie, you
should take a look.


Antal Szabó

Bob Nystrom

unread,
Oct 30, 2012, 10:12:42 AM10/30/12
to magpi...@googlegroups.com
On Mon, Oct 29, 2012 at 3:23 PM, Szabó Antal <szabo.a...@gmail.com> wrote:
Hi!

Thanks for the help!

I made some changes, and now it works perfectly on Windows!

Awesome, this is great to hear.
 
I made a pull request, so you can review the changes.

Done. Nice code!
 

I also opened a new issue, which I found while compiling magpie, you should take a look.

Good catch. I had forgotten that I didn't pull all of the support for "else" in match expressions over from the Java interpreter. It's fully supported now. Thanks for noticing this.

Cheers!

- bob

Paul Woolcock

unread,
Jan 9, 2013, 9:22:57 PM1/9/13
to magpi...@googlegroups.com
Hello! Sorry to revive this thread, but I'm seem to be missing something.  I have tried compiling the C++ VM on multiple different linuxes (linuces?), and every time, g++ gets stuck on ExprCompiler.cpp.  It looks like every method that takes a `magpie::gc<magpie::Expr>` parameter is causing this error:

    error: cannot allocate an object of abstract type 'magpie::Expr'
    In file included from ../src/Syntax/Ast.h:223:0,
                                 ../src/VM/Method.h:4,
                                 ../src/Compiler/ExprCompiler.cpp:2:
    ../src/Syntax/Ast.generated.h:94:7: note:    because the following virtual functions are pure within 'magpie::Expr':

This goes on and on for pretty much every single method that takes a gc<Expr>.  My C++ is a little rusty, but this seems like an odd error for *just* me to be getting...is there a compiler flag I need to turn on or something?  Does anyone else see this?

Bob Nystrom

unread,
Jan 9, 2013, 11:48:50 PM1/9/13
to magpi...@googlegroups.com
On Wed, Jan 9, 2013 at 6:22 PM, Paul Woolcock <pwoo...@gmail.com> wrote:
Hello! Sorry to revive this thread, but I'm seem to be missing something.  I have tried compiling the C++ VM on multiple different linuxes (linuces?), and every time, g++ gets stuck on ExprCompiler.cpp.  It looks like every method that takes a `magpie::gc<magpie::Expr>` parameter is causing this error:

    error: cannot allocate an object of abstract type 'magpie::Expr'
    In file included from ../src/Syntax/Ast.h:223:0,
                                 ../src/VM/Method.h:4,
                                 ../src/Compiler/ExprCompiler.cpp:2:
    ../src/Syntax/Ast.generated.h:94:7: note:    because the following virtual functions are pure within 'magpie::Expr':

This goes on and on for pretty much every single method that takes a gc<Expr>.

Strange! Does it say which functions are missing? Feel free to throw some more error output spew here.
 
  My C++ is a little rusty, but this seems like an odd error for *just* me to be getting...

Well, the set of people on Earth who've tried to build the Magpie VM at this point is probably pretty small, so this could very well mean 50% of all people who tried it are running into this issue. :)
 
is there a compiler flag I need to turn on or something?  Does anyone else see this?

Not that I'm aware of, but I haven't personally had a chance to try the Linux build yet (I'm on Mac). In theory, thanks to gyp, it should Just Work (TM), but gyp is a little... uh... odd sometimes.

For what it's worth, I'm doing a bunch of hacking on the gyp files right now (I'm integrating libuv into Magpie) so that may or may not affect this when that lands.

- bob

Paul Woolcock

unread,
Jan 10, 2013, 7:29:30 AM1/10/13
to magpi...@googlegroups.com
Ok, you asked for it :)

~/code/magpie/1$ make
  CXX(target) out/Debug/obj.target/magpie/../src/Base/MagpieString.o
  CXX(target) out/Debug/obj.target/magpie/../src/Compiler/Compiler.o
  CXX(target) out/Debug/obj.target/magpie/../src/Compiler/ExprCompiler.o
../src/Compiler/ExprCompiler.cpp: In member function ‘void magpie::ExprCompiler::compile(magpie::Module*, int, magpie::gc<magp
ie::Pattern>, magpie::gc<magpie::Pattern>, magpie::gc<magpie::Pattern>, magpie::gc<magpie::Expr>)’:
../src/Compiler/ExprCompiler.cpp:128:48: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   because the following virtual functions are pure within ‘magpie::Expr’:
../src/Syntax/Ast.generated.h:104:16: note:     virtual void magpie::Expr::accept(magpie::ExprVisitor&, int)
../src/Compiler/ExprCompiler.cpp: In member function ‘void magpie::ExprCompiler::compileParamField(magpie::PatternCompiler&, m
agpie::gc<magpie::Pattern>, int)’:
../src/Compiler/ExprCompiler.cpp:174:67: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘virtual void magpie::ExprCompiler::visit(magpie::AsyncExpr&, int)’:
../src/Compiler/ExprCompiler.cpp:245:38: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘virtual void magpie::ExprCompiler::visit(magpie::RecordLValue&, int)’:
../src/Compiler/ExprCompiler.cpp:673:33: error: cannot allocate an object of abstract type ‘magpie::Expr’
In file included from ../src/Syntax/Ast.h:223:0,                                                                      [35/345]
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘void magpie::ExprCompiler::compileAssignment(magpie::gc<magpie::SourcePo
s>, magpie::gc<magpie::ResolvedName>, int, bool)’:
../src/Compiler/ExprCompiler.cpp:759:53: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp:763:76: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp:768:76: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘void magpie::ExprCompiler::compileClosures(magpie::gc<magpie::SourcePos>
, magpie::ResolvedProcedure&)’:
../src/Compiler/ExprCompiler.cpp:788:41: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp:793:45: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘virtual void magpie::PatternCompiler::visit(magpie::RecordPattern&, int)
’:
../src/Compiler/ExprCompiler.cpp:958:79: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp:964:78: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘virtual void magpie::PatternCompiler::visit(magpie::TypePattern&, int)’:
../src/Compiler/ExprCompiler.cpp:981:68: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘virtual void magpie::PatternCompiler::visit(magpie::ValuePattern&, int)’:
../src/Compiler/ExprCompiler.cpp:994:71: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
../src/Compiler/ExprCompiler.cpp: In member function ‘void magpie::PatternCompiler::writeTest(const magpie::Pattern&, int)’:
../src/Compiler/ExprCompiler.cpp:1022:55: error: cannot allocate an object of abstract type ‘magpie::Expr’

In file included from ../src/Syntax/Ast.h:223:0,
                 from ../src/VM/Method.h:4,
                 from ../src/Compiler/ExprCompiler.cpp:2:
../src/Syntax/Ast.generated.h:94:7: note:   since type ‘magpie::Expr’ has pure virtual functions
make: *** [out/Debug/obj.target/magpie/../src/Compiler/ExprCompiler.o] Error 1

Paul Woolcock

unread,
Jan 10, 2013, 9:34:15 AM1/10/13
to magpi...@googlegroups.com
By the way, it looks like the commit that "broke" ExprCompiler.cpp on linux was

    cd61db31f62cbf67caa692aa31f378567ac038d8 "Slightly better stack trace labels."

Magpie still doesn't compile for me before that commit, but at least ExprCompiler.cpp does.

Szabó Antal

unread,
Jan 10, 2013, 9:48:37 AM1/10/13
to magpi...@googlegroups.com
Does it compile for you after I added the linux support?

(for example at c964ecd481dae530c47d56716f47455187ee10fd)

2013/1/10 Paul Woolcock <pwoo...@gmail.com>:

Paul Woolcock

unread,
Jan 10, 2013, 9:53:39 AM1/10/13
to Magpie
Yes, it compiles there. I'm currently bisecting to find where it
broke.

On Jan 10, 9:48 am, Szabó Antal <szabo.antal...@gmail.com> wrote:
> Does it compile for you after I added the linux support?
>
> (for example at c964ecd481dae530c47d56716f47455187ee10fd)
>
> 2013/1/10 Paul Woolcock <pwool...@gmail.com>:

Paul Woolcock

unread,
Jan 10, 2013, 10:30:55 AM1/10/13
to Magpie
It looks like it first broke at

c5b8100c22dca14be485cbb13fc157c7db492d7c "Move file loading into
VM.",

and it looks like it just needs the following change:

... in src/Platform/Environment_linux.cpp

gc<String> getCoreLibPath()
{
- char* relativePath[PATH_MAX];
+ char relativePath[PATH_MAX];

Paul Woolcock

unread,
Jan 10, 2013, 10:38:45 AM1/10/13
to Magpie
Of course, that doesn't fix the original problem I was having.

Paul Woolcock

unread,
Jan 10, 2013, 11:54:46 AM1/10/13
to Magpie
Ok, I sent a pull request that fixes *almost* all the problems with
building on linux. Still working on the ExprCompiler.cpp fix.

Bob Nystrom

unread,
Jan 10, 2013, 11:53:22 PM1/10/13
to magpi...@googlegroups.com
On Thu, Jan 10, 2013 at 8:54 AM, Paul Woolcock <pwoo...@gmail.com> wrote:
Ok, I sent a pull request that fixes *almost* all the problems with
building on linux.  Still working on the ExprCompiler.cpp fix.

Ah, I know exactly what's going on here. Give me a few minutes and I'll push a fix. Stupid implicit conversion constructors. <sigh>

- bob

Bob Nystrom

unread,
Jan 11, 2013, 12:15:15 AM1/11/13
to magpi...@googlegroups.com
For those following the thread, but not github, this is fixed now. :)

- bob
Reply all
Reply to author
Forward
0 new messages