Commit graph

670 commits

Author SHA1 Message Date
joeduffy
e72cf059fb Fix up dependency probing
This changes a few things with dependency probing:

1) Probe for Mupack files, not Mufiles.

2) Substitute defaults in the PackageURL before probing.

3) Trace the full search paths when an import fails to resolve.
   This will help diagnose dependency resolution issues.
2017-02-09 11:01:02 -08:00
joeduffy
be7dcec123 Support sugared "*" semvers
This adds support for sugared "*" semvers, which is a shortcut for
">=0.0.0" (in other words, any version matches).  This is a minor part
of marapongo/mu#18.  I'm just doing it now as a convenience for dev
scenarios, as we start to do real packages and dependencies between them.
2017-02-09 10:48:18 -08:00
joeduffy
37f262e046 Prepare the Mu standard library package
This change:

* Renames the Mu standard library NPM package from "mu" to "@mu/mu".
  This reflects the convention that MuPackages published on NPM will,
  at least initially, be published under the "@mu" scope.  This
  indicates that a package is intended to be consumed by Mu programs.

* Adds an NPM peerDependency on the Mu package from the AWS package.

* Adds a Mu dependency on the Mu package from the AWS MuPackage.
2017-02-09 09:43:18 -08:00
joeduffy
1069372cca Save TypeScript definition files
To prepare a MuPackage for consumption by another MuPackage, we need
to save the definition files output by the TypeScript compiler.  In
theory, we could regenerate these definitions from the MuPackage itself;
in fact, when we tackle cross-language, this will be necessary.  For
now, however, it's much simpler to simply save the definition outputs
alongside the Mupack.json package metadata.

Note that we do not save "code" outputs.  The MuIL format encodes all
computations and so the only thing we need for dependent packages is
the header files to compile against; all "link" and runtime dependencies
are satisfied by the MuIL format and Mu toolchain.
2017-02-09 09:07:10 -08:00
joeduffy
aaefbae956 Eliminate json.ts from the Mu standard library
This is a leftover bit of code from a long time ago, and is no longer needed.
2017-02-09 08:44:39 -08:00
joeduffy
26c16474c2 Use tsconfig.json's outDir by default
There are a variety of ways to specify a MuJS output location, including
the command line --out (-o for short) flag.  If that isn't present, we simply
dump the Mupack.json file in the current working directory.  However, in order
to prepare Mupackage files for packaging, distribution, and reuse, we actually
want to store the Mupack.json file alongside all the other package assets (like
TypeScript header files).  So it makes sense to recognize the outDir, if present,
in the tsconfig.json file, and use it as the default if not otherwise specified.
2017-02-09 08:42:49 -08:00
joeduffy
2f968b778c Permit any for object literals
This change permits object literals with the type of `any`; although
they will typically get coerced to record/interface types prior to use,
there is no reason to ban `any`.  In fact, it is the idiomatic way of
encoding "objects as bags of properties" that is common to dynamic
languages like JavaScript, Python, etc.
2017-02-08 17:03:38 -08:00
joeduffy
9de4b7ce5d Fully qualify more tokens
This changes transformIdentifierExpression to call through to the
general purpose function that understands how to transform any Symbol
reference into a fully qualified token suitable for serialization.
2017-02-08 16:49:32 -08:00
joeduffy
75eb10203b Transform null and undefined literals
This change recognizes identifier expressions that mention the null and
undefined constants, transforming them into null literals.  Note that
marapongo/mu#70 tracks mimicking the subtle differences between
undefined and null in ECMAScript.
2017-02-08 16:33:53 -08:00
joeduffy
7f094a3054 Chase exports
This change adds support for loading from export locations.  All we
need to do is keep chasing the referent pointer until we bottom out
on an actual method, property, etc.
2017-02-08 16:19:25 -08:00
joeduffy
914e88672c Omit object expression for module loads
In the event that we're loading a property straight from a module,
we needn't actually load the module at all; instead, we refer to it
using a fully qualified token.
2017-02-08 16:12:18 -08:00
joeduffy
840f0bd05d Transform cross-module references into correct tokens
In many cases, property access expressions interact with types.  For
example, the expression `o.j.bar()` likely accesses variable `o`, then
its property `j`, then `j`'s method `bar`.  In other cases, however,
property access elements are actually modules.  For example, in:

    import * as o from "o";
    o.j.bar();

This change recognizes this situation and emits code correctly.
2017-02-08 16:07:19 -08:00
joeduffy
69b23ca2ea Implement structured token binding
This change fixes a whole host of issues with our current token binding
logic.  There are two primary aspects of this change:

