Commit graph

670 commits

Author SHA1 Message Date
joeduffy 36b4a6f848 Implement stack traces
This change implements stack traces.  This is primarily so that we
can print out a full stack trace in the face of an unhandled exception,
and is done simply by recording the full trace during evaluation
alongside the existing local variable scopes.
2017-02-12 09:38:19 -08:00
joeduffy a16bb714e4 Implement dynamic loading
This change implements dynamic loads in the binder and evaluator.
2017-02-12 08:22:44 -08:00
joeduffy 93d9df1c4c Issue a MuJS warning on unused dependencies 2017-02-12 06:23:22 -08:00
joeduffy a8812bdbf0 Use strings for property keys
In dynamic scenarios, property keys could be arbitrary strings, including
invalid identifiers.  This change reflects that in the runtime representation
of objects and also in the object literal and overall indexing logic.
2017-02-11 15:45:37 -08:00
joeduffy 11faf22c60 Produce a string literal for dynamic loads 2017-02-11 15:38:12 -08:00
joeduffy 3759f71e67 Transform element access expressions properly
This change transforms element access expressions much like we do
property access expressions, in that we recognize several static load
situations.  (The code is rearranged to share more logic.)  The code
also now recognizes situations where we must devolve into a dynamic
load (e.g., due to a string literal, dynamic LHS, etc).
2017-02-11 15:32:14 -08:00
joeduffy 10f5d43245 Also erase TypeLiterals
This change erases TypeLiterals to ObjectLiterals, for much the same reason.
Also for much the same reason, it'd be nice to eventually preserve these.
2017-02-11 14:51:05 -08:00
joeduffy a7f23fc65a Fix a few verification errors
This change fixes a few issues:

* Emit ObjectLiteral types as `dynamic`.  We can do better here, including
  spilling the "anonymous" types, for cases where cross-module exports/imports
  are leveraged.  For the time being, however, we will erase them to dynamic.
  This is a heck of a lot better than emitting garbage `__object` type tokens.

* Implement TypeScript TypeAssertionExpression lowering into casts.

* Recognize static class property references.  Previously, we tried to load
  the class as a location, which resulted in nonsense, unverifiable MuIL.  Now
  we properly detect that the target is a property symbol with the static
  modifier, and emit the token without an object reference (as expected).

* Accompany the above with a bunch of tests that stress these paths.
2017-02-11 14:45:31 -08:00
joeduffy 2e8b04f2a7 Get the minimal AWS sample compiling/verifying/evaluating 2017-02-11 13:33:11 -08:00
joeduffy 53a568da87 Modify the ResourceProvider.Update API
This changes two aspects of the ResourceProvider.Update RPC API:

1. Update needs to return an ID, in case the resource had to be
   recreated in response to the request.

2. Include both the old and the new values for properties that are
   being updated.
2017-02-11 13:14:29 -08:00
joeduffy a60dc045cb Tokenize properties and block scoped variables
We weren't properly emitting fully qualified tokens for properties
and "block scoped variables" (of which, module properties qualify).
This change fixes that, bringing the ec2instance verification error
count down from 22 to 7.
2017-02-11 10:10:02 -08:00
joeduffy b2d43e1c59 Permit dynamic to flow through to eval
This change "kicks the can" of dealing with `dynamic` down the road.
Namely, the binder will be permissive about letting dynamic objects
flow through to the evaluation phase.  At that point, the evaluator
will be responsible for performing duck typing, etc.
2017-02-11 08:39:45 -08:00
joeduffy 7a2d2b4cb1 Typecheck new expressions 2017-02-11 08:28:47 -08:00
joeduffy dc9f91c3cf Support dynamic object literals
This change introduces support for dynamic object literals.  If the
type of a literal is dynamic, then the property initializers for that
literal are naked strings; if the type of a literal is anything else,
however, we expect that the property names are full blown member tokens.
2017-02-11 08:20:06 -08:00
joeduffy c6b9abb7a0 Issue an error if a dependency is missing 2017-02-11 08:02:28 -08:00
joeduffy 8f24cd20ba Simplify certain types
This change simplifies certain types while lowering to MuIL, fixing
a number of assertion failures that cropped up after my tightening of
the type checking (namely, asserting rather than silently logging).

This comes in the following forms:

1) StringLiteral, NumberLiteral, and BooleanLiteral types can simply
   become String, Number, and Boolean, respectively.  This loses some
   static type-checking (e.g., ensuring that values are within range),
   however at least the physical runtime type will match.

2) EnumLiteral types can simply adopt their base types, with similar
   downsides and caveats to the other literal types (range widening).

3) Any union types that contain Undefined or Null types can be simplified
   to omit those types.  If, after filtering them out, we are left with
   a single type (admitting the recursive case of multiple XLiterals that
   simplified down to the exact same primitive type), we will eliminate
   the union altogether and just use the underlying simple type.  This
   handles the case of optional interface properties, e.g. `T?`, which are
   internally represented in TypeScript as `T|undefined` union types.

