and binop, *-macros

This commit is contained in:
Erik Svedäng 2016-04-27 21:09:43 +02:00
parent 43fd972ef5
commit 05efae290d
7 changed files with 53 additions and 4 deletions

14
LIBRARIES.md Normal file
View File

@ -0,0 +1,14 @@
# Core Libraries
See ```lisp/core.carp```
# GL
See ```lisp/gl.carp```
# The '*' macros
Since the functions in Carp can't accept a variable number of args there are a bunch of helper macros that allows you to circumvent this limitation. Here are some examples:
```clojure
(str* "This string " "and this string, here's a number " 123 ", etc...")
(println* "X = " x ", Y = " y)
(and* true false false true false)
```

View File

@ -34,7 +34,7 @@
- Macro splicing
- Modules
- A Set-type with reader syntax #{}
- Instantiate generic functions like '=' for primitive types
- Instantiate generic functions like '=' for primitive types when calling them
## Modules
- Name

View File

@ -5,6 +5,19 @@
;;(reset! log-deps-when-baking-ast true)
;; (defn and-internal [forms]
;; (match forms
;; (a b) (list 'and-binary a b)
;; (a ... xs) (list 'and-binary a (and-internal xs))))
;; (defmacro and* [... forms]
;; (and-internal forms))
;; (defn use-and []
;; (if (and* true true false true)
;; @"YES"
;; @"NO"))
;; (bake use-and)
;;(tester/run-suite "")

View File

@ -25,7 +25,7 @@
(defn binop? [form]
(match form
(x ... _) (contains? '(+ - * / <) x)
(x ... _) (contains? '(+ - * / < and) x)
_ false))
(defn gen-fn-type [arg-count]
@ -42,7 +42,9 @@
(if (binop? l)
(match l
(op left right) {:node :binop
:type (gen-typevar)
:type (if (= op 'and)
:bool
(gen-typevar))
:op op
:left (form-to-ast left)
:right (form-to-ast right)})

View File

@ -3,6 +3,7 @@
;; (reset! profile-infer-time true)
;; (reset! profile-external-compiler-time true)
(load-lisp (str carp-dir "lisp/test_binops.carp"))
(load-lisp (str carp-dir "lisp/test_printing.carp"))
(load-lisp (str carp-dir "lisp/test_equality.carp"))
(load-lisp (str carp-dir "lisp/test_globals.carp"))

17
lisp/test_binops.carp Normal file
View File

@ -0,0 +1,17 @@
(tester/set-suite! "binops")
(deftest test-and-1
(do
(defn use-and-1 []
(and true false))
(bake use-and-1)
(assert-eq false (use-and-1))))
(deftest test-and-2
(do
(defn use-and-2 []
(and true true))
(bake use-and-2)
(assert-eq true (use-and-2))))
(tester/run-suite "binops")

View File

@ -9,6 +9,8 @@
#include "types.h"
#include "platform.h"
#define and &&
#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else