From fcb8ce8340f4226a38d08f9e2f108e5ec0a95018 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 13 Jun 2019 23:32:50 -0400 Subject: Some fixes. --- documentation/research/browser.md | 1 + documentation/research/game_programming.md | 3 + documentation/research/machine_learning.md | 1 + documentation/research/operating_system.md | 4 + .../research/paradigm/probabilistic_programming.md | 1 + documentation/research/text_editor & ide.md | 1 + new-luxc/source/luxc/lang/host/jvm/inst.lux | 4 +- new-luxc/source/luxc/lang/statement/jvm.lux | 12 +- .../luxc/lang/translation/jvm/procedure/host.lux | 43 +++++- stdlib/source/lux/host.jvm.lux | 1 + .../tool/compiler/phase/extension/analysis/jvm.lux | 164 ++++++++++++++++----- 11 files changed, 183 insertions(+), 52 deletions(-) diff --git a/documentation/research/browser.md b/documentation/research/browser.md index f3c6bf511..8401cb621 100644 --- a/documentation/research/browser.md +++ b/documentation/research/browser.md @@ -34,6 +34,7 @@ # Reference +1. https://evertpot.com/tabs-are-the-wrong-abstraction/ 1. http://news.mit.edu/2018/system-patches-private-browsing-0223 1. https://vivaldi.com/blog/vivaldi-makes-history/?hl=en-us&version=1.8.770.56&os=W10.0.14393 1. https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/ diff --git a/documentation/research/game_programming.md b/documentation/research/game_programming.md index 28796493d..5a3f00682 100644 --- a/documentation/research/game_programming.md +++ b/documentation/research/game_programming.md @@ -143,6 +143,8 @@ # NPC artificial intelligence +1. https://en.wikipedia.org/wiki/Monte_Carlo_tree_search +1. http://www.roguelikeradio.com/2018/02/episode-144-ai.html 1. https://www.red3d.com/cwr/boids/ 1. https://www.blog.drewcutchins.com/blog/2018-8-16-flocking 1. http://www.gabrielgambetta.com/generic-search.html @@ -167,6 +169,7 @@ # Design +1. [Level Design Patterns in 2D Games](http://akhalifa.com/documents/level-design-patterns.pdf) 1. https://en.wikipedia.org/wiki/Rules_of_Play # Voxel diff --git a/documentation/research/machine_learning.md b/documentation/research/machine_learning.md index 3f93192cb..018c259c2 100644 --- a/documentation/research/machine_learning.md +++ b/documentation/research/machine_learning.md @@ -6,6 +6,7 @@ # Reference +1. https://nostalgebraist.tumblr.com/post/185326092369/the-transformer-explained 1. [HyperE: Hyperbolic Embeddings for Entities](https://hazyresearch.github.io/hyperE/) 1. https://www.samcoope.com/posts/playing_around_with_noise_as_targets 1. https://lobste.rs/s/hgejxf/why_is_machine_learning_most_often diff --git a/documentation/research/operating_system.md b/documentation/research/operating_system.md index d03f2c478..b9e457951 100644 --- a/documentation/research/operating_system.md +++ b/documentation/research/operating_system.md @@ -1,3 +1,7 @@ +# Intepreter + +1. [Jitk: A Trustworthy In-Kernel Interpreter Infrastructure](https://css.csail.mit.edu/jitk/) + # Architecture 1. [TabulaROSA: Tabular Operating System Architecture for Massively Parallel Heterogeneous Compute Engines](https://arxiv.org/abs/1807.05308) diff --git a/documentation/research/paradigm/probabilistic_programming.md b/documentation/research/paradigm/probabilistic_programming.md index beff4a300..46302cf93 100644 --- a/documentation/research/paradigm/probabilistic_programming.md +++ b/documentation/research/paradigm/probabilistic_programming.md @@ -5,6 +5,7 @@ # Reference +1. http://willcrichton.net/notes/probabilistic-programming-under-the-hood/ 1. [Ask HN: What companies are using probabilistic programming?](https://news.ycombinator.com/item?id=17220861) 1. https://www-forbes-com.cdn.ampproject.org/v/s/www.forbes.com/sites/quora/2018/05/18/even-the-most-advanced-computer-programmers-have-probably-never-heard-of-this-concept/amp/?amp_js_v=a1&_gsa=1#amp_tf=From%20%251%24s&share=https%3A%2F%2Fwww.forbes.com%2Fsites%2Fquora%2F2018%2F05%2F18%2Feven-the-most-advanced-computer-programmers-have-probably-never-heard-of-this-concept%2Famp%2F%23amp_tf%3DFrom%2520%25251%2524s&share=https%3A%2F%2Fwww.forbes.com%2Fsites%2Fquora%2F2018%2F05%2F18%2Feven-the-most-advanced-computer-programmers-have-probably-never-heard-of-this-concept%2F&share=https%3A%2F%2Fwww.forbes.com%2Fsites%2Fquora%2F2018%2F05%2F18%2Feven-the-most-advanced-computer-programmers-have-probably-never-heard-of-this-concept%2F 1. [Deep Probabilistic Programming Languages: A Qualitative Study](https://arxiv.org/abs/1804.06458) diff --git a/documentation/research/text_editor & ide.md b/documentation/research/text_editor & ide.md index 34127863a..b78dec81d 100644 --- a/documentation/research/text_editor & ide.md +++ b/documentation/research/text_editor & ide.md @@ -42,6 +42,7 @@ # Reference +1. https://www.simplethread.com/editor-plugins-belong-in-lock-file/ 1. [How to Design an IDE-Friendly Language with Peter Gromov @donnerpeter](https://www.youtube.com/watch?v=lubc8udiP_8) 1. https://shaunlebron.github.io/parinfer/ 1. https://www.reddit.com/r/emacs/comments/6ztnj9/what_are_the_things_that_you_do_not_like_in_emacs/?st=j7kdafu2&sh=af9ca25d diff --git a/new-luxc/source/luxc/lang/host/jvm/inst.lux b/new-luxc/source/luxc/lang/host/jvm/inst.lux index aeb9621ef..35f779799 100644 --- a/new-luxc/source/luxc/lang/host/jvm/inst.lux +++ b/new-luxc/source/luxc/lang/host/jvm/inst.lux @@ -102,7 +102,7 @@ (~~ (declare MONITORENTER MONITOREXIT)) ## Return - (~~ (declare RETURN IRETURN LRETURN DRETURN ARETURN)) + (~~ (declare RETURN IRETURN LRETURN FRETURN DRETURN ARETURN)) )) (import: #long org/objectweb/asm/Label @@ -218,7 +218,7 @@ [MONITORENTER] [MONITOREXIT] ## Return - [RETURN] [IRETURN] [LRETURN] [DRETURN] [ARETURN] + [RETURN] [IRETURN] [LRETURN] [FRETURN] [DRETURN] [ARETURN] ) (template [] diff --git a/new-luxc/source/luxc/lang/statement/jvm.lux b/new-luxc/source/luxc/lang/statement/jvm.lux index a21cc76c8..0de84d65b 100644 --- a/new-luxc/source/luxc/lang/statement/jvm.lux +++ b/new-luxc/source/luxc/lang/statement/jvm.lux @@ -136,14 +136,6 @@ (def: string-descriptor (type.descriptor (type.class "java.lang.String" (list)))) -(def: parameter-types - (-> (List Var) (Check (List [Var Type]))) - (monad.map check.monad - (function (_ parameterJ) - (do check.monad - [[_ parameterT] check.var] - (wrap [parameterJ parameterT]))))) - (def: jvm::class (Handler Anchor Inst Definition) (/.custom @@ -167,7 +159,7 @@ (do phase.monad [parameters (statement.lift-analysis (typeA.with-env - (parameter-types parameters))) + (jvm.parameter-types parameters))) #let [mapping (list@fold (function (_ [parameterJ parameterT] mapping) (dictionary.put parameterJ parameterT mapping)) luxT.fresh @@ -180,7 +172,7 @@ (case [(type.descriptor type) value] (^template [ ] (^ [(static ) [_ ( value)]]) - ( #$.Public $.finalF name value)) + ( #$.Public ($.++F $.staticF $.finalF) name value)) ([type.boolean-descriptor #.Bit _def.boolean-field] [type.byte-descriptor #.Int _def.byte-field] [type.short-descriptor #.Int _def.short-field] diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux b/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux index ce5d797b4..173bb9066 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux @@ -985,8 +985,8 @@ #.None (list))) -(def: (with-anonymous-init class env) - (-> Text Environment Def) +(def: (with-anonymous-init class env super-class constructor-argsI) + (-> Text Environment Class (List (Typed Inst)) Def) (let [store-capturedI (|> env list.size list.indices @@ -997,7 +997,11 @@ _.fuse)] (_def.method #$.Public $.noneM "" (anonymous-init-method env) (|>> (_.ALOAD 0) - (_.INVOKESPECIAL jvm.object-class "" (jvm.method (list) #.None (list)) #0) + ((_.fuse (list@map product.right constructor-argsI))) + (_.INVOKESPECIAL (product.left super-class) + "" + (jvm.method (list@map product.left constructor-argsI) #.None (list)) + #0) store-capturedI _.RETURN)))) @@ -1056,6 +1060,12 @@ self-name arguments returnT exceptionsT (normalize-method-body local-mapping body)])) overriden-methods)] + constructor-argsI (monad.map @ + (function (_ [argJT argS]) + (do @ + [argG (generate argS)] + (wrap [argJT argG]))) + constructor-args) method-definitions (|> normalized-methods (monad.map @ (function (_ [ownerT name strict-fp? annotations vars @@ -1072,7 +1082,31 @@ returnT (list@map (|>> #jvm.Class) exceptionsT)) - bodyG))))) + (let [returnI (case returnT + (#.Some returnT) + (case returnT + (#jvm.Primitive returnT) + (case returnT + (^or #jvm.Boolean + #jvm.Byte #jvm.Short #jvm.Int + #jvm.Char) + _.IRETURN + + #jvm.Long + _.LRETURN + + #jvm.Float + _.FRETURN + + #jvm.Double + _.DRETURN) + + _ + _.ARETURN) + + #.None + _.RETURN)] + (|>> bodyG returnI))))))) (:: @ map _def.fuse)) _ (generation.save! true ["" class-name] [class-name @@ -1080,6 +1114,7 @@ class-name (list) super-class super-interfaces (|>> (///function.with-environment total-environment) + (..with-anonymous-init class-name total-environment super-class constructor-argsI) method-definitions))])] (anonymous-instance class-name total-environment)))])) diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index 0c15560c0..d4eb214e7 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -1306,6 +1306,7 @@ []))) )} (wrap (list (` ("jvm class anonymous" + [(~+ (list@map var$ class-vars))] (~ (class$ super)) [(~+ (list@map class$ interfaces))] [(~+ (list@map constructor-arg$ constructor-args))] diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux index a013c564e..94aec9628 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux @@ -1439,9 +1439,12 @@ ) (template [] - [(exception: #export ( {methods (List Text)}) + [(exception: #export ( {methods (List [Text Method])}) (exception.report - ["Methods" (exception.enumerate %t methods)]))] + ["Methods" (exception.enumerate + (function (_ [name method]) + (format (%t name) " " (jvm.method-signature method))) + methods)]))] [missing-abstract-methods] [invalid-overriden-methods] @@ -1811,30 +1814,132 @@ (type: #export (Method-Definition a) (#Overriden-Method (Overriden-Method a))) +(def: #export parameter-types + (-> (List Var) (Check (List [Var .Type]))) + (monad.map check.monad + (function (_ parameterJ) + (do check.monad + [[_ parameterT] check.existential] + (wrap [parameterJ parameterT]))))) + +(def: (mismatched-methods super-set sub-set) + (-> (List [Text Method]) (List [Text Method]) (List [Text Method])) + (list.filter (function (_ [sub-name subJT]) + (|> super-set + (list.filter (function (_ [super-name superJT]) + (and (text@= super-name sub-name) + (method@= superJT subJT)))) + list.size + (n/= 1) + not)) + sub-set)) + +(exception: #export (class-parameter-mismatch {expected (List Text)} + {actual (List jvm.Generic)}) + (exception.report + ["Expected (amount)" (%n (list.size expected))] + ["Expected (parameters)" (exception.enumerate %t expected)] + ["Actual (amount)" (%n (list.size actual))] + ["Actual (parameters)" (exception.enumerate (|>> #jvm.Generic jvm.signature) actual)])) + +(type: Renamer (Dictionary Text Text)) + +(def: (re-map-super [name actual-parameters]) + (-> Class (Operation Renamer)) + (do ////.monad + [class (////.lift (reflection!.load name)) + #let [expected-parameters (|> (java/lang/Class::getTypeParameters class) + array.to-list + (list@map (|>> java/lang/reflect/TypeVariable::getName)))] + _ (////.assert ..class-parameter-mismatch [expected-parameters actual-parameters] + (n/= (list.size expected-parameters) + (list.size actual-parameters)))] + (wrap (|> (list.zip2 expected-parameters actual-parameters) + (list@fold (function (_ [expected actual] mapping) + (case actual + (#jvm.Var actual) + (dictionary.put actual expected mapping) + + _ + mapping)) + (dictionary.new text.hash)))))) + +(def: (re-map-generic mapping generic) + (-> Renamer jvm.Generic jvm.Generic) + (case generic + (#jvm.Var var) + (#jvm.Var (|> mapping (dictionary.get var) (maybe.default var))) + + (#jvm.Wildcard wildcard) + (case wildcard + #.None + generic + + (#.Some [bound limit]) + (#jvm.Wildcard (#.Some [bound (re-map-generic mapping limit)]))) + + (#jvm.Class name parameters) + (#jvm.Class name (list@map (re-map-generic mapping) parameters)))) + +(def: (re-map-type mapping type) + (-> Renamer jvm.Type jvm.Type) + (case type + (#jvm.Primitive primitive) + type + + (#jvm.Generic generic) + (#jvm.Generic (re-map-generic mapping generic)) + + (#jvm.Array type) + (#jvm.Array (re-map-type mapping type)))) + +(def: (re-map-return mapping return) + (-> Renamer jvm.Return jvm.Return) + (case return + #.None + return + + (#.Some return) + (#.Some (re-map-type mapping return)))) + +(def: (re-map-method mapping [inputs output exceptions]) + (-> Renamer jvm.Method jvm.Method) + [(list@map (re-map-type mapping) inputs) + (re-map-return mapping output) + (list@map (re-map-generic mapping) exceptions)]) + (def: class::anonymous Handler (..custom [($_ <>.and + (.tuple (<>.some ..var)) ..class (.tuple (<>.some ..class)) (.tuple (<>.some ..typed)) (.tuple (<>.some ..overriden-method-definition))) - (function (_ extension-name analyse [super-class + (function (_ extension-name analyse [parameters + super-class super-interfaces constructor-args methods]) (do ////.monad - [name (///.lift (do macro.monad + [parameters (typeA.with-env + (..parameter-types parameters)) + #let [mapping (list@fold (function (_ [parameterJ parameterT] mapping) + (dictionary.put parameterJ parameterT mapping)) + luxT.fresh + parameters)] + name (///.lift (do macro.monad [where macro.current-module-name id macro.count] (wrap (format (text.replace-all .module-separator ..jvm-package-separator where) ..jvm-package-separator "anonymous-class" (%n id))))) super-classT (typeA.with-env - (luxT.class luxT.fresh super-class)) + (luxT.class mapping super-class)) super-interfaceT+ (typeA.with-env (monad.map check.monad - (luxT.class luxT.fresh) + (luxT.class mapping) super-interfaces)) #let [selfT (inheritance-relationship-type (#.Primitive name (list)) super-classT @@ -1842,44 +1947,31 @@ constructor-argsA+ (monad.map @ (function (_ [type term]) (do @ [argT (typeA.with-env - (luxT.type luxT.fresh type)) + (luxT.type mapping type)) termA (typeA.with-type argT (analyse term))] (wrap [type termA]))) constructor-args) - methodsA (monad.map @ (analyse-overriden-method analyse selfT luxT.fresh) methods) + methodsA (monad.map @ (analyse-overriden-method analyse selfT mapping) methods) required-abstract-methods (////.lift (all-abstract-methods (list& super-class super-interfaces))) available-methods (////.lift (all-methods (list& super-class super-interfaces))) - #let [overriden-methods (list@map (function (_ [parent-type method-name - strict-fp? annotations vars - self-name arguments return exceptions - body]) - [method-name (jvm.method (list@map product.right arguments) - return - (list@map (|>> #jvm.Class) exceptions))]) - methods) - missing-abstract-methods (list.filter (function (_ [abstract-method-name abstract-methodJT]) - (|> overriden-methods - (list.filter (function (_ [method-name methodJT]) - (and (text@= method-name abstract-method-name) - (method@= abstract-methodJT methodJT)))) - list.size - (n/= 1) - not)) - required-abstract-methods) - invalid-overriden-methods (list.filter (function (_ [method-name methodJT]) - (|> available-methods - (list.filter (function (_ [abstract-method-name abstract-methodJT]) - (and (text@= method-name abstract-method-name) - (method@= abstract-methodJT methodJT)))) - list.size - (n/= 1) - not)) - overriden-methods)] + overriden-methods (monad.map @ (function (_ [parent-type method-name + strict-fp? annotations vars + self-name arguments return exceptions + body]) + (do @ + [re-mapping (re-map-super parent-type)] + (wrap [method-name (re-map-method re-mapping + (jvm.method (list@map product.right arguments) + return + (list@map (|>> #jvm.Class) exceptions)))]))) + methods) + #let [missing-abstract-methods (mismatched-methods overriden-methods required-abstract-methods) + invalid-overriden-methods (mismatched-methods available-methods overriden-methods)] _ (typeA.infer selfT) - _ (////.assert ..missing-abstract-methods (list@map product.left missing-abstract-methods) + _ (////.assert ..missing-abstract-methods missing-abstract-methods (list.empty? missing-abstract-methods)) - _ (////.assert ..invalid-overriden-methods (list@map product.left invalid-overriden-methods) + _ (////.assert ..invalid-overriden-methods invalid-overriden-methods (list.empty? invalid-overriden-methods))] (wrap (#/////analysis.Extension extension-name (list (/////analysis.text name) -- cgit v1.2.3