Skip to content

Commit

Permalink
Add vector constructor syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
takagi committed Dec 17, 2016
1 parent 718730e commit 4e8e3f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/lang/syntax.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
:inline-if-test-expression
:inline-if-then-expression
:inline-if-else-expression
;; Vector constructor
:constructor-p
:constructor-operator
:constructor-operands
;; Arithmetic
:arithmetic-p
:arithmetic-operator
Expand Down Expand Up @@ -282,6 +286,30 @@
(_ (error "The value ~S is an invalid expression." form))))


;;;
;;; Vector constructor
;;;

(defparameter +constructor-operators+
'(float3 float4 double3 double4))

(defun constructor-p (form)
(cl-pattern:match form
((name . _) (and (member name +constructor-operators+)
t))
(_ nil)))

(defun constructor-operator (form)
(unless (constructor-p form)
(error "The form ~S is invalid." form))
(car form))

(defun constructor-operands (form)
(unless (constructor-p form)
(error "The form ~S is invalid." form))
(cdr form))


;;;
;;; Arithmetic
;;;
Expand Down
5 changes: 5 additions & 0 deletions t/lang/syntax.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
"basic case 5")


;;;
;;; test Vector constructor
;;;


;;;
;;; test Arithmetic
;;;
Expand Down

0 comments on commit 4e8e3f6

Please sign in to comment.