aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/lux.lux13
-rw-r--r--source/program.lux5
-rw-r--r--src/lux/analyser/host.clj2
-rw-r--r--src/lux/compiler/host.clj83
-rw-r--r--src/lux/type.clj4
5 files changed, 90 insertions, 17 deletions
diff --git a/source/lux.lux b/source/lux.lux
index ac28bf372..bce5c421a 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -1970,12 +1970,14 @@
))
(def #export (print x)
- (-> Text (,))
- (_jvm_invokevirtual java.io.PrintStream print [java.lang.Object]
- (_jvm_getstatic java.lang.System out) [x]))
+ (-> Text (IO (,)))
+ (lambda [_]
+ (exec (_jvm_invokevirtual java.io.PrintStream print [java.lang.Object]
+ (_jvm_getstatic java.lang.System out) [x])
+ [])))
(def #export (println x)
- (-> Text (,))
+ (-> Text (IO (,)))
(print (text:++ x "\n")))
(def #export (some f xs)
@@ -2065,8 +2067,7 @@
(let [[sname stype] slot
[module name] (split-slot sname)]
[($tag [module name]) ($symbol ["" name])])))
- slots))
- _ (println (text:++ "Using pattern: " (syntax:show pattern)))]
+ slots))]
(#Right [state (: (List Syntax)
(list (` (_lux_case (~ struct) (~ pattern) (~ body)))))]))
diff --git a/source/program.lux b/source/program.lux
index cefec07d4..364c57d89 100644
--- a/source/program.lux
+++ b/source/program.lux
@@ -12,7 +12,4 @@
(filter p xs'))))
(_jvm_program _
- (exec (println "Hello, world!")
- (|> (int:+ 2 2) ->text ($ text:++ "2 + 2 = ") println)
- (println (->text (using Int:Ord
- (< 5 10))))))
+ (println "Hello, world!"))
diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj
index 9f80c43cc..182eb9ebb 100644
--- a/src/lux/analyser/host.clj
+++ b/src/lux/analyser/host.clj
@@ -246,5 +246,5 @@
(defn analyse-jvm-program [analyse ?args ?body]
(|do [=body (&/with-scope ""
(&&env/with-local "" (&/V "lux;AppT" (&/T &type/List &type/Text))
- (analyse-1+ analyse ?body)))]
+ (&&/analyse-1 analyse (&/V "lux;AppT" (&/T &type/IO &type/Unit)) ?body)))]
(return (&/|list (&/V "jvm-program" =body)))))
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index 8782acfa5..87753dce3 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -474,11 +474,82 @@
(|do [^ClassWriter *writer* &/get-writer]
(&/with-writer (doto (.visitMethod *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "main" "([Ljava/lang/String;)V" nil nil)
(.visitCode))
- (|do [main-writer &/get-writer
+ (|do [^MethodVisitor main-writer &/get-writer
+ :let [$loop (new Label)
+ $end (new Label)
+ _ (doto main-writer
+ ;; Tail: Begin
+ (.visitLdcInsn (int 2)) ;; S
+ (.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object") ;; V
+ (.visitInsn Opcodes/DUP) ;; VV
+ (.visitLdcInsn (int 0)) ;; VVI
+ (.visitLdcInsn "lux;Nil") ;; VVIT
+ (.visitInsn Opcodes/AASTORE) ;; V
+ (.visitInsn Opcodes/DUP) ;; VV
+ (.visitLdcInsn (int 1)) ;; VVI
+ (.visitInsn Opcodes/ACONST_NULL) ;; VVIN
+ (.visitInsn Opcodes/AASTORE) ;; V
+ ;; Tail: End
+ ;; Size: Begin
+ (.visitVarInsn Opcodes/ALOAD 0) ;; VA
+ (.visitInsn Opcodes/ARRAYLENGTH) ;; VI
+ ;; Size: End
+ ;; Loop: Begin
+ (.visitLabel $loop)
+ (.visitLdcInsn (int 1)) ;; VII
+ (.visitInsn Opcodes/ISUB) ;; VI
+ (.visitInsn Opcodes/DUP) ;; VII
+ (.visitJumpInsn Opcodes/IFLT $end) ;; VI
+ ;; Head: Begin
+ (.visitInsn Opcodes/DUP) ;; VII
+ (.visitVarInsn Opcodes/ALOAD 0) ;; VIIA
+ (.visitInsn Opcodes/SWAP) ;; VIAI
+ (.visitInsn Opcodes/AALOAD) ;; VIO
+ (.visitInsn Opcodes/SWAP) ;; VOI
+ (.visitInsn Opcodes/DUP_X2) ;; IVOI
+ (.visitInsn Opcodes/POP) ;; IVO
+ ;; Head: End
+ ;; Tuple: Begin
+ (.visitLdcInsn (int 2)) ;; IVOS
+ (.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object") ;; IVO2
+ (.visitInsn Opcodes/DUP_X1) ;; IV2O2
+ (.visitInsn Opcodes/SWAP) ;; IV22O
+ (.visitLdcInsn (int 0)) ;; IV22OI
+ (.visitInsn Opcodes/SWAP) ;; IV22IO
+ (.visitInsn Opcodes/AASTORE) ;; IV2
+ (.visitInsn Opcodes/DUP_X1) ;; I2V2
+ (.visitInsn Opcodes/SWAP) ;; I22V
+ (.visitLdcInsn (int 1)) ;; I22VI
+ (.visitInsn Opcodes/SWAP) ;; I22IV
+ (.visitInsn Opcodes/AASTORE) ;; I2
+ ;; Tuple: End
+ ;; Cons: Begin
+ (.visitLdcInsn (int 2)) ;; I2I
+ (.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object") ;; I2V
+ (.visitInsn Opcodes/DUP) ;; I2VV
+ (.visitLdcInsn (int 0)) ;; I2VVI
+ (.visitLdcInsn "lux;Cons") ;; I2VVIT
+ (.visitInsn Opcodes/AASTORE) ;; I2V
+ (.visitInsn Opcodes/DUP_X1) ;; IV2V
+ (.visitInsn Opcodes/SWAP) ;; IVV2
+ (.visitLdcInsn (int 1)) ;; IVV2I
+ (.visitInsn Opcodes/SWAP) ;; IVVI2
+ (.visitInsn Opcodes/AASTORE) ;; IV
+ ;; Cons: End
+ (.visitInsn Opcodes/SWAP) ;; VI
+ (.visitJumpInsn Opcodes/GOTO $loop)
+ ;; Loop: End
+ (.visitLabel $end) ;; VI
+ (.visitInsn Opcodes/POP) ;; V
+ (.visitVarInsn Opcodes/ASTORE (int 0)) ;;
+ )]
_ (compile ?body)
- :let [_ (doto ^MethodVisitor main-writer
- (.visitInsn Opcodes/POP)
- (.visitInsn Opcodes/RETURN)
- (.visitMaxs 0 0)
- (.visitEnd))]]
+ :let [_ (doto main-writer
+ (.visitInsn Opcodes/ACONST_NULL)
+ (.visitMethodInsn Opcodes/INVOKEINTERFACE "lux/Function" "apply" &&/apply-signature))]
+ :let [_ (doto main-writer
+ (.visitInsn Opcodes/POP)
+ (.visitInsn Opcodes/RETURN)
+ (.visitMaxs 0 0)
+ (.visitEnd))]]
(return nil)))))
diff --git a/src/lux/type.clj b/src/lux/type.clj
index d5be5a7c6..9034abb53 100644
--- a/src/lux/type.clj
+++ b/src/lux/type.clj
@@ -15,6 +15,10 @@
(def Unit (&/V "lux;TupleT" (&/|list)))
(def $Void (&/V "lux;VariantT" (&/|list)))
+(def IO
+ (&/V "lux;AllT" (&/T (&/V "lux;Some" (&/V "lux;Nil" nil)) "IO" "a"
+ (&/V "lux;LambdaT" (&/T Unit (&/V "lux;BoundT" "a"))))))
+
(def List
(&/V "lux;AllT" (&/T (&/V "lux;Some" (&/V "lux;Nil" nil)) "lux;List" "a"
(&/V "lux;VariantT" (&/|list (&/T "lux;Nil" Unit)