There are two follow up work items for later on:

* marapongo/mu#64 tracks support for non-nullability.  At the moment we
  are tossing away any `|undefined` or `|null` unions, including `T?`,
  because MuIL currently permits nullability everywhere, but we want to
  consider honoring these annotations (eventually).

* marapongo/mu#82 tracks support for union types.  This is how we intended
  to support true enum types, so tossing away this information is a bit
  unfortunate.  But this is a feature for another day.
2017-02-11 07:13:49 -08:00
joeduffy c5807c4b57 Issue proper errors for unsupported types 2017-02-10 17:04:01 -08:00
joeduffy 02aa1c4ee0 Add some MuJS debug logging 2017-02-10 16:53:27 -08:00
joeduffy 0802399a8c Distinguish between object and dynamic (fka any)
This change prepares to mimick the TypeScript behavior of `any` which,
it turns out, is closer to Python and Ruby duck typing than what we have
here.  It also introduces `object` to mean "the base of all types".

MuJS has been updated to map `any` to `dynamic`.

At this point, the conversion logic now distinguishes between NoConversion,
ImplicitConversion, and AutoCastConversion cases, the latter being a case
in which `dynamic` is the source and so a duck-type-style cast must occur.
Right now we do not honor the AutoCastConversion case anywhere, so we still
have not achieved the duck-typing semantics of the source language.

