Commit Graph

1845 Commits

Author SHA1 Message Date
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
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
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
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
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
thebarbershaveshimself
4547806f67 deleted useless comment 2020-06-13 12:25:39 -07:00
thebarbershaveshimself
8fb044c699 added error for malformed deftype 2020-06-13 12:07:20 -07:00
scottolsen
5955df79c8 Move interface registration functions into Interfaces.hs
This PR moves interface handling code out of Primitives.hs and into its
own module. The actual primitives user's rely on to define and implement
interfaces still live in Primitives.hs, but now all the
registration/internal context mgmt code related to interfaces lives in
its own module.

Hopefully this will make it easier to modify and extend!
2020-06-10 01:02:13 -04:00
scottolsen
131dca342d Refactor Primitives.hs functions
This change mostly just factors out case statements from a variety of
functions using two useful utilities `maybe` and `either`.

Essentially, these functions enable you to express a case against a
Maybe or Either in terms of a function and default value, and generally
help readability. In our case they:

- Allow us to remove tons of repetitive return statements.
- Allow us to remove do's.
- Eliminate some cases and simplify the code structure.

This commit contains no behavioral changes
2020-06-10 00:14:08 -04:00
scottolsen
1c1a29eea4 Refactor primitiveImplements 2020-06-09 16:51:38 -04:00
scottolsen
45f4ad5f07 Refactor primitive(File,Line,Column)
Using `maybe` makes many functions much shorter and hopefully more
manageable. Generally speaking, it allows us to remove case statements
over Maybes.
2020-06-09 15:45:28 -04:00
scottolsen
f6a854ef7b Replace Map manipulations on Meta with Meta module functions
This commit replaces instances that used `Data.Map` functions to
manipulate MetaData with their `Meta` module counterparts. In some cases
this allows us to drop the `Data.Map` dependency. In others, it's still
required since we take a similar approach for Envs--we should eventually
abstract away the underlying Map representation of `Env` too.
2020-06-09 15:00:49 -04:00
scottolsen
6ae3fc3008 Add Meta module
The Meta module does two things:

- Collects functions related to working with Carp MetaData in one place
- Hides the underlying implementation of MetaData
  MetaData is backed by `Data.Map` previously, we'd alter MetaData by
  getting the underlying map directly and calling Map functions to modify
  the contents. The functions in the Meta module encapsulate this--now
  callers may manipulate MetaData without having to know anything about
  the underlying Map implementation. This should make it easier to swap
  out the underlying representation in the future as well.
2020-06-09 14:28:07 -04:00
Erik Svedäng
7e440cae8c
Merge pull request #856 from jacereda/c99fixes
C99 fixes
2020-06-08 22:08:31 +02:00
Erik Svedäng
651c36f0d9
Merge pull request #859 from jacereda/pkgconfig-flags
Add pkgconfigflags.
2020-06-08 21:57:43 +02:00
Basile Pesin
72cc7bfca2 Evaluation for nested static calls 2020-06-07 00:22:39 +02:00
scottolsen
f3aa543fe0 Add a note about issue #521 2020-06-03 11:16:10 -04:00
scottolsen
ff0596ebab Restore tyvar check in constraints; special case interface
Previously, I'd removed the type var check in constraint conflict
checking. This doesn't seem to be problematic, but it might not be the
best way to implement the desired result, which is special conflict
checking for interfaces.

This approach is more conservative and simply bypasses the check for
interface implementation constraint solving only.
2020-06-02 10:54:09 -04:00
Scott Olsen
f062e054dd Merge branch 'master' of https://github.com/carp-lang/Carp into constrained-interfaces 2020-06-02 00:46:00 -04:00
Scott Olsen
7dbb4dd400 Replace conflicting vars with special names 2020-06-02 00:40:49 -04:00
Scott Olsen
94adcc1b30 Allow unification of type vars using the same name
Previously we disallowed unification of type variables with types that
contained the same variable name; e.g. unification of `a` with `(Ref
a)` was disallowed by the type system.

While this was a pain for defining custom struct types, it becomes even
more problematic after the past commit, as, since interfaces now solve a
constraint, it means a n interface (a -> a) cannot be unified with an
implementation ((Ref a) -> (Ref a)).

As it turns out, simply removing this rule causes no evident breakages
or problems, and makes the newly constrained and type rigorous interface
matching more ergonomic to work with in addition to removing the custom
struct definition annoyances.
2020-06-01 23:33:11 -04:00
Scott Olsen
9f5f99a696 Solve for constraints when matching interfaces
Previously, we only checked that interface signatures and implementation
signatures were unifiable. This check is actually not sufficient, and
leads to interface typings that are overly permissive. For example, the
interface (a -> a) unifies with everything, even an implementation typed
(Int -> Double) which is patently incorrect.

Solving a basic constraint between the interface an implementation fixes
this issue.
2020-06-01 23:29:42 -04:00
Scott Olsen
7b2991bb0d Allow "Instantiate" functions to implement interfaces
This change makes it possible to declare auto-derived getter/setter
functions on types as implementations of interfaces, e.g. Pair.a.

The same checks for normal functions apply to the instantiations. For
example, given an interface:

```
(definterface left (Fn [(Ref (f a b))] (Ref a)))
```

`Pair.a` can implement this interface, but `Maybe.Just` cannot--since it
results in a kind mismatch.

I also realized that interfaces are currently too flexible/permissive.
For example, given an interface:

```
(definterface id (Fn [a] a))
```

