]> Repositorios git - scryer-prolog.git/commitdiff
fix sign error in shl on fixnum with n >= 63 (#499)
authorMark Thom <[email protected]>
Sun, 17 May 2020 05:00:37 +0000 (23:00 -0600)
committerMark Thom <[email protected]>
Sun, 17 May 2020 05:00:37 +0000 (23:00 -0600)
src/prolog/machine/arithmetic_ops.rs
src/prolog/machine/mod.rs
src/prolog/read.rs

index 32cad18ab50454d1b1863e7b242b92d395ac49f7..f51785bd6fff6c94b7232a887a508b5ac7eb0e7b 100644 (file)
@@ -781,8 +781,13 @@ impl MachineState {
         match (n1, n2) {
             (Number::Fixnum(n1), Number::Fixnum(n2)) => {
                 if let Ok(n2) = u32::try_from(n2) {
-                    if let Some(result) = n1.checked_shl(n2) {
-                        return Ok(Number::from(result));
+                    if n2 < 63 {
+                        if let Some(result) = n1.checked_shl(n2) {
+                            return Ok(Number::from(result));
+                        }
+                    } else {
+                        let n1 = Integer::from(n1);
+                        return Ok(Number::from(n1 << n2));
                     }
                 }
 
index 78e3215a5f4cdab57501afa158696f42ad0e04cc..e9bab93786d467b5f82465a70f9168431f3a81f1 100644 (file)
@@ -462,30 +462,33 @@ impl Machine {
         }
 
         wam.compile_scryerrc();
+        wam.configure_streams();
 
-        wam.current_input_stream.options.alias  = Some(clause_name!("user_input"));
+        wam
+    }
+
+    pub fn configure_streams(&mut self) {
+        self.current_input_stream.options.alias = Some(clause_name!("user_input"));
 
-        wam.indices.stream_aliases.insert(
+        self.indices.stream_aliases.insert(
             clause_name!("user_input"),
-            wam.current_input_stream.clone(),
+            self.current_input_stream.clone(),
         );
 
-        wam.indices.streams.insert(
-            wam.current_input_stream.clone()
+        self.indices.streams.insert(
+            self.current_input_stream.clone()
         );
 
-        wam.current_output_stream.options.alias = Some(clause_name!("user_output"));
+        self.current_output_stream.options.alias = Some(clause_name!("user_output"));
 
-        wam.indices.stream_aliases.insert(
+        self.indices.stream_aliases.insert(
             clause_name!("user_output"),
-            wam.current_output_stream.clone(),
+            self.current_output_stream.clone(),
         );
 
-        wam.indices.streams.insert(
-            wam.current_output_stream.clone()
+        self.indices.streams.insert(
+            self.current_output_stream.clone()
         );
-
-        wam
     }
 
     #[inline]
index 61065b80297ea405533afd3fcde680468f22450a..5c29586250e3cf771b3c1289c6e4f8fbc76104c4 100644 (file)
@@ -42,10 +42,16 @@ pub mod readline {
     }
 
     impl ReadlineStream {
-        pub fn input_stream(pending_input: String) -> Stream {
+        #[inline]
+        pub fn new(pending_input: String) -> Self {
             let mut rl = Editor::<()>::new();
             rl.bind_sequence(KeyPress::Tab, Cmd::Insert(1, "\t".to_string()));
-            Stream::from(ReadlineStream { rl, pending_input: Cursor::new(pending_input) })
+            ReadlineStream { rl, pending_input: Cursor::new(pending_input) }
+        }
+
+        #[inline]
+        pub fn input_stream(pending_input: String) -> Stream {
+            Stream::from(Self::new(pending_input))
         }
 
         fn call_readline(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {