Commit Graph

4655 Commits

Author SHA1 Message Date
Jorge Acereda
134d9a5b02 Implement load-stack. 2020-06-28 19:53:43 +02:00
Jorge Acereda
0d7533e887 Register additional modules in project. 2020-06-27 21:48:46 +02:00
hellerve
43951a4c9f core: use abort in unreachable 2020-06-26 18:57:06 +02:00
hellerve
fb3ef6a47f core: add Bool.zero 2020-06-23 12:26:53 +02:00
hellerve
a96f774bc5 core: add unreachable 2020-06-23 12:19:14 +02:00
Erik Svedäng
73bb5735c1
Merge pull request #893 from scolsen/private
Implement Privacy Checking
2020-06-22 20:51:08 +02:00
Erik Svedäng
59ded9cb02
Merge pull request #890 from scolsen/opaque
Add the Opaque type
2020-06-22 20:47:26 +02:00
Jorge Acereda
e6cf941187 Added add-c to include additional compilation units in the compiler invocation. 2020-06-21 17:22:24 +02:00
scottolsen
0b34f9b31a Add a valid use of a private binding to private-binding test 2020-06-19 15:01:27 -04:00
scottolsen
915a539d2d Add a test for private bindings
This commit adds a simple test to ensure binding privacy works as
expected.
2020-06-19 14:53:00 -04:00
scottolsen
c5857c74c6 Add privacy checking to expansions
The previous commit added privacy checking to the evaluator--as it turns
out, this is only sufficient for top-level forms--interior forms, e.g.
forms in a `defn` are examined by `Expand` via `expandAll` and never
reach the `Eval` check.

To remedy this, I've added the check to symbol expansions. I've also
tweaked the signature of `expandSymbol` to align it with other functions
(e.g. `expandArray`).
2020-06-19 14:37:10 -04:00
scottolsen
b94b49bf86 Implement private
Even though `private?` has been around for a while, and we document the
behavior of `private` as marking a binding as private to a module--it
was never implemented as far as I can tell.

This implements private by adding a simple check to the evaluator. If a
binding is found in the global context, we check if it's marked as
private. If so, we inform the user that it can't be called from outside
of its module.

Note that we don't perform this check if the binding is found in the
internal env, since that means it's a function called within the same
module and thus is ok (even if marked as private).

After this change, something like the following works, granting us
proper encapsulation:

```
;; File Foo.carp
(deftype Foo [bar Int])

(private Foo.bar)

(defmodule Foo
  (defn get [foo]
    (Foo.bar foo))
)

;; Enter REPL
(load "Foo.carp")
(Foo.bar &(Foo.init 1))
The binding: Foo.bar is private; it may only be used within the module
that defines it. at REPL:1:2.
@(Foo.get &(Foo.init 1))
Compiled to 'out/Untitled' (executable)
1
=> 0
```

N.B. I also had to remove a private declaration from fmt-internal--this
declaration didn't really make much sense anyway, as fmt-internal is a
global function, so module-based privacy is not enforceable.
2020-06-19 10:30:55 -04:00
scottolsen
ccd270f956 Regenerate docs 2020-06-19 09:19:59 -04:00
scottolsen
6b9064f9af Generate Opaque docs (again) 2020-06-19 09:19:04 -04:00
scottolsen
da3be90b55 Merge branch 'master' of https://github.com/carp-lang/Carp into opaque 2020-06-19 09:18:34 -04:00
Erik Svedäng
753deaf0e6
Merge pull request #862 from Vertmo/fix-nesteddefn-eval
Generalization of the evaluation of static defn
2020-06-19 09:44:11 +02:00
Erik Svedäng
15bdf38f23
Merge pull request #888 from hellerve/veit/phantoms
core: add Phantom
2020-06-19 09:30:42 +02:00
Erik Svedäng
12b9586ef1
Merge pull request #887 from scolsen/allow-interior-type-vars
Allow "phantom constructors"
2020-06-19 09:28:40 +02:00
Erik Svedäng
84970e48dc
Merge pull request #892 from Vertmo/glfw-constants
Added some of GLFW constants
2020-06-19 07:50:22 +02:00
Basile Pesin
3b258badce Added some of GLFW constants 2020-06-18 23:19:31 +02:00
scottolsen
b63f981575 Update Opaque docs; fix typos 2020-06-18 09:57:28 -04:00
scottolsen
5c170239c8 Generate docs for Opaque 2020-06-18 09:50:29 -04:00
scottolsen
becf6f09fa Add Opaque to doc generation 2020-06-18 09:47:46 -04:00
scottolsen
204ebc85e4 Load the Opaque type 2020-06-17 18:16:58 -04:00
scottolsen
b3a5ab8622 Add the Opaque type
The opaque type is an uninhabited type with no constructors.  Opaque can
be used to force some abstract type to range over a type constructor
without concerning oneself with the inhabitant of the constructor--in
other words, it may be used to enable a type to work for all inhabitants
and can express relationships between types. It can facillitate generic
programming.

Consider an example:

```
;; The type of indicies over containers of a single type argument
(deftype (Index (f Opaque) b) [at b])

(definterface tabulate (Fn [(Ref (Fn [(Index (f Opaque) b)] c))] (f c)))
(definterface positions (f (Index (f Opaque) b)))

(implements tabulate tabulate)
(defn tabulate [h]
  (fmap h @&positions))

(deftype (Tuple a) [x a y a])

(defmodule Tuple
  (sig positions (Tuple (Index (Tuple Opaque) Bool)))
  (def positions (Tuple.init (Index.init true) (Index.init false)))
)
```

In the above example, the Opaque type allows us to define tabulate
generically defined over Tuples without having to ensure their
inhabitants match, allowing us to fully determine the resulting values
type via tabulate's function argument. Without Opaque, Index would
contain a generic type which would be unreseolved upon the call to
`tabulate`. It allows us to ensure the `positions` we call are the
positions of the correct constructor type `f` wihtout worrying having to
restrict ourselves to only calling `Indexes` over an `f` of a specific
type  (e.g. `(f a)`)--in other words, it allows us to constrain
functions by constructor types only.

Thanks to Opaque, tabulate can generate an `(Array Int)`, `(Array
Bool)`, `(Array String)` all solely dependent on the return type of `h`.
2020-06-17 18:14:23 -04:00
hellerve
1d0944a187 core: add docs for phantom 2020-06-17 19:06:49 +02:00
Scott Olsen
ac5f88afd0 Merge branch 'master' of https://github.com/carp-lang/Carp into allow-interior-type-vars 2020-06-17 01:26:54 -04:00
Scott Olsen
8112ca04d3 Allow vars in polymorphic constructors to be members
Prior to this commit, a type such as: `(deftype (Foo (f a) [bar a]))`
was rejected by the compiler. However, such a type is sensible--Foo
ranges over some container type `f`, and it is essentially Foo's job to
provide a view into `f`, granting access to `a` and whisking `f` away
via the phantom constructor.

After this change, this type definition is now valid.

Note that one often needs to wrap phantom constructor cases in `the`
unless the type can be determined by the overarching context:

```
(deftype (Foo (f a) [bar a]))
(the (Foo (Maybe Int)) (Foo.init 1))
;; => (Foo 1)
```
2020-06-17 01:05:46 -04:00
Erik Svedäng
c0d9350ab3
Merge pull request #878 from scolsen/tips
Add a doc capturing common patterns
2020-06-16 20:10:12 +02:00
Erik Svedäng
c7b926f259
Merge pull request #882 from TheAceShinigami/refactorPredicate
Refactor predicate
2020-06-16 20:09:32 +02:00
Erik Svedäng
b25cebc563
Merge pull request #880 from TheAceShinigami/master
include implemented functions in info
2020-06-16 20:08:56 +02:00
Erik Svedäng
3fffdd2f30
Merge pull request #883 from Vertmo/nested-lambdas-and-implicit-envs
Fixed lambda capture in presence of let bindings
2020-06-16 20:06:50 +02:00
Erik Svedäng
934896d05d
Merge pull request #881 from jacereda/exit-code
Return 0 from main when the return type is unit.
2020-06-16 20:04:04 +02:00
Basile Pesin
94ce645b76 Added a descriptive comment for the new case in collectCapturedVars and removed duplicate code 2020-06-15 21:44:11 +02:00
Basile Pesin
dd6d3e9008 Fixed lambda capture in presence of let bindings 2020-06-15 21:44:11 +02:00
Basile Pesin
aa0a3e7ea9 Improved error message for HasStaticCall 2020-06-15 09:11:25 +02:00
thebarbershaveshimself
965f503cd0 extracted XObj predicates into Obj.hs 2020-06-14 16:31:17 -07:00
Jorge Acereda
1301531032 Return 0 from main when the return type is unit. 2020-06-14 23:32:36 +02:00
thebarbershaveshimself
b8433647f2 include implemented functions in info 2020-06-14 13:23:36 -07:00
Erik Svedäng
fc6d6aa626
Merge pull request #876 from leblowl/bug-843-fix
Attempt at fixing #843
2020-06-14 19:25:23 +02:00
Erik Svedäng
b1615648f2
Merge pull request #873 from TheAceShinigami/master
added error for malformed deftype
2020-06-14 19:23:44 +02:00
Erik Svedäng
2952475f35
Merge pull request #869 from jacereda/no-which
Use POSIX command builtin instead of which to avoid another build dep…
2020-06-14 19:21:42 +02:00
Erik Svedäng
33b86690c6
Merge pull request #868 from scolsen/inter-refactor
Move interfaces code into its own module
2020-06-14 19:17:19 +02:00
Lucas Leblow
59758c33f8 V2 of match-ref-1 regression test 2020-06-14 09:30:49 -06:00
Lucas Leblow
bf7602e609 Add regression test 2020-06-14 09:21:40 -06:00
Scott Olsen
a45f17b6be Update style, remove personal pronouns 2020-06-14 11:01:05 -04:00
hellerve
e5fd0e73f9 core: add phantom 2020-06-14 12:16:45 +02:00
Scott Olsen
fc4f55de36 Add a doc capturing common patterns
The first pattern is one I've found handy for returning some data
structure that contains the results of running two different
ownership-taking functions on some argument.
2020-06-13 23:54:06 -04:00
Lucas Leblow
fd89b64425 Attempt 2; only delete values, not refs 2020-06-13 18:05:37 -06:00
Lucas Leblow
5dd7c03a72 Attempt at fixing 843 2020-06-13 16:19:29 -06:00