Compare commits

...

48 Commits

Author SHA1 Message Date
CrossNox 3d1b3ac76b add test 3 years ago
CrossNox 48f46ab996 fix test 3 years ago
CrossNox c4ad2bd78b fix code 3 years ago
CrossNox 55c7d785f5 add test 3 years ago
CrossNox 081f23cf24 add test 3 years ago
CrossNox 63a394044e add test 3 years ago
CrossNox 32a503d3c5 add test 3 years ago
CrossNox 6272dabed0 add test 3 years ago
CrossNox a24ac2f2af add test 3 years ago
CrossNox 949f62a40c add test 3 years ago
CrossNox 7ad147a831 add test 3 years ago
CrossNox 8bc15e0a6a add test 3 years ago
CrossNox bb88ad3eb2 fix code 3 years ago
CrossNox 85973d341b add test 3 years ago
CrossNox cd1742b350 fix code 3 years ago
CrossNox 76b5bc4272 fix test 3 years ago
CrossNox 5cc567243b add test 3 years ago
CrossNox a80bc3dbdc fix code 3 years ago
CrossNox 9164cb3099 add test 3 years ago
CrossNox e72cd50873 fix code 3 years ago
CrossNox 8d84000497 add tess 3 years ago
CrossNox 3a35ac8d1b fix tests 3 years ago
CrossNox 8c2fb2e1bb add test 3 years ago
CrossNox 4336f940fc add test 3 years ago
CrossNox 75b4afe7c3 fix code 3 years ago
CrossNox 41bb3803d1 add test 3 years ago
CrossNox f5b0d348cc add test 3 years ago
CrossNox 87d8289e6a fix code 3 years ago
CrossNox dba3b06470 add test 3 years ago
CrossNox 7438e69f5d add test 3 years ago
CrossNox 50bd615b27 fix code 3 years ago
CrossNox bcd9b1985b add test 3 years ago
CrossNox bfecf26ffc fix code 3 years ago
CrossNox a78a6df377 add test 3 years ago
CrossNox 4bd40e4102 add test 3 years ago
CrossNox ffedc7ef1f fix code 3 years ago
CrossNox 3fb827e11f add test 3 years ago
CrossNox e4260c5cfe fix code 3 years ago
CrossNox 5278eff87e add test 3 years ago
CrossNox dc36a57eb6 fix code 3 years ago
CrossNox 7f2f89407f add test 3 years ago
CrossNox 722f40dd33 add test 3 years ago
CrossNox e428c03104 add test 3 years ago
CrossNox 4f8108125c fix code 3 years ago
CrossNox 19879581a2 fix test 3 years ago
CrossNox aa4ba3aa07 add test 3 years ago
CrossNox b222ba2486 fix code 3 years ago
CrossNox 421dda19d4 add test 3 years ago
  1. 120
      src/rustint/core.clj
  2. 249
      test/rustint/core_test.clj

