Permalink
Browse files

Nuked it from orbit!

First pass at tearing down the whole language and rebuilding it
in terms of multimethods. The spec doesn't work and most of the
base lib is commented out, but it runs!
  • Loading branch information...
munificent committed Apr 2, 2011
1 parent b789d2f commit e509e13fd74ba252faf00288196769412cf7811c
Showing with 396 additions and 2,509 deletions.
  1. +12 −41 base/init.mag
  2. +2 −2 src/com/stuffwithstuff/magpie/NiceRepl.java
  3. +2 −2 src/com/stuffwithstuff/magpie/NiceReplCharacterReader.java
  4. +2 −2 src/com/stuffwithstuff/magpie/Repl.java
  5. +2 −2 src/com/stuffwithstuff/magpie/ReplCharacterReader.java
  6. +0 −33 src/com/stuffwithstuff/magpie/ast/CallExpr.java
  7. +8 −24 src/com/stuffwithstuff/magpie/ast/Expr.java
  8. +1 −5 src/com/stuffwithstuff/magpie/ast/ExprVisitor.java
  9. +4 −1 src/com/stuffwithstuff/magpie/ast/MessageExpr.java
  10. +10 −3 src/com/stuffwithstuff/magpie/ast/{UsingExpr.java → MethodExpr.java}
  11. +0 −29 src/com/stuffwithstuff/magpie/ast/QuotationExpr.java
  12. +0 −19 src/com/stuffwithstuff/magpie/ast/ThisExpr.java
  13. +0 −26 src/com/stuffwithstuff/magpie/ast/UnquoteExpr.java
  14. +1 −1 src/com/stuffwithstuff/magpie/interpreter/Callable.java
  15. +4 −33 src/com/stuffwithstuff/magpie/interpreter/ClassObj.java
  16. +3 −166 src/com/stuffwithstuff/magpie/interpreter/EnvironmentBuilder.java
  17. +18 −42 src/com/stuffwithstuff/magpie/interpreter/EvalContext.java
  18. +44 −55 src/com/stuffwithstuff/magpie/interpreter/ExprEvaluator.java
  19. +2 −4 src/com/stuffwithstuff/magpie/interpreter/FnObj.java
  20. +2 −2 src/com/stuffwithstuff/magpie/interpreter/Function.java
  21. +23 −191 src/com/stuffwithstuff/magpie/interpreter/Interpreter.java
  22. +0 −382 src/com/stuffwithstuff/magpie/interpreter/JavaToMagpie.java
  23. +0 −389 src/com/stuffwithstuff/magpie/interpreter/MagpieToJava.java
  24. +0 −29 src/com/stuffwithstuff/magpie/interpreter/Member.java
  25. +0 −45 src/com/stuffwithstuff/magpie/interpreter/MemberSet.java
  26. +1 −3 src/com/stuffwithstuff/magpie/interpreter/MultimethodObj.java
  27. +2 −5 src/com/stuffwithstuff/magpie/interpreter/PatternBinderBase.java
  28. +2 −5 src/com/stuffwithstuff/magpie/interpreter/PatternTester.java
  29. +0 −23 src/com/stuffwithstuff/magpie/interpreter/Scope.java
  30. +2 −7 src/com/stuffwithstuff/magpie/interpreter/builtin/ArrayBuiltIns.java
  31. +0 −31 src/com/stuffwithstuff/magpie/interpreter/builtin/BoolBuiltIns.java
  32. +2 −2 src/com/stuffwithstuff/magpie/interpreter/builtin/BuiltIn.java
  33. +1 −1 src/com/stuffwithstuff/magpie/interpreter/builtin/BuiltInCallable.java
  34. +16 −24 src/com/stuffwithstuff/magpie/interpreter/builtin/BuiltInFunctions.java
  35. +12 −183 src/com/stuffwithstuff/magpie/interpreter/builtin/BuiltIns.java
  36. +2 −28 src/com/stuffwithstuff/magpie/interpreter/builtin/ClassBuiltIns.java
  37. +3 −5 src/com/stuffwithstuff/magpie/interpreter/builtin/ClassConstruct.java
  38. +0 −13 src/com/stuffwithstuff/magpie/interpreter/builtin/ExpressionBuiltIns.java
  39. +2 −2 src/com/stuffwithstuff/magpie/interpreter/builtin/FieldGetter.java
  40. +1 −1 src/com/stuffwithstuff/magpie/interpreter/builtin/FieldProperty.java
  41. +2 −2 src/com/stuffwithstuff/magpie/interpreter/builtin/FieldSetter.java
  42. +9 −6 src/com/stuffwithstuff/magpie/interpreter/builtin/IntBuiltIns.java
  43. +0 −326 src/com/stuffwithstuff/magpie/interpreter/builtin/MagpieParserBuiltIns.java
  44. +0 −16 src/com/stuffwithstuff/magpie/interpreter/builtin/MultimethodBuiltIns.java
  45. +2 −10 src/com/stuffwithstuff/magpie/interpreter/builtin/ObjectBuiltIns.java
  46. +2 −3 src/com/stuffwithstuff/magpie/interpreter/builtin/ReflectBuiltIns.java
  47. +2 −6 src/com/stuffwithstuff/magpie/interpreter/builtin/RuntimeBuiltIns.java
  48. +13 −4 src/com/stuffwithstuff/magpie/interpreter/builtin/StringBuiltIns.java
  49. +0 −25 src/com/stuffwithstuff/magpie/parser/BacktickParser.java
  50. +0 −37 src/com/stuffwithstuff/magpie/parser/BraceParser.java
  51. +1 −1 src/com/stuffwithstuff/magpie/parser/BreakParser.java
  52. +2 −0 src/com/stuffwithstuff/magpie/parser/ClassParser.java
  53. +1 −1 src/com/stuffwithstuff/magpie/parser/CommaParser.java
  54. +2 −28 src/com/stuffwithstuff/magpie/parser/ConvertAssignmentExpr.java
  55. +94 −51 src/com/stuffwithstuff/magpie/parser/DefParser.java
  56. +2 −2 src/com/stuffwithstuff/magpie/parser/DoParser.java
  57. +1 −1 src/com/stuffwithstuff/magpie/parser/EqualsParser.java
  58. +2 −2 src/com/stuffwithstuff/magpie/parser/ExtendParser.java
  59. +1 −1 src/com/stuffwithstuff/magpie/parser/FieldParser.java
  60. +1 −1 src/com/stuffwithstuff/magpie/parser/FnParser.java
  61. +3 −12 src/com/stuffwithstuff/magpie/parser/Grammar.java
  62. +3 −6 src/com/stuffwithstuff/magpie/parser/InfixParser.java
  63. +1 −1 src/com/stuffwithstuff/magpie/parser/LiteralParser.java
  64. +2 −2 src/com/stuffwithstuff/magpie/parser/LoopParser.java
  65. +3 −21 src/com/stuffwithstuff/magpie/parser/MagpieParser.java
  66. +2 −2 src/com/stuffwithstuff/magpie/parser/MatchParser.java
  67. +0 −15 src/com/stuffwithstuff/magpie/parser/MessageInfixParser.java
  68. +32 −0 src/com/stuffwithstuff/magpie/parser/MessageParser.java
  69. +0 −12 src/com/stuffwithstuff/magpie/parser/MessagePrefixParser.java
  70. +1 −1 src/com/stuffwithstuff/magpie/parser/NothingParser.java
  71. +0 −15 src/com/stuffwithstuff/magpie/parser/ParenthesisInfixParser.java
  72. +2 −1 src/com/stuffwithstuff/magpie/parser/ParenthesisPrefixParser.java
  73. +17 −7 src/com/stuffwithstuff/magpie/parser/PatternParser.java
  74. +2 −4 src/com/stuffwithstuff/magpie/parser/PrefixParser.java
  75. +1 −1 src/com/stuffwithstuff/magpie/parser/ReturnParser.java
  76. +0 −10 src/com/stuffwithstuff/magpie/parser/ThisParser.java
  77. +0 −12 src/com/stuffwithstuff/magpie/parser/UsingParser.java
  78. +2 −2 src/com/stuffwithstuff/magpie/parser/VarParser.java
  79. +2 −1 src/com/stuffwithstuff/magpie/parser/WithParser.java