First, the prior token syntax was ambiguous, due to our choice of
delimiter characters.  For instance, "/" could be used both as a module
member delimiter, in addition to being a valid character for sub-modules.
The result is that we could not look at a token and know for certain
which kind it is.  There was also some annoyance with "." being the
delimiter for class members in addition to being the leading character
for special names like ".this", ".super", and ".ctor".  Now, we just use
":" as the delimiter character for everything.  The result is unambiguous.

Second, the simplistic token table lookup really doesn't work.  This is
for three reasons: 1) decorated types like arrays, maps, pointers, and
functions shouldn't need token lookup in the classical sense; 2) largely
because of decorated naming, the mapping of token pieces to symbolic
information isn't straightforward and requires parsing; 3) default modules
need to be expanded and the old method only worked for simple cases and,
in particular, would not work when combined with decorated names.
2017-02-08 14:10:16 -08:00
joeduffy
f9c02a12a3 Improve some token-related assertion messages 2017-02-08 10:12:09 -07:00
joeduffy
6e554603b9 Quality property access type tokens 2017-02-08 10:04:36 -07:00
joeduffy
5fb638a9f9 Add some quotes to a few error messages 2017-02-08 09:57:54 -07:00
joeduffy
31ff4e96a6 Add missing ClassMemberToken case 2017-02-08 09:56:10 -07:00
joeduffy
93c6c936c3 Permit nil typemap entries
Previously we asserted that typemap entries are never nil.  It turns
out we represent "void" as the absence of a type in MuIL, and so we need
to permit these for constructors, etc.
2017-02-08 09:53:29 -07:00
joeduffy
130838b1b1 Walk arguments in calls and function invokes 2017-02-08 09:53:00 -07:00
joeduffy
9b773b4e95 Transform super() calls
This change recognizes the special case of a `super` variable load
in the position of a function call.  Left on its own, this yields
unverifiable MuIL, because we attempt to invoke a non-function.
2017-02-08 09:39:41 -07:00
joeduffy
3396163b93 Rename Mu.out.json baselines to Mupack.json
This matches the default file name from the MuJS CLI, which makes
rebaselining ever-so-slightly more convenient.
2017-02-08 09:02:31 -07:00
joeduffy
4b8ac3f4bc Emit fully resolved tokens for intra-module types
This change fixes the type token emission logic in MuJS to emit fully
resolved tokens for intra-module type references.  The prior logic emitted
simple identifiers when type references were contained within a single file.
This hearkens back to the days where we used simple names, coupled with a
lexical symbol table, to resolve such things.

This brings the AWS MuPack verification error count to 57 from 84.
2017-02-08 08:56:39 -07:00
joeduffy
c76201d751 Add a newline to the end of serialized MuJS MuPackages 2017-02-08 08:55:26 -07:00
joeduffy
4b56cc61f2 Fix the -o alias so it correctly maps to --out 2017-02-08 08:24:38 -07:00
joeduffy
ebb2b018ad Bind class member definitions in a separate pass
This change further rearranges the phasing of binding to account for
the fact that class definitions may freely reference exports, which won't
be known until after binding class names.  Therefore, we bind class names
first and then the definitions (function signatures and variables).

This brings the AWS MuPackage's number of verification errors down to 84
from 136.
2017-02-08 08:14:08 -07:00
joeduffy
13872b77c7 Use stable map enumeration in the binder 2017-02-07 09:58:23 -07:00
joeduffy
6c26693fea Move default to a property on package, not a bit on module
The old method of specifying a default module for a package was using
a bit on the module definition itself.  The new method is to specify the
module name as part of the package definition itself.

The new approach makes more sense for a couple reasons.  1) it doesn't
make sense to have more than one "default" for a given package, and yet
the old model didn't prevent this; the new one prevents it by construction.
2) The defaultness of a module is really an aspect of the package, not the
module, who is generally unaware of the package containing it.

The other reason is that I'm auditing the code for nondeterministic map
enumerations, and this came up, which simply pushed me over the edge.
2017-02-06 18:33:31 -07:00
joeduffy
4cf8654bf1 Fix a few lint issues 2017-02-06 18:08:22 -07:00
joeduffy
ca313f10d5 Emit proper TypeToken AST nodes 2017-02-03 21:03:34 -08:00
joeduffy
4cb66fc520 Implement extends/implements heritage clauses 2017-02-03 20:57:35 -08:00
joeduffy
8254a7977c Fix a lint error that crept in: missing semicolon 2017-02-03 20:20:43 -08:00
joeduffy
c3f4f0ad0d Propagate source location for this and super 2017-02-03 20:20:22 -08:00
joeduffy
deb015a15d Implement multi-pass module binding
The prior module binding logic was naive.  It turns out that, because of inter-module
references within the same package, the order of binding certain modules and its members
within a package matters.  This leads to a more Java/C#/JavaScript/etc. multi-pass model,
versus a classical single-pass C/C++ model (which requires forward declarations).