Most, if not all, functions can implement this interface, even when the
implementation clearly doesn't conform. For example, `Pair.a` or even a
function with the type `([String] Int)` are both valid implementations
of this interface. This is because we currently only check if interfaces
and implementation signatures are unifiable. Since we consider any type
unifiable with a variable, any implementation passes, even when the
argument type and return type are clearly not the same. We'll need to
constraint solve on the interface and implementation signatures to fix
this--since that's a more significant change, it's omitted from this PR.
For now a new TODO will have to suffice.
2020-06-01 20:41:54 -04:00
Jorge Acereda
6656d96791 Add pkgconfigflags. 2020-06-01 21:34:12 +02:00
Erik Svedäng
8715502e05
Merge pull request #850 from Vertmo/fix-nestedlambdas-capture
Fixed the issue with nested capture and nested lambdas
2020-06-01 21:10:14 +02:00
Jorge Acereda
121e3fa56d C99 fixes 2020-05-30 22:37:01 +02:00
Jorge Acereda
543a90ffa0 Add joinLines. 2020-05-30 09:19:26 +02:00
Basile Pesin
4ab29d84ac Fixed the issue with nested capture and nested lambdas 2020-05-28 20:05:27 +02:00
scottolsen
e1a7c3149a Return an error instead of () on invalid s-expressions
`s-expr` accepts either a binding that evaluates to a List or a list
literal such as `'(1 2 3)`. Other forms do not yield s-expressions, and
so we return an error. For example, `(s-expr '[1 2])` returns an error
since an array does not form a list s-expression.
2020-05-27 16:04:34 -04:00
scottolsen
96a9dcf95b Make Sexpression a command, enhance module introspection
Originally, s-expr was a primitive and didn't evaluate its arguments.
This however make it difficult to use, in addition to forcing us to make
an extra unnecessary lookup. This commit converts s-expr to a command,
which makes it a lot simpler to use in macro definitions and in dynamic
code in general.

Additionally, I've enhanced it to do two things:

- Allow users to get the module for a type instead of the definition
  form using an optional argument.
- List the contents of a module upon getting its s-expr.

Many thanks to @hellerve who both suggested this change and advised.
2020-05-27 13:30:35 -04:00
hellerve
0959538d00 parser: add base16 and base2 literals 2020-05-27 11:45:29 +02:00
Erik Svedäng
7a393d38d3
Merge pull request #838 from scolsen/s-epr-interfaces
Improve introspection support for interfaces
2020-05-26 20:44:55 +02:00
Erik Svedäng
4c4bf56c5c
Merge pull request #844 from sdilts/register-type-doc
Improve register-type documentation
2020-05-26 20:34:18 +02:00
hellerve
1d7ef556f2 eval: make ref literals work in the repl 2020-05-26 11:11:27 +02:00
sdilts
f26738ef4e Improve register-type documentation
Add info about specifying c names in the `register-type` docstring
2020-05-25 12:38:52 -06:00
Scott Olsen
9b9aa76b59 Improve introspection support for interfaces
Previously, introspecting an interface only returned `definterface` and
its name. We now return the form corresponding to the interface's types
signature, which enables us to introspect more effectively; e.g.
returning the appropriate arity of an interface.
2020-05-24 17:02:35 -04:00
Erik Svedäng
69ffac4097
Merge pull request #832 from Vertmo/cleanup-types
Separated Types utilities into SymPath.hs and TypesToC.hs
2020-05-24 11:49:14 +02:00
Erik Svedäng
ea372b1728
Merge pull request #827 from jacereda/cmdline-eval
Command line switches to evaluate code
2020-05-24 11:45:44 +02:00
Basile Pesin
8de9a416cb Separated Types utilities into SymPath.hs and TypesToC.hs 2020-05-24 11:08:17 +02:00
Erik Svedäng
2050909302
Merge pull request #831 from scolsen/info-refactor
Info Refactor
2020-05-24 08:51:02 +02:00
Scott Olsen
4a29c6a998 Rename s-exp -> s-expr 2020-05-23 15:42:32 -04:00
Jorge Acereda
1244edd3d2 Comment empty struct rationale. 2020-05-23 19:31:39 +02:00
Scott Olsen
fbc226ce2f Move Info into its own module
Unlike many of the other datatypes in Obj.hs, Info does not introduce
mutually recursive dependencies. Obj.hs is quite large and contains a
lot of different functionality, so I think it helps to move anything
that we can separate out into its own module in order to start
simplifying the Obj.hs and its responsibilities.
2020-05-23 13:09:53 -04:00
Jorge Acereda
6bce3b1ee1 Implement --eval-preload and --eval-postload. 2020-05-22 22:45:46 +02:00
Jorge Acereda
18194b52de Fix REPL main function, it didn't return 0. 2020-05-22 21:31:18 +02:00
Scott Olsen
ce994931d6 Update s-exp doc to account for type precedence
In Carp, types automatically generate modules. When a type binding is
passed to `s-exp` it returns the deftype form rather than the type's
module form.
2020-05-22 11:50:53 -04:00
Scott Olsen
e943490ec7 Return an explicit empty list in s-exp
Before we used dyanmicNil, which, while equivalent to the empty list,
isn't quite the same thing. This new approach ensures an empty list is
actually printed to the REPL.
2020-05-22 11:45:33 -04:00
Scott Olsen
2f9815171e Make error output of s-exp prettier 2020-05-22 11:42:21 -04:00
Scott Olsen
6e72181b3a Remove traces 2020-05-22 01:30:25 -04:00
Scott Olsen
50cffa3246 Map type ddefs to symbols, check the global env
This commit changes the s-exp primitive to lookup paths in the global
env--using the context env isn't sufficient for type/module definitions.
2020-05-22 01:11:11 -04:00
Scott Olsen
505d628b18 Map deftype forms to symbols in primitiveSexpress 2020-05-21 20:21:04 -04:00
Scott Olsen
f4153bfa56 Map special forms to symbols
This commit makes the forms returned by the s-exp primitive usable with
other dynamic functions that operate on symbols. By default, a special
form like `Defn` is *not* a symbol. So, we map all the special forms to
symbols in order to use the returned s-exps smoothly with other dynamic
functions (which operate on symbols).
2020-05-21 20:15:24 -04:00
Scott Olsen
391cede9e0 Handle defmodule cases in s-exp
This is another special case. Instead of `(defmodule Foo)` it will only
return the module name.

