Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Created October 19, 2015 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriid/7819cb62b0c5044dafec to your computer and use it in GitHub Desktop.
Save dmitriid/7819cb62b0c5044dafec to your computer and use it in GitHub Desktop.
-module(lc).

-export([lc/0]).

lc() ->
 [{X, Y} || X <- lists:seq(1, 5), Y <- lists:seq(1, 5), X rem 2 == 0, Y rem 2 == 1 ].

core:

module 'lc' ['lc'/0,
	     'module_info'/0,
	     'module_info'/1]
    attributes []
'lc'/0 =
    %% Line 5
    fun () ->
	%% Line 6
	( letrec
	      'lc$^0'/1 =
		  fun (_cor10) ->
		      case _cor10 of
			<[X|_cor1]> when 'true' ->
			    ( letrec
				  'lc$^1'/1 =
				      fun (_cor11) ->
					  case _cor11 of
					    <[Y|_cor4]>
						when try
						      let <_cor5> =
							  call 'erlang':'rem'
							      (X, 2)
						      in  let <_cor6> =
							      call 'erlang':'=='
								  (_cor5, 0)
							  in  let <_cor7> =
								  call 'erlang':'rem'
								      (Y, 2)
							      in  let <_cor8> =
								      call 'erlang':'=='
									  (_cor7, 1)
								  in  call 'erlang':'and'
									  (_cor6, _cor8)
						  of <Try> ->
						      Try
						  catch <T,R> ->
						      'false' ->
						let <_cor12> =
						    apply 'lc$^1'/1
							(_cor4)
						in  ( [{X,Y}|_cor12]
						      -| ['compiler_generated'] )
					    ( <[Y|_cor4]> when 'true' ->
						  apply 'lc$^1'/1
						      (_cor4)
					      -| ['compiler_generated'] )
					    <[]> when 'true' ->
						apply 'lc$^0'/1
						    (_cor1)
					    ( <_cor11> when 'true' ->
						  ( primop 'match_fail'
							({'function_clause',_cor11})
						    -| [{'function_name',{'lc$^1',1}}] )
					      -| ['compiler_generated'] )
					  end
			      in  let <_cor9> =
				      call 'lists':'seq'
					  (1, 5)
				  in  apply 'lc$^1'/1
					  (_cor9)
			      -| ['list_comprehension'] )
			<[]> when 'true' ->
			    []
			( <_cor10> when 'true' ->
			      ( primop 'match_fail'
				    ({'function_clause',_cor10})
				-| [{'function_name',{'lc$^0',1}}] )
			  -| ['compiler_generated'] )
		      end
	  in  let <_cor2> =
		  call 'lists':'seq'
		      (1, 5)
	      in  apply 'lc$^0'/1
		      (_cor2)
	  -| ['list_comprehension'] )
'module_info'/0 =
    fun () ->
	call 'erlang':'get_module_info'
	    ('lc')
'module_info'/1 =
    fun (_cor0) ->
	call 'erlang':'get_module_info'
	    ('lc', _cor0)
end

.S

{module, lc}.  %% version = 0

{exports, [{lc,0},{module_info,0},{module_info,1}]}.

{attributes, []}.

{labels, 15}.


{function, lc, 0, 2}.
  {label,1}.
    {line,[{location,"lc.erl",5}]}.
    {func_info,{atom,lc},{atom,lc},0}.
  {label,2}.
    {allocate,0,0}.
    {move,{integer,5},{x,1}}.
    {move,{integer,1},{x,0}}.
    {line,[{location,"lc.erl",6}]}.
    {call_ext,2,{extfunc,lists,seq,2}}.
    {call_last,1,{f,8},0}.


{function, module_info, 0, 4}.
  {label,3}.
    {line,[]}.
    {func_info,{atom,lc},{atom,module_info},0}.
  {label,4}.
    {move,{atom,lc},{x,0}}.
    {line,[]}.
    {call_ext_only,1,{extfunc,erlang,get_module_info,1}}.


{function, module_info, 1, 6}.
  {label,5}.
    {line,[]}.
    {func_info,{atom,lc},{atom,module_info},1}.
  {label,6}.
    {move,{x,0},{x,1}}.
    {move,{atom,lc},{x,0}}.
    {line,[]}.
    {call_ext_only,2,{extfunc,erlang,get_module_info,2}}.


{function, '-lc/0-lc$^0/1-0-', 1, 8}.
  {label,7}.
    {line,[{location,"lc.erl",6}]}.
    {func_info,{atom,lc},{atom,'-lc/0-lc$^0/1-0-'},1}.
  {label,8}.
    {test,is_nonempty_list,{f,9},[{x,0}]}.
    {allocate,2,1}.
    {get_list,{x,0},{y,1},{y,0}}.
    {move,{integer,5},{x,1}}.
    {move,{integer,1},{x,0}}.
    {line,[{location,"lc.erl",6}]}.
    {call_ext,2,{extfunc,lists,seq,2}}.
    {move,{y,1},{x,2}}.
    {move,{y,0},{x,1}}.
    {call_last,3,{f,11},2}.
  {label,9}.
    {test,is_nil,{f,7},[{x,0}]}.
    return.