This is part of fixing marapongo/mu#79.
2017-02-10 16:44:18 -08:00
joeduffy 7b81580fb9 Remove some unused variables 2017-02-10 15:30:48 -08:00
joeduffy fa69ed43f4 Tweak a couple error messages 2017-02-10 15:18:30 -08:00
joeduffy acd52778b7 Eliminate the expandTags functionality
This change eliminates the AWS package's cloudformation.expandTags
functionality.  The primary reason is that we haven't yet implemented
string/array intrinsics (see marapongo/mu#80), and so the presence of
this routine was preventing verification of the AWS library.  But, it
turns out, the expandTags routine was violating our "zero artistic
license" principle for the foundational cloud packages.  Namely, it
was auto-adding the Name=<name> tag, when the name property was set,
capturing an idiomatic AWS resource pattern.  Instead of doing that,
we will just project tags in their raw form, and add such conveniences
(possibly) add a higher level in the layer cake.
2017-02-10 15:10:30 -08:00
joeduffy 11b7880547 Further reshuffle Protobufs; generate JavaScript code
After a bit more thinking, we will create new SDK packages for each
of the languages we wish to support writing resource providers in.
This is where the RPC goo will live, so I have created a new sdk/
directory, moved the Protobuf/gRPC definitions underneath sdk/proto/,
and put the generated code into sdk/go/ and sdk/js/.
2017-02-10 09:28:46 -08:00
joeduffy d67de40cf6 Move Mu library source files underneath src/ directory 2017-02-10 09:10:36 -08:00
joeduffy 0b299f0ae5 Update ec2instance so that it compiles/verifies/evals 2017-02-10 09:10:13 -08:00
joeduffy 6b60852c76 Generate Golang Protobuf/gRPC code
This change moves the RPC definitions to the pkg/murpc package,
underneath the proto folder.  This is to ensure that the resulting
Protobufs get a good package name "murpc" that is unique within the
overall toolchain.  It also includes a `generate.sh` script that
can be used to manually regenerate client/server code.  Finally,
we are actually checking in the generated files underneath pkg/murpc.
2017-02-10 09:08:06 -08:00
joeduffy 20452a99e1 Add Protobuf definitions for resource providers 2017-02-10 08:55:26 -08:00
joeduffy 6e472f8ab4 Colorize Mu output
This change adds colorization to the core Mu tool's output, similar
to what we added to MuJS in
cf6bbd460d.
2017-02-09 17:26:49 -08:00
joeduffy 432b9666fe Add an install script for the AWS library
Eventually this won't be required, but for now, it will simplify
bringing up our first end-to-end working example.
2017-02-09 16:36:53 -08:00
joeduffy c821634761 Restructure the examples
This restructures the examples directory a bit, into three buckets:

* basic/: simplistic examples, like hello world and whatnot.

* conversions/: actual conversions from existing samples (with the source cited).

* scenarios/: more complex examples that demonstrate various features of the system.
2017-02-09 16:07:45 -08:00
joeduffy c333bf6f01 Tag an object moniker TODO with marapongo/mu#76 2017-02-09 16:02:45 -08:00
joeduffy 79f8b1bef7 Implement a DOT graph converter
This change adds a --dot option to the eval command, which will simply
output the MuGL graph using the DOT language.  This allows you to use
tools like Graphviz to inspect the resulting graph, including using the
`dot` command to generate images (like PNGs and whatnot).

For example, the simple MuGL program:

    class C extends mu.Resource {...}
    class B extends mu.Resource {...}
    class A extends mu.Resource {
        private b: B;
        private c: C;
        constructor() {
            this.b = new B();
            this.c = new C();
        }
    }
    let a = new A();

Results in the following DOT file, from `mu eval --dot`:

    strict digraph {
        Resource0 [label="A"];
        Resource0 -> {Resource1 Resource2}
        Resource1 [label="B"];
        Resource2 [label="C"];
    }

Eventually the auto-generated ResourceN identifiers will go away in
favor of using true object monikers (marapongo/mu#76).
2017-02-09 15:56:15 -08:00
joeduffy c26ec0aa65 Parent the predefined Resource class to the mu/resource module 2017-02-09 15:06:02 -08:00
joeduffy c0b0a87b07 Use tokens when printing initialized modules/classes 2017-02-09 15:04:26 -08:00
joeduffy c2897d5b70 Fix HasBaseName's logic 2017-02-09 15:01:23 -08:00
joeduffy 1b2ec4eebd Add some handy logging to graph generation 2017-02-09 15:01:08 -08:00
joeduffy 9fb8819375 Fix a possible nil deref in verbose logging 2017-02-09 14:52:33 -08:00
joeduffy e14ca5f4ff Manually print the stack-trace when --logtostderr is enabled
Glog doesn't actually print out the stack traces for all goroutines,
when --logtostderr is enabled, the same way it normally does.  This
makes debugging more complex in some cases.  So, we'll manually do it.
2017-02-09 14:50:41 -08:00
joeduffy b241ea3795 Fix a few messages (print the token value, not pointer address) 2017-02-09 14:35:45 -08:00
joeduffy eb7bfcf355 Implement new expression evaluation 2017-02-09 14:32:44 -08:00
joeduffy e8f54f3f4d Add a minimal MuJS blueprint example 2017-02-09 13:36:18 -08:00
joeduffy 8485929192 Transform interface heritage clauses
Turns out we hadn't been transforming interface heritage clauses --
extends and implements -- like we were classes.  This change fixes
that.  As a result, we're down to 14 verification errors for AWS.
2017-02-09 13:27:08 -08:00
joeduffy 3eb72b62d5 Introduce an <error> type
This change renames the old Error type to Exception -- more consistent
with our AST, etc. nodes anyway -- and introduces a new Error type ("<error>")
to use when something during typechecking or binding fails.

The old way led to errors like:

    error: MU504: tags.ts:32:18: Symbol 'Tag:push' not found
    error: MU522: tags.ts:32:8: Cannot invoke a non-function; 'any' is not a function

This is because of cascading errors during type-checking; the symbol not found
error means we cannot produce the right type for the function invoke that
consumes it.  But the 'any' part is weird.  Instead, this new change produces:

    error: MU504: tags.ts:32:18: Symbol 'Tag:push' not found
    error: MU522: tags.ts:32:8: Cannot invoke a non-function; '<error>' is not a function

It's slightly better.  And furthermore, it gives us a leg to stand on someday
should we decide to get smarter about detecting cascades and avoiding issuing
the secondary error messages (we can just check for the Error type).
2017-02-09 12:58:34 -08:00
joeduffy 42bdcb7bca Fix an inner break bug
We need to break out of two levels of loops, now that we've added
the outer loop around the possible filename candidates.
2017-02-09 12:53:09 -08:00
joeduffy 3a27a44d2c Strip .js, .d.ts, and .ts module name suffixes 2017-02-09 12:43:32 -08:00
joeduffy 6ad42d9063 Probe for MuPackages in MuJS dependency resolution
This change also accepts MuPackages during MuJS dependency resolution.
The old logic wasn't quite right, because it would skip over MuPackage
files, and keep probing upwards, possibly binding to the wrong, pre-
compilation, Mufile.  Note that we must still probe for both Mupackages
and Mufiles, because of intra-package dependencies.

After this change, the AWS MuPackage is down to 28 verification errors.
2017-02-09 12:35:53 -08:00
joeduffy a91f3e6050 Fix more phasing issues
This change fixes a few more phasing issues in the compiler.  Namely,
it now splits all passes into three distinct phases:

1. Declarations: simply populating names.

2. Definitions: chasing down any references to other names from those
   declared entities.  For instance, base classes, other modules, etc.

3. Bodies: fully type-checking everything else, which will depend
   upon both declarations and definitions being fully present.
2017-02-09 12:24:02 -08:00
joeduffy 9bcfbe859f Dealias symbols when producing tokens 2017-02-09 11:32:33 -08:00
joeduffy 330a6c3d25 Probe for Mupacks, not Mufiles, for dependencies 2017-02-09 11:23:27 -08:00
joeduffy a3e18fb79a Add a basic Mu standard library install script 2017-02-09 11:18:08 -08:00