@ -1927,10 +1927,53 @@
; user=> (palabra-reservada? 13) ; user=> (palabra-reservada? 13)
; false ; false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO (defn palabra-reservada? [arg]
;(defn palabra-reservada? (let [keywords (hash-set
; 'EOF,
;) 'String,
'Write,
'abs,
'as,
'as_str,
'atan,
'bool,
'char,
'chars,
'const,
'else,
'exit,
'expect,
'f64,
'flush,
'fn,
'format!,
'from,
'i64,
'if,
'io,
'let,
'mut,
'new,
'nth,
'parse,
'print!,
'println!,
'process,
'read_line,
'return,
'sin,
'sqrt,
'std,
'stdin,
'stdout,
'to_string,
'trim,
'unwrap,
'use,
'usize,
'while,
)] (contains? keywords arg))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IDENTIFICADOR?: Recibe un elemento y devuelve true si es un identificador valido en Rust; si no, false. ; IDENTIFICADOR?: Recibe un elemento y devuelve true si es un identificador valido en Rust; si no, false.
@ -1944,10 +1987,18 @@
; user=> (identificador? '12e0) ; user=> (identificador? '12e0)
; false ; false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO (defn identificador? [arg]
;(defn identificador? (and
; (symbol? arg)
;) (not (palabra-reservada? arg))
(contains?
(set
(map char (range 97 122))
)
(first (name arg))
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DUMP: Recibe un vector con instrucciones de la RI y las imprime numeradas a partir de 0. Siempre devuelve nil. ; DUMP: Recibe un vector con instrucciones de la RI y las imprime numeradas a partir de 0. Siempre devuelve nil.
@ -1967,10 +2018,17 @@
; 0 nil ; 0 nil
; nil ; nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO
;(defn dump (defn format_elem [idx itm]
; (format "%d %s" idx itm)
;) )
(defn dump [args]
(
cond (nil? args) (println "0 nil")
:else (dorun (map println (map-indexed format_elem args)))
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; YA-DECLARADO-LOCALMENTE?: Recibe un identificador y un contexto (un vector formado por dos subvectores: el primero ; YA-DECLARADO-LOCALMENTE?: Recibe un identificador y un contexto (un vector formado por dos subvectores: el primero
@ -2110,10 +2168,29 @@
; user=> (convertir-formato-impresion '("Las raices cuadradas de {} son +{:.8} y -{:.8}" 4.0 1.999999999985448 1.999999999985448)) ; user=> (convertir-formato-impresion '("Las raices cuadradas de {} son +{:.8} y -{:.8}" 4.0 1.999999999985448 1.999999999985448))
; ("Las raices cuadradas de %.0f son +%.8f y -%.8f" 4.0 1.999999999985448 1.999999999985448) ; ("Las raices cuadradas de %.0f son +%.8f y -%.8f" 4.0 1.999999999985448 1.999999999985448)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TODO
;(defn convertir-formato-impresion (defn especificador-formato [arg, rustf]
; (cond
;) (string? arg) "%s"
(int? arg) "%d"
(and (float? arg) (nil? rustf)) "%.0f"
(and (float? arg) (not (nil? rustf))) (format "%%%sf" rustf)
)
)
(defn get-rust-formatters [s]
(map last (re-seq #"\{:?(.\d)?\}" s))
)
(defn convertir-formato-impresion [args]
(let [clojure-fspecifiers (
map
especificador-formato
(rest args)
(get-rust-formatters (first args))
)
] args)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DIVIDIR: Recibe dos numeros y devuelve su cociente, manteniendo su tipo. ; DIVIDIR: Recibe dos numeros y devuelve su cociente, manteniendo su tipo.
@ -2131,10 +2208,13 @@
; user=> (dividir 1 2.0) ; user=> (dividir 1 2.0)
; 0.5 ; 0.5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TODO (defn dividir [arg1 arg2]
;(defn dividir (
; cond
;) (and (float? arg2) (int? arg1)) (/ arg1 arg2)
:else (quot arg1 arg2)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; COMPATIBLES?: Recibe dos elementos. Si el primero es un tipo de dato de Rust y el segundo es un valor de Clojure ; COMPATIBLES?: Recibe dos elementos. Si el primero es un tipo de dato de Rust y el segundo es un valor de Clojure

@ -127,3 +127,252 @@
(is (= (compatibles? 'char ['a]) true)) (is (= (compatibles? 'char ['a]) true))
) )
) )
(deftest dividir-test01
(testing "Test 01 dividir"
(is (= (dividir 12 3) 4))
)
)
(deftest dividir-test02
(testing "Test 02 dividir"
(is (= (dividir 12.0 3) 4.0))
)
)
(deftest dividir-test03
(testing "Test 03 dividir"
(is (= (dividir 12 3.0) 4.0))
)
)
(deftest dividir-test04
(testing "Test 04h dividir"
(is (= (dividir 12.0 3.0) 4.0))
)
)
(deftest dividir-test05
(testing "Test 05 dividir"
(is (= (dividir 1 2) 0))
)
)
(deftest dividir-test06
(testing "Test 06 dividir"
(is (= (dividir 1 2.0) 0.5))
)
)
(deftest identificador-test01
(testing "Test 01 identificador"
(is (= (identificador? 'boolean) true))
)
)
(deftest identificador-test02
(testing "Test 02 identificador"
(is (= (identificador? 'bool) false))
)
)
(deftest identificador-test03
(testing "Test 03 identificador"
(is (= (identificador? 'e120) true))
)
)
(deftest identificador-test04
(testing "Test 04 identificador"
(is (= (identificador? '12e0) false))
)
)
(deftest palabra-reservada-test01
(testing "Test 01 palabra reservada"
(is (= (palabra-reservada? 'while) true))
)
)
(deftest palabra-reservada-test02
(testing "Test 02 palabra reservada"
(is (= (palabra-reservada? 'until) false))
)
)
(deftest palabra-reservada-test03
(testing "Test 03 palabra reservada"
(is (= (palabra-reservada? 13) false))
)
)
(deftest dump-01
(testing "Test 01 dump"
(let [
printed (with-out-str (dump '[[POPREF 2] [PUSHFI 2] MUL [PUSHFI 1] ADD NEG]))
]
(is (= printed "0 [POPREF 2]\n1 [PUSHFI 2]\n2 MUL\n3 [PUSHFI 1]\n4 ADD\n5 NEG\n"
))
)
)
)
(deftest dump-01-nil
(testing "Test 01 dump nil"
(is (nil? (dump '[[POPREF 2] [PUSHFI 2] MUL [PUSHFI 1] ADD NEG])))
)
)
(deftest dump-02
(testing "Test 02 dump"
(let [
printed (with-out-str (dump '[HLT]))
]
(is (= printed "0 HLT\n"
))
)
)
)
(deftest dump-02-nil
(testing "Test 02 dump nil"
(is (nil? (dump '[HLT])))
)
)
(deftest dump-03
(testing "Test 03 dump"
(let [
printed (with-out-str (dump nil))
]
(is (= printed "0 nil\n"
))
)
)
)
(deftest dump-03-nil
(testing "Test 03 dump nil"
(is (nil? (dump nil)))
)
)
(deftest convertir-formato-impresion-01
(testing "Test 01 convertir-formato-impresion"
(is (=
(convertir-formato-impresion '("Hola, mundo!"))
'("Hola, mundo!")
)
)
)
)
(deftest convertir-formato-impresion-02
(testing "Test 02 convertir-formato-impresion"
(is (=
(convertir-formato-impresion '("Hola, mundo 2!"))
'("Hola, mundo 2!")
)
)
)
)
(deftest convertir-formato-impresion-03
(testing "Test 03 convertir-formato-impresion"
(is (=
(convertir-formato-impresion '("Hola, mundo {}!" 2))
'("Hola, mundo %d!" 2)
)
)
)
)
(deftest get-rust-formatters-01
(testing "Test 01 get-rust-formatters"
(is (=
(get-rust-formatters "Hola, Mundo!")
'()
)
)
)
)
(deftest get-rust-formatters-02
(testing "Test 02 get-rust-formatters"
(is (=
(get-rust-formatters "- My name is {}, James {}.\n- Hello, {}{}{}!")
'(nil nil nil nil nil)
)
)
)
)
(deftest get-rust-formatters-03
(testing "Test 03 get-rust-formatters"
(is (=
(get-rust-formatters "{} elevado a la {} es\t{}")
'(nil nil nil)
)
)
)
)
(deftest get-rust-formatters-04
(testing "Test 04 get-rust-formatters"
(is (=
(get-rust-formatters "Las raices cuadradas de {} son +{:.8} y -{:.8}")
'(nil ".8" ".8")
)
)
)
)
(deftest test-especificador-formato-01
(testing "Test 01 especificador formato"
(is (=
(especificador-formato "Bond" nil)
"%s"
)
)
)
)
(deftest test-especificador-formato-02
(testing "Test 02 especificador formato"
(is (=
(especificador-formato 0 nil)
"%d"
)
)
)
)
(deftest test-especificador-formato-03
(testing "Test 03 especificador formato"
(is (=
(especificador-formato 2.0 nil)
"%.0f"
)
)
)
)
(deftest test-especificador-formato-04
(testing "Test 04 especificador formato"
(is (=
(especificador-formato 2.0 ".4")
"%.4f"
)
)
)
)
(deftest test-especificador-formato-05
(testing "Test 05 especificador formato"
(is (=
(especificador-formato 2.0 ".8")
"%.8f"
)
)
)
)

Loading…
Cancel
Save