View
@@ -1,44 +1,15 @@
// WARNING. This file and the files it imports bootstrap low-level things like
// the type system and basic operators like == and <. The order that code is
// evaluated here is significant, and subtle.
def (this String) string -> this
def (nothing) string -> "nothing"
def (true) string -> "true"
def (false) string -> "false"
// Implement Trueable for the built-in classes so we can evaluate conditionals.
import("true.mag")
def print() -> prints("\n")
def print(text String) -> prints(text +("\n"))
def print(any) -> print(any string)
// Import the base classes used to implement the keyword parsers.
import("syntax/Token.mag")
import("syntax/patterns.mag")
def not(true) -> false
def not(false) -> true
// Define the parsers for the full Magpie syntax. Do these as early as possible
// since it's a pain to not have them. These are ordered roughly in order of
// what's most useful to have.
import("syntax/parsing.mag")
import("syntax/AndParser.mag")
import("syntax/OrParser.mag")
import("syntax/ClassParser.mag")
import("syntax/IfParser.mag")
import("syntax/OperatorParser.mag")
// Need these so that we have == available as early as possible. Match
// expressions use that to evaluate, and some of the parsers use those, so we
// will need it to parse some files.
import("operators.mag")
// Define the "regular" base library stuff. This chunk should be relatively
// straightforward.
import("Array.mag")
import("Class.mag")
import("Int.mag")
import("Record.mag")
import("String.mag")
import("Tuple.mag")
import("Error.mag")
import("Object.mag")
// Finally, import stuff that just defines interfaces since they are only used
// during type-checking.
import("Stringable.mag")
import("syntax/Expression.mag")
// Make + default to string concatenation. We'll only hit this if both
// arguments are not Ints.
def (this) +(other) -> this string +(other string)
@@ -18,7 +18,7 @@ protected CharacterReader createReader() {
@Override
protected void printResult(String result) {
Term.set(Term.ForeColor.GRAY);
System.out.print(" = ");
System.out.print("= ");
Term.set(Term.ForeColor.GREEN);
System.out.println(result);
Term.restoreColor();
@@ -27,7 +27,7 @@ protected void printResult(String result) {
@Override
protected void printError(String message) {
Term.set(Term.ForeColor.RED);
System.out.println("!! " + message);
System.out.println("! " + message);
Term.restoreColor();
}
}
@@ -51,11 +51,11 @@ public String lookAhead(int count) {
}
private void readLine() {
String prompt = ">> ";
String prompt = "> ";
if (mFirstLine) {
mFirstLine = false;
} else {
prompt = " | ";
prompt = "| ";
}
Term.set(Term.ForeColor.GRAY);
@@ -69,11 +69,11 @@ protected CharacterReader createReader() {
}
protected void printResult(String result) {
System.out.print(" = ");
System.out.print("= ");
System.out.println(result);
}
protected void printError(String message) {
System.out.println("!! " + message);
System.out.println("! " + message);
}
}
@@ -44,10 +44,10 @@ public String lookAhead(int count) {
private void readLine() {
if (mFirstLine) {
System.out.print(">> ");
System.out.print("> ");
mFirstLine = false;
} else {
System.out.print(" | ");
System.out.print("| ");
}
try {

This file was deleted.

Oops, something went wrong.
@@ -7,7 +7,6 @@
import com.stuffwithstuff.magpie.ast.pattern.MatchCase;
import com.stuffwithstuff.magpie.ast.pattern.Pattern;
import com.stuffwithstuff.magpie.parser.Position;
import com.stuffwithstuff.magpie.util.Expect;
import com.stuffwithstuff.magpie.util.Pair;
/**
@@ -62,13 +61,6 @@ public static Expr break_(Position position) {
return new BreakExpr(position);
}
public static Expr call(Expr target, Expr arg) {
Expect.notNull(target);
Expect.notNull(arg);
return new CallExpr(target, arg);
}
public static FnExpr fn(Expr body) {
return new FnExpr(Position.none(), body);
}
@@ -110,19 +102,23 @@ public static Expr match(Position position,
}
public static Expr message(Position position, Expr receiver, String name, Expr arg) {
return call(message(position, receiver, name), arg);
return new MessageExpr(position, receiver, name, arg);
}
public static Expr message(Position position, Expr receiver, String name) {
return new MessageExpr(position, receiver, name);
return message(position, receiver, name, Expr.nothing());
}
public static Expr method(Position position, String name, Pattern pattern, Expr body) {
return new MethodExpr(position, name, pattern, body);
}
public static Expr name(Position position, String name) {
return new MessageExpr(position, null, name);
return message(position, null, name, null);
}
public static Expr name(String name) {
return new MessageExpr(Position.none(), null, name);
return name(Position.none(), name);
}
public static Expr nothing() {
@@ -133,10 +129,6 @@ public static Expr nothing(Position position) {
return new NothingExpr(Position.none());
}
public static Expr quote(Position position, Expr body) {
return new QuotationExpr(position, body);
}
public static Expr record(Position position,
List<Pair<String, Expr>> fields) {
return new RecordExpr(position, fields);
@@ -156,10 +148,6 @@ public static Expr string(Position position, String text) {
return new StringExpr(position, text);
}
public static Expr this_(Position position) {
return new ThisExpr(position);
}
public static Expr tuple(List<Expr> fields) {
return new TupleExpr(fields);
}
@@ -168,10 +156,6 @@ public static Expr tuple(Expr... fields) {
return new TupleExpr(Arrays.asList(fields));
}
public static Expr using(Position position, String name) {
return new UsingExpr(position, name);
}
public static Expr var(String name, Expr value) {
return var(value.getPosition(), name, value);
}
@@ -5,21 +5,17 @@
R visit(BlockExpr expr, C context);
R visit(BoolExpr expr, C context);
R visit(BreakExpr expr, C context);
R visit(CallExpr expr, C context);
R visit(FnExpr expr, C context);
R visit(IntExpr expr, C context);
R visit(LoopExpr expr, C context);
R visit(MatchExpr expr, C context);
R visit(MessageExpr expr, C context);
R visit(MethodExpr expr, C context);
R visit(NothingExpr expr, C context);
R visit(QuotationExpr expr, C context);
R visit(RecordExpr expr, C context);
R visit(ReturnExpr expr, C context);
R visit(ScopeExpr expr, C context);
R visit(StringExpr expr, C context);
R visit(ThisExpr expr, C context);
R visit(TupleExpr expr, C context);
R visit(UnquoteExpr expr, C context);
R visit(UsingExpr expr, C context);
R visit(VariableExpr expr, C context);
}
@@ -3,15 +3,17 @@
import com.stuffwithstuff.magpie.parser.Position;
public class MessageExpr extends Expr {
MessageExpr(Position position, Expr receiver, String name) {
MessageExpr(Position position, Expr receiver, String name, Expr arg) {
super(position);
mReceiver = receiver;
mName = name;
mArg = arg;
}
public Expr getReceiver() { return mReceiver; }
public String getName() { return mName; }
public Expr getArg() { return mArg; }
@Override
public <R, C> R accept(ExprVisitor<R, C> visitor, C context) {
@@ -30,4 +32,5 @@ public void toString(StringBuilder builder, String indent) {
private final Expr mReceiver;
private final String mName;
private final Expr mArg;
}
@@ -1,14 +1,19 @@
package com.stuffwithstuff.magpie.ast;
import com.stuffwithstuff.magpie.ast.pattern.Pattern;
import com.stuffwithstuff.magpie.parser.Position;
public class UsingExpr extends Expr {
UsingExpr(Position position, String name) {
public class MethodExpr extends Expr {
MethodExpr(Position position, String name, Pattern pattern, Expr body) {
super(position);
mName = name;
mPattern = pattern;
mBody = body;
}
public String getName() { return mName; }
public Pattern getPattern() { return mPattern; }
public Expr getBody() { return mBody; }
@Override
public <R, C> R accept(ExprVisitor<R, C> visitor, C context) {
@@ -17,8 +22,10 @@
@Override
public void toString(StringBuilder builder, String indent) {
builder.append("using ").append(mName);
builder.append("not impl");
}
private final String mName;
private final Pattern mPattern;
private final Expr mBody;
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -8,6 +8,6 @@
*/
public interface Callable {
Callable bindTo(ClassObj classObj);
Obj invoke(Interpreter interpreter, Obj thisObj, Obj arg);
Obj invoke(Interpreter interpreter, Obj arg);
Pattern getPattern();
}
Oops, something went wrong.

0 comments on commit e509e13

Please sign in to comment.