To do this, we bind things in this order within a package:

* First, we add an entry for each module.  It is largely empty, but at least names resolve.

* Second, we bind all imports.  Since all modules are known, all inter-module tokens resolve.

* Next, we can bind class symbols.  Note that we must do this prior to module properties,
  methods, and exports, since they might be referenced and need to exist first.  As before,
  we do not yet bind function bodies, since those can reference anything.

* Now we bind all module "members", meaning any module scoped properties and methods.  Again,
  we do not bind function bodies just yet.  This is just a symbolic binding step.

* Next, we can finally bind exports.  Because exports may reference any members, all of the
  above must have been done first.  But all possibly exported symbols are now resolved.

* Finally, we can bind function bodies.
2017-02-03 19:57:53 -08:00
joeduffy
15ba2949dc Add a mu verify command
This adds a `mu verify` command that simply runs the verification
pass against a MuPackage and its MuIL.  This is handy for compiler
authors to verify that the right stuff is getting emitted.
2017-02-03 19:27:37 -08:00
joeduffy
a1c94275e0 Restructure format/output selection a bit
This change restructures how MuJS selects the format and output a
bit, so that simply running `mujs -f yaml` will output a default
`Mupack.yaml` in the current directory.
2017-02-03 14:56:36 -08:00
joeduffy
21aa240eca Save MuJS output to Mupack.json by default
This change stops printing the AST to output after compilation.  It's
a little confusing and, especially as Mu test programs are getting larger,
staring at 1,000s of lines of JSON whiz by is losing it's fun.

By default, the compiler saves output into Mupack.json.  This can be
overridden with the --out switch (-o for short).  Both JSON and YAML files
are supported (as are unrecognized extensions, which get JSON by default).
Another switch --format (-f for short) is supported to explicitly specify
the output format.  A special -out of "-" means "print to stdoutput", so
for instance, running `mujs -o=- -f=yaml` will print YAML to the console.
2017-02-03 12:41:10 -08:00
joeduffy
a0de263930 Add a tsconfig to the Thumbnailer example 2017-02-03 12:14:40 -08:00
joeduffy
7854e0d393 Merge branch 'master' of github.com:marapongo/mu 2017-02-03 12:09:56 -08:00
joeduffy
03b065015f Add a missing } 2017-02-03 12:09:48 -08:00
joeduffy
6e0d17c47c Don't attempt to transform if there were errors
This change doesn't attempt to transform the resulting AST if there
were any compiler errors.  The old code erroneously proceeded in cases
where errors occurred but an AST was actually produced, leading to
possible assertions and other unexpected conditions.
2017-02-03 12:08:41 -08:00
Joe Duffy
382de02bc6 Minor comment update 2017-02-03 05:40:22 -08:00
Joe Duffy
dbf86736e1 Move ec2instance example underneath aws/
I just introduced the examples/aws/ directory yesterday to hold some
of our basic AWS examples, as I expect us to start accumulating more
of them.  So this just moves ec2instance underneath that directory.
We should probably think about further reorganizing these (e.g., into
demos/, scenarios/, etc.), ass we accumulate more examples.
2017-02-03 05:38:06 -08:00
Joe Duffy
929aa0e0a7 Merge pull request #75 from lukehoban/ec2instance
Simple EC2 instance example
2017-02-03 05:34:29 -08:00
Luke Hoban
464bd4fe28 Simple EC2 instance example 2017-02-02 22:03:12 -08:00
joeduffy
f6c96c2c86 Bind and validate function calls 2017-02-02 17:11:58 -08:00
joeduffy
a5b7a35629 Fix up some error messages 2017-02-02 16:58:53 -08:00
joeduffy
cf6bbd460d Colorize MuJS errors/warnings
I've had a few times where I missed errors/warnings whizzing by alongside
other spew.  Although this was probably technically a "waste" of 10 minutes,
it actually would have saved me at least 10 in the past.  So, there you go.
2017-02-02 16:47:45 -08:00
joeduffy
9adcc8cff9 Print the export token during describe 2017-02-02 15:03:51 -08:00
joeduffy
5492ccba7c Add map tests
This adds map tests for ES6-style maps encoded in MuPack/MuIL.

It also fixes one simple bug, where we should not populate the
compiler options with TypeScript defaults *unless* they are (a)
missing from the arguments and (b) not discovered from a tsconfig
file.  Otherwise, we will rewrite overrides with the defaults.
2017-02-02 14:57:37 -08:00
joeduffy
f84d9341dd Add a clean target
This change just adds a clean target to the MuJS compiler's package
file.  If you rename tests, the old files stick around inside of bin/,
possibly causing superfluous test failures.  A clean does the trick.
2017-02-02 14:30:28 -08:00