Note that we only return the module name if it's actually only a module
and not found in the type environment.
2020-05-21 19:39:39 -04:00
Scott Olsen
0fb209d3fb Add s-exp primitive
This primitive returns the s-expression associated with a binding--in
other words, the form a user wrote to define a binding.

We handle special cases such as interfaces and deftypes, whose original
defining forms are stored in the type environment instead of the global
environment.

Note that presently this doesn't always return *exactly* the form the
user wrote. Specifically, the following cases are special:

- Interfaces -- returns `(interface foo)` instead of the full form
- Defndynamic -- returns `(dynamic foo [x] x)` instead of `defndynamic`
- Defmacro -- returns `(macro [x] x)` instead of `defmacro`

In spite of these wrinkles, I think it's a useful function to have,
particularly for type introspection in dynamic functions/macros.
2020-05-21 19:32:58 -04:00
Jorge Acereda
59ef5bbf2b Added --compile-fast to compile with tcc. 2020-05-21 20:04:54 +02:00
scottolsen
bc4933776f Fix typo in comment. 2020-05-20 23:50:17 -04:00
scottolsen
1b648c9821 Only apply sig constraints to root definitions
Previously, sig constraints were applied to interior let bindings just
the same as they were to root defn forms (due to a recursive call to
genF). Now, we ignore sig constraints *unless* we're constraining the
root definition form (the form that's actually constrained by the sig).

Now that sigs are being unified correctly, this over-constraining caused
issues with any functions using let bindings to anonymous functions
since the lambdas were constrained by the defined functions signature.
See Binary.unsafe-bytes->int16-seq and family for one example.
2020-05-20 23:33:09 -04:00
scottolsen
088a871489 Update sigFromDefnOrDef to handle relative definitions
Previously, sig resolution for definitions inside of modules didn't work
because this function didn't check for relative paths. This meant that
pretty much all signatures weren't honored, since forward declarations
of metadata only work within the context of modules, and so are
unqualified paths (the right module qualifications need to be extracted
from the Context).
2020-05-20 18:09:10 -04:00
scottolsen
502eb60fb7 Unify similar primitiveMeta cases
The two success cases on SymPaths were quite similar, so, I've factored
out the pattern match into a case clause, and the shared logic into a
local binding.
2020-05-20 09:43:51 -04:00
scottolsen
402696158f Fix type inconsistency 2020-05-19 17:32:47 -04:00
scottolsen
7bf67db992 Make lookupInterfaces and define respect interface lists 2020-05-19 17:30:25 -04:00
scottolsen
36f21f0620 Don't duplicate implementations
Previously, if one called:

```
(implements inc "foo")
(implements inc "foo")
```

It would result in duplication in the implements meta `(inc inc)`.

This commit resolves that issue--interfaces will only be added to the
`implements` meta if they're not already present.
2020-05-19 16:13:17 -04:00
scottolsen
000befe264 Update primitiveMeta; make primitiveImplements take a list
This commit does two things:

1. Updates `primitiveMeta` to handle a previously unhandled case, a
   qualified name in a module.

   Before `meta` use to fail to find its argument binding in a cases
   like this one:

   ```
   (defmodule Foo (hidden bar) (meta Foo.bar "hidden"))
   ```

   This is because `meta` used to cons path strings to the path even if
   the path was already qualified with a module name as in the example
   above. We now treat these cases separately, and instances like the
   above work.

2. Update `primitiveImplements` to set the implements meta to a dynamic
   list of interface names, instead of a single interface.

   This makes sense since functions could implement multiple generic
   interfaces. An example of the new behavior:

   ```
   (implements inc foo)
   (implements dec foo)
   (meta foo "implements")
   => (dec inc)
   ```
2020-05-19 16:03:37 -04:00
hellerve
32d4095a5d core: make NULL Ptr a instead of a 2020-05-18 23:21:16 +02:00
hellerve
b9b5ffba45 parse: add \return, \backspace, \formfeed, and \u unicode literals 2020-05-17 12:02:42 +02:00
Dhananjay Balan
8d769800ef Add FreeBSD as a supported platform 2020-05-13 13:45:01 +02:00
Erik Svedäng
dcca7505d1
Merge pull request #786 from hellerve/veit/move-to-templates
Move templates out of the compiler into deftemplates
2020-05-12 22:24:54 +02:00
Erik Svedäng
aae743fb35
Merge pull request #769 from scolsen/implement-prim
Add an `implements` primitive, update core
2020-05-12 21:45:29 +02:00
scottolsen
89a445ef43 Add a TODO about deduping Lookup code 2020-05-12 14:08:22 -04:00
hellerve
fce423aee9 core: move as many templates as possible out of the compiler 2020-05-12 12:44:17 +02:00
hellerve
d2235112dd core: move the first function into carp template 2020-05-12 11:32:26 +02:00
Jorge Acereda
2186b34e94 Roll our own UTF-8 support. 2020-05-12 01:14:02 +02:00
scottolsen
681054be63 Merge branch 'master' of https://github.com/carp-lang/Carp into implement-prim 2020-05-11 14:42:11 -04:00
scottolsen
446972f5be Emit warnings when undefined interfaces are implemented
We'll now emit a nice warning when a user implements an interface that
isn't defined. Retro active registry still works--so if the user defines
the interface before calling the function, the implementation is
registered correctly, so we only show a warning since so long as the
interface is defined before use, implementing it before it's defined is
OK.
2020-05-11 14:06:32 -04:00
Jorge Acereda
c6bcd67523 Allow unicode identifiers 2020-05-11 16:10:41 +02:00
Jorge Acereda
9b08b6df3c Merge 2020-05-11 16:10:35 +02:00
Jorge Acereda
83e8c1a874 Fix Char_str(). 2020-05-11 16:08:40 +02:00
Erik Svedäng
ac2ad0c760 Will emit Fn instead of λ on all platforms. 2020-05-11 13:31:00 +02:00
Erik Svedäng
935e91e3b3 Enforce UTF-8 encoding when saving main.c 2020-05-11 12:52:14 +02:00
Scott Olsen
70e97f82f8 Merge branch 'master' of https://github.com/carp-lang/Carp into implement-prim 2020-05-10 23:19:32 -04:00
Scott Olsen
e6f8f3aff1 Pass the correct interface name
Previously, I was passing the wrong binding into the typeenv, causing
interface overwrites. This fixes that issue -.-.
2020-05-10 12:38:01 -04:00
Scott Olsen
0be5a8db59 Add missing period to implements docstring 2020-05-10 01:21:58 -04:00
Scott Olsen
a2721bafd5 Make lookups generic, recursively lookup impls
Before, we were only looking up interface implementation in a single
context. We needed to use something like MultiSymLookup, but on the
presence and value of a meta key, rather than a binder name.

So, I extracted the local fns in multiSymLookup out into their own
functions and make lookup functions generic, and of the type:

LookupFunc :: a -> Env -> [Binders]

This seems to suit most purposes. Eventually, MultiSymLookup can be
redefined in terms of these simpler lookup mechanisms.
2020-05-10 00:12:12 -04:00
Scott Olsen
240f017b62 Toward support for retroactive registry? 2020-05-09 17:10:12 -04:00
Scott Olsen
2a81565b54 Allow implements to be called before defining
This commit makes the implements primitive work similar to `doc`--If one
calls it before a function is defined, once the definition is provided,
it will auto-implement an interface.
2020-05-09 16:15:08 -04:00
scottolsen
040e9e4391 Add an implements primitive, update core
This change adds a new primitive Implements which changes interface
implementations from being implicit to being explicit. Going forward,
users will have to declare (implements <interface> <implementation>) to
explicitly add a function to an interface. This provides two benefits:

- Prevents unwitting name clashes. Previously, if one defined a function
  that happened to have the same name as an interface, it was
  automatically assumed the function implemented that interface when this
  is not always the intention, especially in large programs.
- Name flexibility. One can now implement an interface with a function
  that has a different name than the interface, which allows for greater
  flexibility.

I've updated core to make the necessary calls to the new primitive.

Since str and copy are derived automatically for types, we treat these
functions as a special case and auto-implement the interfaces.
2020-05-09 12:59:47 -04:00
Nils 'Linkie Pi' Reid
b132f4f922 Merge branch 'master' of https://github.com/carp-lang/Carp into dynamic-while 2020-05-09 09:28:42 +02:00
Erik Svedäng
33cf195369
Merge pull request #762 from linkpy/graceful-defmodule-errors
Graceful handling of invalid usages of `defmodule`.
2020-05-09 09:17:30 +02:00
Erik Svedäng
94e49ae61a
Merge pull request #763 from hellerve/veit/set-and-let
Make dynamic set! and let interplay nicely
2020-05-09 09:16:09 +02:00
Erik Svedäng
2a9a54cdcf
Merge pull request #759 from scolsen/constructors-are-functions
Make polymorphic struct types and functions unifiable
2020-05-09 09:04:25 +02:00
Nils 'Linkie Pi' Reid
4228eeb425 Fixes a mistake in the error cases of primitiveDeftemplate. 2020-05-08 18:09:54 +02:00
hellerve
3890cb8258 test: add regression test for nested lets and set! 2020-05-08 18:01:35 +02:00
hellerve
e9a9f2517b eval: make set! and let interplay nicely 2020-05-08 17:58:03 +02:00
Nils 'Linkie Pi' Reid
40f31aba38 Corrected the invalid usage cases of primitiveDeftemplate. 2020-05-08 17:57:57 +02:00
Nils 'Linkie Pi' Reid
05a8a4458d Reworded the error messages for deftemplate to keep consistency. 2020-05-08 17:01:51 +02:00
Nils 'Linkie Pi' Reid
abc490dbcf Changed Symbol to symbol in the error messages for defmodule for consistency. 2020-05-08 16:56:57 +02:00
Nils 'Linkie Pi' Reid
7c24e2d400 Adjusted one of the error message when defmodule isn't correctly used. 2020-05-08 16:39:46 +02:00
Nils 'Linkie Pi' Reid
9520e90d78 Added cases to primitiveDefmodule to gracefully handle invalid usages. 2020-05-08 16:35:11 +02:00
Nils 'Linkie Pi' Reid
5410b38375 Implemented the while structure in the evaluator. 2020-05-08 16:14:00 +02:00
Nils 'Linkie Pi' Reid
06c01d399a Merge branch 'master' of https://github.com/carp-lang/Carp into inline-c 2020-05-08 15:19:03 +02:00
Nils 'Linkie Pi' Reid
9772bc20f9 Fixed the issues with deftemplate.
Removed `inline-c` command.
2020-05-08 15:08:36 +02:00
Nils 'Linkie Pi' Reid
104637d6de Implemented the deftemplate command. 2020-05-08 14:49:56 +02:00
Erik Svedäng
28527c2826
Merge pull request #760 from hellerve/veit/command-docs
Document and enforce documentation on registration
2020-05-08 13:10:25 +02:00
hellerve
fe9d6050b5 primitives: fix example usage string 2020-05-08 12:19:34 +02:00
hellerve
2fcccdc87d commands: fix example usage string 2020-05-08 12:18:43 +02:00
hellerve
b27fa1dec5 commands: document and enforce documentation on registration 2020-05-08 12:14:20 +02:00
Erik Svedäng
1fa9de140e Fix for #721, plus adds support for more cases of calling static code from repl. 2020-05-08 11:51:04 +02:00
Nils 'Linkie Pi' Reid
be3ccbd8e3 Removed StringUtils which is replaced by rawstrings. 2020-05-08 09:57:36 +02:00
Nils 'Linkie Pi' Reid
632ee6c65f Removed an unused import.
Changed the error reporting of `inline-c`.
2020-05-08 09:55:54 +02:00
Scott Olsen
cd9e46990c Make Structs and Functions unifiable
This commit makes function types unifiable to *only* polymorphic
constructors (StructTy with a VarTy name). This enables one to implement
interfaces defined against constructors against functions so long as:

- The number of function arguments match the number of type constructor
arguments.

Thus, one can define:

```
(definterface constructor (Fn [(f a b)] (f a b)))
(defmodule Test (defn constructor [f] (the (Fn ([a b] a) f))))
```

But how is this useful?

Here's one scenario this corrects in practice. In Haskell, the `some`
function is typed generically as `some :: f a -> f [a]`. `some` takes a
type and successively  applies it until it returns an empty value, then
it returns a list of results of the applications. This is great for
types that actually have state, such as parsers, but for many values of
`f` it makes no sense. E.G. given a `Maybe` the function will never
terminate, since `Maybe.Just x` will never transform into the empty
value on its own. This problem is even worse when we don't have inherent
laziness to help us short-circuit application where possible.

In fact, using an obvious definition of `some`, a function is the only
(non-bottom) type in the `f a` position that may lead to eventual
termination without requiring rewriting `some` to explicitly match
against values. One could tuck a function away in a type constructor and
devise a clever enough instance of choice to make this work, but it's
simpler to define it against a function.

Another case: type equivalences. When types are unifiable with
constructors, it gives us an easy way to define concepts generically
across types and functions.

```
(definterface app (Fn [(f a) a] a))
(defmodule Func (defn app [f x] (f x)))
(defmodule Maybe (defn app [m x]
  (match m (Maybe.Nothing) (Maybe.Nothing)
           _ (Maybe.Just x))))
:i app
app : (Fn [(f a), a] a) = {
      Func.app
      Maybe.app
}

(definterface compose (Fn [(f a) (f b)] (f c)))
(defmodule Func (defn compose [f g] (fn [x] (f (g x)))))
:i Func.compose (Fn [(Fn [a] b c), (Fn [d] a c)] (Fn [d] b e))
;; In this case, we define composition as the explicit application of
;; the product
(defmodule Maybe (defn compose [ma mb]
  (let [x (match ma (Maybe.Nothing) (zero)
                    (Maybe.Just a) a)
        y (match mb (Maybe.Nothing) (zero)
                    (Maybe.Just b) b)]
    (Maybe.Just (Pair x y)))))
:i compose
compose : (Fn [(f a), (f b)] (f c)) = {
      Func.compose
      Maybe.compose
}
```

In a more general sense, this would enable us to use functions as a
constructor type, analogous to the use of (->) in haskell. The gist is,
this commit will let us extend our higher-kinded generic functions to
functions.
2020-05-07 23:59:43 -04:00
Nils 'Linkie Pi' Reid
9b0d85702d Merge branch 'master' of https://github.com/carp-lang/Carp into inline-c 2020-05-07 21:22:10 +02:00
Erik Svedäng
570d775156
Merge pull request #756 from linkpy/rawstrings
Rawstrings
2020-05-07 20:38:58 +02:00
scottolsen
9afbd35d27 Remove left-over trace 2020-05-07 12:59:59 -04:00
scottolsen
72df8b942b Support sumtypes with higher-kinded members
This commit does two things:

- Update validate to permit type defintions like:
  `(deftype (Higher (f a)) (Obj [(f a)]))`
- Replace all type vars in such cases so that we generate the correct C
  code.
2020-05-07 12:55:14 -04:00
Nils 'Linkie Pi' Reid
516e142003 Added rawstrings. 2020-05-07 18:53:37 +02:00
Nils 'Linkie Pi' Reid
947ec26a8e Made the inline-c command to accepts quoted symbols. 2020-05-07 15:18:47 +02:00
Nils 'Linkie Pi' Reid
c53032fab8 Moved the InlinedC to Binders so they support reloading. 2020-05-07 15:18:44 +02:00
Nils 'Linkie Pi' Reid
8fc614862a Fixed the inline-c function to correctly handle escaped chars in the C code. 2020-05-07 15:18:29 +02:00
Nils 'Linkie Pi' Reid
c2ffb4c509 Made the inline-c command to split the strings it receives by \n. 2020-05-07 15:18:29 +02:00
Nils 'Linkie Pi' Reid
1b6954b213 Added the inline-c command and its C emision. 2020-05-07 15:18:27 +02:00
scottolsen
e1b1a74861 Update structty scoring to handle ConcreteNameTy 2020-05-07 15:17:45 +02:00
Nils 'Linkie Pi' Reid
5bc08f200c WIP 2020-05-07 15:17:45 +02:00
Erik Svedäng
3ddf34f62d Note about transformation. 2020-05-06 17:00:01 +02:00
scottolsen
e990176192 Fix non-exhuastive patterns in concretize
This change supports more flexible Sumtype declarations.

We used to allow a sumtype declaration such as:

`(deftype (State a) Done (Value [a]))`

Which the compiler accepts. However, concretization for this type
failed, since we didn't handle the solitary Sym case `Done` when
concretizing the type.

This commit fixes that issue, so that now the following works:

```
(deftype (State a) Done (Value [a]))
;; Omitting the type annotation here would result in the obvious
;; unresolved generic type error.
(defn emit-done [] (the (State Int) (State.Done)))
(emit-done)
;; => State.Done
```
2020-05-06 10:42:47 -04:00
Erik Svedäng
672c7e1b69 FIX for issue #698, meta-set! was inserting modified modules at wrong
path (creating duplicate modules).
2020-05-06 14:26:46 +02:00
Erik Svedäng
28042c21aa Better error when too many dependency functions are found. 2020-05-06 13:04:08 +02:00
Erik Svedäng
8f2347a123 Only let force reload affect reloading, not the flag set on loads. 2020-05-06 10:38:55 +02:00
Erik Svedäng
12ec75ba8b Can configure 'force-reload' that makes 'load-once' work just like 'load'. 2020-05-06 10:27:10 +02:00
Erik Svedäng
870d549da9 Merge branch 'master' into do-not-reload-core-libs 2020-05-06 10:08:56 +02:00
Erik Svedäng
9c3efc4418
Merge pull request #752 from scolsen/constraint-fix
Solve for polymorphic constructor constraints
2020-05-06 10:06:28 +02:00
Scott Olsen
dccd624a13 Solve for polymorphic constructor constraints
Looks like I forgot a tiny but important change for the polymorphic
constructor support--constraint solving!

I only found this out when refactoring an applicative <*> or 'sequence'
definition-- the definition has a polymorphic constructor with a
function argument: `(f (Fn [a] b))`.

When carp attempted to resolve this type against a type returned by lift
which has the type `[a] (f a)`, a generically lifted value, including
functions, it complained:

`can't match (r1 r2)` with type `(r3 (Fn [r4] r5))`. (numbers are
arbitrary here and just for illustration).

Sure enough, we weren't solving for such a constraint. The constraint
resolution now works as expected.
2020-05-05 23:41:53 -04:00
Scott Olsen
7fc8a6ab2e Simplify CheckKinds implementation using recursion 2020-05-05 22:52:03 -04:00
Scott Olsen
deb1ecd51a Revert debugging change in TypeError 2020-05-05 22:40:37 -04:00
Scott Olsen
fc045f6957 Update error messaging for kinds
I've updated the UninhabitedConstructor type error message based on
@hellerve's excellent suggestion. I've also tried to make the kind
mismatch interface error clearer.
2020-05-05 22:35:36 -04:00
Scott Olsen
56d3b02d0f Address minor formatting issues
I removed commented code; fixed a spacing issue, and removed unnecessary
type annotations in Int.carp.
2020-05-05 22:24:31 -04:00
scottolsen
6431f4bb14 Merge branch 'master' of https://github.com/carp-lang/Carp into kind-checking 2020-05-05 17:00:28 -04:00
scottolsen
0686c0420f Fix typo in UninhabitedConstructor error 2020-05-05 15:02:05 -04:00
scottolsen
0fa8da9d95 Ensure type members are inhabited; add error
This change checks that members of struct types are completely
inhabited. Using uninhabited constructors was previously allowed, but
led to errors.

After this commit, declarations like:

```
(deftype Foo [pos Maybe])
```

Will throw a repl error.
2020-05-05 14:21:26 -04:00
scottolsen
38d063ad44 Add kinds checking for interfaces.
This commit adds basic kinds checking on interfaces, such that an
interface that takes a type constructor (f a) can't be implemented by a
function using a concrete type like `Int` in that position.
2020-05-05 11:23:25 -04:00
Erik Svedäng
e1fc59ef3a Fix for #545. 2020-05-05 16:36:33 +02:00
Erik Svedäng
1466b228db Less noise. 2020-05-05 15:07:41 +02:00
Erik Svedäng
ca804beace Added support for (load-once). 2020-05-05 15:00:57 +02:00
Erik Svedäng
6f70dbd18e Merge branch 'master' into match-on-refs 2020-05-05 13:57:58 +02:00
Erik Svedäng
685a627356
Merge pull request #746 from scolsen/polymorphic-constructors
Polymorphic Constructors
2020-05-05 09:53:56 +02:00
Erik Svedäng
d86af17516
Merge pull request #743 from linkpy/c-type-aliases
Registered type aliasing
2020-05-05 09:46:48 +02:00
Erik Svedäng
9951468a5a
Merge pull request #742 from hellerve/veit/fix-719
Make primitives proper AST objects
2020-05-05 09:45:00 +02:00
scottolsen
8280105399 Pass the right set of mappings to the constraint solver 2020-05-04 17:44:31 -04:00
scottolsen
317c6ff3d7 Solve for polymorphic constructor constraints
Now that constructors can be polymorphic, we need to support resolving
constraints for that case.
2020-05-04 17:28:56 -04:00
scottolsen
93ad2debd6 Add missing case to Validate.hs 2020-05-04 16:03:26 -04:00
Nils 'Linkie Pi' Reid
2a24d2c38c Refactored 2020-05-04 21:36:33 +02:00
Nils 'Linkie Pi' Reid
e1bd09bbad Fixed a typo. 2020-05-04 21:22:13 +02:00
Nils 'Linkie Pi' Reid
5850b71b19 Made the syntax (register-type Name "c_name") to work. 2020-05-04 21:22:13 +02:00
Nils 'Linkie Pi' Reid
de480a934c Made a ExternalType (Just String) to emit a typedef line.
Made the syntax `(register-type ABC "abc" [fields])` to work.
Forced the scoring of a `ExternalType` to 0 to avoid emitting code before the actual typedef.
2020-05-04 21:22:13 +02:00
Nils 'Linkie Pi' Reid
d7f315a03e Reverted Carp's version to its original value. 2020-05-04 21:22:13 +02:00
Nils 'Linkie Pi' Reid
3d250cc65b WIP 2020-05-04 21:22:07 +02:00
scottolsen
8dbdb73c1a Wrap struct names in primitives in ConcreteNameTy 2020-05-04 12:52:37 -04:00
scottolsen
fa8aacb47a Wrap struct names in Sumtypes in ConcreteNameTy
I've also removed a swap file that I accidentally must have commited >.>
2020-05-04 12:51:19 -04:00
scottolsen
91072d9aec Wrap struct names in deftype in ConcreteNameTy 2020-05-04 12:46:42 -04:00
scottolsen
74df915149 Wrap staticarray templates in ConcreteNameTy 2020-05-04 12:41:02 -04:00
scottolsen
620b834d37 Wrap all Array template structs in ConcreteNameTy 2020-05-04 12:37:49 -04:00
scottolsen
0e071fb6fe Update Emit to handle ConcreteNameTy 2020-05-04 12:32:30 -04:00
scottolsen
104917c51c Update concretize to handle ConcreteNameTys 2020-05-04 12:29:34 -04:00
scottolsen
24f8c0738e Fix whitespace error in Validate.hs 2020-05-04 12:14:30 -04:00
scottolsen
40252acf7c Add ConcreteNameTy handling to constraint generation 2020-05-04 12:12:43 -04:00
scottolsen
0cd6503883 Update type validation to handle ConcreteNameTy 2020-05-04 12:10:41 -04:00
scottolsen
4cd5fba580 Update AssignTypes to handle ConcreteNameTys 2020-05-04 11:59:48 -04:00
scottolsen
d3eeb243c2 Update InitialTypes to handle ConcreteNameTys 2020-05-04 11:56:19 -04:00
scottolsen
5468998fe7 Update structty scoring to handle ConcreteNameTy 2020-05-04 11:48:22 -04:00
scottolsen
c092aa3c8b Update lookup code to match against ConcreteNameTys 2020-05-04 11:45:34 -04:00
scottolsen
5168c3b9b2 Update Obj<->Ty handling for Structs
Now that structs may have a variable in the constructor position, I've
updated the Obj to Ty (and inverse) translations to account for vars or
concrete type names.
2020-05-04 11:33:27 -04:00
scottolsen
ab4cd499db Add ConcreteNameTy
In order to support polymorphic constructors (higher-kinds) we'll need
to resolve type variables in the constructor position, such as (a b).

This is a first step toward supporting polymorphic constructors. We add
a new type to represent concrete struct names, and have updated the
struct type resolving code to handle the presence of variables and
resolve to the new ConcreteName type.
2020-05-04 11:18:23 -04:00
Nils 'Linkie Pi' Reid
22a112c959 Made invalid usages of register-type to gracefully errors out. 2020-05-04 17:11:24 +02:00
Nils 'Linkie Pi' Reid
e7fd3bbd42 Changed the handler to only accept 1 field list. 2020-05-04 17:05:58 +02:00
Erik Svedäng
3e98719ec2 Important TODO. 2020-05-04 13:56:45 +02:00
Erik Svedäng
5ebd1abcc8 Bug is fixed, tests run. 2020-05-04 11:50:49 +02:00
Erik Svedäng
7bcecd9b7c Undo, that didn't work. 2020-05-04 10:28:24 +02:00
Erik Svedäng
854a93c07e This fixes the returing-a-ref bug for inner forms, defns still don't work. 2020-05-04 10:10:22 +02:00
hellerve
e867a5a977 primitives: document 2020-05-01 13:43:53 +02:00
hellerve
a761b561e3 all: use dynor and dynand 2020-05-01 12:50:31 +02:00
hellerve
10a76a20fc all: make primitives proper ast types 2020-05-01 11:59:51 +02:00
hellerve
7e20fc022a eval: make Dynamic.or and Dynamic.and primitives (fixes #718) 2020-05-01 10:05:13 +02:00
Erik Svedäng
b63b940799
Merge pull request #725 from hellerve/veit/add-bit-width
Add bit-width command
2020-04-30 13:34:41 +02:00
Erik Svedäng
8e04cb476e Renamed Dynamic.String.join and Dynamic.Symbol.join to concat. 2020-04-30 13:32:54 +02:00
Erik Svedäng
4988b40945 Nested sumtypes work with match-ref too. 2020-04-30 12:42:23 +02:00
Erik Svedäng
9a3aa2d130 Matching on refs generates correct C. 2020-04-30 11:20:05 +02:00
Erik Svedäng
1ba44c3ff4 Bugfix. 2020-04-30 10:58:39 +02:00
Erik Svedäng
f2808686d8 Created a specific function for generating constraints for case
matchers, instead of relying on the one for functions.
2020-04-30 10:48:24 +02:00
Erik Svedäng
6ef83fe8d1 Merge branch 'master' into match-on-refs 2020-04-30 10:10:03 +02:00
scottolsen
11691579bb Remove extra lines 2020-04-29 17:57:07 -04:00
scottolsen
f4f94a2f26 Handle nested sumtypes in match lhs
By rolling back previous changes we lost nested sumtype matches. This
restores that capability.
2020-04-29 17:38:12 -04:00
scottolsen
9dbabf4c53 Extend inner environments with lhs case bindings
Previously, we'd stopped doing this, but it leads to issues with matches
on functions, e.g.

```
(deftype A (F [(Fn [] Int)]))

(defn m [a]
  (match a
    (A.F f) (f)))

(defn main []
  (println* (m (A.F (fn [] 123)))))
```

Will result in a runtime error if the environment isn't extended.
2020-04-29 17:01:42 -04:00
hellerve
5e41e0dcc3 repl: rename concat to concatenated 2020-04-29 19:39:51 +02:00
hellerve
a88e4f6fbf core: add toggle for balance hints 2020-04-29 19:39:00 +02:00
hellerve
15d011accc repl: show the unclosed parens and brackets in the prompt in multiline input 2020-04-29 19:39:00 +02:00
Erik Svedäng
14111d00f9 Prep. 2020-04-29 16:46:56 +02:00
Erik Svedäng
f12833828f Helper function. 2020-04-29 16:35:48 +02:00
Erik Svedäng
00d6506f41 Compiles, but crashes due to freeing the bound variable of the ref. 2020-04-29 15:43:09 +02:00
Erik Svedäng
3f132604f6 Added a variation on match; match-ref. 2020-04-29 15:19:11 +02:00
Erik Svedäng
2bf5649751 Also add templates to interfaces. 2020-04-29 14:40:54 +02:00
Erik Svedäng
6f692e93a8 Working on match. 2020-04-29 14:39:03 +02:00
Erik Svedäng
abe61691a3 Nested sumtypes work. 2020-04-29 13:44:13 +02:00
Erik Svedäng
e96259fe7e Merge branch 'master' into match-on-refs 2020-04-29 11:35:36 +02:00
Erik Svedäng
89dcad4e79 Merge branch 'master' into static-arrays 2020-04-29 10:39:44 +02:00
Erik Svedäng
979077b388 Some cleanup and start of tests for Static Array. 2020-04-29 10:39:15 +02:00
Erik Svedäng
14b608a36e Static array kinda works now. 2020-04-28 10:06:17 +02:00
hellerve
30ed0ae8c3 all: various long fixes 2020-04-23 21:50:30 +02:00
Erik Svedäng
98d4538efc Example. 2020-04-23 14:35:49 +02:00
Erik Svedäng
90e4c21121 Use '$' as sigil instead. 2020-04-23 11:16:37 +02:00
Erik Svedäng
affcbe2330 Use #[] as syntax instead. 2020-04-23 10:20:37 +02:00
Erik Svedäng
57e3330204 Change syntax. 2020-04-23 10:05:22 +02:00
Erik Svedäng
689d8f1390 Added (fake) deleter for static array. 2020-04-23 10:01:37 +02:00
Erik Svedäng
9853fba9d6 Progress, but can't use the ref to the StaticArray at all since it's
referring to something that's not "alive" according to memory system.
2020-04-23 09:43:32 +02:00
Jorge Acereda
a6055eec5f Long type to ensure longs are actually 64 bits. 2020-04-22 10:40:06 +02:00
hellerve
cd2c49e49c commands: add bit-width 2020-04-22 09:36:44 +02:00
Erik Svedäng
63e083f7bd Can generate some code for static arrays. 2020-04-21 17:32:18 +02:00
Erik Svedäng
7a63ad5449
Merge pull request #716 from hellerve/veit/fix-713
Guard against calling main directly
2020-04-21 07:37:42 +02:00
hellerve
7fc9432179 eval: build and run on main 2020-04-20 10:22:21 +02:00
hellerve
3c033204d8 eval: guard against calling main directly 2020-04-18 12:15:05 +02:00
hellerve
a25dba2e03 eval: generate deps of autogenerated main function 2020-04-18 09:24:49 +02:00
Erik Svedäng
3b1c9607c8
Merge pull request #695 from hellerve/veit/new-evaluator
New evaluator
2020-04-17 14:45:30 +02:00
hellerve
a52c02be29 eval rewrite: rebase changes 2020-04-17 12:29:21 +02:00
hellerve
7c7bb71584 eval: final rewrite version 2020-04-17 11:58:28 +02:00
hellerve
22c53406a3 all: fixes for new evaluator 2020-04-17 11:58:28 +02:00
hellerve
e2b52655ef eval: initial working rewrite 2020-04-17 11:58:28 +02:00
hellerve
aca498d3e0 interim 2020-04-17 11:58:28 +02:00
hellerve
c3358ed4c5 interim 2020-04-17 11:58:28 +02:00
hellerve
6185099044 interim 2020-04-17 11:58:26 +02:00
hellerve
b6f045f992 eval: make defined? point to right primitive 2020-04-17 11:56:05 +02:00
hellerve
25732af8f0 interim 2020-04-17 11:56:05 +02:00
hellerve
488ab414fc eval: better error messages with info 2020-04-17 11:56:05 +02:00
sdilts
3bd1766498 print lisp form instead of internal representation
When invalid syntax is reached, print out offending form
with line source information instead of the internal representation.
2020-04-17 11:56:05 +02:00
hellerve
95458a2458 repl: remove unneeded import 2020-04-17 11:56:05 +02:00
hellerve
378906329e repl: make multi code blocks work again 2020-04-17 11:56:05 +02:00
hellerve
a5e0ca2432 core: print info if only symbol is entered on repl 2020-04-17 11:56:05 +02:00
hellerve
680278cd69 eval: add capability to call a function directly 2020-04-17 11:56:05 +02:00
hellerve
151199fd7e repl: add :i for info 2020-04-17 11:56:05 +02:00
hellerve
88a0fbd0e3 eval: don’t pretty unit at the repl 2020-04-17 11:56:05 +02:00
hellerve
8b11a997b4 eval: cleanup 2020-04-17 11:56:05 +02:00
hellerve
fd78bf07a9 eval: feature parity 2020-04-17 11:56:05 +02:00