From: Michael D. Lowis Date: Tue, 21 Nov 2023 03:44:14 +0000 (-0500) Subject: fixed up comparison operators X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=56b9bec254e7ccf861eab026d3b64aef47dca02c;p=proto%2Faas.git fixed up comparison operators --- diff --git a/aas.rb b/aas.rb index 3ff42f6..c3307ba 100755 --- a/aas.rb +++ b/aas.rb @@ -111,7 +111,7 @@ module Targets def eqi emit "popq %rax" emit "popq %rbx" - emit "cmpq %rbx, %rax" + emit "cmpq %rax, %rbx" emit "sete %al" emit "movzbq %al, %rax" emit "pushq %rax" @@ -121,7 +121,7 @@ module Targets def nei emit "popq %rax" emit "popq %rbx" - emit "cmpq %rbx, %rax" + emit "cmpq %rax, %rbx" emit "setne %al" emit "movzbq %al, %rax" emit "pushq %rax" @@ -131,7 +131,7 @@ module Targets def lti emit "popq %rax" emit "popq %rbx" - emit "cmpq %rbx, %rax" + emit "cmpq %rax, %rbx" emit "setl %al" emit "movzbq %al, %rax" emit "pushq %rax" @@ -141,7 +141,7 @@ module Targets def gti emit "popq %rax" emit "popq %rbx" - emit "cmpq %rbx, %rax" + emit "cmpq %rax, %rbx" emit "setg %al" emit "movzbq %al, %rax" emit "pushq %rax" @@ -151,7 +151,7 @@ module Targets def ltei emit "popq %rax" emit "popq %rbx" - emit "cmpq %rbx, %rax" + emit "cmpq %rax, %rbx" emit "setle %al" emit "movzbq %al, %rax" emit "pushq %rax" @@ -161,7 +161,7 @@ module Targets def gtei emit "popq %rax" emit "popq %rbx" - emit "cmpq %rbx, %rax" + emit "cmpq %rax, %rbx" emit "setge %al" emit "movzbq %al, %rax" emit "pushq %rax" diff --git a/cerise.m b/cerise.m index ba239de..48e0867 100644 --- a/cerise.m +++ b/cerise.m @@ -1,9 +1,9 @@ sum(a,b) { - return a*\/=+\-\$?!%]+/ INTEGER = /[0-9]+/ @@ -76,10 +76,12 @@ class Lexer elsif @data.scan(OPERATORS) type = @data.matched end - Tok.new(@data.matched, @file, @data.pos, type) if type + tok = Tok.new(@data.matched, @file, @data.pos, type) if type else - Tok.new("EOF", @file, @data.pos, :eof) + tok = Tok.new("EOF", @file, @data.pos, :eof) end +# pp tok + tok end end @@ -673,8 +675,10 @@ class Parser def expression() left = simple_expr() if matches_any(["==", "!=", "<", "<=", ">", ">="]) + loc = location + op = consume() right = simple_expr() - left = IR::Op.new(op.location, nil, op.text, left, right) + left = IR::Op.new(loc, nil, op.text, left, right) end left end @@ -682,18 +686,20 @@ class Parser def simple_expr() # Handle unary ops first if matches_any(["+", "-", :not]) + loc = location op = consume() left = term() - left = IR::Op.new(op.location, nil, op.text, left, nil) + left = IR::Op.new(location, nil, op.text, left, nil) else left = term() end # now look for binary ops while matches_any(["+", "-", :or]) + loc = location op = consume() - right = term(); - left = IR::Op.new(location, nil, op.text, left, right) + right = term() + left = IR::Op.new(loc, nil, op.text, left, right) end left end @@ -701,9 +707,10 @@ class Parser def term() left = factor() while matches_any(["*", "/", "%", :and]) + loc = location op = consume() right = factor(); - left = IR::Op.new(location, nil, op.text, left, right) + left = IR::Op.new(loc, nil, op.text, left, right) end left end @@ -749,7 +756,7 @@ class Parser elsif tok.type == :ident IR::Var.new(tok.pos, nil, tok.text.to_sym) else - error("invalid constant") + error("invalid constant #{tok}") end end end @@ -798,6 +805,16 @@ module Codegen puts " modi" when "<" puts " lti" + when "<=" + puts " ltei" + when ">" + puts " gti" + when ">=" + puts " gtei" + when "==" + puts " eqi" + when "!=" + puts " nei" else raise "not implemented" end