-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Chia-Network/20230227-defmac
Strict dialect of chialisp that deprecates defmacro and introduces a strict macro type, defmac
- Loading branch information
Showing
38 changed files
with
2,558 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(mod (A) | ||
(include *strict-cl-21*) | ||
|
||
(include defmac_assert.clib) | ||
|
||
(assert | ||
1 | ||
A | ||
13 | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
( | ||
(defun assert_ (items) | ||
(if (r items) | ||
(qq (if (unquote (f items)) (unquote (assert_ (r items))) (x))) | ||
(f items) | ||
) | ||
) | ||
|
||
(defmac assert items (assert_ items)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(mod () | ||
(include *strict-cl-21*) | ||
|
||
(include defmac_simple_if.clib) | ||
|
||
(if_ t1 t2 t3) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
( | ||
(defmac if_ (C T E) (qq (if (unquote C) (unquote T) (unquote E)))) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
|
||
;; A macro-level function to pass through only real integers. | ||
(defun pass-through-integers (X) | ||
(if (not (number? X)) | ||
(x "not a number given to only-integers" X) | ||
X | ||
) | ||
) | ||
|
||
;; A macro which at preprocessing time throws if the given argument | ||
;; wasn't a lexical integer. | ||
(defmac only-integers (X) (pass-through-integers X)) | ||
|
||
;; Note: when macro expanding, N is the N argument to the body of | ||
;; the double macro, not the integer literal, so we use the function | ||
;; version of pass-through-integers in the macro body. | ||
(defmac double (N) (* 2 (pass-through-integers N))) | ||
|
||
;; Here the macro form of only-integers can determine whether the | ||
;; double macro produced an integer or some other expression. | ||
(only-integers (double "hithere")) | ||
) |
26 changes: 26 additions & 0 deletions
26
resources/tests/strict/double-constant-pass-in-function.clsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
|
||
;; A macro-level function to pass through only real integers. | ||
(defun pass-through-integers (X) | ||
(if (not (number? X)) | ||
(x "not a number given to only-integers" X) | ||
X | ||
) | ||
) | ||
|
||
;; A macro which at preprocessing time throws if the given argument | ||
;; wasn't a lexical integer. | ||
(defmac only-integers (X) (pass-through-integers X)) | ||
|
||
;; Note: when macro expanding, N is the N argument to the body of | ||
;; the double macro, not the integer literal, so we use the function | ||
;; version of pass-through-integers in the macro body. | ||
(defmac double (N) (* 2 (pass-through-integers N))) | ||
|
||
;; Here the macro form of only-integers can determine whether the | ||
;; double macro produced an integer or some other expression. | ||
(defun F (N) (+ N (only-integers (double 99)))) | ||
|
||
(F X) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
|
||
;; A macro-level function to pass through only real integers. | ||
(defun pass-through-integers (X) | ||
(if (not (number? X)) | ||
(x "not a number given to only-integers" X) | ||
X | ||
) | ||
) | ||
|
||
;; A macro which at preprocessing time throws if the given argument | ||
;; wasn't a lexical integer. | ||
(defmac only-integers (X) (pass-through-integers X)) | ||
|
||
;; Note: when macro expanding, N is the N argument to the body of | ||
;; the double macro, not the integer literal, so we use the function | ||
;; version of pass-through-integers in the macro body. | ||
(defmac double (N) (* 2 (pass-through-integers N))) | ||
|
||
;; Here the macro form of only-integers can determine whether the | ||
;; double macro produced an integer or some other expression. | ||
(only-integers (double 99)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
;; Ensure macros can expand inside other macros when using advanced primitives. | ||
(defmac classify-expr (G) | ||
(if (number? G) | ||
1 | ||
(if (symbol? G) | ||
2 | ||
(if (string? G) | ||
3 | ||
(if (l G) | ||
4 | ||
0 | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
(if X | ||
(classify-expr X) | ||
(list (classify-expr ()) (classify-expr 33) (classify-expr test) (classify-expr "foo") (classify-expr (* 3 2)) (classify-expr (list 1 2 3))) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
(defmac factorial (N) | ||
(if (> 2 N) 1 (qq (* (unquote N) (factorial (- N 1)))))) | ||
(factorial 5) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
(list X (+ X 1) (+ X2)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
(list X (+ X 1) (+ X 2)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
(list X (list X) (list (list X))) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
;; This wouldn't be able to be rejected because X1 is coming from a macro | ||
;; expansion. This should fail in strict but succeed wrong non-strict. | ||
(if X | ||
(+ X1 2) | ||
5 | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
(if X | ||
(+ X 2) | ||
5 | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
( | ||
(include defmac_simple_if.clib) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(mod (X) | ||
(include *strict-cl-21*) | ||
|
||
(include test-inner-include.clinc) | ||
|
||
(if_ X (* X 2) (+ X 1)) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,7 @@ impl CldbRun { | |
self.runner.clone(), | ||
self.prim_map.clone(), | ||
&self.step, | ||
None, | ||
), | ||
}; | ||
|
||
|
Oops, something went wrong.