gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Inconsistent acceptance of types Function0 #247

Closed KimBruce closed 5 years ago

KimBruce commented 7 years ago

The type Function0[[T]] is in the Grace documentation, but isn't recognized in a dialect except by prefixing it with the local name for the imported standardGrace library.

I.e., suppose we are writing a dialect that starts with:

dialect "none"
import "standardGrace" as sg
inherit sg.methods

Then the only way to access Function0 (and similar types) is to write:

type Function0⟦T⟧ = sg.Function0⟦T⟧

An interesting point is that this fix is NOT necessary when running in the browser, only on the command line. The command for executing the command-line is (and the error response) if I leave out the renaming/prefixing of Function0.

../j2/minigrace-js gradualTypesND.grace
gradualTypesND.grace[121:44-52]: Syntax error: unknown variable or method 'Function0'. This may be a spelling mistake or an attempt to access a variable in another scope.
  120:     at (name : String) put (value:V) -> Done
  121:     find (name : String) butIfMissing (bl: Function0⟦V⟧) → V

(I'm also not sure why I need to use j2 rather than js to get this to run)

apblack commented 7 years ago

You need to use j2 rather than js because the j2 directory is where the compiler lives after you have bootstrapped it. The js directory is now for source code only. One day soon, I'll make install work again ;-)

If something works in the browser but not at the command line, my guess is that you have an old version of standardGrace on your GRACE_MODULE_PATH, and that's the one that the compiler is picking up. What is your GRACE_MODULE_PATH?

KimBruce commented 7 years ago

It is /usr/local/lib/grace/modules

Nothing in there has been updated since April. I assumed that I should reset it to the regular minigrace/j2 directory, but it still is not finding standardGrace.js. See below. I don't see why it is searching the js directory (which does not have it) rather than the j2 directory.

KimsMacPro:kimtypecheck kim$ ../js/minigrace-js gradualTypesND.grace 
module "standardGrace.js" not found.  Tried:
/Users/kim/Documents/External_bus/GraceDesign/BlackMinigrace/minigrace/js/standardGrace.js
module "standardGrace.js" not found
[]
KimsMacPro:kimtypecheck kim$ echo $GRACE_MODULE_PATH
/Users/kim/Documents/External_bus/GraceDesign/BlackMinigrace/minigrace/j2/
KimsMacPro:kimtypecheck kim$ ls /Users/kim/Documents/External_bus/GraceDesign/BlackMinigrace/minigrace/j2/
ast.js          grace-debug     stringMap.js
buildinfo.js        gracelib.js     sys.gct
collectionsPrelude.js   identifierKinds.js  timer.gct
compiler-js     identifierresolution.js timer.js
compiler.js     io.gct          typeComparison.js
dom.gct         lexer.js        unicode.gct
dom.js          minigrace-js        unicodedata.js
errormessages.js    mirrors.gct     unixFilePath.js
genjs.js        parser.js       util.js
grace           standardGrace.js    xmodule.js

What am I missing here?

apblack commented 7 years ago

I don't see why it is searching the js directory ...

Because the executable that you are running lives in the js directory. Implicitly, the directory in which the executable lives is on the search path.

Try running the j2/minigrace-js compiler instead.

I have to agree that all of this is a bit obscure. I got the JS compiler working well enough to bootstrap itself, and then stopped messing with it, because I had a class to teach. It's all a bit delicate, because the compiler needs to load itself dynamically, but not to load the bits of the compiler that it has just compiled by mistake, so there need to be two different search paths while it is bootstrapping.

I think that for production use the solution is to cat the whole compiler into one big JS file. That's what I would put in /usr/local/bin on an install. After finals ...

apblack commented 5 years ago

I believe that make install works again. It does indeed cat the whole compiler into one big file.