aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/target/php.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/target/php.lux')
-rw-r--r--stdlib/source/lux/target/php.lux544
1 files changed, 0 insertions, 544 deletions
diff --git a/stdlib/source/lux/target/php.lux b/stdlib/source/lux/target/php.lux
deleted file mode 100644
index f85bf5f03..000000000
--- a/stdlib/source/lux/target/php.lux
+++ /dev/null
@@ -1,544 +0,0 @@
-(.module:
- [lux (#- Location Code Global static int if cond or and not comment for try)
- ["@" target]
- [abstract
- [equivalence (#+ Equivalence)]
- [hash (#+ Hash)]
- ["." enum]]
- [control
- [pipe (#+ case> cond> new>)]
- [parser
- ["<.>" code]]]
- [data
- ["." text
- ["%" format (#+ format)]]
- [collection
- ["." list ("#\." functor fold)]]]
- [macro
- [syntax (#+ syntax:)]
- ["." template]
- ["." code]]
- [math
- [number
- ["n" nat]
- ["f" frac]]]
- [type
- abstract]])
-
-(def: input_separator ", ")
-(def: statement_suffix ";")
-
-(def: nest
- (-> Text Text)
- (.let [nested_new_line (format text.new_line text.tab)]
- (|>> (format text.new_line)
- (text.replace_all text.new_line nested_new_line))))
-
-(def: block
- (-> Text Text)
- (|>> ..nest (text.enclose ["{" (format text.new_line "}")])))
-
-(def: group
- (-> Text Text)
- (text.enclose ["(" ")"]))
-
-(abstract: #export (Code brand)
- Text
-
- (implementation: #export equivalence
- (All [brand] (Equivalence (Code brand)))
-
- (def: (= reference subject)
- (\ text.equivalence = (:representation reference) (:representation subject))))
-
- (implementation: #export hash
- (All [brand] (Hash (Code brand)))
-
- (def: &equivalence ..equivalence)
- (def: hash (|>> :representation (\ text.hash hash))))
-
- (def: #export manual
- (-> Text Code)
- (|>> :abstraction))
-
- (def: #export code
- (-> (Code Any) Text)
- (|>> :representation))
-
- (template [<type> <super>+]
- [(with_expansions [<brand> (template.identifier [<type> "'"])]
- (abstract: (<brand> brand) Any)
- (`` (type: #export <type> (|> Any <brand> (~~ (template.splice <super>+))))))]
-
- [Expression [Code]]
- [Computation [Expression' Code]]
- [Location [Computation' Expression' Code]]
- [Statement [Code]]
- )
-
- (template [<type> <super>+]
- [(with_expansions [<brand> (template.identifier [<type> "'"])]
- (abstract: #export <brand> Any)
- (`` (type: #export <type> (|> <brand> (~~ (template.splice <super>+))))))]
-
- [Literal [Computation' Expression' Code]]
- [Var [Location' Computation' Expression' Code]]
- [Access [Location' Computation' Expression' Code]]
- [Constant [Location' Computation' Expression' Code]]
- [Global [Location' Computation' Expression' Code]]
- [Label [Code]]
- )
-
- (type: #export Argument
- {#reference? Bit
- #var Var})
-
- (def: #export ;
- (-> Expression Statement)
- (|>> :representation
- (text.suffix ..statement_suffix)
- :abstraction))
-
- (def: #export var
- (-> Text Var)
- (|>> (format "$") :abstraction))
-
- (template [<name> <type>]
- [(def: #export <name>
- (-> Text <type>)
- (|>> :abstraction))]
-
- [constant Constant]
- [label Label]
- )
-
- (def: #export (set_label label)
- (-> Label Statement)
- (:abstraction (format (:representation label) ":")))
-
- (def: #export (go_to label)
- (-> Label Statement)
- (:abstraction
- (format "goto " (:representation label) ..statement_suffix)))
-
- (def: #export null
- Literal
- (:abstraction "NULL"))
-
- (def: #export bool
- (-> Bit Literal)
- (|>> (case> #0 "false"
- #1 "true")
- :abstraction))
-
- (def: #export int
- (-> Int Literal)
- (.let [to_hex (\ n.hex encode)]
- (|>> .nat
- to_hex
- (format "0x")
- :abstraction)))
-
- (def: #export float
- (-> Frac Literal)
- (|>> (cond> [(f.= f.positive_infinity)]
- [(new> "+INF" [])]
-
- [(f.= f.negative_infinity)]
- [(new> "-INF" [])]
-
- [(f.= f.not_a_number)]
- [(new> "NAN" [])]
-
- ## else
- [%.frac])
- :abstraction))
-
- (def: sanitize
- (-> Text Text)
- (`` (|>> (~~ (template [<find> <replace>]
- [(text.replace_all <find> <replace>)]
-
- ["\" "\\"]
- [text.tab "\t"]
- [text.vertical_tab "\v"]
- [text.null "\0"]
- [text.back_space "\b"]
- [text.form_feed "\f"]
- [text.new_line "\n"]
- [text.carriage_return "\r"]
- [text.double_quote (format "\" text.double_quote)]
- ["$" "\$"]
- ))
- )))
-
- (def: #export string
- (-> Text Literal)
- (|>> ..sanitize
- (text.enclose [text.double_quote text.double_quote])
- :abstraction))
-
- (def: arguments
- (-> (List Expression) Text)
- (|>> (list\map ..code) (text.join_with ..input_separator) ..group))
-
- (def: #export (apply/* args func)
- (-> (List Expression) Expression Computation)
- (|> (format (:representation func) (..arguments args))
- :abstraction))
-
- ## TODO: Remove when no longer using JPHP.
- (def: #export (apply/*' args func)
- (-> (List Expression) Expression Computation)
- (apply/* (list& func args) (..constant "call_user_func")))
-
- (def: parameters
- (-> (List Argument) Text)
- (|>> (list\map (function (_ [reference? var])
- (.if reference?
- (format "&" (:representation var))
- (:representation var))))
- (text.join_with ..input_separator)
- ..group))
-
- (template [<name> <reference?>]
- [(def: #export <name>
- (-> Var Argument)
- (|>> [<reference?>]))]
-
- [parameter #0]
- [reference #1]
- )
-
- (def: #export (closure uses arguments body!)
- (-> (List Argument) (List Argument) Statement Literal)
- (let [uses (case uses
- #.Nil
- ""
-
- _
- (format "use " (..parameters uses)))]
- (|> (format "function " (..parameters arguments)
- " " uses " "
- (..block (:representation body!)))
- ..group
- :abstraction)))
-
- (syntax: (arity_inputs {arity <code>.nat})
- (wrap (case arity
- 0 (.list)
- _ (|> (dec arity)
- (enum.range n.enum 0)
- (list\map (|>> %.nat code.local_identifier))))))
-
- (syntax: (arity_types {arity <code>.nat})
- (wrap (list.repeat arity (` ..Expression))))
-
- (template [<arity> <function>+]
- [(with_expansions [<apply> (template.identifier ["apply/" <arity>])
- <inputs> (arity_inputs <arity>)
- <types> (arity_types <arity>)
- <definitions> (template.splice <function>+)]
- (def: #export (<apply> function [<inputs>])
- (-> Expression [<types>] Computation)
- (..apply/* (.list <inputs>) function))
-
- (template [<function>]
- [(`` (def: #export (~~ (template.identifier [<function> "/" <arity>]))
- (<apply> (..constant <function>))))]
-
- <definitions>))]
-
- [0
- [["func_num_args"]
- ["func_get_args"]
- ["time"]
- ["phpversion"]]]
-
- [1
- [["isset"]
- ["var_dump"]
- ["is_null"]
- ["empty"]
- ["count"]
- ["array_pop"]
- ["array_reverse"]
- ["intval"]
- ["floatval"]
- ["strval"]
- ["ord"]
- ["chr"]
- ["print"]
- ["exit"]
- ["iconv_strlen"] ["strlen"]
- ["log"]
- ["ceil"]
- ["floor"]
- ["is_nan"]]]
-
- [2
- [["intdiv"]
- ["fmod"]
- ["number_format"]
- ["array_key_exists"]
- ["call_user_func_array"]
- ["array_slice"]
- ["array_push"]
- ["pack"]
- ["unpack"]
- ["iconv_strpos"] ["strpos"]
- ["pow"]
- ["max"]]]
-
- [3
- [["array_fill"]
- ["array_slice"]
- ["array_splice"]
- ["iconv"]
- ["iconv_strpos"] ["strpos"]
- ["iconv_substr"] ["substr"]]]
- )
-
- (def: #export (key_value key value)
- (-> Expression Expression Expression)
- (:abstraction (format (:representation key) " => " (:representation value))))
-
- (def: #export (array/* values)
- (-> (List Expression) Literal)
- (|> values
- (list\map ..code)
- (text.join_with ..input_separator)
- ..group
- (format "array")
- :abstraction))
-
- (def: #export (array_merge/+ required optionals)
- (-> Expression (List Expression) Computation)
- (..apply/* (list& required optionals) (..constant "array_merge")))
-
- (def: #export (array/** kvs)
- (-> (List [Expression Expression]) Literal)
- (|> kvs
- (list\map (function (_ [key value])
- (format (:representation key) " => " (:representation value))))
- (text.join_with ..input_separator)
- ..group
- (format "array")
- :abstraction))
-
- (def: #export (new constructor inputs)
- (-> Constant (List Expression) Computation)
- (|> (format "new " (:representation constructor) (arguments inputs))
- :abstraction))
-
- (def: #export (the field object)
- (-> Text Expression Computation)
- (|> (format (:representation object) "->" field)
- :abstraction))
-
- (def: #export (do method inputs object)
- (-> Text (List Expression) Expression Computation)
- (|> (format (:representation (..the method object))
- (..arguments inputs))
- :abstraction))
-
- (def: #export (nth idx array)
- (-> Expression Expression Access)
- (|> (format (:representation array) "[" (:representation idx) "]")
- :abstraction))
-
- (def: #export (global name)
- (-> Text Global)
- (|> (..var "GLOBALS") (..nth (..string name)) :transmutation))
-
- (def: #export (? test then else)
- (-> Expression Expression Expression Computation)
- (|> (format (..group (:representation test)) " ? "
- (..group (:representation then)) " : "
- (..group (:representation else)))
- ..group
- :abstraction))
-
- (template [<name> <op>]
- [(def: #export (<name> parameter subject)
- (-> Expression Expression Computation)
- (|> (format (:representation subject) " " <op> " " (:representation parameter))
- ..group
- :abstraction))]
-
- [or "||"]
- [and "&&"]
- [== "=="]
- [=== "==="]
- [< "<"]
- [<= "<="]
- [> ">"]
- [>= ">="]
- [+ "+"]
- [- "-"]
- [* "*"]
- [/ "/"]
- [% "%"]
- [bit_or "|"]
- [bit_and "&"]
- [bit_xor "^"]
- [bit_shl "<<"]
- [bit_shr ">>"]
- [concat "."]
- )
-
- (template [<unary> <name>]
- [(def: #export <name>
- (-> Computation Computation)
- (|>> :representation (format <unary>) :abstraction))]
-
- ["!" not]
- ["~" bit_not]
- ["-" negate]
- )
-
- (def: #export (set var value)
- (-> Location Expression Computation)
- (|> (format (:representation var) " = " (:representation value))
- ..group
- :abstraction))
-
- (def: #export (set! var value)
- (-> Location Expression Statement)
- (:abstraction (format (:representation var) " = " (:representation value) ";")))
-
- (def: #export (set? var)
- (-> Var Computation)
- (..apply/1 [var] (..constant "isset")))
-
- (template [<name> <modifier>]
- [(def: #export <name>
- (-> Var Statement)
- (|>> :representation (format <modifier> " ") (text.suffix ..statement_suffix) :abstraction))]
-
- [define_global "global"]
- )
-
- (template [<name> <modifier> <location>]
- [(def: #export (<name> location value)
- (-> <location> Expression Statement)
- (:abstraction (format <modifier> " " (:representation location)
- " = " (:representation value)
- ..statement_suffix)))]
-
- [define_static "static" Var]
- [define_constant "const" Constant]
- )
-
- (def: #export (if test then! else!)
- (-> Expression Statement Statement Statement)
- (:abstraction
- (format "if" (..group (:representation test)) " "
- (..block (:representation then!))
- " else "
- (..block (:representation else!)))))
-
- (def: #export (when test then!)
- (-> Expression Statement Statement)
- (:abstraction
- (format "if" (..group (:representation test)) " "
- (..block (:representation then!)))))
-
- (def: #export (then pre! post!)
- (-> Statement Statement Statement)
- (:abstraction
- (format (:representation pre!)
- text.new_line
- (:representation post!))))
-
- (def: #export (while test body!)
- (-> Expression Statement Statement)
- (:abstraction
- (format "while" (..group (:representation test)) " "
- (..block (:representation body!)))))
-
- (def: #export (do_while test body!)
- (-> Expression Statement Statement)
- (:abstraction
- (format "do " (..block (:representation body!))
- " while" (..group (:representation test))
- ..statement_suffix)))
-
- (def: #export (for_each array value body!)
- (-> Expression Var Statement Statement)
- (:abstraction
- (format "foreach(" (:representation array)
- " as " (:representation value)
- ") " (..block (:representation body!)))))
-
- (type: #export Except
- {#class Constant
- #exception Var
- #handler Statement})
-
- (def: (catch except)
- (-> Except Text)
- (let [declaration (format (:representation (get@ #class except))
- " " (:representation (get@ #exception except)))]
- (format "catch" (..group declaration) " "
- (..block (:representation (get@ #handler except))))))
-
- (def: #export (try body! excepts)
- (-> Statement (List Except) Statement)
- (:abstraction
- (format "try " (..block (:representation body!))
- text.new_line
- (|> excepts
- (list\map catch)
- (text.join_with text.new_line)))))
-
- (template [<name> <keyword>]
- [(def: #export <name>
- (-> Expression Statement)
- (|>> :representation (format <keyword> " ") (text.suffix ..statement_suffix) :abstraction))]
-
- [throw "throw"]
- [return "return"]
- [echo "echo"]
- )
-
- (def: #export (define name value)
- (-> Constant Expression Expression)
- (..apply/2 (..constant "define")
- [(|> name :representation ..string)
- value]))
-
- (def: #export (define_function name arguments body!)
- (-> Constant (List Argument) Statement Statement)
- (:abstraction
- (format "function " (:representation name)
- (..parameters arguments)
- " "
- (..block (:representation body!)))))
-
- (template [<name> <keyword>]
- [(def: #export <name>
- Statement
- (|> <keyword>
- (text.suffix ..statement_suffix)
- :abstraction))]
-
- [break "break"]
- [continue "continue"]
- )
-
- (def: #export splat
- (-> Expression Expression)
- (|>> :representation (format "...") :abstraction))
- )
-
-(def: #export (cond clauses else!)
- (-> (List [Expression Statement]) Statement Statement)
- (list\fold (function (_ [test then!] next!)
- (..if test then! next!))
- else!
- (list.reverse clauses)))
-
-(def: #export command_line_arguments
- Var
- (..var "argv"))