diff options
author | Eduardo Julian | 2014-12-12 18:46:37 -0400 |
---|---|---|
committer | Eduardo Julian | 2014-12-12 18:46:37 -0400 |
commit | 5b4e9f024b19f5f246d3ddeb3d7e5f5b53d4ac47 (patch) | |
tree | b07ad1c7cfc4e87f7dd465dadc77a33b9c69f701 /src/lang/compiler.clj | |
parent | 9e2f13474246faebc0ab3126208b99acd715ec3c (diff) |
Analyser can now distinguish between local and global vars & point the compiler to the right place to look for data.
Diffstat (limited to 'src/lang/compiler.clj')
-rw-r--r-- | src/lang/compiler.clj | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/lang/compiler.clj b/src/lang/compiler.clj index 1976c48e9..a71a66b8b 100644 --- a/src/lang/compiler.clj +++ b/src/lang/compiler.clj @@ -18,7 +18,8 @@ (defmacro ^:private defcompiler [name match body] `(defn ~name [~'*state*] - (let [~'*writer* (:writer ~'*state*)] + (let [~'*writer* (:writer ~'*state*) + ~'*type* (:type (:form ~'*state*))] (match (:form (:form ~'*state*)) ~match (do ~body @@ -71,17 +72,27 @@ :else (assert false (str "[Unknown literal type] " ?literal " : " (class ?literal))))) -(defcompiler ^:private compile-ident - [::&analyser/ident ?name] - (doto *writer* - (.visitVarInsn Opcodes/ALOAD (int 0)))) +(defcompiler ^:private compile-local + [::&analyser/local ?idx] + (do (prn 'LOCAL ?idx) + (doto *writer* + (.visitVarInsn Opcodes/ALOAD (int ?idx))))) -(defcompiler ^:private compile-call - [::&analyser/call [?owner-class ?fn] ?args] - (do (doseq [arg ?args] - (compile-form (assoc *state* :form arg))) +(defcompiler ^:private compile-global + [::&analyser/global ?owner-class ?name] + (do (prn 'GLOBAL ?owner-class ?name *type*) (doto *writer* - (.visitMethodInsn Opcodes/INVOKESTATIC (->class ?owner-class) ?fn "(Ljava/lang/Object;)Ljava/lang/Object;")))) + (.visitFieldInsn Opcodes/GETSTATIC (->class ?owner-class) ?name (->java-sig *type*))))) + +(defcompiler ^:private compile-call + [::&analyser/call ?fn ?args] + (do (prn 'compile-call ?fn) + (doseq [arg ?args] + (compile-form (assoc *state* :form arg))) + (match (:form ?fn) + [::&analyser/global ?owner-class ?fn-name] + (doto *writer* + (.visitMethodInsn Opcodes/INVOKESTATIC (->class ?owner-class) ?fn-name "(Ljava/lang/Object;)Ljava/lang/Object;"))))) (defcompiler ^:private compile-static-access [::&analyser/static-access ?class ?member] @@ -203,7 +214,8 @@ )) (let [+compilers+ [compile-literal - compile-ident + compile-local + compile-global compile-call compile-static-access compile-dynamic-access |