Wiki

Ticket #172 (new enhancement)

Opened 15 years ago

Last modified 14 years ago

Provide an interactive mode for Cobra (REPL)

Reported by: webnov8 Owned by:
Priority: minor Milestone:
Component: Cobra Compiler Version:
Keywords: Cc:

Description

REPLs are great for rapid prototyping, and learning the language. Most major languages provide one so it's only fitting that Cobra does too.

This can probably be done easier after the use of the Mono libraries are integrated.

This interactive mode will be entered when cobra is invoked without the -files option or source files.

Change History

Changed 15 years ago by Chuck

  • priority changed from medium to minor
  • milestone Cobra 0.9 deleted

I don't know about "most major languages provide one" as in "over half" but certainly many do.

Currently "cobra" prints a little bit of help to get you on your way to get more help, compile a file, etc. I think that should remain and we use "cobra -ip" or "cobra -repl" to get the ip/repl going.

This is not a 0.9 milestone.

Changed 14 years ago by lgastako

I think lack of a REPL is one of the things that has slowed down my adoption of Cobra the most... I would be happy to work on creating a workable REPL except for two things -- 1. I don't see any existing easy-to-access "eval" type of functionality in the cobra source code anywhere and 2. I don't know how much time I'll have, but I'm less worried about #2 since this ticket hasn't been touched in 17 months... so I probably won't make things worse at least.

Can you point me in the right direction for trying to build a cobra "eval" function? (Or ideally tell me where the existing one that I missed lives :))

Changed 14 years ago by hopscc

The cobra compiler itself is one - probably as close to exists currently - its just not very good at handling expressions less than a complete program (:-)

Another option would be per ticket:24 - Cobra support DLR
The info here leads you to a reimplementation of the existing Cobra AST Nodes using the .Net/C# AST equivalents. Not trivial
A better way might be to add a optional phase to the compiler post-bindings that converts the Cobra AST Nodes to ones based on .Net and drops into whatever else is needed for executing via DLR ... perhaps less non-trivial

Heres some notes I made on a Q+D console REPL early on:
REPL:

  • simple accumulate and execute cycle - create app that accumulates source code input lines till 'compile' or 'run' cmd
  • emit source lines to file (adding any needed wrapping program boilerplate)
  • run the cobra compiler on emitted file, compile file and run it...
  • support additional cmds: 'run', 'compile', 'exit', 'save', 'load', ('merge'), 'edit', 'list' 'alias'
  • app provides a simple one line editor a la readline
  • Pull out compiler tokenise/parse/AST gen/bindings layers and syntax chk/tokenise lines as entered..

(Re)animate a REPL discussion topic if want ...

Changed 14 years ago by Charles

If there were an "eval" lurking somewhere, we surely would have done the minor additional work to make the REPL. :-)

Are you looking for a REPL because you want to explore the language interactively, because you want to embed it in your application or something else? Just curious. I already understand that REPLs can be useful.

Cobra has been created purely as a compiled language, so there will be some real work involved with getting a repl going. Some thoughts:

As hopscc pointed out, a DLR back-end is one option.

Another possibility is to write a node visitor that does the interpretation. If you search CobraWorkspace/Source/Phases for "visitor" you'll find 3 examples of node visitors.

Another possibility is writing a foo.cobra file with the appropriate trappings, compiling, loading the assembly and executing. This could be a fun exercise, but may yield problems that prevent real world usage including memory consumption of assemblies and performance. You may be able to skip writing the Cobra source to disk, but not currently the assembly.

There may be other possibilities. That's off the top of my head.

Note: See TracTickets for help on using tickets.