{function, '-lc/0-lc$^1/1-1-', 3, 11}.
  {label,10}.
    {line,[{location,"lc.erl",6}]}.
    {func_info,{atom,lc},{atom,'-lc/0-lc$^1/1-1-'},3}.
  {label,11}.
    {test,is_nonempty_list,{f,13},[{x,0}]}.
    {get_list,{x,0},{x,3},{x,4}}.
    {gc_bif,'rem',{f,12},5,[{x,2},{integer,2}],{x,5}}.
    {gc_bif,'rem',{f,12},6,[{x,3},{integer,2}],{x,6}}.
    {test,is_eq,{f,12},[{x,5},{integer,0}]}.
    {test,is_eq,{f,12},[{x,6},{integer,1}]}.
    {allocate,2,5}.
    {move,{x,4},{x,0}}.
    {move,{x,2},{y,0}}.
    {move,{x,3},{y,1}}.
    {line,[{location,"lc.erl",6}]}.
    {call,3,{f,11}}.
    {test_heap,5,1}.
    {put_tuple,2,{x,1}}.
    {put,{y,0}}.
    {put,{y,1}}.
    {put_list,{x,1},{x,0},{x,0}}.
    {deallocate,2}.
    return.
  {label,12}.
    {move,{x,4},{x,0}}.
    {call_only,3,{f,11}}.
  {label,13}.
    {test,is_nil,{f,14},[{x,0}]}.
    {move,{x,1},{x,0}}.
    {call_only,1,{f,8}}.
  {label,14}.
    {test_heap,2,1}.
    {put_list,{x,0},nil,{x,1}}.
    {move,{atom,function_clause},{x,0}}.
    {line,[{location,"lc.erl",6}]}.
    {call_ext,2,{extfunc,erlang,error,2}}.
@dmitriid
Copy link
Author

-module(lc).

-export([lc/0]).

lc() ->
    [{X, Y} || X <- lists:seq(1, 5), X rem 2 == 0, Y <- lists:seq(1, 5), Y rem 2 == 1].

core:

module 'lc' ['lc'/0,
         'module_info'/0,
         'module_info'/1]
    attributes []
'lc'/0 =
    %% Line 5
    fun () ->
    %% Line 6
    ( letrec
          'lc$^0'/1 =
          fun (_cor8) ->
              case _cor8 of
            <[%% Line 7
              X|_cor1]>
                when %% Line 7
                  try
                  let <_cor2> =
                      call 'erlang':'rem'
                      (X, 2)
                  in  call 'erlang':'=='
                      (_cor2, 0)
                  of <Try> ->
                  Try
                  catch <T,R> ->
                  'false' ->
                ( letrec
                  'lc$^1'/1 =
                      fun (_cor9) ->
                      case _cor9 of
                        <[%% Line 7
                          Y|_cor5]>
                        when %% Line 8
                          try
                              let <_cor6> =
                              call 'erlang':'rem'
                                  (Y, 2)
                              in  call 'erlang':'=='
                                  (_cor6, 1)
                          of <Try> ->
                              Try
                          catch <T,R> ->
                              'false' ->
                        let <_cor10> =
                            %% Line 7
                            apply 'lc$^1'/1
                            (_cor5)
                        in  ( [{X,Y}|_cor10]
                              -| ['compiler_generated'] )
                        ( <[%% Line 7
                        Y|_cor5]> when 'true' ->
                          %% Line 7
                          apply 'lc$^1'/1
                              (_cor5)
                          -| ['compiler_generated'] )
                        <[]> when 'true' ->
                        %% Line 7
                        apply 'lc$^0'/1
                            (_cor1)
                        ( <_cor9> when 'true' ->
                          ( primop 'match_fail'
                            ({'function_clause',_cor9})
                            -| [{'function_name',{'lc$^1',1}}] )
                          -| ['compiler_generated'] )
                      end
                  in  let <_cor7> =
                      %% Line 7
                      call 'lists':'seq'
                      (1, 5)
                  in  apply 'lc$^1'/1
                      (_cor7)
                  -| ['list_comprehension'] )
            ( <[%% Line 7
                X|_cor1]> when 'true' ->
                  %% Line 7
                  apply 'lc$^0'/1
                  (_cor1)
              -| ['compiler_generated'] )
            <[]> when 'true' ->
                []
            ( <_cor8> when 'true' ->
                  ( primop 'match_fail'
                    ({'function_clause',_cor8})
                -| [{'function_name',{'lc$^0',1}}] )
              -| ['compiler_generated'] )
              end
      in  let <_cor3> =
          %% Line 7
          call 'lists':'seq'
              (1, 5)
          in  apply 'lc$^0'/1
              (_cor3)
      -| ['list_comprehension'] )
'module_info'/0 =
    fun () ->
    call 'erlang':'get_module_info'
        ('lc')
'module_info'/1 =
    fun (_cor0) ->
    call 'erlang':'get_module_info'
        ('lc', _cor0)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment