summaryrefslogtreecommitdiff
path: root/modules/language/python/module.scm
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-08-24 22:23:23 +0200
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-08-24 22:23:23 +0200
commit582d1c6f0be332ad4cb9f421bea5c2be56a12408 (patch)
tree3c0f8e487d1c57b509ae19ee4d858a90728ea7b3 /modules/language/python/module.scm
parent333a82328a53024f341a74a0f738ce0d6f0f6d4f (diff)
socket.py
Diffstat (limited to 'modules/language/python/module.scm')
-rw-r--r--modules/language/python/module.scm29
1 files changed, 27 insertions, 2 deletions
diff --git a/modules/language/python/module.scm b/modules/language/python/module.scm
index 51270c2..8e705a8 100644
--- a/modules/language/python/module.scm
+++ b/modules/language/python/module.scm
@@ -8,6 +8,7 @@
#:use-module (language python try)
#:use-module (language python dir)
#:use-module (language python list)
+ #:use-module (language python dict)
#:export (Module private public import __import__ modules))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
@@ -238,10 +239,34 @@
(apply f l))
(apply f l)))
-(define modules (make-hash-table))
+(define-python-class ms (dict)
+ (define __getitem__
+ (lambda (self k)
+ (if (string? k)
+ (aif it (py-get (slot-ref self 't) k #f)
+ it
+ (let* ((l (map string->symbol (string-split k #\.)))
+ (pth (cons* 'language 'python 'module l)))
+ (Module (reverse pth) (reverse l))))
+ (pylist-ref (slot-ref self 't) k))))
+
+ (define get
+ (lambda* (self k #:optional (e #f))
+ (if (string? k)
+ (aif it (py-get (slot-ref self 't) k #f)
+ it
+ (let* ((l (map string->symbol (string-split k #\.)))
+ (pth (cons* 'language 'python 'module l)))
+ (Module (reverse pth) (reverse l))))
+ (py-get (slot-ref self 't) k e)))))
+
+
+
+(define modules (ms))
(define (__import__ x)
(let ((x (py-get modules x #f)))
(if x
(values)
(let ((e (Module x)))
- (pylist-set! modules x e)))))
+ (pylist-set! modules x e)
+ e))))