jckarter / clay

The Clay programming language
http://claylabs.com/clay
Other
404 stars 34 forks source link

Repl support: statements, imports, variables #416

Closed galchinsky closed 12 years ago

galchinsky commented 12 years ago

Yet another try. Not much changes, but I merging becomes harder and harder, so please pull.

It seems to work with all except variant instances. Instances are needed to normal work of exceptions. Now it isn't work, so things like printer module should be load before repl starting. If you need to debug an existing module with REPL, it won't be a problem.

$ cat pr.clay
import printer.(println);
$cat one.clay
var x = 5;
addFive(y) = x + y;
$./clay -repl pr.clay
clay>record zar[T](a:T, b:T);
clay>println(zar[Int](1,2));
zar[Int32](1, 2)
clay>import one.(addFive);
clay>println(addFive(5));
10

To do list:

  1. Add prelude.repl
  2. add :rebuild command to repl that will compile all loaded things from scratch, so variant instances should work. Optional feature - all global variables workspace should be stored and loaded after rebuild. An alternative may be another representation of variants.
  3. Add autoprinting if the line is an expression, not a statement
  4. libedit support or something like that (what about windows users?)
  5. repl tests
stepancheg commented 12 years ago

@galchinsky it is sad that test is not in your to do list.

galchinsky commented 12 years ago

It's not a problem to add. I'm not familiar with the test system though

galchinsky commented 12 years ago

Is it ok now?

galchinsky commented 12 years ago

fixed

jckarter commented 12 years ago

Cool. I'll test it locally. As @stepancheg said, it'd be nice to have some automated testing too. I don't know how well-suited runtests.py is to testing the REPL; it may be better to write some standalone expect scripts instead.

stepancheg commented 12 years ago

@jckarter @galchinsky program loaded with expect will be hard to debug, I would write another clay-repl-test program written in pure C++ (in addtion to clay and claydoc binaries).

galchinsky commented 12 years ago

Shouldn't importedNames be a part of Module struct? loadDependent is called from repl when a new module is imported

jckarter commented 12 years ago

importedNames is redundant as part of a fully-loaded module; it's only necessary to catch and raise an error if you try to import multiple modules or symbols with the same name during load initialization, as in import foo; import bar.(a as foo);.

galchinsky commented 12 years ago

But the main module can't be named 'fully-loaded' in repl. You can always load some more. If I add a pointer to importedNames what shall I send in https://github.com/galchinsky/clay/blob/orig/compiler/src/interactive.cpp#L82 ?

jckarter commented 12 years ago

You're right. For the repl it makes sense to keep importedNames as part of the Module's state.

jckarter commented 12 years ago

OK, so importedNames has to be per-loadDependents, with a pointer passed into loadDependent. You should be able to pass an empty set in from the REPL; by that point, the publicSymbols and allSymbols maps should be populated, and redundant imports should be caught.

galchinsky commented 12 years ago

I just didnt notice the loop in loadDep. Fuu. Module-state works fine

jckarter commented 12 years ago

Great, merged. I'll file issues for any REPL bugs I find.